@rpg-engine/long-bow 0.1.794 → 0.2.2

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 (129) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +181 -181
  3. package/dist/components/Button.d.ts +1 -0
  4. package/dist/components/Equipment/EquipmentSet.d.ts +5 -3
  5. package/dist/components/Item/Cards/ItemTooltip.d.ts +6 -0
  6. package/dist/components/Item/Inventory/ItemContainer.d.ts +4 -6
  7. package/dist/components/Item/Inventory/ItemContainerTypes.d.ts +6 -0
  8. package/dist/components/Item/Inventory/ItemSlot.d.ts +5 -9
  9. package/dist/components/Item/Inventory/itemContainerHelper.d.ts +2 -7
  10. package/dist/components/PropertySelect/PropertySelect.d.ts +12 -0
  11. package/dist/components/QuestInfo/QuestInfo.d.ts +14 -0
  12. package/dist/components/RelativeListMenu.d.ts +13 -0
  13. package/dist/index.d.ts +1 -1
  14. package/dist/long-bow.cjs.development.js +748 -1194
  15. package/dist/long-bow.cjs.development.js.map +1 -1
  16. package/dist/long-bow.cjs.production.min.js +1 -1
  17. package/dist/long-bow.cjs.production.min.js.map +1 -1
  18. package/dist/long-bow.esm.js +748 -1196
  19. package/dist/long-bow.esm.js.map +1 -1
  20. package/dist/mocks/equipmentSet.mocks.d.ts +2 -2
  21. package/dist/stories/Button.stories.d.ts +5 -0
  22. package/dist/stories/Chat.stories.d.ts +5 -0
  23. package/dist/stories/CheckButton.stories.d.ts +5 -0
  24. package/dist/stories/DraggableContainer.stories.d.ts +5 -0
  25. package/dist/stories/Dropdown.stories.d.ts +5 -0
  26. package/dist/stories/EquipmentSet.stories.d.ts +5 -0
  27. package/dist/stories/ItemContainer.stories.d.ts +5 -0
  28. package/dist/stories/ListMenu.stories.d.ts +5 -0
  29. package/dist/stories/Multitab.stories.d.ts +6 -0
  30. package/dist/stories/NPCDialog.stories.d.ts +7 -0
  31. package/dist/stories/ProgressBar.stories.d.ts +8 -0
  32. package/dist/stories/PropertySelect.stories.d.ts +5 -0
  33. package/dist/stories/QuestInfo.stories.d.ts +5 -0
  34. package/dist/stories/RPGUIContainers.stories.d.ts +5 -0
  35. package/dist/stories/RadioButton.stories.d.ts +5 -0
  36. package/dist/stories/RangeSlider.stories.d.ts +5 -0
  37. package/dist/stories/ScrollList.stories.d.ts +5 -0
  38. package/dist/stories/SimpleProgressBar.stories.d.ts +5 -0
  39. package/dist/stories/SkillProgressBar.stories.d.ts +5 -0
  40. package/dist/stories/SkillsContainer.stories.d.ts +5 -0
  41. package/dist/stories/Text.stories.d.ts +7 -0
  42. package/package.json +98 -96
  43. package/src/components/Abstractions/SlotsContainer.tsx +42 -42
  44. package/src/components/Button.tsx +30 -29
  45. package/src/components/Chat/Chat.tsx +193 -193
  46. package/src/components/CheckButton.tsx +65 -65
  47. package/src/components/DraggableContainer.tsx +150 -150
  48. package/src/components/Dropdown.tsx +57 -57
  49. package/src/components/Equipment/EquipmentSet.tsx +138 -180
  50. package/src/components/Input.tsx +11 -11
  51. package/src/components/Item/Cards/ItemTooltip.tsx +32 -0
  52. package/src/components/Item/Inventory/ItemContainer.tsx +68 -113
  53. package/src/components/Item/Inventory/ItemContainerTypes.ts +6 -0
  54. package/src/components/Item/Inventory/ItemSlot.tsx +212 -158
  55. package/src/components/Item/Inventory/itemContainerHelper.ts +146 -81
  56. package/src/components/ListMenu.tsx +65 -65
  57. package/src/components/Multitab/Tab.tsx +57 -57
  58. package/src/components/Multitab/TabBody.tsx +13 -13
  59. package/src/components/Multitab/TabsContainer.tsx +97 -97
  60. package/src/components/NPCDialog/NPCDialog.tsx +145 -145
  61. package/src/components/NPCDialog/NPCDialogText.tsx +53 -53
  62. package/src/components/NPCDialog/QuestionDialog/QuestionDialog.tsx +237 -242
  63. package/src/components/ProgressBar.tsx +91 -91
  64. package/src/components/PropertySelect/PropertySelect.tsx +101 -0
  65. package/src/components/PropertySelect/img/ui-arrows/arrow01-left-clicked.png +0 -0
  66. package/src/components/PropertySelect/img/ui-arrows/arrow01-left.png +0 -0
  67. package/src/components/PropertySelect/img/ui-arrows/arrow01-right-clicked.png +0 -0
  68. package/src/components/PropertySelect/img/ui-arrows/arrow01-right.png +0 -0
  69. package/src/components/PropertySelect/img/ui-arrows/arrow02-left-clicked.png +0 -0
  70. package/src/components/PropertySelect/img/ui-arrows/arrow02-left.png +0 -0
  71. package/src/components/PropertySelect/img/ui-arrows/arrow02-right-clicked.png +0 -0
  72. package/src/components/PropertySelect/img/ui-arrows/arrow02-right.png +0 -0
  73. package/src/components/QuestInfo/QuestInfo.tsx +143 -0
  74. package/src/components/QuestInfo/img/default.png +0 -0
  75. package/src/components/RPGUIContainer.tsx +47 -47
  76. package/src/components/RPGUIRoot.tsx +14 -14
  77. package/src/components/RadioButton.tsx +53 -53
  78. package/src/components/RangeSlider.tsx +68 -68
  79. package/src/components/RelativeListMenu.tsx +83 -0
  80. package/src/components/ScrollList.tsx +77 -77
  81. package/src/components/SimpleProgressBar.tsx +62 -62
  82. package/src/components/SkillProgressBar.tsx +123 -124
  83. package/src/components/SkillsContainer.tsx +196 -235
  84. package/src/components/TextArea.tsx +11 -11
  85. package/src/components/Truncate.tsx +25 -25
  86. package/src/components/shared/Column.tsx +16 -16
  87. package/src/components/shared/SpriteFromAtlas.tsx +99 -99
  88. package/src/components/typography/DynamicText.tsx +49 -49
  89. package/src/constants/uiColors.ts +10 -10
  90. package/src/hooks/useEventListener.ts +21 -21
  91. package/src/hooks/useOutsideAlerter.ts +25 -25
  92. package/src/index.tsx +25 -25
  93. package/src/libs/StringHelpers.ts +3 -3
  94. package/src/mocks/atlas/icons/icons.json +735 -303
  95. package/src/mocks/atlas/icons/icons.png +0 -0
  96. package/src/mocks/atlas/items/items.json +5215 -5195
  97. package/src/mocks/atlas/items/items.png +0 -0
  98. package/src/mocks/equipmentSet.mocks.ts +347 -347
  99. package/src/mocks/itemContainer.mocks.ts +281 -249
  100. package/src/mocks/skills.mocks.ts +122 -122
  101. package/src/stories/Button.stories.tsx +36 -0
  102. package/src/stories/Chat.stories.tsx +170 -0
  103. package/src/stories/CheckButton.stories.tsx +48 -0
  104. package/src/stories/DraggableContainer.stories.tsx +28 -0
  105. package/src/stories/Dropdown.stories.tsx +46 -0
  106. package/src/stories/EquipmentSet.stories.tsx +51 -0
  107. package/src/stories/ItemContainer.stories.tsx +51 -0
  108. package/src/stories/ListMenu.stories.tsx +56 -0
  109. package/src/stories/Multitab.stories.tsx +51 -0
  110. package/src/stories/NPCDialog.stories.tsx +130 -0
  111. package/src/stories/ProgressBar.stories.tsx +23 -0
  112. package/src/stories/PropertySelect.stories.tsx +41 -0
  113. package/src/stories/QuestInfo.stories.tsx +76 -0
  114. package/src/stories/RPGUIContainers.stories.tsx +42 -0
  115. package/src/stories/RadioButton.stories.tsx +49 -0
  116. package/src/stories/RangeSlider.stories.tsx +60 -0
  117. package/src/stories/ScrollList.stories.tsx +85 -0
  118. package/src/stories/SimpleProgressBar.stories.tsx +22 -0
  119. package/src/stories/SkillProgressBar.stories.tsx +30 -0
  120. package/src/stories/SkillsContainer.stories.tsx +31 -0
  121. package/src/stories/Text.stories.tsx +42 -0
  122. package/src/types/eventTypes.ts +4 -4
  123. package/src/types/index.d.ts +2 -2
  124. package/dist/components/Item/Cards/ItemCard.d.ts +0 -9
  125. package/dist/components/shared/SpriteIcon.d.ts +0 -9
  126. package/dist/components/store/UI.store.d.ts +0 -38
  127. package/src/components/Item/Cards/ItemCard.tsx +0 -36
  128. package/src/components/shared/SpriteIcon.tsx +0 -67
  129. package/src/components/store/UI.store.ts +0 -232
@@ -1,158 +1,212 @@
1
- import { IItem, IItemContainer, ItemSlotType } from '@rpg-engine/shared';
2
- import React from 'react';
3
- import styled from 'styled-components';
4
- import atlasJSON from '../../../mocks/atlas/items/items.json';
5
- import atlasIMG from '../../../mocks/atlas/items/items.png';
6
- import { SpriteFromAtlas } from '../../shared/SpriteFromAtlas';
7
-
8
- export enum SlotContainerType {
9
- INVENTORY = 'Inventory',
10
- EQUIPMENT_SET = 'EquipmentSet',
11
- }
12
-
13
- const EquipmentSlotSpriteByType: any = {
14
- Neck: 'accessories/corruption-necklace.png',
15
- LeftHand: 'swords/broad-sword.png',
16
- Ring: 'rings/iron-ring.png',
17
- Head: 'helmets/viking-helmet.png',
18
- Torso: 'armors/iron-armor.png',
19
- Legs: 'legs/studded-legs.png',
20
- Feet: 'boots/iron-boots.png',
21
- Inventory: 'containers/bag.png',
22
- RightHand: 'shields/plate-shield.png',
23
- Accessory: 'gloves/plate-gloves.png',
24
- };
25
-
26
- interface IProps {
27
- slotIndex: number;
28
- item: IItem | null;
29
- itemContainer?: IItemContainer | null;
30
- slotContainerType: SlotContainerType | null;
31
- slotSpriteMask?: ItemSlotType | null;
32
- onMouseOver: (
33
- event: any,
34
- slotIndex: number,
35
- item: IItem | null,
36
- x: number,
37
- y: number
38
- ) => void;
39
- onMouseOut: () => void;
40
- onClick: (
41
- item: IItem,
42
- posX: number,
43
- posY: number,
44
- slotContainerType: SlotContainerType | null
45
- ) => void;
46
- onCancelContextMenu: () => void;
47
- }
48
-
49
- export const ItemSlot: React.FC<IProps> = ({
50
- slotIndex,
51
- item,
52
- slotContainerType,
53
- slotSpriteMask,
54
- onMouseOver,
55
- onMouseOut,
56
- onClick,
57
- onCancelContextMenu,
58
- }) => {
59
- const getLeftPositionValue = (quantity: number) => {
60
- if (quantity > 0 && quantity < 10) return '2.5rem';
61
- else if (quantity > 9 && quantity < 100) return '2.0rem';
62
- else if (quantity > 99) return '1rem';
63
- return '2.5rem';
64
- };
65
-
66
- const renderItem = (itemToRender: IItem | null) => {
67
- const element = [];
68
- if (itemToRender?.texturePath) {
69
- element.push(
70
- <SpriteFromAtlas
71
- atlasIMG={atlasIMG}
72
- atlasJSON={atlasJSON}
73
- spriteKey={itemToRender.texturePath}
74
- imgScale={3}
75
- />
76
- );
77
- }
78
- if (itemToRender?.isStackable && itemToRender?.stackQty) {
79
- element.push(
80
- <ItemQty left={getLeftPositionValue(itemToRender.stackQty)}>
81
- {' '}
82
- {itemToRender.stackQty}{' '}
83
- </ItemQty>
84
- );
85
- }
86
- return element;
87
- };
88
-
89
- const renderEquipment = (itemToRender: IItem | null) => {
90
- if (
91
- itemToRender?.texturePath &&
92
- itemToRender.allowedEquipSlotType?.includes(slotSpriteMask!)
93
- ) {
94
- return (
95
- <SpriteFromAtlas
96
- atlasIMG={atlasIMG}
97
- atlasJSON={atlasJSON}
98
- spriteKey={itemToRender.texturePath}
99
- imgScale={3}
100
- />
101
- );
102
- } else {
103
- return (
104
- <SpriteFromAtlas
105
- atlasIMG={atlasIMG}
106
- atlasJSON={atlasJSON}
107
- spriteKey={EquipmentSlotSpriteByType[slotSpriteMask!]}
108
- imgScale={3}
109
- grayScale={true}
110
- opacity={0.4}
111
- />
112
- );
113
- }
114
- };
115
-
116
- const onRenderSlot = (itemToRender: IItem | null) => {
117
- if (slotContainerType === SlotContainerType.EQUIPMENT_SET)
118
- return renderEquipment(itemToRender);
119
- return renderItem(itemToRender);
120
- };
121
-
122
- return (
123
- <Container
124
- className="rpgui-icon empty-slot"
125
- onMouseOver={event =>
126
- onMouseOver(event, slotIndex, item, event.clientX, event.clientY)
127
- }
128
- onMouseOut={() => onMouseOut()}
129
- onClick={e => {
130
- if (item) {
131
- onClick(item, e.clientX, e.clientY, slotContainerType);
132
- } else {
133
- onCancelContextMenu();
134
- }
135
- }}
136
- >
137
- {onRenderSlot(item)}
138
- </Container>
139
- );
140
- };
141
-
142
- const Container = styled.div`
143
- margin: 0.1rem;
144
- .sprite-from-atlas-img {
145
- position: relative;
146
- top: 1.5rem;
147
- left: 1.5rem;
148
- }
149
- `;
150
-
151
- interface IItemQtyProps {
152
- left: string;
153
- }
154
- const ItemQty = styled.span<IItemQtyProps>`
155
- position: relative;
156
- top: 1.5rem;
157
- left: ${props => props.left};
158
- `;
1
+ import {
2
+ IItem,
3
+ IItemContainer,
4
+ ItemContainerType,
5
+ ItemSlotType,
6
+ ItemType,
7
+ } from '@rpg-engine/shared';
8
+
9
+ import { observer } from 'mobx-react-lite';
10
+ import React, { useEffect, useState } from 'react';
11
+ import styled from 'styled-components';
12
+ import atlasJSON from '../../../mocks/atlas/items/items.json';
13
+ import atlasIMG from '../../../mocks/atlas/items/items.png';
14
+ import { RelativeListMenu } from '../../RelativeListMenu';
15
+ import { SpriteFromAtlas } from '../../shared/SpriteFromAtlas';
16
+ import { ItemTooltip } from '../Cards/ItemTooltip';
17
+ import { generateContextMenu, IContextMenuItem } from './itemContainerHelper';
18
+
19
+ const EquipmentSlotSpriteByType: any = {
20
+ Neck: 'accessories/corruption-necklace.png',
21
+ LeftHand: 'swords/broad-sword.png',
22
+ Ring: 'rings/iron-ring.png',
23
+ Head: 'helmets/viking-helmet.png',
24
+ Torso: 'armors/iron-armor.png',
25
+ Legs: 'legs/studded-legs.png',
26
+ Feet: 'boots/iron-boots.png',
27
+ Inventory: 'containers/bag.png',
28
+ RightHand: 'shields/plate-shield.png',
29
+ Accessory: 'gloves/plate-gloves.png',
30
+ };
31
+
32
+ interface IProps {
33
+ slotIndex: number;
34
+ item: IItem | null;
35
+ itemContainer?: IItemContainer | null;
36
+ itemContainerType: ItemContainerType | null;
37
+ slotSpriteMask?: ItemSlotType | null;
38
+ onSelected: (selectedOption: string, item: IItem) => void;
39
+ onMouseOver: (
40
+ event: any,
41
+ slotIndex: number,
42
+ item: IItem | null,
43
+ x: number,
44
+ y: number
45
+ ) => void;
46
+ onMouseOut?: () => void;
47
+ onClick: (
48
+ ItemType: ItemType,
49
+ itemContainerType: ItemContainerType | null,
50
+ item: IItem
51
+ ) => void;
52
+ }
53
+
54
+ export const ItemSlot: React.FC<IProps> = observer(
55
+ ({
56
+ slotIndex,
57
+ item,
58
+ itemContainerType: containerType,
59
+ slotSpriteMask,
60
+ onMouseOver,
61
+ onMouseOut,
62
+ onClick,
63
+ onSelected,
64
+ }) => {
65
+ const [isTooltipVisible, setTooltipVisible] = useState(false);
66
+
67
+ const [isContextMenuVisible, setIsContextMenuVisible] = useState(false);
68
+
69
+ const [contextActions, setContextActions] = useState<IContextMenuItem[]>(
70
+ []
71
+ );
72
+
73
+ useEffect(() => {
74
+ if (item) {
75
+ setContextActions(generateContextMenu(item.type, containerType));
76
+ }
77
+ }, [item]);
78
+
79
+ const getLeftPositionValue = (quantity: number) => {
80
+ if (quantity > 0 && quantity < 10) return '2.5rem';
81
+ else if (quantity > 9 && quantity < 100) return '2.0rem';
82
+ else if (quantity > 99) return '1rem';
83
+ return '2.5rem';
84
+ };
85
+
86
+ const renderItem = (itemToRender: IItem | null) => {
87
+ const element = [];
88
+ if (itemToRender?.texturePath) {
89
+ element.push(
90
+ <SpriteFromAtlas
91
+ key={itemToRender._id}
92
+ atlasIMG={atlasIMG}
93
+ atlasJSON={atlasJSON}
94
+ spriteKey={itemToRender.texturePath}
95
+ imgScale={3}
96
+ />
97
+ );
98
+ }
99
+ if (itemToRender?.isStackable && itemToRender?.stackQty) {
100
+ element.push(
101
+ <ItemQty
102
+ left={getLeftPositionValue(itemToRender.stackQty)}
103
+ key={`qty-${itemToRender._id}`}
104
+ >
105
+ {' '}
106
+ {itemToRender.stackQty}{' '}
107
+ </ItemQty>
108
+ );
109
+ }
110
+ return element;
111
+ };
112
+
113
+ const renderEquipment = (itemToRender: IItem | null) => {
114
+ if (
115
+ itemToRender?.texturePath &&
116
+ itemToRender.allowedEquipSlotType?.includes(slotSpriteMask!)
117
+ ) {
118
+ return (
119
+ <SpriteFromAtlas
120
+ key={itemToRender._id}
121
+ atlasIMG={atlasIMG}
122
+ atlasJSON={atlasJSON}
123
+ spriteKey={itemToRender.texturePath}
124
+ imgScale={3}
125
+ />
126
+ );
127
+ } else {
128
+ return (
129
+ <SpriteFromAtlas
130
+ atlasIMG={atlasIMG}
131
+ atlasJSON={atlasJSON}
132
+ spriteKey={EquipmentSlotSpriteByType[slotSpriteMask!]}
133
+ imgScale={3}
134
+ grayScale={true}
135
+ opacity={0.4}
136
+ />
137
+ );
138
+ }
139
+ };
140
+
141
+ const onRenderSlot = (itemToRender: IItem | null) => {
142
+ switch (containerType) {
143
+ case ItemContainerType.Equipment:
144
+ return renderEquipment(itemToRender);
145
+ case ItemContainerType.Inventory:
146
+ return renderItem(itemToRender);
147
+ default:
148
+ return renderItem(itemToRender);
149
+ }
150
+ };
151
+
152
+ return (
153
+ <Container
154
+ className="rpgui-icon empty-slot"
155
+ onMouseOver={event =>
156
+ onMouseOver(event, slotIndex, item, event.clientX, event.clientY)
157
+ }
158
+ onMouseOut={() => {
159
+ if (onMouseOut) onMouseOut();
160
+ }}
161
+ onMouseEnter={() => setTooltipVisible(true)}
162
+ onMouseLeave={() => setTooltipVisible(false)}
163
+ onClick={() => {
164
+ setTooltipVisible(false);
165
+
166
+ if (item) {
167
+ setIsContextMenuVisible(!isContextMenuVisible);
168
+ onClick(item.type, containerType, item);
169
+ }
170
+ }}
171
+ >
172
+ {isContextMenuVisible && contextActions && (
173
+ <RelativeListMenu
174
+ options={contextActions}
175
+ onSelected={(optionId: string) => {
176
+ setIsContextMenuVisible(false);
177
+ if (item) {
178
+ onSelected(optionId, item);
179
+ }
180
+ }}
181
+ onOutsideClick={() => {
182
+ setIsContextMenuVisible(false);
183
+ }}
184
+ />
185
+ )}
186
+
187
+ {isTooltipVisible && item && <ItemTooltip label={item.name} />}
188
+
189
+ {onRenderSlot(item)}
190
+ </Container>
191
+ );
192
+ }
193
+ );
194
+
195
+ const Container = styled.div`
196
+ margin: 0.1rem;
197
+ .sprite-from-atlas-img {
198
+ position: relative;
199
+ top: 1.5rem;
200
+ left: 1.5rem;
201
+ }
202
+ position: relative;
203
+ `;
204
+
205
+ interface IItemQtyProps {
206
+ left: string;
207
+ }
208
+ const ItemQty = styled.span<IItemQtyProps>`
209
+ position: relative;
210
+ top: 1.5rem;
211
+ left: ${props => props.left};
212
+ `;
@@ -1,81 +1,146 @@
1
- import {
2
- ActionsByItemType,
3
- ItemSocketEventsDisplayLabels,
4
- ItemType,
5
- } from '@rpg-engine/shared';
6
-
7
- export interface IContextMenuItem {
8
- id: string;
9
- text: string;
10
- }
11
-
12
- export enum ContainerType {
13
- INVENTORY = 'Inventory',
14
- EQUIPMENT_SET = 'EquipmentSet',
15
- }
16
-
17
- // TODO: Refactor this file
18
- const generateContextList = (actionsByTypeList: any) => {
19
- const contextMenu: IContextMenuItem[] = actionsByTypeList.map(
20
- (action: string) => {
21
- return { id: action, text: ItemSocketEventsDisplayLabels[action] };
22
- }
23
- );
24
- return contextMenu;
25
- };
26
-
27
- export const handleContextMenuList = (itemType: ItemType) => {
28
- let contextActionMenu: IContextMenuItem[] = [];
29
-
30
- switch (itemType) {
31
- case ItemType.Weapon:
32
- case ItemType.Armor:
33
- case ItemType.Accessory:
34
- case ItemType.Jewelry:
35
- case ItemType.Tool:
36
- contextActionMenu = generateContextList(ActionsByItemType.Equipment);
37
- break;
38
- case ItemType.Consumable:
39
- contextActionMenu = generateContextList(ActionsByItemType.Consumable);
40
- break;
41
- case ItemType.CraftMaterial:
42
- contextActionMenu = generateContextList(ActionsByItemType.CraftMaterial);
43
- break;
44
- case ItemType.Other:
45
- case ItemType.Information:
46
- case ItemType.Quest:
47
- case ItemType.Container:
48
- contextActionMenu = generateContextList(ActionsByItemType.Other);
49
- break;
50
- default:
51
- contextActionMenu = generateContextList(ActionsByItemType.Other);
52
- break;
53
- }
54
- return contextActionMenu;
55
- };
56
-
57
- export const handleEquipmentContextMenuList = (itemType: ItemType) => {
58
- let contextActionMenu: IContextMenuItem[] = [];
59
- switch (itemType) {
60
- case ItemType.Weapon:
61
- case ItemType.Armor:
62
- case ItemType.Accessory:
63
- case ItemType.Jewelry:
64
- case ItemType.Tool:
65
- contextActionMenu = generateContextList(
66
- ActionsByItemType.EquipmenSetItems
67
- );
68
- break;
69
- case ItemType.Container:
70
- contextActionMenu = generateContextList(
71
- ActionsByItemType.EquipmenSetContainer
72
- );
73
- break;
74
- default:
75
- contextActionMenu = generateContextList(
76
- ActionsByItemType.EquipmenSetItems
77
- );
78
- break;
79
- }
80
- return contextActionMenu;
81
- };
1
+ import {
2
+ ActionsForEquipmentSet,
3
+ ActionsForInventory,
4
+ ActionsForLoot,
5
+ ActionsForMapContainer,
6
+ ItemContainerType,
7
+ ItemSocketEventsDisplayLabels,
8
+ ItemType
9
+ } from '@rpg-engine/shared';
10
+
11
+ export interface IContextMenuItem {
12
+ id: string;
13
+ text: string;
14
+ }
15
+
16
+ const generateContextMenuListOptions = (actionsByTypeList: any) => {
17
+ const contextMenu: IContextMenuItem[] = actionsByTypeList.map(
18
+ (action: string) => {
19
+ return { id: action, text: ItemSocketEventsDisplayLabels[action] };
20
+ }
21
+ );
22
+ return contextMenu;
23
+ };
24
+
25
+ export const generateContextMenu = (
26
+ itemType: ItemType,
27
+ itemContainerType: ItemContainerType | null
28
+ ) => {
29
+ let contextActionMenu: IContextMenuItem[] = [];
30
+
31
+ if (itemContainerType === ItemContainerType.Inventory) {
32
+ switch (itemType) {
33
+ case ItemType.Weapon:
34
+ case ItemType.Armor:
35
+ case ItemType.Accessory:
36
+ case ItemType.Jewelry:
37
+ contextActionMenu = generateContextMenuListOptions(
38
+ ActionsForInventory.Equipment
39
+ );
40
+ break;
41
+ case ItemType.Container:
42
+ contextActionMenu = generateContextMenuListOptions(
43
+ ActionsForInventory.Container
44
+ );
45
+ break;
46
+ case ItemType.Consumable:
47
+ contextActionMenu = generateContextMenuListOptions(
48
+ ActionsForInventory.Consumable
49
+ );
50
+ break;
51
+ case ItemType.CraftMaterial:
52
+ contextActionMenu = generateContextMenuListOptions(
53
+ ActionsForInventory.CraftMaterial
54
+ );
55
+ break;
56
+ case ItemType.Tool:
57
+ contextActionMenu = generateContextMenuListOptions(
58
+ ActionsForInventory.Tool
59
+ );
60
+ break;
61
+
62
+ default:
63
+ contextActionMenu = generateContextMenuListOptions(
64
+ ActionsForInventory.Other
65
+ );
66
+ break;
67
+ }
68
+ }
69
+ if (itemContainerType === ItemContainerType.Equipment) {
70
+ switch (itemType) {
71
+ case ItemType.Container:
72
+ contextActionMenu = generateContextMenuListOptions(
73
+ ActionsForEquipmentSet.Container
74
+ );
75
+
76
+ break;
77
+ default:
78
+ contextActionMenu = generateContextMenuListOptions(
79
+ ActionsForEquipmentSet.Equipment
80
+ );
81
+ }
82
+ }
83
+ if (itemContainerType === ItemContainerType.Loot) {
84
+ switch (itemType) {
85
+ case ItemType.Weapon:
86
+ case ItemType.Armor:
87
+ case ItemType.Accessory:
88
+ case ItemType.Jewelry:
89
+ contextActionMenu = generateContextMenuListOptions(
90
+ ActionsForLoot.Equipment
91
+ );
92
+ break;
93
+ case ItemType.Consumable:
94
+ contextActionMenu = generateContextMenuListOptions(
95
+ ActionsForLoot.Consumable
96
+ );
97
+ break;
98
+ case ItemType.CraftMaterial:
99
+ contextActionMenu = generateContextMenuListOptions(
100
+ ActionsForLoot.CraftMaterial
101
+ );
102
+ break;
103
+ case ItemType.Tool:
104
+ contextActionMenu = generateContextMenuListOptions(ActionsForLoot.Tool);
105
+ break;
106
+ default:
107
+ contextActionMenu = generateContextMenuListOptions(
108
+ ActionsForLoot.Other
109
+ );
110
+ break;
111
+ }
112
+ }
113
+ if (itemContainerType === ItemContainerType.MapContainer) {
114
+ switch (itemType) {
115
+ case ItemType.Weapon:
116
+ case ItemType.Armor:
117
+ case ItemType.Accessory:
118
+ case ItemType.Jewelry:
119
+ contextActionMenu = generateContextMenuListOptions(
120
+ ActionsForMapContainer.Equipment
121
+ );
122
+ break;
123
+ case ItemType.Consumable:
124
+ contextActionMenu = generateContextMenuListOptions(
125
+ ActionsForMapContainer.Consumable
126
+ );
127
+ break;
128
+ case ItemType.CraftMaterial:
129
+ contextActionMenu = generateContextMenuListOptions(
130
+ ActionsForMapContainer.CraftMaterial
131
+ );
132
+ break;
133
+ case ItemType.Tool:
134
+ contextActionMenu = generateContextMenuListOptions(
135
+ ActionsForMapContainer.Tool
136
+ );
137
+ break;
138
+ default:
139
+ contextActionMenu = generateContextMenuListOptions(
140
+ ActionsForMapContainer.Other
141
+ );
142
+ break;
143
+ }
144
+ }
145
+ return contextActionMenu;
146
+ };