@rpg-engine/long-bow 0.3.51 → 0.3.53
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.
- package/dist/components/CircularController/CircularController.d.ts +6 -3
- package/dist/components/Item/Inventory/ItemContainer.d.ts +4 -1
- package/dist/components/Item/Inventory/ItemSlot.d.ts +1 -0
- package/dist/components/Shortcuts/Shortcuts.d.ts +12 -0
- package/dist/components/Shortcuts/ShortcutsSetter.d.ts +12 -0
- package/dist/components/Shortcuts/SingleShortcut.d.ts +1 -0
- package/dist/components/Spellbook/Spellbook.d.ts +5 -3
- package/dist/components/Spellbook/constants.d.ts +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/long-bow.cjs.development.js +292 -146
- package/dist/long-bow.cjs.development.js.map +1 -1
- package/dist/long-bow.cjs.production.min.js +1 -1
- package/dist/long-bow.cjs.production.min.js.map +1 -1
- package/dist/long-bow.esm.js +293 -146
- package/dist/long-bow.esm.js.map +1 -1
- package/dist/stories/{QuickSpells.stories.d.ts → Shortcuts.stories.d.ts} +2 -2
- package/package.json +2 -2
- package/src/components/Abstractions/SlotsContainer.tsx +2 -2
- package/src/components/CircularController/CircularController.tsx +119 -36
- package/src/components/Item/Inventory/ItemContainer.tsx +39 -4
- package/src/components/Item/Inventory/ItemSlot.tsx +38 -3
- package/src/components/Shortcuts/Shortcuts.tsx +129 -0
- package/src/components/Shortcuts/ShortcutsSetter.tsx +132 -0
- package/src/components/Shortcuts/SingleShortcut.ts +61 -0
- package/src/components/Spellbook/Spellbook.tsx +15 -9
- package/src/components/Spellbook/constants.ts +5 -9
- package/src/components/TradingMenu/TradingMenu.tsx +2 -2
- package/src/components/TradingMenu/items.mock.ts +59 -0
- package/src/index.tsx +1 -1
- package/src/mocks/itemContainer.mocks.ts +22 -20
- package/src/stories/CircullarController.stories.tsx +9 -5
- package/src/stories/ItemContainer.stories.tsx +76 -2
- package/src/stories/Shortcuts.stories.tsx +39 -0
- package/src/stories/Spellbook.stories.tsx +35 -38
- package/dist/components/Spellbook/QuickSpells.d.ts +0 -10
- package/dist/components/Spellbook/SpellbookShortcuts.d.ts +0 -10
- package/src/components/Spellbook/QuickSpells.tsx +0 -120
- package/src/components/Spellbook/SpellbookShortcuts.tsx +0 -77
- package/src/stories/QuickSpells.stories.tsx +0 -38
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { IShortcut, ShortcutType } from '@rpg-engine/shared';
|
|
1
2
|
import { Meta, Story } from '@storybook/react';
|
|
2
3
|
import React, { useEffect, useState } from 'react';
|
|
3
4
|
import { RPGUIRoot } from '../components/RPGUIRoot';
|
|
4
5
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
defaultShortcut,
|
|
7
|
+
SHORTCUTS_STORAGE_KEY,
|
|
7
8
|
} from '../components/Spellbook/constants';
|
|
8
9
|
import { mockSpells } from '../components/Spellbook/mockSpells';
|
|
9
10
|
import { ISpellbookProps, Spellbook } from '../components/Spellbook/Spellbook';
|
|
11
|
+
import atlasJSON from '../mocks/atlas/items/items.json';
|
|
12
|
+
import atlasIMG from '../mocks/atlas/items/items.png';
|
|
10
13
|
|
|
11
14
|
const meta: Meta = {
|
|
12
15
|
title: 'Spellbook',
|
|
@@ -16,66 +19,58 @@ const meta: Meta = {
|
|
|
16
19
|
export default meta;
|
|
17
20
|
|
|
18
21
|
const Template: Story<ISpellbookProps> = args => {
|
|
19
|
-
const [
|
|
22
|
+
const [shortcuts, setShortcuts] = useState<IShortcut[]>([]);
|
|
20
23
|
|
|
21
24
|
useEffect(() => {
|
|
22
|
-
const shortcuts = localStorage.getItem(
|
|
25
|
+
const shortcuts = localStorage.getItem(SHORTCUTS_STORAGE_KEY);
|
|
23
26
|
if (shortcuts) {
|
|
24
|
-
|
|
27
|
+
setShortcuts(JSON.parse(shortcuts));
|
|
25
28
|
}
|
|
26
29
|
}, []);
|
|
27
30
|
|
|
28
31
|
const setSpellShortcut = (key: string, index: number) => {
|
|
29
|
-
const
|
|
30
|
-
localStorage.getItem(
|
|
31
|
-
);
|
|
32
|
+
const shortcuts = JSON.parse(
|
|
33
|
+
localStorage.getItem(SHORTCUTS_STORAGE_KEY) as string
|
|
34
|
+
) as IShortcut[];
|
|
32
35
|
|
|
33
36
|
const spell = mockSpells.find(s => s.key === key);
|
|
34
37
|
if (!spell) {
|
|
35
38
|
return;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
|
-
if (!
|
|
39
|
-
const
|
|
40
|
-
defaultSpellShortcut,
|
|
41
|
-
defaultSpellShortcut,
|
|
42
|
-
defaultSpellShortcut,
|
|
43
|
-
defaultSpellShortcut,
|
|
44
|
-
];
|
|
41
|
+
if (!shortcuts) {
|
|
42
|
+
const newShortcuts: IShortcut[] = Array(6).fill(defaultShortcut);
|
|
45
43
|
|
|
46
|
-
|
|
44
|
+
newShortcuts[index] = {
|
|
45
|
+
type: ShortcutType.Spell,
|
|
46
|
+
payload: spell,
|
|
47
|
+
};
|
|
47
48
|
|
|
48
|
-
localStorage.setItem(
|
|
49
|
-
SPELL_SHORTCUTS_STORAGE_KEY,
|
|
50
|
-
JSON.stringify(newSpellShortcuts)
|
|
51
|
-
);
|
|
49
|
+
localStorage.setItem(SHORTCUTS_STORAGE_KEY, JSON.stringify(newShortcuts));
|
|
52
50
|
} else {
|
|
53
|
-
|
|
51
|
+
shortcuts[index] = {
|
|
52
|
+
type: ShortcutType.Spell,
|
|
53
|
+
payload: spell,
|
|
54
|
+
};
|
|
54
55
|
|
|
55
|
-
localStorage.setItem(
|
|
56
|
-
SPELL_SHORTCUTS_STORAGE_KEY,
|
|
57
|
-
JSON.stringify(spellShortcuts)
|
|
58
|
-
);
|
|
56
|
+
localStorage.setItem(SHORTCUTS_STORAGE_KEY, JSON.stringify(shortcuts));
|
|
59
57
|
}
|
|
60
58
|
|
|
61
|
-
|
|
59
|
+
setShortcuts(shortcuts);
|
|
62
60
|
};
|
|
63
61
|
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
localStorage.getItem(
|
|
62
|
+
const removeShortcut = (index: number) => {
|
|
63
|
+
const shortcuts = JSON.parse(
|
|
64
|
+
localStorage.getItem(SHORTCUTS_STORAGE_KEY) as string
|
|
67
65
|
);
|
|
68
66
|
|
|
69
|
-
if (!
|
|
67
|
+
if (!shortcuts) return;
|
|
70
68
|
|
|
71
|
-
|
|
69
|
+
shortcuts[index] = defaultShortcut;
|
|
72
70
|
|
|
73
|
-
localStorage.setItem(
|
|
74
|
-
SPELL_SHORTCUTS_STORAGE_KEY,
|
|
75
|
-
JSON.stringify(spellShortcuts)
|
|
76
|
-
);
|
|
71
|
+
localStorage.setItem(SHORTCUTS_STORAGE_KEY, JSON.stringify(shortcuts));
|
|
77
72
|
|
|
78
|
-
|
|
73
|
+
setShortcuts(shortcuts);
|
|
79
74
|
};
|
|
80
75
|
|
|
81
76
|
return (
|
|
@@ -89,8 +84,8 @@ const Template: Story<ISpellbookProps> = args => {
|
|
|
89
84
|
<Spellbook
|
|
90
85
|
{...args}
|
|
91
86
|
setSpellShortcut={setSpellShortcut}
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
removeShortcut={removeShortcut}
|
|
88
|
+
shortcuts={shortcuts}
|
|
94
89
|
/>
|
|
95
90
|
</div>
|
|
96
91
|
</RPGUIRoot>
|
|
@@ -104,4 +99,6 @@ Default.args = {
|
|
|
104
99
|
spells: mockSpells,
|
|
105
100
|
magicLevel: 3,
|
|
106
101
|
mana: 5,
|
|
102
|
+
atlasIMG,
|
|
103
|
+
atlasJSON,
|
|
107
104
|
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { IRawSpell } from '@rpg-engine/shared';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
export declare type QuickSpellsProps = {
|
|
4
|
-
quickSpells: IRawSpell[];
|
|
5
|
-
onSpellCast: (spellKey: string) => void;
|
|
6
|
-
mana: number;
|
|
7
|
-
isBlockedCastingByKeyboard?: boolean;
|
|
8
|
-
};
|
|
9
|
-
export declare const QuickSpells: React.FC<QuickSpellsProps>;
|
|
10
|
-
export declare const SpellShortcut: import("styled-components").StyledComponent<"button", any, {}, never>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { IRawSpell } from '@rpg-engine/shared';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
declare type Props = {
|
|
4
|
-
setSettingShortcutIndex: (index: number) => void;
|
|
5
|
-
settingShortcutIndex: number;
|
|
6
|
-
shortcuts: IRawSpell[];
|
|
7
|
-
removeShortcut: (index: number) => void;
|
|
8
|
-
};
|
|
9
|
-
export declare const SpellbookShortcuts: React.FC<Props>;
|
|
10
|
-
export {};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { IRawSpell } from '@rpg-engine/shared';
|
|
2
|
-
import React, { useEffect } from 'react';
|
|
3
|
-
import styled from 'styled-components';
|
|
4
|
-
import { uiColors } from '../../constants/uiColors';
|
|
5
|
-
|
|
6
|
-
export type QuickSpellsProps = {
|
|
7
|
-
quickSpells: IRawSpell[];
|
|
8
|
-
onSpellCast: (spellKey: string) => void;
|
|
9
|
-
mana: number;
|
|
10
|
-
isBlockedCastingByKeyboard?: boolean;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const QuickSpells: React.FC<QuickSpellsProps> = ({
|
|
14
|
-
quickSpells,
|
|
15
|
-
onSpellCast,
|
|
16
|
-
mana,
|
|
17
|
-
isBlockedCastingByKeyboard = false,
|
|
18
|
-
}) => {
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
const handleKeyDown = (e: KeyboardEvent) => {
|
|
21
|
-
if (isBlockedCastingByKeyboard) return;
|
|
22
|
-
|
|
23
|
-
const shortcutIndex = Number(e.key) - 1;
|
|
24
|
-
if (shortcutIndex >= 0 && shortcutIndex <= 3) {
|
|
25
|
-
const shortcut = quickSpells[shortcutIndex];
|
|
26
|
-
if (shortcut?.key && mana >= shortcut?.manaCost) {
|
|
27
|
-
onSpellCast(shortcut.key);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
window.addEventListener('keydown', handleKeyDown);
|
|
33
|
-
|
|
34
|
-
return () => {
|
|
35
|
-
window.removeEventListener('keydown', handleKeyDown);
|
|
36
|
-
};
|
|
37
|
-
}, [quickSpells, isBlockedCastingByKeyboard]);
|
|
38
|
-
|
|
39
|
-
return (
|
|
40
|
-
<List>
|
|
41
|
-
{Array.from({ length: 4 }).map((_, i) => (
|
|
42
|
-
<SpellShortcut
|
|
43
|
-
key={i}
|
|
44
|
-
onClick={onSpellCast.bind(null, quickSpells[i]?.key)}
|
|
45
|
-
disabled={mana < quickSpells[i]?.manaCost}
|
|
46
|
-
>
|
|
47
|
-
<span className="mana">
|
|
48
|
-
{quickSpells[i]?.key && quickSpells[i]?.manaCost}
|
|
49
|
-
</span>
|
|
50
|
-
<span className="magicWords">
|
|
51
|
-
{quickSpells[i]?.magicWords.split(' ').map(word => word[0])}
|
|
52
|
-
</span>
|
|
53
|
-
<span className="keyboard">{i + 1}</span>
|
|
54
|
-
</SpellShortcut>
|
|
55
|
-
))}
|
|
56
|
-
</List>
|
|
57
|
-
);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export const SpellShortcut = styled.button`
|
|
61
|
-
width: 3rem;
|
|
62
|
-
height: 3rem;
|
|
63
|
-
background-color: ${uiColors.lightGray};
|
|
64
|
-
border: 2px solid ${uiColors.darkGray};
|
|
65
|
-
border-radius: 50%;
|
|
66
|
-
text-transform: uppercase;
|
|
67
|
-
font-size: 0.7rem;
|
|
68
|
-
font-weight: bold;
|
|
69
|
-
display: flex;
|
|
70
|
-
align-items: center;
|
|
71
|
-
justify-content: center;
|
|
72
|
-
position: relative;
|
|
73
|
-
|
|
74
|
-
span {
|
|
75
|
-
pointer-events: none;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
.mana {
|
|
79
|
-
position: absolute;
|
|
80
|
-
top: -5px;
|
|
81
|
-
right: 0;
|
|
82
|
-
font-size: 0.65rem;
|
|
83
|
-
color: ${uiColors.blue};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
.magicWords {
|
|
87
|
-
margin-top: 4px;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
.keyboard {
|
|
91
|
-
position: absolute;
|
|
92
|
-
bottom: -5px;
|
|
93
|
-
left: 0;
|
|
94
|
-
font-size: 0.65rem;
|
|
95
|
-
color: ${uiColors.yellow};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
&:hover,
|
|
99
|
-
&:focus {
|
|
100
|
-
background-color: ${uiColors.darkGray};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
&:active {
|
|
104
|
-
background-color: ${uiColors.gray};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
&:disabled {
|
|
108
|
-
opacity: 0.5;
|
|
109
|
-
}
|
|
110
|
-
`;
|
|
111
|
-
|
|
112
|
-
const List = styled.p`
|
|
113
|
-
width: 100%;
|
|
114
|
-
display: flex;
|
|
115
|
-
align-items: center;
|
|
116
|
-
justify-content: center;
|
|
117
|
-
gap: 0.5rem;
|
|
118
|
-
box-sizing: border-box;
|
|
119
|
-
margin: 0 !important;
|
|
120
|
-
`;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { IRawSpell } from '@rpg-engine/shared';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import styled from 'styled-components';
|
|
4
|
-
import { uiColors } from '../../constants/uiColors';
|
|
5
|
-
|
|
6
|
-
type Props = {
|
|
7
|
-
setSettingShortcutIndex: (index: number) => void;
|
|
8
|
-
settingShortcutIndex: number;
|
|
9
|
-
shortcuts: IRawSpell[];
|
|
10
|
-
removeShortcut: (index: number) => void;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const SpellbookShortcuts: React.FC<Props> = ({
|
|
14
|
-
setSettingShortcutIndex,
|
|
15
|
-
settingShortcutIndex,
|
|
16
|
-
shortcuts,
|
|
17
|
-
removeShortcut,
|
|
18
|
-
}) => (
|
|
19
|
-
<List id="shortcuts_list">
|
|
20
|
-
Spells shortcuts:
|
|
21
|
-
{Array.from({ length: 4 }).map((_, i) => (
|
|
22
|
-
<SpellShortcut
|
|
23
|
-
key={i}
|
|
24
|
-
onClick={() => {
|
|
25
|
-
removeShortcut(i);
|
|
26
|
-
if (!shortcuts[i]?.key) setSettingShortcutIndex(i);
|
|
27
|
-
}}
|
|
28
|
-
disabled={settingShortcutIndex !== -1 && settingShortcutIndex !== i}
|
|
29
|
-
isBeingSet={settingShortcutIndex === i}
|
|
30
|
-
>
|
|
31
|
-
<span>{shortcuts[i]?.magicWords.split(' ').map(word => word[0])}</span>
|
|
32
|
-
</SpellShortcut>
|
|
33
|
-
))}
|
|
34
|
-
</List>
|
|
35
|
-
);
|
|
36
|
-
const SpellShortcut = styled.button<{ isBeingSet?: boolean }>`
|
|
37
|
-
width: 2.6rem;
|
|
38
|
-
height: 2.6rem;
|
|
39
|
-
background-color: ${uiColors.lightGray};
|
|
40
|
-
border: 2px solid
|
|
41
|
-
${({ isBeingSet }) => (isBeingSet ? uiColors.yellow : uiColors.darkGray)};
|
|
42
|
-
border-radius: 50%;
|
|
43
|
-
text-transform: uppercase;
|
|
44
|
-
font-size: 0.7rem;
|
|
45
|
-
font-weight: bold;
|
|
46
|
-
display: flex;
|
|
47
|
-
align-items: center;
|
|
48
|
-
justify-content: center;
|
|
49
|
-
|
|
50
|
-
span {
|
|
51
|
-
margin-top: 4px;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
&:hover,
|
|
55
|
-
&:focus {
|
|
56
|
-
background-color: ${uiColors.darkGray};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
&:active {
|
|
60
|
-
background-color: ${uiColors.gray};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
&:disabled {
|
|
64
|
-
opacity: 0.5;
|
|
65
|
-
}
|
|
66
|
-
`;
|
|
67
|
-
|
|
68
|
-
const List = styled.p`
|
|
69
|
-
width: 100%;
|
|
70
|
-
display: flex;
|
|
71
|
-
align-items: center;
|
|
72
|
-
justify-content: flex-end;
|
|
73
|
-
gap: 0.5rem;
|
|
74
|
-
padding: 0.5rem;
|
|
75
|
-
box-sizing: border-box;
|
|
76
|
-
margin: 0 !important;
|
|
77
|
-
`;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Meta, Story } from '@storybook/react';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { RPGUIRoot } from '../components/RPGUIRoot';
|
|
4
|
-
import { SPELL_SHORTCUTS_STORAGE_KEY } from '../components/Spellbook/constants';
|
|
5
|
-
import {
|
|
6
|
-
QuickSpells,
|
|
7
|
-
QuickSpellsProps,
|
|
8
|
-
} from '../components/Spellbook/QuickSpells';
|
|
9
|
-
|
|
10
|
-
const meta: Meta = {
|
|
11
|
-
title: 'QuickSpells',
|
|
12
|
-
component: QuickSpells,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export default meta;
|
|
16
|
-
|
|
17
|
-
const Template: Story<QuickSpellsProps> = args => {
|
|
18
|
-
return (
|
|
19
|
-
<RPGUIRoot>
|
|
20
|
-
<div
|
|
21
|
-
style={{
|
|
22
|
-
width: '100%',
|
|
23
|
-
}}
|
|
24
|
-
>
|
|
25
|
-
<QuickSpells {...args} />
|
|
26
|
-
</div>
|
|
27
|
-
</RPGUIRoot>
|
|
28
|
-
);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const Default = Template.bind({});
|
|
32
|
-
Default.args = {
|
|
33
|
-
onSpellCast: spellKey => console.log(spellKey),
|
|
34
|
-
quickSpells: JSON.parse(
|
|
35
|
-
localStorage.getItem(SPELL_SHORTCUTS_STORAGE_KEY) as string
|
|
36
|
-
),
|
|
37
|
-
mana: 100,
|
|
38
|
-
};
|