@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,192 +1,232 @@
1
- import {
2
- IItem,
3
- IPayloadProps,
4
- ItemSocketEvents,
5
- ItemSocketEventsDisplayLabels,
6
- ItemType,
7
- } from '@rpg-engine/shared';
8
- import { makeAutoObservable, toJS } from 'mobx';
9
- import {
10
- handleContextMenuList,
11
- handleEquipmentContextMenuList,
12
- IContextMenuItem,
13
- } from '../Item/Inventory/itemContainerHelper';
14
- import { SlotContainerType } from '../Item/Inventory/ItemSlot';
15
-
16
- interface IContextMenu {
17
- visible: boolean;
18
- posX: number;
19
- posY: number;
20
- slotItem: IItem | null;
21
- slotIndex?: number | null;
22
- contextActions: IContextMenuItem[];
23
- }
24
-
25
- interface IHoverDetail {
26
- visible: boolean;
27
- posX: number;
28
- posY: number;
29
- item: IItem | null;
30
- }
31
-
32
- interface ISetContextMenu extends Omit<IContextMenu, 'contextActions'> {}
33
-
34
- const initialState = {
35
- visible: false,
36
- posX: 0,
37
- posY: 0,
38
- contextActions: [],
39
- slotItem: null,
40
- };
41
-
42
- const initialHoverState = {
43
- visible: false,
44
- posX: 0,
45
- posY: 0,
46
- item: null,
47
- };
48
- class UIStore {
49
- public contextMenu: IContextMenu | null = initialState;
50
-
51
- public onHoverDetail: IHoverDetail | null = initialHoverState;
52
-
53
- constructor() {
54
- makeAutoObservable(this);
55
- }
56
-
57
- public setContextMenu(contextMenu: ISetContextMenu, itemType: ItemType) {
58
- const contextActions = handleContextMenuList(itemType);
59
-
60
- this.contextMenu = {
61
- ...contextMenu,
62
- contextActions,
63
- };
64
-
65
- console.log(toJS(this.contextMenu));
66
- }
67
-
68
- public setEquipContextMenu(
69
- contextMenu: ISetContextMenu,
70
- itemType: ItemType,
71
- isItemContainer: boolean | undefined
72
- ) {
73
- const contextActions = handleEquipmentContextMenuList(itemType);
74
- if (isItemContainer)
75
- contextActions.push({
76
- id: ItemSocketEvents.ContainerOpen,
77
- text: ItemSocketEventsDisplayLabels[ItemSocketEvents.ContainerOpen],
78
- });
79
- this.contextMenu = {
80
- ...contextMenu,
81
- contextActions,
82
- };
83
-
84
- console.log(toJS(this.contextMenu));
85
- }
86
-
87
- public clearContextMenu() {
88
- this.contextMenu = initialState;
89
- }
90
-
91
- public setItemHoverDetail(hoverDetail: IHoverDetail) {
92
- if (hoverDetail?.item === null) this.clearItemHoverDetail();
93
-
94
- this.onHoverDetail = {
95
- ...hoverDetail,
96
- };
97
- }
98
-
99
- public clearItemHoverDetail() {
100
- this.onHoverDetail = initialHoverState;
101
- }
102
-
103
- public handleOnItemClick = (
104
- item: IItem,
105
- posX: number,
106
- posY: number,
107
- slotContainerType: SlotContainerType | null
108
- ): void => {
109
- if (
110
- !item ||
111
- JSON.stringify(this.contextMenu?.slotItem) === JSON.stringify(item)
112
- ) {
113
- this.clearContextMenu();
114
- this.clearItemHoverDetail();
115
- return;
116
- }
117
- switch (slotContainerType) {
118
- case SlotContainerType.EQUIPMENT_SET:
119
- this.setEquipContextMenu(
120
- {
121
- visible: true,
122
- posX,
123
- posY,
124
- slotItem: item,
125
- },
126
- item.type,
127
- item.isItemContainer
128
- );
129
- break;
130
- case SlotContainerType.INVENTORY:
131
- this.setContextMenu(
132
- {
133
- visible: true,
134
- posX,
135
- posY,
136
- slotItem: item,
137
- },
138
- item.type
139
- );
140
- break;
141
- default:
142
- this.setContextMenu(
143
- {
144
- visible: true,
145
- posX,
146
- posY,
147
- slotItem: item,
148
- },
149
- item.type
150
- );
151
- }
152
-
153
- this.clearItemHoverDetail();
154
- };
155
-
156
- public handleOnMouseHover = (
157
- event: any,
158
- slotIndex: number,
159
- item: IItem | null,
160
- posX: number,
161
- posY: number,
162
- onMouseOver: any
163
- ): void => {
164
- if (item) {
165
- this.setItemHoverDetail({
166
- visible: true,
167
- posX,
168
- posY,
169
- item: item,
170
- });
171
- }
172
- if (onMouseOver) {
173
- onMouseOver(event, slotIndex, item);
174
- }
175
- };
176
-
177
- public onSelected(
178
- selectedActionId: ItemSocketEvents | string,
179
- onActionSelected: any
180
- ) {
181
- let payloadData: IPayloadProps = {
182
- actionType: selectedActionId,
183
- item: this.contextMenu?.slotItem!,
184
- };
185
- if (onActionSelected) {
186
- onActionSelected(payloadData);
187
- }
188
- this.clearContextMenu!();
189
- }
190
- }
191
-
192
- export const uiStore = new UIStore();
1
+ import {
2
+ IItem,
3
+ IPayloadProps,
4
+ ItemSocketEvents,
5
+ ItemSocketEventsDisplayLabels,
6
+ ItemType,
7
+ } from '@rpg-engine/shared';
8
+ import { makeAutoObservable, toJS } from 'mobx';
9
+ import { IPosition } from '../../types/eventTypes';
10
+ import {
11
+ handleContextMenuList,
12
+ handleEquipmentContextMenuList,
13
+ IContextMenuItem,
14
+ } from '../Item/Inventory/itemContainerHelper';
15
+ import { SlotContainerType } from '../Item/Inventory/ItemSlot';
16
+
17
+ interface IContextMenu {
18
+ visible: boolean;
19
+ posX: number;
20
+ posY: number;
21
+ slotItem: IItem | null;
22
+ slotIndex?: number | null;
23
+ contextActions: IContextMenuItem[];
24
+ }
25
+
26
+ interface IHoverDetail {
27
+ visible: boolean;
28
+ posX: number;
29
+ posY: number;
30
+ item: IItem | null;
31
+ }
32
+
33
+ interface ISetContextMenu extends Omit<IContextMenu, 'contextActions'> {}
34
+
35
+ const initialState = {
36
+ visible: false,
37
+ posX: 0,
38
+ posY: 0,
39
+ contextActions: [],
40
+ slotItem: null,
41
+ };
42
+
43
+ const initialHoverState = {
44
+ visible: false,
45
+ posX: 0,
46
+ posY: 0,
47
+ item: null,
48
+ };
49
+
50
+ const initialPosition = {
51
+ x: 0,
52
+ y: 0
53
+ }
54
+ class UIStore {
55
+ public contextMenu: IContextMenu | null = initialState;
56
+ public onHoverDetail: IHoverDetail | null = initialHoverState;
57
+
58
+ public draggablePosition: IPosition = initialPosition;
59
+
60
+
61
+ constructor() {
62
+ makeAutoObservable(this);
63
+ }
64
+
65
+ public setContextMenu(contextMenu: ISetContextMenu, itemType: ItemType) {
66
+ const contextActions = handleContextMenuList(itemType);
67
+
68
+ this.contextMenu = {
69
+ ...contextMenu,
70
+ contextActions,
71
+ };
72
+
73
+ console.log(toJS(this.contextMenu));
74
+ }
75
+
76
+ public setEquipContextMenu(
77
+ contextMenu: ISetContextMenu,
78
+ itemType: ItemType,
79
+ isItemContainer: boolean | undefined
80
+ ) {
81
+ const contextActions = handleEquipmentContextMenuList(itemType);
82
+ if (isItemContainer)
83
+ contextActions.push({
84
+ id: ItemSocketEvents.ContainerOpen,
85
+ text: ItemSocketEventsDisplayLabels[ItemSocketEvents.ContainerOpen],
86
+ });
87
+ this.contextMenu = {
88
+ ...contextMenu,
89
+ contextActions,
90
+ };
91
+
92
+ console.log(toJS(this.contextMenu));
93
+ }
94
+
95
+ public clearContextMenu() {
96
+ this.contextMenu = initialState;
97
+ }
98
+
99
+ public setItemHoverDetail(hoverDetail: IHoverDetail) {
100
+ if (hoverDetail?.item === null) this.clearItemHoverDetail();
101
+
102
+ this.onHoverDetail = {
103
+ ...hoverDetail,
104
+ };
105
+ }
106
+
107
+ public clearItemHoverDetail() {
108
+ this.onHoverDetail = initialHoverState;
109
+ }
110
+
111
+ public handleOnItemClick = (
112
+ item: IItem,
113
+ posX: number,
114
+ posY: number,
115
+ slotContainerType: SlotContainerType | null
116
+ ): void => {
117
+ if (
118
+ !item ||
119
+ JSON.stringify(this.contextMenu?.slotItem) === JSON.stringify(item)
120
+ ) {
121
+ this.clearContextMenu();
122
+ this.clearItemHoverDetail();
123
+ return;
124
+ }
125
+
126
+ this.setDraggablePosition(this.getOffsets())
127
+
128
+ switch (slotContainerType) {
129
+ case SlotContainerType.EQUIPMENT_SET:
130
+ this.setEquipContextMenu(
131
+ {
132
+ visible: true,
133
+ posX,
134
+ posY,
135
+ slotItem: item,
136
+ },
137
+ item.type,
138
+ item.isItemContainer
139
+ );
140
+ break;
141
+ case SlotContainerType.INVENTORY:
142
+ this.setContextMenu(
143
+ {
144
+ visible: true,
145
+ posX,
146
+ posY,
147
+ slotItem: item,
148
+ },
149
+ item.type
150
+ );
151
+ break;
152
+ default:
153
+ this.setContextMenu(
154
+ {
155
+ visible: true,
156
+ posX,
157
+ posY,
158
+ slotItem: item,
159
+ },
160
+ item.type
161
+ );
162
+ }
163
+
164
+ this.clearItemHoverDetail();
165
+ };
166
+
167
+ public handleOnMouseHover = (
168
+ event: any,
169
+ slotIndex: number,
170
+ item: IItem | null,
171
+ posX: number,
172
+ posY: number,
173
+ onMouseOver: any
174
+ ): void => {
175
+ if (item) {
176
+ this.setDraggablePosition(this.getOffsets())
177
+ this.setItemHoverDetail({
178
+ visible: true,
179
+ posX: posX,
180
+ posY: posY,
181
+ item: item,
182
+ });
183
+ }
184
+ if (onMouseOver) {
185
+ onMouseOver(event, slotIndex, item);
186
+ }
187
+ };
188
+
189
+ public onSelected(
190
+ selectedActionId: ItemSocketEvents | string,
191
+ onActionSelected: any
192
+ ) {
193
+ let payloadData: IPayloadProps = {
194
+ actionType: selectedActionId,
195
+ item: this.contextMenu?.slotItem!,
196
+ };
197
+ if (onActionSelected) {
198
+ onActionSelected(payloadData);
199
+ }
200
+ this.clearContextMenu!();
201
+ }
202
+
203
+ public setDraggablePosition(currentPosition: IPosition){
204
+ this.draggablePosition = { ...currentPosition }
205
+ }
206
+
207
+ private getOffsets = () => {
208
+ const p = { x: 0, y: 0};
209
+ // const body = document.getElementsByTagName('body')
210
+ let body = document.querySelector('body') as any | null;
211
+
212
+ if( body != null){
213
+ p.x = body.offsetLeft;
214
+ p.y = body.offsetTop;
215
+ while(body!.offsetParent){
216
+ console.log(`offsetParent: ${body!.offsetParent}`)
217
+ p.x = p.x + body!.offsetLeft
218
+ p.y = p.y + body!.offsetTop;
219
+ if (body == document.getElementsByTagName("body")[0]) {
220
+ break;
221
+ }
222
+ else {
223
+ body = body!.offsetParent;
224
+ }
225
+ }
226
+ }
227
+ return p;
228
+ }
229
+
230
+ }
231
+
232
+ export const uiStore = new UIStore();
@@ -1,49 +1,49 @@
1
- import React, { useEffect, useState } from 'react';
2
- import styled from 'styled-components';
3
-
4
- interface IProps {
5
- text: string;
6
- onFinish?: () => void;
7
- onStart?: () => void;
8
- }
9
-
10
- export const DynamicText: React.FC<IProps> = ({ text, onFinish, onStart }) => {
11
- const [textState, setTextState] = useState<string>('');
12
-
13
- useEffect(() => {
14
- let i = 0;
15
- const interval = setInterval(() => {
16
- // on every interval, show one more character
17
-
18
- if (i === 0) {
19
- if (onStart) {
20
- onStart();
21
- }
22
- }
23
-
24
- if (i < text.length) {
25
- setTextState(text.substring(0, i + 1));
26
- i++;
27
- } else {
28
- clearInterval(interval);
29
- if (onFinish) {
30
- onFinish();
31
- }
32
- }
33
- }, 50);
34
-
35
- return () => {
36
- clearInterval(interval);
37
- };
38
- }, [text]);
39
-
40
- return <TextContainer>{textState}</TextContainer>;
41
- };
42
-
43
- const TextContainer = styled.p`
44
- font-size: 0.7rem !important;
45
- color: white;
46
- text-shadow: 1px 1px 0px #000000;
47
- letter-spacing: 1.2px;
48
- word-break: normal;
49
- `;
1
+ import React, { useEffect, useState } from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ interface IProps {
5
+ text: string;
6
+ onFinish?: () => void;
7
+ onStart?: () => void;
8
+ }
9
+
10
+ export const DynamicText: React.FC<IProps> = ({ text, onFinish, onStart }) => {
11
+ const [textState, setTextState] = useState<string>('');
12
+
13
+ useEffect(() => {
14
+ let i = 0;
15
+ const interval = setInterval(() => {
16
+ // on every interval, show one more character
17
+
18
+ if (i === 0) {
19
+ if (onStart) {
20
+ onStart();
21
+ }
22
+ }
23
+
24
+ if (i < text.length) {
25
+ setTextState(text.substring(0, i + 1));
26
+ i++;
27
+ } else {
28
+ clearInterval(interval);
29
+ if (onFinish) {
30
+ onFinish();
31
+ }
32
+ }
33
+ }, 50);
34
+
35
+ return () => {
36
+ clearInterval(interval);
37
+ };
38
+ }, [text]);
39
+
40
+ return <TextContainer>{textState}</TextContainer>;
41
+ };
42
+
43
+ const TextContainer = styled.p`
44
+ font-size: 0.7rem !important;
45
+ color: white;
46
+ text-shadow: 1px 1px 0px #000000;
47
+ letter-spacing: 1.2px;
48
+ word-break: normal;
49
+ `;
@@ -1,10 +1,10 @@
1
- export const colors = {
2
- darkGrey: '#3e3e3e',
3
- darkYellow: '#FFC857',
4
- orange: '#E9724C',
5
- cardinal: '#C5283D',
6
- raisinBlack: '#191923',
7
- navyBlue: '#0E79B2',
8
- purple: '#8C3D8C',
9
- blue: '#3772FF',
10
- };
1
+ export const colors = {
2
+ darkGrey: '#3e3e3e',
3
+ darkYellow: '#FFC857',
4
+ orange: '#E9724C',
5
+ cardinal: '#C5283D',
6
+ raisinBlack: '#191923',
7
+ navyBlue: '#0E79B2',
8
+ purple: '#8C3D8C',
9
+ blue: '#3772FF',
10
+ };
@@ -1,21 +1,21 @@
1
- import React from 'react';
2
-
3
- //@ts-ignore
4
- export const useEventListener = (type, handler, el = window) => {
5
- const savedHandler = React.useRef();
6
-
7
- React.useEffect(() => {
8
- savedHandler.current = handler;
9
- }, [handler]);
10
-
11
- React.useEffect(() => {
12
- //@ts-ignore
13
- const listener = e => savedHandler.current(e);
14
-
15
- el.addEventListener(type, listener);
16
-
17
- return () => {
18
- el.removeEventListener(type, listener);
19
- };
20
- }, [type, el]);
21
- };
1
+ import React from 'react';
2
+
3
+ //@ts-ignore
4
+ export const useEventListener = (type, handler, el = window) => {
5
+ const savedHandler = React.useRef();
6
+
7
+ React.useEffect(() => {
8
+ savedHandler.current = handler;
9
+ }, [handler]);
10
+
11
+ React.useEffect(() => {
12
+ //@ts-ignore
13
+ const listener = e => savedHandler.current(e);
14
+
15
+ el.addEventListener(type, listener);
16
+
17
+ return () => {
18
+ el.removeEventListener(type, listener);
19
+ };
20
+ }, [type, el]);
21
+ };
@@ -1,25 +1,25 @@
1
- import { useEffect } from 'react';
2
-
3
- export function useOutsideClick(ref: any, id: string) {
4
- useEffect(() => {
5
- /**
6
- * Alert if clicked on outside of element
7
- */
8
- function handleClickOutside(event: any) {
9
- if (ref.current && !ref.current.contains(event.target)) {
10
- const event = new CustomEvent('clickOutside', {
11
- detail: {
12
- id,
13
- },
14
- });
15
- document.dispatchEvent(event);
16
- }
17
- }
18
- // Bind the event listener
19
- document.addEventListener('mousedown', handleClickOutside);
20
- return () => {
21
- // Unbind the event listener on clean up
22
- document.removeEventListener('mousedown', handleClickOutside);
23
- };
24
- }, [ref]);
25
- }
1
+ import { useEffect } from 'react';
2
+
3
+ export function useOutsideClick(ref: any, id: string) {
4
+ useEffect(() => {
5
+ /**
6
+ * Alert if clicked on outside of element
7
+ */
8
+ function handleClickOutside(event: any) {
9
+ if (ref.current && !ref.current.contains(event.target)) {
10
+ const event = new CustomEvent('clickOutside', {
11
+ detail: {
12
+ id,
13
+ },
14
+ });
15
+ document.dispatchEvent(event);
16
+ }
17
+ }
18
+ // Bind the event listener
19
+ document.addEventListener('mousedown', handleClickOutside);
20
+ return () => {
21
+ // Unbind the event listener on clean up
22
+ document.removeEventListener('mousedown', handleClickOutside);
23
+ };
24
+ }, [ref]);
25
+ }