@rpg-engine/long-bow 0.3.34 → 0.3.36
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/Spellbook/QuickSpells.d.ts +9 -0
- package/dist/components/Spellbook/Spell.d.ts +11 -0
- package/dist/components/Spellbook/Spellbook.d.ts +15 -0
- package/dist/components/Spellbook/SpellbookShortcuts.d.ts +10 -0
- package/dist/components/Spellbook/constants.d.ts +3 -0
- package/dist/components/Spellbook/mockSpells.d.ts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/long-bow.cjs.development.js +265 -5
- 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 +266 -8
- package/dist/long-bow.esm.js.map +1 -1
- package/dist/stories/QuickSpells.stories.d.ts +5 -0
- package/dist/stories/Spellbook.stories.d.ts +5 -0
- package/package.json +2 -2
- package/src/components/Item/Inventory/ItemSlot.tsx +27 -1
- package/src/components/Spellbook/QuickSpells.tsx +116 -0
- package/src/components/Spellbook/Spell.tsx +201 -0
- package/src/components/Spellbook/Spellbook.tsx +144 -0
- package/src/components/Spellbook/SpellbookShortcuts.tsx +77 -0
- package/src/components/Spellbook/constants.ts +12 -0
- package/src/components/Spellbook/mockSpells.ts +60 -0
- package/src/index.tsx +2 -0
- package/src/mocks/itemContainer.mocks.ts +4 -4
- package/src/stories/QuickSpells.stories.tsx +38 -0
- package/src/stories/Spellbook.stories.tsx +107 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Meta } from '@storybook/react';
|
|
2
|
+
import { QuickSpellsProps } from '../components/Spellbook/QuickSpells';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
export declare const Default: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, QuickSpellsProps>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Meta } from '@storybook/react';
|
|
2
|
+
import { ISpellbookProps } from '../components/Spellbook/Spellbook';
|
|
3
|
+
declare const meta: Meta;
|
|
4
|
+
export default meta;
|
|
5
|
+
export declare const Default: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, ISpellbookProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rpg-engine/long-bow",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.36",
|
|
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.6.
|
|
86
|
+
"@rpg-engine/shared": "^0.6.71",
|
|
87
87
|
"dayjs": "^1.11.2",
|
|
88
88
|
"font-awesome": "^4.7.0",
|
|
89
89
|
"fs-extra": "^10.1.0",
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
IItem,
|
|
4
4
|
IItemContainer,
|
|
5
5
|
ItemContainerType,
|
|
6
|
+
ItemRarities,
|
|
6
7
|
ItemSlotType,
|
|
7
8
|
ItemType,
|
|
8
9
|
} from '@rpg-engine/shared';
|
|
@@ -258,6 +259,7 @@ export const ItemSlot: React.FC<IProps> = observer(
|
|
|
258
259
|
|
|
259
260
|
return (
|
|
260
261
|
<Container
|
|
262
|
+
item={item}
|
|
261
263
|
className="rpgui-icon empty-slot"
|
|
262
264
|
onMouseUp={() => {
|
|
263
265
|
const data = item ? item : null;
|
|
@@ -392,12 +394,36 @@ export const ItemSlot: React.FC<IProps> = observer(
|
|
|
392
394
|
}
|
|
393
395
|
);
|
|
394
396
|
|
|
395
|
-
const
|
|
397
|
+
const rarityColor = (item: IItem | null) => {
|
|
398
|
+
switch (item?.rarity) {
|
|
399
|
+
case ItemRarities.Uncommon:
|
|
400
|
+
return 'rgba(13, 193, 13, 0.6)';
|
|
401
|
+
case ItemRarities.Rare:
|
|
402
|
+
return 'rgba(8, 104, 187, 0.6)';
|
|
403
|
+
case ItemRarities.Epic:
|
|
404
|
+
return 'rgba(191, 0, 255, 0.6)';
|
|
405
|
+
case ItemRarities.Legendary:
|
|
406
|
+
return 'rgba(255, 191, 0,0.6)';
|
|
407
|
+
default:
|
|
408
|
+
return 'unset';
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
interface ContainerTypes {
|
|
413
|
+
item: IItem | null;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const Container = styled.div<ContainerTypes>`
|
|
396
417
|
margin: 0.1rem;
|
|
397
418
|
.sprite-from-atlas-img {
|
|
398
419
|
position: relative;
|
|
399
420
|
top: 1.5rem;
|
|
400
421
|
left: 1.5rem;
|
|
422
|
+
border-color: ${({ item }) => rarityColor(item)};
|
|
423
|
+
box-shadow: ${({ item }) => `0 0 5px 2px ${rarityColor(item)}`} inset, ${({
|
|
424
|
+
item,
|
|
425
|
+
}) => `0 0 4px 3px ${rarityColor(item)}`};
|
|
426
|
+
//background-color: ${({ item }) => rarityColor(item)};
|
|
401
427
|
}
|
|
402
428
|
position: relative;
|
|
403
429
|
`;
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
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
|
+
.mana {
|
|
75
|
+
position: absolute;
|
|
76
|
+
top: -5px;
|
|
77
|
+
right: 0;
|
|
78
|
+
font-size: 0.65rem;
|
|
79
|
+
color: ${uiColors.blue};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.magicWords {
|
|
83
|
+
margin-top: 4px;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.keyboard {
|
|
87
|
+
position: absolute;
|
|
88
|
+
bottom: -5px;
|
|
89
|
+
left: 0;
|
|
90
|
+
font-size: 0.65rem;
|
|
91
|
+
color: ${uiColors.yellow};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
&:hover,
|
|
95
|
+
&:focus {
|
|
96
|
+
background-color: ${uiColors.darkGray};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
&:active {
|
|
100
|
+
background-color: ${uiColors.gray};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
&:disabled {
|
|
104
|
+
opacity: 0.5;
|
|
105
|
+
}
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
const List = styled.p`
|
|
109
|
+
width: 100%;
|
|
110
|
+
display: flex;
|
|
111
|
+
align-items: center;
|
|
112
|
+
justify-content: center;
|
|
113
|
+
gap: 0.5rem;
|
|
114
|
+
box-sizing: border-box;
|
|
115
|
+
margin: 0 !important;
|
|
116
|
+
`;
|
|
@@ -0,0 +1,201 @@
|
|
|
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
|
+
import { uiFonts } from '../../constants/uiFonts';
|
|
6
|
+
|
|
7
|
+
interface Props extends IRawSpell {
|
|
8
|
+
charMana: number;
|
|
9
|
+
charMagicLevel: number;
|
|
10
|
+
onClick?: (spellKey: string) => void;
|
|
11
|
+
isSettingShortcut?: boolean;
|
|
12
|
+
spellKey: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const Spell: React.FC<Props> = ({
|
|
16
|
+
spellKey,
|
|
17
|
+
name,
|
|
18
|
+
description,
|
|
19
|
+
magicWords,
|
|
20
|
+
manaCost,
|
|
21
|
+
charMana,
|
|
22
|
+
charMagicLevel,
|
|
23
|
+
onClick,
|
|
24
|
+
isSettingShortcut,
|
|
25
|
+
minMagicLevelRequired,
|
|
26
|
+
}) => {
|
|
27
|
+
const disabled = isSettingShortcut
|
|
28
|
+
? charMagicLevel < minMagicLevelRequired
|
|
29
|
+
: manaCost > charMana || charMagicLevel < minMagicLevelRequired;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<Container
|
|
33
|
+
disabled={disabled}
|
|
34
|
+
onClick={onClick?.bind(null, spellKey)}
|
|
35
|
+
isSettingShortcut={isSettingShortcut && !disabled}
|
|
36
|
+
className="spell"
|
|
37
|
+
>
|
|
38
|
+
{disabled && (
|
|
39
|
+
<Overlay>
|
|
40
|
+
{charMagicLevel < minMagicLevelRequired
|
|
41
|
+
? 'Low magic level'
|
|
42
|
+
: manaCost > charMana && 'No mana'}
|
|
43
|
+
</Overlay>
|
|
44
|
+
)}
|
|
45
|
+
<SpellImage>{magicWords.split(' ').map(word => word[0])}</SpellImage>
|
|
46
|
+
<Info>
|
|
47
|
+
<Title>
|
|
48
|
+
<span>{name}</span>
|
|
49
|
+
<span className="spell">({magicWords})</span>
|
|
50
|
+
</Title>
|
|
51
|
+
<Description>{description}</Description>
|
|
52
|
+
</Info>
|
|
53
|
+
|
|
54
|
+
<Divider />
|
|
55
|
+
<Cost>
|
|
56
|
+
<span>Mana cost:</span>
|
|
57
|
+
<span className="mana">{manaCost}</span>
|
|
58
|
+
</Cost>
|
|
59
|
+
</Container>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const Container = styled.button<{ isSettingShortcut?: boolean }>`
|
|
64
|
+
display: block;
|
|
65
|
+
background: none;
|
|
66
|
+
border: 2px solid transparent;
|
|
67
|
+
border-radius: 1rem;
|
|
68
|
+
width: 100%;
|
|
69
|
+
display: flex;
|
|
70
|
+
height: 5rem;
|
|
71
|
+
gap: 1rem;
|
|
72
|
+
align-items: center;
|
|
73
|
+
padding: 0 1rem;
|
|
74
|
+
text-align: left;
|
|
75
|
+
position: relative;
|
|
76
|
+
|
|
77
|
+
animation: ${({ isSettingShortcut }) =>
|
|
78
|
+
isSettingShortcut ? 'border-color-change 1s infinite' : 'none'};
|
|
79
|
+
|
|
80
|
+
@keyframes border-color-change {
|
|
81
|
+
0% {
|
|
82
|
+
border-color: ${uiColors.yellow};
|
|
83
|
+
}
|
|
84
|
+
50% {
|
|
85
|
+
border-color: transparent;
|
|
86
|
+
}
|
|
87
|
+
100% {
|
|
88
|
+
border-color: ${uiColors.yellow};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
&:hover,
|
|
93
|
+
&:focus {
|
|
94
|
+
background-color: ${uiColors.darkGray};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&:active {
|
|
98
|
+
background: none;
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
|
|
102
|
+
const SpellImage = styled.div`
|
|
103
|
+
width: 4rem;
|
|
104
|
+
height: 4rem;
|
|
105
|
+
font-size: ${uiFonts.size.xLarge};
|
|
106
|
+
font-weight: bold;
|
|
107
|
+
background-color: ${uiColors.darkGray};
|
|
108
|
+
color: ${uiColors.lightGray};
|
|
109
|
+
display: flex;
|
|
110
|
+
justify-content: center;
|
|
111
|
+
align-items: center;
|
|
112
|
+
text-transform: uppercase;
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
const Info = styled.span`
|
|
116
|
+
width: 0;
|
|
117
|
+
flex: 1;
|
|
118
|
+
`;
|
|
119
|
+
|
|
120
|
+
const Title = styled.p`
|
|
121
|
+
display: flex;
|
|
122
|
+
flex-wrap: wrap;
|
|
123
|
+
align-items: center;
|
|
124
|
+
margin-bottom: 5px;
|
|
125
|
+
margin: 0;
|
|
126
|
+
|
|
127
|
+
span {
|
|
128
|
+
font-size: ${uiFonts.size.medium} !important;
|
|
129
|
+
font-weight: bold !important;
|
|
130
|
+
color: ${uiColors.yellow} !important;
|
|
131
|
+
margin-right: 0.5rem;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.spell {
|
|
135
|
+
font-size: ${uiFonts.size.small} !important;
|
|
136
|
+
font-weight: normal !important;
|
|
137
|
+
color: ${uiColors.lightGray} !important;
|
|
138
|
+
}
|
|
139
|
+
`;
|
|
140
|
+
|
|
141
|
+
const Description = styled.div`
|
|
142
|
+
font-size: ${uiFonts.size.small} !important;
|
|
143
|
+
line-height: 1.1 !important;
|
|
144
|
+
`;
|
|
145
|
+
|
|
146
|
+
const Divider = styled.div`
|
|
147
|
+
width: 1px;
|
|
148
|
+
height: 100%;
|
|
149
|
+
margin: 0 1rem;
|
|
150
|
+
background-color: ${uiColors.lightGray};
|
|
151
|
+
`;
|
|
152
|
+
|
|
153
|
+
const Cost = styled.p`
|
|
154
|
+
display: flex;
|
|
155
|
+
align-items: center;
|
|
156
|
+
flex-direction: column;
|
|
157
|
+
gap: 0.5rem;
|
|
158
|
+
|
|
159
|
+
div {
|
|
160
|
+
z-index: 1;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.mana {
|
|
164
|
+
position: relative;
|
|
165
|
+
font-size: ${uiFonts.size.medium};
|
|
166
|
+
font-weight: bold;
|
|
167
|
+
z-index: 1;
|
|
168
|
+
|
|
169
|
+
&::after {
|
|
170
|
+
position: absolute;
|
|
171
|
+
content: '';
|
|
172
|
+
top: 0;
|
|
173
|
+
left: 0;
|
|
174
|
+
background-color: ${uiColors.blue};
|
|
175
|
+
width: 100%;
|
|
176
|
+
height: 100%;
|
|
177
|
+
border-radius: 50%;
|
|
178
|
+
transform: scale(1.8);
|
|
179
|
+
filter: blur(10px);
|
|
180
|
+
z-index: -1;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
`;
|
|
184
|
+
|
|
185
|
+
const Overlay = styled.p`
|
|
186
|
+
margin: 0 !important;
|
|
187
|
+
position: absolute;
|
|
188
|
+
top: 0;
|
|
189
|
+
left: 0;
|
|
190
|
+
width: 100%;
|
|
191
|
+
height: 100%;
|
|
192
|
+
border-radius: 1rem;
|
|
193
|
+
display: flex;
|
|
194
|
+
justify-content: center;
|
|
195
|
+
align-items: center;
|
|
196
|
+
color: ${uiColors.yellow};
|
|
197
|
+
font-size: ${uiFonts.size.large} !important;
|
|
198
|
+
font-weight: bold;
|
|
199
|
+
z-index: 10;
|
|
200
|
+
background-color: rgba(0 0 0 / 0.2);
|
|
201
|
+
`;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { IRawSpell } from '@rpg-engine/shared';
|
|
2
|
+
import React, { Fragment, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { uiFonts } from '../../constants/uiFonts';
|
|
5
|
+
import { DraggableContainer } from '../DraggableContainer';
|
|
6
|
+
import { Input } from '../Input';
|
|
7
|
+
import { RPGUIContainerTypes } from '../RPGUIContainer';
|
|
8
|
+
import { Spell } from './Spell';
|
|
9
|
+
import { SpellbookShortcuts } from './SpellbookShortcuts';
|
|
10
|
+
|
|
11
|
+
export interface ISpellbookProps {
|
|
12
|
+
onClose?: () => void;
|
|
13
|
+
onInputFocus?: () => void;
|
|
14
|
+
onInputBlur?: () => void;
|
|
15
|
+
spells: IRawSpell[];
|
|
16
|
+
magicLevel: number;
|
|
17
|
+
mana: number;
|
|
18
|
+
onSpellClick: (spellKey: string) => void;
|
|
19
|
+
setSpellShortcut: (key: string, index: number) => void;
|
|
20
|
+
spellShortcuts: IRawSpell[];
|
|
21
|
+
removeSpellShortcut: (index: number) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const Spellbook: React.FC<ISpellbookProps> = ({
|
|
25
|
+
onClose,
|
|
26
|
+
onInputFocus,
|
|
27
|
+
onInputBlur,
|
|
28
|
+
spells,
|
|
29
|
+
magicLevel,
|
|
30
|
+
mana,
|
|
31
|
+
onSpellClick,
|
|
32
|
+
setSpellShortcut,
|
|
33
|
+
spellShortcuts,
|
|
34
|
+
removeSpellShortcut,
|
|
35
|
+
}) => {
|
|
36
|
+
const [search, setSearch] = useState('');
|
|
37
|
+
const [settingShortcutIndex, setSettingShortcutIndex] = useState(-1);
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const handleEscapeClose = (e: KeyboardEvent) => {
|
|
41
|
+
if (e.key === 'Escape') {
|
|
42
|
+
onClose?.();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
document.addEventListener('keydown', handleEscapeClose);
|
|
47
|
+
|
|
48
|
+
return () => {
|
|
49
|
+
document.removeEventListener('keydown', handleEscapeClose);
|
|
50
|
+
};
|
|
51
|
+
}, [onClose]);
|
|
52
|
+
|
|
53
|
+
const spellsToDisplay = useMemo(() => {
|
|
54
|
+
return spells
|
|
55
|
+
.sort((a, b) => {
|
|
56
|
+
if (a.minMagicLevelRequired > b.minMagicLevelRequired) return 1;
|
|
57
|
+
if (a.minMagicLevelRequired < b.minMagicLevelRequired) return -1;
|
|
58
|
+
return 0;
|
|
59
|
+
})
|
|
60
|
+
.filter(
|
|
61
|
+
spell =>
|
|
62
|
+
spell.name.toLocaleLowerCase().includes(search.toLocaleLowerCase()) ||
|
|
63
|
+
spell.magicWords
|
|
64
|
+
.toLocaleLowerCase()
|
|
65
|
+
.includes(search.toLocaleLowerCase())
|
|
66
|
+
);
|
|
67
|
+
}, [search, spells]);
|
|
68
|
+
|
|
69
|
+
const setShortcut = (spellKey: string) => {
|
|
70
|
+
setSpellShortcut?.(spellKey, settingShortcutIndex);
|
|
71
|
+
setSettingShortcutIndex(-1);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<DraggableContainer
|
|
76
|
+
type={RPGUIContainerTypes.Framed}
|
|
77
|
+
onCloseButton={onClose}
|
|
78
|
+
width="inherit"
|
|
79
|
+
height="inherit"
|
|
80
|
+
cancelDrag="#spellbook-search, #shortcuts_list, .spell"
|
|
81
|
+
>
|
|
82
|
+
<Container>
|
|
83
|
+
<Title>Learned Spells</Title>
|
|
84
|
+
|
|
85
|
+
<SpellbookShortcuts
|
|
86
|
+
setSettingShortcutIndex={setSettingShortcutIndex}
|
|
87
|
+
settingShortcutIndex={settingShortcutIndex}
|
|
88
|
+
shortcuts={spellShortcuts}
|
|
89
|
+
removeShortcut={removeSpellShortcut}
|
|
90
|
+
/>
|
|
91
|
+
|
|
92
|
+
<Input
|
|
93
|
+
placeholder="Search for spell"
|
|
94
|
+
value={search}
|
|
95
|
+
onChange={e => setSearch(e.target.value)}
|
|
96
|
+
onFocus={onInputFocus}
|
|
97
|
+
onBlur={onInputBlur}
|
|
98
|
+
id="spellbook-search"
|
|
99
|
+
/>
|
|
100
|
+
|
|
101
|
+
<SpellList>
|
|
102
|
+
{spellsToDisplay.map(spell => (
|
|
103
|
+
<Fragment key={spell.key}>
|
|
104
|
+
<Spell
|
|
105
|
+
charMana={mana}
|
|
106
|
+
charMagicLevel={magicLevel}
|
|
107
|
+
onClick={
|
|
108
|
+
settingShortcutIndex !== -1 ? setShortcut : onSpellClick
|
|
109
|
+
}
|
|
110
|
+
spellKey={spell.key}
|
|
111
|
+
isSettingShortcut={settingShortcutIndex !== -1}
|
|
112
|
+
{...spell}
|
|
113
|
+
/>
|
|
114
|
+
</Fragment>
|
|
115
|
+
))}
|
|
116
|
+
</SpellList>
|
|
117
|
+
</Container>
|
|
118
|
+
</DraggableContainer>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const Title = styled.h1`
|
|
123
|
+
font-size: ${uiFonts.size.large} !important;
|
|
124
|
+
margin-bottom: 0 !important;
|
|
125
|
+
`;
|
|
126
|
+
|
|
127
|
+
const Container = styled.div`
|
|
128
|
+
width: 100%;
|
|
129
|
+
height: 100%;
|
|
130
|
+
color: white;
|
|
131
|
+
display: flex;
|
|
132
|
+
flex-direction: column;
|
|
133
|
+
`;
|
|
134
|
+
|
|
135
|
+
const SpellList = styled.div`
|
|
136
|
+
width: 100%;
|
|
137
|
+
min-height: 0;
|
|
138
|
+
flex: 1;
|
|
139
|
+
overflow-y: auto;
|
|
140
|
+
display: flex;
|
|
141
|
+
flex-direction: column;
|
|
142
|
+
gap: 1.5rem;
|
|
143
|
+
margin-top: 1rem;
|
|
144
|
+
`;
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
`;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IRawSpell } from '@rpg-engine/shared';
|
|
2
|
+
|
|
3
|
+
export const SPELL_SHORTCUTS_STORAGE_KEY = 'spellShortcuts';
|
|
4
|
+
|
|
5
|
+
export const defaultSpellShortcut: IRawSpell = {
|
|
6
|
+
key: '',
|
|
7
|
+
manaCost: 0,
|
|
8
|
+
magicWords: '',
|
|
9
|
+
name: '',
|
|
10
|
+
description: '',
|
|
11
|
+
minMagicLevelRequired: 0,
|
|
12
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { IRawSpell } from '@rpg-engine/shared';
|
|
2
|
+
|
|
3
|
+
enum SpellsBlueprint {
|
|
4
|
+
SelfHealingSpell = 'self-healing-spell',
|
|
5
|
+
FoodCreationSpell = 'food-creation-spell',
|
|
6
|
+
ArrowCreationSpell = 'arrow-creation-spell',
|
|
7
|
+
BoltCreationSpell = 'bolt-creation-spell',
|
|
8
|
+
BlankRuneCreationSpell = 'blank-rune-creation-spell',
|
|
9
|
+
SelfHasteSpell = 'self-haste-spell',
|
|
10
|
+
FireRuneCreationSpell = 'fire-rune-creation-spell',
|
|
11
|
+
HealRuneCreationSpell = 'healing-rune-creation-spell',
|
|
12
|
+
PoisonRuneCreationSpell = 'poison-rune-creation-spell',
|
|
13
|
+
DarkRuneCreationSpell = 'dark-rune-creation-spell',
|
|
14
|
+
GreaterHealingSpell = 'greater-healing-spell',
|
|
15
|
+
EnergyBoltCreationSpell = 'energy-bolt-creation-spell',
|
|
16
|
+
FireBoltCreationSpell = 'fire-bolt-creation-spell',
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const mockSpells: IRawSpell[] = [
|
|
20
|
+
{
|
|
21
|
+
key: SpellsBlueprint.ArrowCreationSpell,
|
|
22
|
+
name: 'Arrow Creation Spell',
|
|
23
|
+
description: 'A spell that creates arrow in your inventory.',
|
|
24
|
+
magicWords: 'iquar elandi',
|
|
25
|
+
manaCost: 10,
|
|
26
|
+
minMagicLevelRequired: 3,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: SpellsBlueprint.BlankRuneCreationSpell,
|
|
30
|
+
name: 'Blank Rune Creation Spell',
|
|
31
|
+
description: 'A spell that creates a blank rune in your inventory.',
|
|
32
|
+
magicWords: 'iquar ansr ki',
|
|
33
|
+
manaCost: 5,
|
|
34
|
+
minMagicLevelRequired: 3,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
key: SpellsBlueprint.BoltCreationSpell,
|
|
38
|
+
name: 'Bolt Creation Spell',
|
|
39
|
+
description: 'A spell that creates bolt in your inventory.',
|
|
40
|
+
magicWords: 'iquar lyn',
|
|
41
|
+
manaCost: 15,
|
|
42
|
+
minMagicLevelRequired: 3,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: SpellsBlueprint.SelfHasteSpell,
|
|
46
|
+
name: 'Self Haste Spell',
|
|
47
|
+
description: 'A self haste spell.',
|
|
48
|
+
magicWords: 'talas hiz',
|
|
49
|
+
manaCost: 40,
|
|
50
|
+
minMagicLevelRequired: 5,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
key: SpellsBlueprint.SelfHealingSpell,
|
|
54
|
+
name: 'Self Healing Spell',
|
|
55
|
+
description: 'A self healing spell.',
|
|
56
|
+
magicWords: 'talas faenya',
|
|
57
|
+
manaCost: 10,
|
|
58
|
+
minMagicLevelRequired: 1,
|
|
59
|
+
},
|
|
60
|
+
];
|
package/src/index.tsx
CHANGED
|
@@ -29,6 +29,8 @@ export * from './components/RPGUIRoot';
|
|
|
29
29
|
export * from './components/shared/SpriteFromAtlas';
|
|
30
30
|
export * from './components/SkillProgressBar';
|
|
31
31
|
export * from './components/SkillsContainer';
|
|
32
|
+
export * from './components/Spellbook/QuickSpells';
|
|
33
|
+
export * from './components/Spellbook/Spellbook';
|
|
32
34
|
export * from './components/TextArea';
|
|
33
35
|
export * from './components/TimeWidget/TimeWidget';
|
|
34
36
|
export * from './components/TradingMenu/TradingMenu';
|