@rpg-engine/long-bow 0.2.67 → 0.2.68

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.
@@ -0,0 +1,4 @@
1
+ import { Meta } from '@storybook/react';
2
+ declare const meta: Meta;
3
+ export default meta;
4
+ export declare const Default: import("@storybook/csf").AnnotatedStoryFn<import("@storybook/react").ReactFramework, import("@storybook/react").Args>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.2.67",
3
+ "version": "0.2.68",
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.21",
86
+ "@rpg-engine/shared": "^0.6.27",
87
87
  "dayjs": "^1.11.2",
88
88
  "fs-extra": "^10.1.0",
89
89
  "lodash": "^4.17.21",
@@ -0,0 +1,217 @@
1
+ import { ICraftableItem, ItemSubType } from '@rpg-engine/shared';
2
+ import React, { useState } from 'react';
3
+ import styled from 'styled-components';
4
+ import { Button, ButtonTypes } from '../Button';
5
+ import { DraggableContainer } from '../DraggableContainer';
6
+ import { Dropdown, IOptionsProps } from '../Dropdown';
7
+ import { RPGUIContainerTypes } from '../RPGUIContainer';
8
+ import { SpriteFromAtlas } from '../shared/SpriteFromAtlas';
9
+
10
+ export interface IItemCraftSelectorProps {
11
+ atlasJSON: any;
12
+ atlasIMG: any;
13
+ onClose: () => void;
14
+ onSelect: (value: string) => void;
15
+ onCraftItem: (value: string | undefined) => void;
16
+ craftablesItems: ICraftableItem[];
17
+ }
18
+
19
+ export interface ShowMessage {
20
+ show: boolean;
21
+ index: number;
22
+ }
23
+
24
+ export const CraftBook: React.FC<IItemCraftSelectorProps> = ({
25
+ atlasIMG,
26
+ atlasJSON,
27
+ onClose,
28
+ onSelect,
29
+ onCraftItem,
30
+ craftablesItems,
31
+ }) => {
32
+ let optionsId: number = 0;
33
+ const [isShown, setIsShown] = useState<ShowMessage>({
34
+ show: false,
35
+ index: 200,
36
+ });
37
+ const [craftItem, setCraftItem] = useState<string>();
38
+
39
+ const getDropdownOptions = () => {
40
+ const options: IOptionsProps[] = [];
41
+
42
+ Object.keys(ItemSubType).forEach(key => {
43
+ options.push({
44
+ id: optionsId,
45
+ value: key,
46
+ option: key,
47
+ });
48
+ optionsId += 1;
49
+ });
50
+
51
+ return options;
52
+ };
53
+
54
+ const modifyString = (str: string) => {
55
+ // Split the string by "/" and "."
56
+ let parts = str.split('/');
57
+ let fileName = parts[parts.length - 1];
58
+ parts = fileName.split('.');
59
+ let name = parts[0];
60
+
61
+ // Replace all occurrences of "-" with " "
62
+ name = name.replace(/-/g, ' ');
63
+
64
+ // Uppercase the first word
65
+ let words = name.split(' ');
66
+ let firstWord = words[0].slice(0, 1).toUpperCase() + words[0].slice(1);
67
+ let modifiedWords = [firstWord].concat(words.slice(1));
68
+ name = modifiedWords.join(' ');
69
+
70
+ return name;
71
+ };
72
+
73
+ const handleClick = () => {
74
+ let element = document.querySelector(
75
+ `input[name='test']:checked`
76
+ ) as HTMLInputElement;
77
+ const elementValue = element.value;
78
+ setCraftItem(elementValue);
79
+ };
80
+
81
+ return (
82
+ <DraggableContainer
83
+ type={RPGUIContainerTypes.Framed}
84
+ width="500px"
85
+ cancelDrag=".equipment-container-body .arrow-selector"
86
+ onCloseButton={() => {
87
+ if (onClose) {
88
+ onClose();
89
+ }
90
+ }}
91
+ >
92
+ <div style={{ width: '100%' }}>
93
+ <Title>{'Harvesting instruments'}</Title>
94
+ <Subtitle>{'Use the tool, you need it'}</Subtitle>
95
+ <hr className="golden" />
96
+ </div>
97
+ <Dropdown
98
+ options={getDropdownOptions()}
99
+ onChange={value => onSelect(value)}
100
+ />
101
+ <RadioInputScroller>
102
+ {craftablesItems?.map((option, index) => (
103
+ <RadioOptionsWrapper key={index}>
104
+ <SpriteAtlasWrapper>
105
+ <SpriteFromAtlas
106
+ atlasIMG={atlasIMG}
107
+ atlasJSON={atlasJSON}
108
+ spriteKey={option.key}
109
+ imgScale={3}
110
+ grayScale={!option.canCraft}
111
+ />
112
+ </SpriteAtlasWrapper>
113
+ <div>
114
+ <input
115
+ className="rpgui-radio"
116
+ type="radio"
117
+ value={option.name}
118
+ name="test"
119
+ disabled={!option.canCraft}
120
+ />
121
+ <label
122
+ onClick={handleClick}
123
+ style={{ display: 'flex', alignItems: 'center' }}
124
+ onMouseEnter={() => setIsShown({ show: true, index: index })}
125
+ onMouseLeave={() => setIsShown({ show: false, index: index })}
126
+ >
127
+ {modifyString(option.name)}
128
+ </label>
129
+
130
+ {isShown &&
131
+ isShown.index === index &&
132
+ option.ingredients.map((option, index) => (
133
+ <Recipes key={index}>
134
+ <SpriteFromAtlas
135
+ atlasIMG={atlasIMG}
136
+ atlasJSON={atlasJSON}
137
+ spriteKey={`${option.key}`}
138
+ imgScale={1}
139
+ />
140
+ <StyledItem>
141
+ {modifyString(option.key)} ({option.qty}x)
142
+ </StyledItem>
143
+ </Recipes>
144
+ ))}
145
+ </div>
146
+ </RadioOptionsWrapper>
147
+ ))}
148
+ </RadioInputScroller>
149
+ <ButtonWrapper>
150
+ <Button buttonType={ButtonTypes.RPGUIButton} onClick={onClose}>
151
+ Cancel
152
+ </Button>
153
+ <Button
154
+ buttonType={ButtonTypes.RPGUIButton}
155
+ onClick={() => onCraftItem(craftItem)}
156
+ >
157
+ Craft
158
+ </Button>
159
+ </ButtonWrapper>
160
+ </DraggableContainer>
161
+ );
162
+ };
163
+
164
+ const StyledItem = styled.div`
165
+ margin-left: 10px;
166
+ `;
167
+
168
+ const Recipes = styled.div`
169
+ font-size: 0.6rem;
170
+ color: yellow !important;
171
+ margin-bottom: 3px;
172
+ display: flex;
173
+ align-items: center;
174
+
175
+ .sprite-from-atlas-img {
176
+ top: 0px;
177
+ left: 0px;
178
+ }
179
+ `;
180
+
181
+ const Title = styled.h1`
182
+ font-size: 0.6rem;
183
+ color: yellow !important;
184
+ `;
185
+ const Subtitle = styled.h1`
186
+ font-size: 0.4rem;
187
+ color: yellow !important;
188
+ `;
189
+
190
+ const RadioInputScroller = styled.div`
191
+ padding-left: 15px;
192
+ padding-top: 10px;
193
+ width: 100%;
194
+ margin-top: 1rem;
195
+ align-items: center;
196
+ margin-left: 20px;
197
+ align-items: flex-start;
198
+ overflow-y: scroll;
199
+ height: 360px;
200
+ `;
201
+
202
+ const SpriteAtlasWrapper = styled.div`
203
+ margin-right: 40px;
204
+ `;
205
+
206
+ const RadioOptionsWrapper = styled.div`
207
+ display: flex;
208
+ align-items: stretch;
209
+ margin-bottom: 40px;
210
+ `;
211
+
212
+ const ButtonWrapper = styled.div`
213
+ display: flex;
214
+ justify-content: space-around;
215
+ padding-top: 20px;
216
+ width: 100%;
217
+ `;
@@ -0,0 +1,41 @@
1
+ import { ICraftableItem } from "@rpg-engine/shared"
2
+
3
+ export const craftableItems: ICraftableItem[] = [
4
+ {
5
+
6
+ canCraft: true,
7
+ key: 'axes/frost-double-axe.png',
8
+ name: 'rost-double-axe',
9
+ ingredients: [
10
+ {key: "crafting-resources/blue-sapphire.png", qty: 10},
11
+ ]
12
+ },
13
+ {
14
+
15
+ canCraft: true,
16
+ key: 'axes/frost-double-axe.png',
17
+ name: 'rost-double-axe',
18
+ ingredients: [
19
+ {key: "crafting-resources/blue-sapphire.png", qty: 10},
20
+ ]
21
+ },
22
+ {
23
+
24
+ canCraft: true,
25
+ key: 'axes/frost-double-axe.png',
26
+ name: 'rost-double-axe',
27
+ ingredients: [
28
+ {key: "crafting-resources/blue-sapphire.png", qty: 10},
29
+ ]
30
+ } , {
31
+
32
+ canCraft: true,
33
+ key: 'axes/frost-double-axe.png',
34
+ name: 'rost-double-axe',
35
+ ingredients: [
36
+ {key: "crafting-resources/blue-sapphire.png", qty: 10},
37
+ ]
38
+ },
39
+
40
+
41
+ ]
@@ -67,6 +67,7 @@ export const SkillsContainer: React.FC<ISkillContainerProps> = ({
67
67
  for (const [key, value] of Object.entries(skillCategory.values)) {
68
68
  //@ts-ignore
69
69
  const skillDetails = (skill[key] as unknown) as ISkillDetails;
70
+
70
71
 
71
72
  output.push(
72
73
  <SkillProgressBar
@@ -7,7 +7,7 @@ import { SpriteFromAtlas } from '../shared/SpriteFromAtlas';
7
7
 
8
8
  export interface IOptionsItemSelectorProps {
9
9
  name: string;
10
- description: string;
10
+ description?: string;
11
11
  imageKey: string;
12
12
  }
13
13
 
@@ -27,6 +27,7 @@ export const ItemSelector: React.FC<IItemSelectorProps> = ({
27
27
  onSelect,
28
28
  }) => {
29
29
  const [selectedValue, setSelectedValue] = useState<string>();
30
+
30
31
  const handleClick = () => {
31
32
  let element = document.querySelector(
32
33
  `input[name='test']:checked`
@@ -56,6 +57,7 @@ export const ItemSelector: React.FC<IItemSelectorProps> = ({
56
57
  <Subtitle>{'Use the tool, you need it'}</Subtitle>
57
58
  <hr className="golden" />
58
59
  </div>
60
+
59
61
  <RadioInputScroller>
60
62
  {options?.map((option, index) => (
61
63
  <RadioOptionsWrapper key={index}>
@@ -105,6 +107,8 @@ const Subtitle = styled.h1`
105
107
  `;
106
108
 
107
109
  const RadioInputScroller = styled.div`
110
+ padding-left: 15px;
111
+ padding-top: 10px;
108
112
  width: 100%;
109
113
  margin-top: 1rem;
110
114
  align-items: center;
package/src/index.tsx CHANGED
@@ -2,6 +2,7 @@ export * from './components/Button';
2
2
  export * from './components/Character/CharacterSelection';
3
3
  export * from './components/Chat/Chat';
4
4
  export * from './components/CheckButton';
5
+ export * from './components/CraftBook/CraftBook';
5
6
  export * from './components/DraggableContainer';
6
7
  export * from './components/Dropdown';
7
8
  export * from './components/DropdownSelectorContainer';
@@ -10,6 +11,7 @@ export * from './components/HistoryDialog';
10
11
  export * from './components/Input';
11
12
  export * from './components/Item/Inventory/ItemContainer';
12
13
  export * from './components/Item/Inventory/ItemSlot';
14
+ export * from './components/itemSelector/ItemSelector';
13
15
  export * from './components/ListMenu';
14
16
  export * from './components/NPCDialog/NPCDialog';
15
17
  export * from './components/NPCDialog/NPCMultiDialog';
@@ -18,17 +20,16 @@ export * from './components/ProgressBar';
18
20
  export * from './components/PropertySelect/PropertySelect';
19
21
  export * from './components/QuestInfo/QuestInfo';
20
22
  export * from './components/QuestList';
21
- export * from './components/RPGUIContainer';
22
- export * from './components/RPGUIRoot';
23
23
  export * from './components/RadioButton';
24
24
  export * from './components/RangeSlider';
25
+ export * from './components/RPGUIContainer';
26
+ export * from './components/RPGUIRoot';
27
+ export * from './components/shared/SpriteFromAtlas';
25
28
  export * from './components/SkillProgressBar';
26
29
  export * from './components/SkillsContainer';
27
30
  export * from './components/TextArea';
28
31
  export * from './components/TimeWidget/TimeWidget';
29
32
  export * from './components/TradingMenu/TradingMenu';
30
33
  export * from './components/Truncate';
31
- export * from './components/itemSelector/ItemSelector';
32
- export * from './components/shared/SpriteFromAtlas';
33
34
  export * from './components/typography/DynamicText';
34
35
  export { useEventListener } from './hooks/useEventListener';
@@ -0,0 +1,40 @@
1
+ import { Meta, Story } from '@storybook/react';
2
+ import React from 'react';
3
+ import { RPGUIRoot } from '..';
4
+ import { CraftBook } from '../components/CraftBook/CraftBook';
5
+ import { craftableItems } from '../components/CraftBook/MockItems';
6
+ import atlasJSON from '../mocks/atlas/items/items.json';
7
+ import atlasIMG from '../mocks/atlas/items/items.png';
8
+
9
+ const meta: Meta = {
10
+ title: 'Craft Book',
11
+ component: CraftBook,
12
+ };
13
+
14
+ export default meta;
15
+
16
+ const Template: Story = args => (
17
+ <RPGUIRoot>
18
+ <CraftBook
19
+ atlasIMG={atlasIMG}
20
+ atlasJSON={atlasJSON}
21
+ onSelect={onSelect}
22
+ onClose={() => console.log('closing Equipment Set Container')}
23
+ craftablesItems={craftableItems}
24
+ onCraftItem={onCraftItem}
25
+ {...args}
26
+ />
27
+ </RPGUIRoot>
28
+ );
29
+
30
+ export const Default = Template.bind({});
31
+
32
+ const onCraftItem = (value: string | undefined) => {
33
+ console.log('Craft', value);
34
+ };
35
+
36
+ const onSelect = (value: string) => {
37
+ console.log('Story package', value);
38
+ };
39
+
40
+ Default.args = {};