@rpg-engine/long-bow 0.1.78 → 0.1.794

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.
Files changed (57) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +181 -181
  3. package/dist/components/store/UI.store.d.ts +4 -0
  4. package/dist/long-bow.cjs.development.js +48 -6
  5. package/dist/long-bow.cjs.development.js.map +1 -1
  6. package/dist/long-bow.cjs.production.min.js +1 -1
  7. package/dist/long-bow.cjs.production.min.js.map +1 -1
  8. package/dist/long-bow.esm.js +48 -6
  9. package/dist/long-bow.esm.js.map +1 -1
  10. package/package.json +96 -96
  11. package/src/components/Abstractions/SlotsContainer.tsx +42 -42
  12. package/src/components/Button.tsx +29 -29
  13. package/src/components/Chat/Chat.tsx +193 -193
  14. package/src/components/CheckButton.tsx +65 -65
  15. package/src/components/DraggableContainer.tsx +150 -150
  16. package/src/components/Dropdown.tsx +57 -57
  17. package/src/components/Equipment/EquipmentSet.tsx +180 -179
  18. package/src/components/Input.tsx +11 -11
  19. package/src/components/Item/Cards/ItemCard.tsx +36 -36
  20. package/src/components/Item/Inventory/ItemContainer.tsx +113 -113
  21. package/src/components/Item/Inventory/ItemSlot.tsx +158 -158
  22. package/src/components/Item/Inventory/itemContainerHelper.ts +81 -81
  23. package/src/components/ListMenu.tsx +65 -65
  24. package/src/components/Multitab/Tab.tsx +57 -57
  25. package/src/components/Multitab/TabBody.tsx +13 -13
  26. package/src/components/Multitab/TabsContainer.tsx +97 -97
  27. package/src/components/NPCDialog/NPCDialog.tsx +145 -145
  28. package/src/components/NPCDialog/NPCDialogText.tsx +53 -53
  29. package/src/components/NPCDialog/QuestionDialog/QuestionDialog.tsx +242 -242
  30. package/src/components/ProgressBar.tsx +91 -91
  31. package/src/components/RPGUIContainer.tsx +47 -47
  32. package/src/components/RPGUIRoot.tsx +14 -14
  33. package/src/components/RadioButton.tsx +53 -53
  34. package/src/components/RangeSlider.tsx +68 -68
  35. package/src/components/ScrollList.tsx +77 -77
  36. package/src/components/SimpleProgressBar.tsx +62 -62
  37. package/src/components/SkillProgressBar.tsx +124 -124
  38. package/src/components/SkillsContainer.tsx +235 -235
  39. package/src/components/TextArea.tsx +11 -11
  40. package/src/components/Truncate.tsx +25 -25
  41. package/src/components/shared/Column.tsx +16 -16
  42. package/src/components/shared/SpriteFromAtlas.tsx +99 -99
  43. package/src/components/shared/SpriteIcon.tsx +67 -67
  44. package/src/components/store/UI.store.ts +232 -192
  45. package/src/components/typography/DynamicText.tsx +49 -49
  46. package/src/constants/uiColors.ts +10 -10
  47. package/src/hooks/useEventListener.ts +21 -21
  48. package/src/hooks/useOutsideAlerter.ts +25 -25
  49. package/src/index.tsx +25 -25
  50. package/src/libs/StringHelpers.ts +3 -3
  51. package/src/mocks/atlas/icons/icons.json +303 -303
  52. package/src/mocks/atlas/items/items.json +5195 -5195
  53. package/src/mocks/equipmentSet.mocks.ts +347 -347
  54. package/src/mocks/itemContainer.mocks.ts +249 -249
  55. package/src/mocks/skills.mocks.ts +122 -122
  56. package/src/types/eventTypes.ts +4 -4
  57. package/src/types/index.d.ts +2 -2
@@ -1,242 +1,242 @@
1
- import React, { useEffect, useState } from 'react';
2
- import styled from 'styled-components';
3
- import { useEventListener } from '../../../hooks/useEventListener';
4
- import { DynamicText } from '../../typography/DynamicText';
5
-
6
- export interface IQuestionDialogAnswer {
7
- id: number;
8
- text: string;
9
- nextQuestionId?: number;
10
- }
11
-
12
- export interface IQuestionDialog {
13
- id: number;
14
- text: string;
15
- answerIds?: number[];
16
- }
17
-
18
- export interface IProps {
19
- questions: IQuestionDialog[];
20
- answers: IQuestionDialogAnswer[];
21
- onClose: () => void;
22
- }
23
-
24
- export const QuestionDialog: React.FC<IProps> = ({
25
- questions,
26
- answers,
27
- onClose,
28
- }) => {
29
- const [currentQuestion, setCurrentQuestion] = useState(questions[0]);
30
-
31
- const [canShowAnswers, setCanShowAnswers] = useState<boolean>(false);
32
-
33
- const onGetFirstAnswer = () => {
34
- if (!currentQuestion.answerIds || currentQuestion.answerIds.length === 0) {
35
- return null;
36
- }
37
-
38
- const firstAnswerId = currentQuestion.answerIds![0];
39
-
40
- return answers.find(answer => answer.id === firstAnswerId);
41
- };
42
-
43
- const [
44
- currentAnswer,
45
- setCurrentAnswer,
46
- ] = useState<IQuestionDialogAnswer | null>(onGetFirstAnswer()!);
47
-
48
- useEffect(() => {
49
- setCurrentAnswer(onGetFirstAnswer()!);
50
- }, [currentQuestion]);
51
-
52
- const onGetAnswers = (answerIds: number[]) => {
53
- return answerIds.map((answerId: number) =>
54
- answers.find(answer => answer.id === answerId)
55
- );
56
- };
57
-
58
- const onKeyPress = (e: KeyboardEvent) => {
59
- switch (e.key) {
60
- case 'ArrowDown':
61
- // select next answer, if any.
62
- // if no next answer, select first answer
63
- // const nextAnswer = onGetAnswers(currentQuestion.answerIds!).find(
64
- // (answer) => answer?.id === currentAnswer!.id + 1
65
- // );
66
-
67
- const nextAnswerIndex = onGetAnswers(
68
- currentQuestion.answerIds!
69
- ).findIndex(answer => answer?.id === currentAnswer!.id + 1);
70
-
71
- const nextAnswerID = currentQuestion.answerIds![nextAnswerIndex];
72
-
73
- // console.log(nextAnswerIndex);
74
-
75
- const nextAnswer = onGetAnswers(currentQuestion.answerIds!).find(
76
- answer => answer?.id === nextAnswerID
77
- );
78
-
79
- setCurrentAnswer(nextAnswer || onGetFirstAnswer()!);
80
-
81
- break;
82
- case 'ArrowUp':
83
- // select previous answer, if any.
84
- // if no previous answer, select last answer
85
-
86
- const previousAnswerIndex = onGetAnswers(
87
- currentQuestion.answerIds!
88
- ).findIndex(answer => answer?.id === currentAnswer!.id - 1);
89
-
90
- const previousAnswerID =
91
- currentQuestion.answerIds &&
92
- currentQuestion.answerIds[previousAnswerIndex];
93
-
94
- const previousAnswer = onGetAnswers(currentQuestion.answerIds!).find(
95
- answer => answer?.id === previousAnswerID
96
- );
97
-
98
- if (previousAnswer) {
99
- setCurrentAnswer(previousAnswer);
100
- } else {
101
- setCurrentAnswer(onGetAnswers(currentQuestion.answerIds!).pop()!);
102
- }
103
-
104
- break;
105
- case 'Enter':
106
- setCanShowAnswers(false);
107
-
108
- if (!currentAnswer?.nextQuestionId) {
109
- onClose();
110
- return;
111
- } else {
112
- setCurrentQuestion(
113
- questions.find(
114
- question => question.id === currentAnswer!.nextQuestionId
115
- )!
116
- );
117
- }
118
-
119
- break;
120
- }
121
- };
122
- useEventListener('keydown', onKeyPress);
123
-
124
- const onAnswerClick = (answer: IQuestionDialogAnswer) => {
125
- setCanShowAnswers(false);
126
- if (answer.nextQuestionId) {
127
- // if there is a next question, go to it
128
- setCurrentQuestion(
129
- questions.find(question => question.id === answer.nextQuestionId)!
130
- );
131
- } else {
132
- // else, finish dialog!
133
- onClose();
134
- }
135
- };
136
-
137
- const onRenderCurrentAnswers = () => {
138
- const answerIds = currentQuestion.answerIds;
139
- if (!answerIds) {
140
- return null;
141
- }
142
-
143
- const answers = onGetAnswers(answerIds);
144
-
145
- if (!answers) {
146
- return null;
147
- }
148
-
149
- return answers.map(answer => {
150
- const isSelected = currentAnswer?.id === answer?.id;
151
- const selectedColor = isSelected ? 'yellow' : 'white';
152
-
153
- if (answer) {
154
- return (
155
- <AnswerRow key={`answer_${answer.id}`}>
156
- <AnswerSelectedIcon color={selectedColor}>
157
- {isSelected ? 'X' : null}
158
- </AnswerSelectedIcon>
159
-
160
- <Answer
161
- key={answer.id}
162
- onClick={() => onAnswerClick(answer)}
163
- color={selectedColor}
164
- >
165
- {answer.text}
166
- </Answer>
167
- </AnswerRow>
168
- );
169
- }
170
-
171
- return null;
172
- });
173
- };
174
-
175
- return (
176
- <Container>
177
- <QuestionContainer>
178
- <DynamicText
179
- text={currentQuestion.text}
180
- onStart={() => setCanShowAnswers(false)}
181
- onFinish={() => setCanShowAnswers(true)}
182
- />
183
- </QuestionContainer>
184
-
185
- {canShowAnswers && (
186
- <AnswersContainer>{onRenderCurrentAnswers()}</AnswersContainer>
187
- )}
188
- </Container>
189
- );
190
- };
191
-
192
- const Container = styled.div`
193
- display: flex;
194
-
195
- word-break: break-all;
196
-
197
- box-sizing: border-box;
198
- justify-content: flex-start;
199
- align-items: flex-start;
200
- flex-wrap: wrap;
201
- `;
202
-
203
- const QuestionContainer = styled.div`
204
- flex: 100%;
205
- width: 100%;
206
- `;
207
-
208
- const AnswersContainer = styled.div`
209
- flex: 100%;
210
- `;
211
-
212
- interface IAnswerProps {
213
- color: string;
214
- }
215
-
216
- const Answer = styled.p<IAnswerProps>`
217
- flex: auto;
218
- color: ${props => props.color} !important;
219
- font-size: 0.65rem !important;
220
- background: inherit;
221
- border: none;
222
- `;
223
-
224
- const AnswerSelectedIcon = styled.span<IAnswerProps>`
225
- flex: 5% 0 0;
226
- color: ${props => props.color} !important;
227
- `;
228
-
229
- const AnswerRow = styled.div`
230
- display: flex;
231
- flex-wrap: wrap;
232
- justify-content: center;
233
- align-items: center;
234
- margin-bottom: 0.5rem;
235
- height: 22px;
236
-
237
- p {
238
- line-height: unset;
239
- margin-top: 0;
240
- margin-bottom: 0rem;
241
- }
242
- `;
1
+ import React, { useEffect, useState } from 'react';
2
+ import styled from 'styled-components';
3
+ import { useEventListener } from '../../../hooks/useEventListener';
4
+ import { DynamicText } from '../../typography/DynamicText';
5
+
6
+ export interface IQuestionDialogAnswer {
7
+ id: number;
8
+ text: string;
9
+ nextQuestionId?: number;
10
+ }
11
+
12
+ export interface IQuestionDialog {
13
+ id: number;
14
+ text: string;
15
+ answerIds?: number[];
16
+ }
17
+
18
+ export interface IProps {
19
+ questions: IQuestionDialog[];
20
+ answers: IQuestionDialogAnswer[];
21
+ onClose: () => void;
22
+ }
23
+
24
+ export const QuestionDialog: React.FC<IProps> = ({
25
+ questions,
26
+ answers,
27
+ onClose,
28
+ }) => {
29
+ const [currentQuestion, setCurrentQuestion] = useState(questions[0]);
30
+
31
+ const [canShowAnswers, setCanShowAnswers] = useState<boolean>(false);
32
+
33
+ const onGetFirstAnswer = () => {
34
+ if (!currentQuestion.answerIds || currentQuestion.answerIds.length === 0) {
35
+ return null;
36
+ }
37
+
38
+ const firstAnswerId = currentQuestion.answerIds![0];
39
+
40
+ return answers.find(answer => answer.id === firstAnswerId);
41
+ };
42
+
43
+ const [
44
+ currentAnswer,
45
+ setCurrentAnswer,
46
+ ] = useState<IQuestionDialogAnswer | null>(onGetFirstAnswer()!);
47
+
48
+ useEffect(() => {
49
+ setCurrentAnswer(onGetFirstAnswer()!);
50
+ }, [currentQuestion]);
51
+
52
+ const onGetAnswers = (answerIds: number[]) => {
53
+ return answerIds.map((answerId: number) =>
54
+ answers.find(answer => answer.id === answerId)
55
+ );
56
+ };
57
+
58
+ const onKeyPress = (e: KeyboardEvent) => {
59
+ switch (e.key) {
60
+ case 'ArrowDown':
61
+ // select next answer, if any.
62
+ // if no next answer, select first answer
63
+ // const nextAnswer = onGetAnswers(currentQuestion.answerIds!).find(
64
+ // (answer) => answer?.id === currentAnswer!.id + 1
65
+ // );
66
+
67
+ const nextAnswerIndex = onGetAnswers(
68
+ currentQuestion.answerIds!
69
+ ).findIndex(answer => answer?.id === currentAnswer!.id + 1);
70
+
71
+ const nextAnswerID = currentQuestion.answerIds![nextAnswerIndex];
72
+
73
+ // console.log(nextAnswerIndex);
74
+
75
+ const nextAnswer = onGetAnswers(currentQuestion.answerIds!).find(
76
+ answer => answer?.id === nextAnswerID
77
+ );
78
+
79
+ setCurrentAnswer(nextAnswer || onGetFirstAnswer()!);
80
+
81
+ break;
82
+ case 'ArrowUp':
83
+ // select previous answer, if any.
84
+ // if no previous answer, select last answer
85
+
86
+ const previousAnswerIndex = onGetAnswers(
87
+ currentQuestion.answerIds!
88
+ ).findIndex(answer => answer?.id === currentAnswer!.id - 1);
89
+
90
+ const previousAnswerID =
91
+ currentQuestion.answerIds &&
92
+ currentQuestion.answerIds[previousAnswerIndex];
93
+
94
+ const previousAnswer = onGetAnswers(currentQuestion.answerIds!).find(
95
+ answer => answer?.id === previousAnswerID
96
+ );
97
+
98
+ if (previousAnswer) {
99
+ setCurrentAnswer(previousAnswer);
100
+ } else {
101
+ setCurrentAnswer(onGetAnswers(currentQuestion.answerIds!).pop()!);
102
+ }
103
+
104
+ break;
105
+ case 'Enter':
106
+ setCanShowAnswers(false);
107
+
108
+ if (!currentAnswer?.nextQuestionId) {
109
+ onClose();
110
+ return;
111
+ } else {
112
+ setCurrentQuestion(
113
+ questions.find(
114
+ question => question.id === currentAnswer!.nextQuestionId
115
+ )!
116
+ );
117
+ }
118
+
119
+ break;
120
+ }
121
+ };
122
+ useEventListener('keydown', onKeyPress);
123
+
124
+ const onAnswerClick = (answer: IQuestionDialogAnswer) => {
125
+ setCanShowAnswers(false);
126
+ if (answer.nextQuestionId) {
127
+ // if there is a next question, go to it
128
+ setCurrentQuestion(
129
+ questions.find(question => question.id === answer.nextQuestionId)!
130
+ );
131
+ } else {
132
+ // else, finish dialog!
133
+ onClose();
134
+ }
135
+ };
136
+
137
+ const onRenderCurrentAnswers = () => {
138
+ const answerIds = currentQuestion.answerIds;
139
+ if (!answerIds) {
140
+ return null;
141
+ }
142
+
143
+ const answers = onGetAnswers(answerIds);
144
+
145
+ if (!answers) {
146
+ return null;
147
+ }
148
+
149
+ return answers.map(answer => {
150
+ const isSelected = currentAnswer?.id === answer?.id;
151
+ const selectedColor = isSelected ? 'yellow' : 'white';
152
+
153
+ if (answer) {
154
+ return (
155
+ <AnswerRow key={`answer_${answer.id}`}>
156
+ <AnswerSelectedIcon color={selectedColor}>
157
+ {isSelected ? 'X' : null}
158
+ </AnswerSelectedIcon>
159
+
160
+ <Answer
161
+ key={answer.id}
162
+ onClick={() => onAnswerClick(answer)}
163
+ color={selectedColor}
164
+ >
165
+ {answer.text}
166
+ </Answer>
167
+ </AnswerRow>
168
+ );
169
+ }
170
+
171
+ return null;
172
+ });
173
+ };
174
+
175
+ return (
176
+ <Container>
177
+ <QuestionContainer>
178
+ <DynamicText
179
+ text={currentQuestion.text}
180
+ onStart={() => setCanShowAnswers(false)}
181
+ onFinish={() => setCanShowAnswers(true)}
182
+ />
183
+ </QuestionContainer>
184
+
185
+ {canShowAnswers && (
186
+ <AnswersContainer>{onRenderCurrentAnswers()}</AnswersContainer>
187
+ )}
188
+ </Container>
189
+ );
190
+ };
191
+
192
+ const Container = styled.div`
193
+ display: flex;
194
+
195
+ word-break: break-all;
196
+
197
+ box-sizing: border-box;
198
+ justify-content: flex-start;
199
+ align-items: flex-start;
200
+ flex-wrap: wrap;
201
+ `;
202
+
203
+ const QuestionContainer = styled.div`
204
+ flex: 100%;
205
+ width: 100%;
206
+ `;
207
+
208
+ const AnswersContainer = styled.div`
209
+ flex: 100%;
210
+ `;
211
+
212
+ interface IAnswerProps {
213
+ color: string;
214
+ }
215
+
216
+ const Answer = styled.p<IAnswerProps>`
217
+ flex: auto;
218
+ color: ${props => props.color} !important;
219
+ font-size: 0.65rem !important;
220
+ background: inherit;
221
+ border: none;
222
+ `;
223
+
224
+ const AnswerSelectedIcon = styled.span<IAnswerProps>`
225
+ flex: 5% 0 0;
226
+ color: ${props => props.color} !important;
227
+ `;
228
+
229
+ const AnswerRow = styled.div`
230
+ display: flex;
231
+ flex-wrap: wrap;
232
+ justify-content: center;
233
+ align-items: center;
234
+ margin-bottom: 0.5rem;
235
+ height: 22px;
236
+
237
+ p {
238
+ line-height: unset;
239
+ margin-top: 0;
240
+ margin-bottom: 0rem;
241
+ }
242
+ `;
@@ -1,91 +1,91 @@
1
- import React from 'react';
2
- import styled from 'styled-components';
3
-
4
- export interface IBarProps {
5
- max: number;
6
- value: number;
7
- color: 'red' | 'blue' | 'green';
8
- style?: Record<string, any>;
9
- displayText?: boolean;
10
- percentageWidth?: number;
11
- minWidth?: number;
12
- }
13
-
14
- export const ProgressBar: React.FC<IBarProps> = ({
15
- max,
16
- value,
17
- color,
18
- displayText = true,
19
- percentageWidth = 40,
20
- minWidth = 100,
21
- style,
22
- }) => {
23
- const calculatePercentageValue = function(max: number, value: number) {
24
- if (value > max) {
25
- value = max;
26
- }
27
- return (value * 100) / max;
28
- };
29
-
30
- return (
31
- <Container
32
- className="rpgui-progress"
33
- data-value={calculatePercentageValue(max, value) / 100}
34
- data-rpguitype="progress"
35
- percentageWidth={percentageWidth}
36
- minWidth={minWidth}
37
- style={style}
38
- >
39
- {displayText && (
40
- <TextOverlay>
41
- <ProgressBarText>
42
- {value}/{max}
43
- </ProgressBarText>
44
- </TextOverlay>
45
- )}
46
- <div className=" rpgui-progress-track">
47
- <div
48
- className={`rpgui-progress-fill ${color} `}
49
- style={{
50
- left: '0px',
51
- width: calculatePercentageValue(max, value) + '%',
52
- }}
53
- ></div>
54
- </div>
55
- <div className=" rpgui-progress-left-edge"></div>
56
- <div className=" rpgui-progress-right-edge"></div>
57
- </Container>
58
- );
59
- };
60
-
61
- const ProgressBarText = styled.span`
62
- font-size: 1rem;
63
- color: white;
64
- text-align: center;
65
- z-index: 1;
66
- position: absolute;
67
- left: 50%;
68
- transform: translateX(-50%);
69
- top: 12px;
70
- `;
71
-
72
- const TextOverlay = styled.div`
73
- width: 100%;
74
- position: relative;
75
- `;
76
-
77
- interface IContainerProps {
78
- percentageWidth?: number;
79
- minWidth?: number;
80
- style?: Record<string, any>;
81
- }
82
-
83
- const Container = styled.div<IContainerProps>`
84
- display: flex;
85
- flex-direction: column;
86
- min-width: ${props => props.minWidth}px;
87
- width: ${props => props.percentageWidth}%;
88
- justify-content: start;
89
- align-items: flex-start;
90
- ${props => props.style}
91
- `;
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ export interface IBarProps {
5
+ max: number;
6
+ value: number;
7
+ color: 'red' | 'blue' | 'green';
8
+ style?: Record<string, any>;
9
+ displayText?: boolean;
10
+ percentageWidth?: number;
11
+ minWidth?: number;
12
+ }
13
+
14
+ export const ProgressBar: React.FC<IBarProps> = ({
15
+ max,
16
+ value,
17
+ color,
18
+ displayText = true,
19
+ percentageWidth = 40,
20
+ minWidth = 100,
21
+ style,
22
+ }) => {
23
+ const calculatePercentageValue = function(max: number, value: number) {
24
+ if (value > max) {
25
+ value = max;
26
+ }
27
+ return (value * 100) / max;
28
+ };
29
+
30
+ return (
31
+ <Container
32
+ className="rpgui-progress"
33
+ data-value={calculatePercentageValue(max, value) / 100}
34
+ data-rpguitype="progress"
35
+ percentageWidth={percentageWidth}
36
+ minWidth={minWidth}
37
+ style={style}
38
+ >
39
+ {displayText && (
40
+ <TextOverlay>
41
+ <ProgressBarText>
42
+ {value}/{max}
43
+ </ProgressBarText>
44
+ </TextOverlay>
45
+ )}
46
+ <div className=" rpgui-progress-track">
47
+ <div
48
+ className={`rpgui-progress-fill ${color} `}
49
+ style={{
50
+ left: '0px',
51
+ width: calculatePercentageValue(max, value) + '%',
52
+ }}
53
+ ></div>
54
+ </div>
55
+ <div className=" rpgui-progress-left-edge"></div>
56
+ <div className=" rpgui-progress-right-edge"></div>
57
+ </Container>
58
+ );
59
+ };
60
+
61
+ const ProgressBarText = styled.span`
62
+ font-size: 1rem;
63
+ color: white;
64
+ text-align: center;
65
+ z-index: 1;
66
+ position: absolute;
67
+ left: 50%;
68
+ transform: translateX(-50%);
69
+ top: 12px;
70
+ `;
71
+
72
+ const TextOverlay = styled.div`
73
+ width: 100%;
74
+ position: relative;
75
+ `;
76
+
77
+ interface IContainerProps {
78
+ percentageWidth?: number;
79
+ minWidth?: number;
80
+ style?: Record<string, any>;
81
+ }
82
+
83
+ const Container = styled.div<IContainerProps>`
84
+ display: flex;
85
+ flex-direction: column;
86
+ min-width: ${props => props.minWidth}px;
87
+ width: ${props => props.percentageWidth}%;
88
+ justify-content: start;
89
+ align-items: flex-start;
90
+ ${props => props.style}
91
+ `;