@rpg-engine/long-bow 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,8 @@ export declare const shortcutMock: ({
10
10
  minLevelRequired: number;
11
11
  minMagicLevelRequired: number;
12
12
  animationKey: string;
13
+ textureAtlas: string;
14
+ texturePath: string;
13
15
  };
14
16
  } | {
15
17
  type: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -83,7 +83,7 @@
83
83
  },
84
84
  "dependencies": {
85
85
  "@rollup/plugin-image": "^2.1.1",
86
- "@rpg-engine/shared": "^0.8.68",
86
+ "@rpg-engine/shared": "^0.8.69",
87
87
  "dayjs": "^1.11.2",
88
88
  "font-awesome": "^4.7.0",
89
89
  "fs-extra": "^10.1.0",
@@ -141,6 +141,9 @@ export const CircularController: React.FC<CircularControllerProps> = ({
141
141
  spellCooldown > shortcutCooldown ? spellCooldown : shortcutCooldown;
142
142
  const isOnCooldown = cooldown > 0 && !!payload;
143
143
 
144
+ const CONTAINER_STYLE = { width: '32px', height: '32px' };
145
+ const IMAGE_SCALE = 1.5;
146
+
144
147
  return (
145
148
  <StyledShortcut
146
149
  key={i}
@@ -158,7 +161,19 @@ export const CircularController: React.FC<CircularControllerProps> = ({
158
161
  {payload && payload.manaCost}
159
162
  </span>
160
163
  <span className="magicWords">
161
- {payload?.magicWords.split(' ').map(word => word[0])}
164
+ {payload?.texturePath ? (
165
+ <SpriteFromAtlas
166
+ atlasIMG={payload.atlasIMG}
167
+ atlasJSON={payload.atlasJSON}
168
+ spriteKey={payload.texturePath}
169
+ imgScale={IMAGE_SCALE}
170
+ containerStyle={CONTAINER_STYLE}
171
+ centered={true}
172
+ borderRadius="50%"
173
+ />
174
+ ) : (
175
+ payload?.magicWords.split(' ').map(word => word[0])
176
+ )}
162
177
  </span>
163
178
  </StyledShortcut>
164
179
  );
@@ -143,6 +143,9 @@ export const Shortcuts: React.FC<ShortcutsProps> = ({
143
143
  spellCooldown > shortcutCooldown ? spellCooldown : shortcutCooldown;
144
144
  const isOnCooldown = cooldown > 0 && !!payload;
145
145
 
146
+ const IMAGE_SCALE = 1.5;
147
+ const IMAGE_SIZE = 32;
148
+
146
149
  return (
147
150
  <StyledShortcut
148
151
  key={i}
@@ -157,12 +160,23 @@ export const Shortcuts: React.FC<ShortcutsProps> = ({
157
160
  {cooldown.toFixed(cooldown < 10 ? 1 : 0)}
158
161
  </span>
159
162
  )}
163
+ <span>
164
+ {payload?.atlasIMG && (
165
+ <SpriteFromAtlas
166
+ atlasIMG={payload.atlasIMG}
167
+ atlasJSON={payload.atlasJSON}
168
+ spriteKey={payload.texturePath ?? ''}
169
+ width={IMAGE_SIZE}
170
+ height={IMAGE_SIZE}
171
+ imgScale={IMAGE_SCALE}
172
+ centered
173
+ borderRadius="50%"
174
+ />
175
+ )}
176
+ </span>
160
177
  <span className={buildClassName('mana', isOnCooldown)}>
161
178
  {payload && payload.manaCost}
162
179
  </span>
163
- <span className="magicWords">
164
- {payload?.magicWords.split(' ').map(word => word[0])}
165
- </span>
166
180
  <span className={buildClassName('keyboard', isOnCooldown)}>
167
181
  {i + 1}
168
182
  </span>
@@ -53,10 +53,29 @@ export const ShortcutsSetter: React.FC<ShortcutsSetterProps> = ({
53
53
  />
54
54
  );
55
55
  }
56
+ const IMAGE_SIZE = 32;
57
+ const IMAGE_SCALE = 1;
56
58
 
57
- const payload = shortcuts[index]?.payload as IRawSpell | undefined;
59
+ const shortcut = shortcuts[index];
58
60
 
59
- return <span>{payload?.magicWords.split(' ').map(word => word[0])}</span>;
61
+ if (shortcut?.type === ShortcutType.Spell && shortcut.payload) {
62
+ const payload = shortcut.payload as IRawSpell; // TypeScript type assertion
63
+
64
+ return (
65
+ <SpriteFromAtlas
66
+ atlasIMG={payload.atlasIMG}
67
+ atlasJSON={payload.atlasJSON}
68
+ spriteKey={payload.texturePath ?? ''}
69
+ width={IMAGE_SIZE}
70
+ height={IMAGE_SIZE}
71
+ imgScale={IMAGE_SCALE}
72
+ centered
73
+ borderRadius="50%"
74
+ />
75
+ );
76
+ }
77
+
78
+ return null;
60
79
  };
61
80
 
62
81
  return (
@@ -3,9 +3,12 @@ import React from 'react';
3
3
  import styled from 'styled-components';
4
4
  import { uiColors } from '../../constants/uiColors';
5
5
  import { uiFonts } from '../../constants/uiFonts';
6
+ import { SpriteFromAtlas } from '../shared/SpriteFromAtlas';
6
7
  import { SpellInfoWrapper } from './cards/SpellInfoWrapper';
7
8
 
8
9
  export interface ISpellProps {
10
+ atlasJSON: any;
11
+ atlasIMG: any;
9
12
  charMana: number;
10
13
  charMagicLevel: number;
11
14
  onPointerUp?: (spellKey: string) => void;
@@ -16,6 +19,8 @@ export interface ISpellProps {
16
19
  }
17
20
 
18
21
  export const Spell: React.FC<ISpellProps> = ({
22
+ atlasIMG,
23
+ atlasJSON,
19
24
  spellKey,
20
25
  charMana,
21
26
  charMagicLevel,
@@ -35,6 +40,9 @@ export const Spell: React.FC<ISpellProps> = ({
35
40
  ? charMagicLevel < minMagicLevelRequired
36
41
  : manaCost > charMana || charMagicLevel < minMagicLevelRequired;
37
42
 
43
+ const CONTAINER_STYLE = { width: '32px', height: '32px' };
44
+ const IMAGE_SCALE = 2;
45
+
38
46
  return (
39
47
  <SpellInfoWrapper spell={spell}>
40
48
  <Container
@@ -55,7 +63,14 @@ export const Spell: React.FC<ISpellProps> = ({
55
63
  {activeCooldown.toFixed(activeCooldown > 10 ? 0 : 1)}
56
64
  </span>
57
65
  ) : null}
58
- {magicWords.split(' ').map(word => word[0])}
66
+ <SpriteFromAtlas
67
+ atlasIMG={atlasIMG}
68
+ atlasJSON={atlasJSON}
69
+ spriteKey={spell.texturePath ?? ''}
70
+ imgScale={IMAGE_SCALE}
71
+ containerStyle={CONTAINER_STYLE}
72
+ centered
73
+ />
59
74
  </SpellImage>
60
75
  <Info>
61
76
  <Title>
@@ -21,6 +21,8 @@ export interface ISpellbookProps {
21
21
  removeShortcut: (index: number) => void;
22
22
  atlasIMG: any;
23
23
  atlasJSON: any;
24
+ iconAtlasIMG?: any;
25
+ iconAtlasJSON?: any;
24
26
  scale?: number;
25
27
  spellCooldowns?: Record<string, number>;
26
28
  }
@@ -38,6 +40,8 @@ export const Spellbook: React.FC<ISpellbookProps> = ({
38
40
  removeShortcut,
39
41
  atlasIMG,
40
42
  atlasJSON,
43
+ iconAtlasIMG,
44
+ iconAtlasJSON,
41
45
  scale,
42
46
  spellCooldowns,
43
47
  }) => {
@@ -99,6 +103,8 @@ export const Spellbook: React.FC<ISpellbookProps> = ({
99
103
  {spellsToDisplay.map(spell => (
100
104
  <Fragment key={spell.key}>
101
105
  <Spell
106
+ atlasIMG={iconAtlasIMG}
107
+ atlasJSON={iconAtlasJSON}
102
108
  charMana={mana}
103
109
  charMagicLevel={magicLevel}
104
110
  onPointerUp={
@@ -1,11 +1,17 @@
1
- import { AnimationEffectKeys, ISpell, SpellCastingType, SpellsBlueprint } from '@rpg-engine/shared';
2
-
1
+ import {
2
+ AnimationEffectKeys,
3
+ ISpell,
4
+ SpellCastingType,
5
+ SpellsBlueprint,
6
+ } from '@rpg-engine/shared';
3
7
 
4
8
  export const mockSpells: ISpell[] = [
5
9
  {
6
- key: SpellsBlueprint.ArrowCreationSpell + '1' as SpellsBlueprint,
10
+ key: (SpellsBlueprint.ArrowCreationSpell + '1') as SpellsBlueprint,
7
11
  name: 'Arrow Creation Spell',
8
12
  description: 'A spell that creates arrow in your inventory.1',
13
+ textureAtlas: 'icons',
14
+ texturePath: 'spell-icons/arrow-creation-spell.png',
9
15
  magicWords: 'iquar elandi',
10
16
  manaCost: 10,
11
17
  minMagicLevelRequired: 3,
@@ -16,12 +22,14 @@ export const mockSpells: ISpell[] = [
16
22
  castingAnimationKey: AnimationEffectKeys.SkillLevelUp,
17
23
  targetHitAnimationKey: AnimationEffectKeys.Rooted,
18
24
  projectileAnimationKey: AnimationEffectKeys.Energy,
19
- usableEffect: () => { }
25
+ usableEffect: () => {},
20
26
  },
21
27
  {
22
- key: SpellsBlueprint.ArrowCreationSpell + '2' as SpellsBlueprint,
28
+ key: (SpellsBlueprint.ArrowCreationSpell + '2') as SpellsBlueprint,
23
29
  name: 'Arrow Creation Spell',
24
30
  description: 'A spell that creates arrow in your inventory.2',
31
+ textureAtlas: 'icons',
32
+ texturePath: 'spell-icons/arrow-creation-spell.png',
25
33
  magicWords: 'iquar elandi',
26
34
  manaCost: 10,
27
35
  minMagicLevelRequired: 3,
@@ -32,12 +40,14 @@ export const mockSpells: ISpell[] = [
32
40
  castingAnimationKey: AnimationEffectKeys.SkillLevelUp,
33
41
  targetHitAnimationKey: AnimationEffectKeys.Rooted,
34
42
  projectileAnimationKey: AnimationEffectKeys.Energy,
35
- usableEffect: () => { }
43
+ usableEffect: () => {},
36
44
  },
37
45
  {
38
- key: SpellsBlueprint.ArrowCreationSpell + '3' as SpellsBlueprint,
46
+ key: (SpellsBlueprint.ArrowCreationSpell + '3') as SpellsBlueprint,
39
47
  name: 'Arrow Creation Spell',
40
48
  description: 'A spell that creates arrow in your inventory.3',
49
+ textureAtlas: 'icons',
50
+ texturePath: 'spell-icons/arrow-creation-spell.png',
41
51
  magicWords: 'iquar elandi',
42
52
  manaCost: 10,
43
53
  minMagicLevelRequired: 3,
@@ -48,12 +58,14 @@ export const mockSpells: ISpell[] = [
48
58
  castingAnimationKey: AnimationEffectKeys.SkillLevelUp,
49
59
  targetHitAnimationKey: AnimationEffectKeys.Rooted,
50
60
  projectileAnimationKey: AnimationEffectKeys.Energy,
51
- usableEffect: () => { }
61
+ usableEffect: () => {},
52
62
  },
53
63
  {
54
- key: SpellsBlueprint.ArrowCreationSpell + '4' as SpellsBlueprint,
64
+ key: (SpellsBlueprint.ArrowCreationSpell + '4') as SpellsBlueprint,
55
65
  name: 'Arrow Creation Spell',
56
66
  description: 'A spell that creates arrow in your inventory.4',
67
+ textureAtlas: 'icons',
68
+ texturePath: 'spell-icons/arrow-creation-spell.png',
57
69
  magicWords: 'iquar elandi',
58
70
  manaCost: 10,
59
71
  minMagicLevelRequired: 3,
@@ -64,12 +76,14 @@ export const mockSpells: ISpell[] = [
64
76
  castingAnimationKey: AnimationEffectKeys.SkillLevelUp,
65
77
  targetHitAnimationKey: AnimationEffectKeys.Rooted,
66
78
  projectileAnimationKey: AnimationEffectKeys.Energy,
67
- usableEffect: () => { }
79
+ usableEffect: () => {},
68
80
  },
69
81
  {
70
- key: SpellsBlueprint.ArrowCreationSpell + '5' as SpellsBlueprint,
82
+ key: (SpellsBlueprint.ArrowCreationSpell + '5') as SpellsBlueprint,
71
83
  name: 'Arrow Creation Spell',
72
84
  description: 'A spell that creates arrow in your inventory.5',
85
+ textureAtlas: 'icons',
86
+ texturePath: 'spell-icons/arrow-creation-spell.png',
73
87
  magicWords: 'iquar elandi',
74
88
  manaCost: 10,
75
89
  minMagicLevelRequired: 3,
@@ -80,6 +94,6 @@ export const mockSpells: ISpell[] = [
80
94
  castingAnimationKey: AnimationEffectKeys.SkillLevelUp,
81
95
  targetHitAnimationKey: AnimationEffectKeys.Rooted,
82
96
  projectileAnimationKey: AnimationEffectKeys.Energy,
83
- usableEffect: () => { }
97
+ usableEffect: () => {},
84
98
  },
85
- ];
99
+ ];
@@ -15,6 +15,8 @@ interface IProps {
15
15
  imgStyle?: any;
16
16
  imgScale?: number;
17
17
  imgClassname?: string;
18
+ centered?: boolean;
19
+ borderRadius?: string;
18
20
  }
19
21
 
20
22
  export const SpriteFromAtlas: React.FC<IProps> = ({
@@ -30,6 +32,8 @@ export const SpriteFromAtlas: React.FC<IProps> = ({
30
32
  grayScale = false,
31
33
  opacity = 1,
32
34
  imgClassname,
35
+ centered,
36
+ borderRadius,
33
37
  }) => {
34
38
  //! If an item is not showing, remember that you MUST run yarn atlas:copy everytime you add a new item to the atlas (it will sync our public folder atlas with src/atlas).
35
39
  //!Due to React's limitations, we cannot import it from the public folder directly!
@@ -55,6 +59,8 @@ export const SpriteFromAtlas: React.FC<IProps> = ({
55
59
  grayScale={grayScale}
56
60
  opacity={opacity}
57
61
  style={imgStyle}
62
+ centered={centered}
63
+ borderRadius={borderRadius}
58
64
  />
59
65
  </Container>
60
66
  );
@@ -71,6 +77,8 @@ interface IImgSpriteProps {
71
77
  scale: number;
72
78
  grayScale: boolean;
73
79
  opacity: number;
80
+ centered?: boolean;
81
+ borderRadius?: string;
74
82
  }
75
83
 
76
84
  interface IContainerProps {
@@ -97,8 +105,9 @@ const ImgSprite = styled.div<IImgSpriteProps>`
97
105
  background-position: -${props => props.frame.x}px -${props => props.frame.y}px;
98
106
  transform: scale(${props => props.scale});
99
107
  position: relative;
100
- top: 8px;
101
- left: 8px;
108
+ top: ${props => (props.centered ? '0' : '8px')};
109
+ left: ${props => (props.centered ? '0' : '8px')};
102
110
  filter: ${props => (props.grayScale ? 'grayscale(100%)' : 'none')};
103
111
  opacity: ${props => props.opacity};
112
+ border-radius: ${props => (props.borderRadius ? props.borderRadius : '0')};
104
113
  `;
@@ -11,6 +11,8 @@ export const shortcutMock = [
11
11
  minLevelRequired: 2,
12
12
  minMagicLevelRequired: 1,
13
13
  animationKey: 'life-heal',
14
+ textureAtlas: 'icons',
15
+ texturePath: 'spell-icons/self-healing-spell.png',
14
16
  },
15
17
  },
16
18
  { type: 2, payload: null },
@@ -1,13 +1,13 @@
1
- import { IShortcut, ShortcutType } from '@rpg-engine/shared';
1
+ import { IRawSpell, IShortcut, ShortcutType } from '@rpg-engine/shared';
2
2
  import { Meta, Story } from '@storybook/react';
3
3
  import React, { useEffect, useState } from 'react';
4
4
  import { RPGUIRoot } from '../components/RPGUIRoot';
5
+ import { ISpellbookProps, Spellbook } from '../components/Spellbook/Spellbook';
5
6
  import {
6
- defaultShortcut,
7
7
  SHORTCUTS_STORAGE_KEY,
8
+ defaultShortcut,
8
9
  } from '../components/Spellbook/constants';
9
10
  import { mockSpells } from '../components/Spellbook/mockSpells';
10
- import { ISpellbookProps, Spellbook } from '../components/Spellbook/Spellbook';
11
11
  import atlasJSON from '../mocks/atlas/items/items.json';
12
12
  import atlasIMG from '../mocks/atlas/items/items.png';
13
13
 
@@ -38,19 +38,25 @@ const Template: Story<ISpellbookProps> = args => {
38
38
  return;
39
39
  }
40
40
 
41
+ const spellRaw = {
42
+ ...spell,
43
+ atlasIMG: atlasIMG,
44
+ atlasJSON: atlasIMG,
45
+ } as IRawSpell;
46
+
41
47
  if (!shortcuts) {
42
48
  const newShortcuts: IShortcut[] = Array(6).fill(defaultShortcut);
43
49
 
44
50
  newShortcuts[index] = {
45
51
  type: ShortcutType.Spell,
46
- payload: spell,
52
+ payload: spellRaw,
47
53
  };
48
54
 
49
55
  localStorage.setItem(SHORTCUTS_STORAGE_KEY, JSON.stringify(newShortcuts));
50
56
  } else {
51
57
  shortcuts[index] = {
52
58
  type: ShortcutType.Spell,
53
- payload: spell,
59
+ payload: spellRaw,
54
60
  };
55
61
 
56
62
  localStorage.setItem(SHORTCUTS_STORAGE_KEY, JSON.stringify(shortcuts));