@rpg-engine/long-bow 0.1.96 → 0.1.99

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.1.96",
3
+ "version": "0.1.99",
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.3.86",
86
+ "@rpg-engine/shared": "^0.4.6",
87
87
  "dayjs": "^1.11.2",
88
88
  "fs-extra": "^10.1.0",
89
89
  "lodash": "^4.17.21",
@@ -2,12 +2,13 @@ import {
2
2
  IEquipmentSet,
3
3
  IItem,
4
4
  IItemContainer,
5
+ ItemContainerType,
5
6
  ItemSlotType,
7
+ ItemType,
6
8
  } from '@rpg-engine/shared';
7
9
  import React from 'react';
8
10
  import styled from 'styled-components';
9
11
  import { DraggableContainer } from '../DraggableContainer';
10
- import { SlotContainerType } from '../Item/Inventory/ItemContainerTypes';
11
12
  import { ItemSlot } from '../Item/Inventory/ItemSlot';
12
13
  import { RPGUIContainerTypes } from '../RPGUIContainer';
13
14
 
@@ -15,12 +16,14 @@ export interface IEquipmentSetProps {
15
16
  equipmentSet: IEquipmentSet;
16
17
  onClose?: () => void;
17
18
  onItemClick?: (
19
+ ItemType: ItemType,
18
20
  item: IItem,
19
- slotContainerType: SlotContainerType | null
21
+ itemContainerType: ItemContainerType | null
20
22
  ) => void;
21
23
  onMouseOver?: (e: any, slotIndex: number, item: IItem | null) => void;
22
24
  onSelected?: (optionId: string) => void;
23
25
  initialPosition?: { x: number; y: number };
26
+ ContainerTypes: ItemContainerType | null;
24
27
  }
25
28
 
26
29
  export const EquipmentSet: React.FC<IEquipmentSetProps> = ({
@@ -77,19 +80,20 @@ export const EquipmentSet: React.FC<IEquipmentSetProps> = ({
77
80
  const item = data as IItem;
78
81
  const itemContainer =
79
82
  (item && (item.itemContainer as IItemContainer)) ?? null;
83
+
80
84
  return (
81
85
  <ItemSlot
82
86
  key={i}
83
87
  slotIndex={i}
84
88
  item={item}
85
89
  itemContainer={itemContainer}
86
- slotContainerType={SlotContainerType.EQUIPMENT_SET}
90
+ itemContainerType={ItemContainerType.Equipment}
87
91
  slotSpriteMask={slotMaksRange[i]}
88
92
  onMouseOver={(event, slotIndex, item) => {
89
93
  if (onMouseOver) onMouseOver(event, slotIndex, item);
90
94
  }}
91
- onClick={(item, slotContainerType) => {
92
- if (onItemClick) onItemClick(item, slotContainerType);
95
+ onClick={(itemType, ContainerType) => {
96
+ if (onItemClick) onItemClick(itemType, item, ContainerType);
93
97
  }}
94
98
  onSelected={(optionId: string) => {
95
99
  if (onSelected) onSelected(optionId);
@@ -1,8 +1,8 @@
1
- import { IItem, IItemContainer } from '@rpg-engine/shared';
1
+ import { IItem, IItemContainer, ItemContainerType } from '@rpg-engine/shared';
2
2
  import React from 'react';
3
3
  import styled from 'styled-components';
4
4
  import { SlotsContainer } from '../../Abstractions/SlotsContainer';
5
- import { SlotContainerType } from './ItemContainerTypes';
5
+
6
6
  import { ItemSlot } from './ItemSlot';
7
7
 
8
8
  export interface IItemContainerProps {
@@ -10,10 +10,12 @@ export interface IItemContainerProps {
10
10
  onClose?: () => void;
11
11
  onItemClick?: (
12
12
  item: IItem,
13
- slotContainerType: SlotContainerType | null
13
+ ItemType: IItem['type'],
14
+ itemContainerType: ItemContainerType | null
14
15
  ) => void;
15
16
  onMouseOver?: (e: any, slotIndex: number, item: IItem | null) => void;
16
17
  onSelected?: (optionId: string, item: IItem) => void;
18
+ ContainerType: ItemContainerType;
17
19
  }
18
20
 
19
21
  export const ItemContainer: React.FC<IItemContainerProps> = ({
@@ -22,6 +24,7 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
22
24
  onMouseOver,
23
25
  onSelected,
24
26
  onItemClick,
27
+ ContainerType,
25
28
  }) => {
26
29
  const onRenderSlots = () => {
27
30
  const slots = [];
@@ -32,12 +35,12 @@ export const ItemContainer: React.FC<IItemContainerProps> = ({
32
35
  key={i}
33
36
  slotIndex={i}
34
37
  item={itemContainer.slots?.[i] || null}
35
- slotContainerType={SlotContainerType.INVENTORY}
38
+ itemContainerType={ContainerType}
36
39
  onMouseOver={(event, slotIndex, item) => {
37
40
  if (onMouseOver) onMouseOver(event, slotIndex, item);
38
41
  }}
39
- onClick={(item, slotContainerType) => {
40
- if (onItemClick) onItemClick(item, slotContainerType);
42
+ onClick={(ItemType, ContainerType, item) => {
43
+ if (onItemClick) onItemClick(item, ItemType, ContainerType);
41
44
  }}
42
45
  onSelected={(optionId: string, item: IItem) => {
43
46
  if (onSelected) onSelected(optionId, item);
@@ -1,4 +1,6 @@
1
1
  export enum SlotContainerType {
2
2
  INVENTORY = 'Inventory',
3
3
  EQUIPMENT_SET = 'EquipmentSet',
4
+ LOOT = 'Loot',
5
+ MAP_CONTAINER = 'Map-Container',
4
6
  }
@@ -1,4 +1,10 @@
1
- import { IItem, IItemContainer, ItemSlotType } from '@rpg-engine/shared';
1
+ import {
2
+ IItem,
3
+ IItemContainer,
4
+ ItemContainerType,
5
+ ItemSlotType,
6
+ ItemType,
7
+ } from '@rpg-engine/shared';
2
8
 
3
9
  import { observer } from 'mobx-react-lite';
4
10
  import React, { useEffect, useState } from 'react';
@@ -8,8 +14,7 @@ import atlasIMG from '../../../mocks/atlas/items/items.png';
8
14
  import { RelativeListMenu } from '../../RelativeListMenu';
9
15
  import { SpriteFromAtlas } from '../../shared/SpriteFromAtlas';
10
16
  import { ItemTooltip } from '../Cards/ItemTooltip';
11
- import { handleContextMenuList, IContextMenuItem } from './itemContainerHelper';
12
- import { SlotContainerType } from './ItemContainerTypes';
17
+ import { handleNewContextMenu, IContextMenuItem } from './itemContainerHelper';
13
18
 
14
19
  const EquipmentSlotSpriteByType: any = {
15
20
  Neck: 'accessories/corruption-necklace.png',
@@ -28,7 +33,7 @@ interface IProps {
28
33
  slotIndex: number;
29
34
  item: IItem | null;
30
35
  itemContainer?: IItemContainer | null;
31
- slotContainerType: SlotContainerType | null;
36
+ itemContainerType: ItemContainerType | null;
32
37
  slotSpriteMask?: ItemSlotType | null;
33
38
  onSelected: (selectedOption: string, item: IItem) => void;
34
39
  onMouseOver: (
@@ -39,14 +44,18 @@ interface IProps {
39
44
  y: number
40
45
  ) => void;
41
46
  onMouseOut?: () => void;
42
- onClick: (item: IItem, slotContainerType: SlotContainerType | null) => void;
47
+ onClick: (
48
+ ItemType: ItemType,
49
+ itemContainerType: ItemContainerType | null,
50
+ item: IItem
51
+ ) => void;
43
52
  }
44
53
 
45
54
  export const ItemSlot: React.FC<IProps> = observer(
46
55
  ({
47
56
  slotIndex,
48
57
  item,
49
- slotContainerType,
58
+ itemContainerType: containerType,
50
59
  slotSpriteMask,
51
60
  onMouseOver,
52
61
  onMouseOut,
@@ -63,7 +72,7 @@ export const ItemSlot: React.FC<IProps> = observer(
63
72
 
64
73
  useEffect(() => {
65
74
  if (item) {
66
- setContextActions(handleContextMenuList(item.type, slotContainerType));
75
+ setContextActions(handleNewContextMenu(item.type, containerType));
67
76
  }
68
77
  }, [item]);
69
78
 
@@ -130,9 +139,14 @@ export const ItemSlot: React.FC<IProps> = observer(
130
139
  };
131
140
 
132
141
  const onRenderSlot = (itemToRender: IItem | null) => {
133
- if (slotContainerType === SlotContainerType.EQUIPMENT_SET)
134
- return renderEquipment(itemToRender);
135
- return renderItem(itemToRender);
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
+ }
136
150
  };
137
151
 
138
152
  return (
@@ -151,7 +165,7 @@ export const ItemSlot: React.FC<IProps> = observer(
151
165
 
152
166
  if (item) {
153
167
  setIsContextMenuVisible(!isContextMenuVisible);
154
- onClick(item, slotContainerType);
168
+ onClick(item.type, containerType, item);
155
169
  }
156
170
  }}
157
171
  >
@@ -1,7 +1,12 @@
1
1
  import {
2
2
  ActionsByItemType,
3
+ ActionsForEquipmentSet,
4
+ ActionsForInventory,
5
+ ActionsForLoot,
6
+ ActionsForMapContainer,
7
+ ItemContainerType,
3
8
  ItemSocketEventsDisplayLabels,
4
- ItemType
9
+ ItemType,
5
10
  } from '@rpg-engine/shared';
6
11
  import { SlotContainerType } from './ItemContainerTypes';
7
12
 
@@ -10,11 +15,6 @@ export interface IContextMenuItem {
10
15
  text: string;
11
16
  }
12
17
 
13
- export enum ContainerType {
14
- INVENTORY = 'Inventory',
15
- EQUIPMENT_SET = 'EquipmentSet',
16
- }
17
-
18
18
  // TODO: Refactor this file
19
19
  const generateContextList = (actionsByTypeList: any) => {
20
20
  const contextMenu: IContextMenuItem[] = actionsByTypeList.map(
@@ -24,8 +24,107 @@ const generateContextList = (actionsByTypeList: any) => {
24
24
  );
25
25
  return contextMenu;
26
26
  };
27
+ export const handleNewContextMenu = (
28
+ itemType: ItemType,
29
+ itemContainerType: ItemContainerType | null
30
+ ) => {
31
+ let contextActionMenu: IContextMenuItem[] = [];
32
+
33
+ if (itemContainerType === ItemContainerType.Inventory) {
34
+ switch (itemType) {
35
+ case ItemType.Weapon:
36
+ case ItemType.Armor:
37
+ case ItemType.Accessory:
38
+ case ItemType.Jewelry:
39
+ case ItemType.Container:
40
+ contextActionMenu = generateContextList(ActionsForInventory.Equipment);
41
+ break;
42
+ case ItemType.Consumable:
43
+ contextActionMenu = generateContextList(ActionsForInventory.Consumable);
44
+ break;
45
+ case ItemType.CraftMaterial:
46
+ contextActionMenu = generateContextList(
47
+ ActionsForInventory.CraftMaterial
48
+ );
49
+ break;
50
+ case ItemType.Tool:
51
+ contextActionMenu = generateContextList(ActionsForInventory.Tool);
52
+ break;
53
+ case ItemType.Other:
54
+ contextActionMenu = generateContextList(ActionsForInventory.Other);
55
+ break;
56
+ }
57
+ }
58
+ if (itemContainerType === ItemContainerType.Equipment) {
59
+ switch (itemType) {
60
+ case ItemType.Weapon:
61
+ case ItemType.Armor:
62
+ case ItemType.Accessory:
63
+ case ItemType.Jewelry:
64
+ case ItemType.Container:
65
+ contextActionMenu = generateContextList(
66
+ ActionsForEquipmentSet.Equipment
67
+ );
68
+ break;
69
+ }
70
+ }
71
+ if (itemContainerType === ItemContainerType.Loot) {
72
+ switch (itemType) {
73
+ case ItemType.Weapon:
74
+ case ItemType.Armor:
75
+ case ItemType.Accessory:
76
+ case ItemType.Jewelry:
77
+ contextActionMenu = generateContextList(ActionsForLoot.Equipment);
78
+ break;
79
+ case ItemType.Consumable:
80
+ contextActionMenu = generateContextList(ActionsForLoot.Consumable);
81
+ break;
82
+ case ItemType.CraftMaterial:
83
+ contextActionMenu = generateContextList(ActionsForLoot.CraftMaterial);
84
+ break;
85
+ case ItemType.Tool:
86
+ contextActionMenu = generateContextList(ActionsForLoot.Tool);
87
+ break;
88
+ case ItemType.Other:
89
+ contextActionMenu = generateContextList(ActionsForLoot.Other);
90
+ break;
91
+ }
92
+ }
93
+ if (itemContainerType === ItemContainerType.MapContainer) {
94
+ switch (itemType) {
95
+ case ItemType.Weapon:
96
+ case ItemType.Armor:
97
+ case ItemType.Accessory:
98
+ case ItemType.Jewelry:
99
+ contextActionMenu = generateContextList(
100
+ ActionsForMapContainer.Equipment
101
+ );
102
+ break;
103
+ case ItemType.Consumable:
104
+ contextActionMenu = generateContextList(
105
+ ActionsForMapContainer.Consumable
106
+ );
107
+ break;
108
+ case ItemType.CraftMaterial:
109
+ contextActionMenu = generateContextList(
110
+ ActionsForMapContainer.CraftMaterial
111
+ );
112
+ break;
113
+ case ItemType.Tool:
114
+ contextActionMenu = generateContextList(ActionsForMapContainer.Tool);
115
+ break;
116
+ case ItemType.Other:
117
+ contextActionMenu = generateContextList(ActionsForMapContainer.Other);
118
+ break;
119
+ }
120
+ }
121
+ return contextActionMenu;
122
+ };
27
123
 
28
- export const handleContextMenuList = (itemType: ItemType, slotContainerType: SlotContainerType | null) => {
124
+ export const handleContextMenuList = (
125
+ itemType: ItemType,
126
+ slotContainerType: SlotContainerType | null
127
+ ) => {
29
128
  let contextActionMenu: IContextMenuItem[] = [];
30
129
 
31
130
  switch (itemType) {
@@ -35,7 +134,9 @@ export const handleContextMenuList = (itemType: ItemType, slotContainerType: Slo
35
134
  case ItemType.Jewelry:
36
135
  case ItemType.Tool:
37
136
  if (slotContainerType === SlotContainerType.EQUIPMENT_SET) {
38
- contextActionMenu = generateContextList(ActionsByItemType.EquipmentSetItems);
137
+ contextActionMenu = generateContextList(
138
+ ActionsByItemType.EquipmentSetItems
139
+ );
39
140
  } else {
40
141
  contextActionMenu = generateContextList(ActionsByItemType.Equipment);
41
142
  }
@@ -1,4 +1,4 @@
1
- import { IItem } from '@rpg-engine/shared';
1
+ import { IItem, ItemContainerType, ItemType } from '@rpg-engine/shared';
2
2
  import { Meta, Story } from '@storybook/react';
3
3
  import React from 'react';
4
4
  import {
@@ -7,7 +7,6 @@ import {
7
7
  } from '../../src/components/Equipment/EquipmentSet';
8
8
  import { RPGUIRoot } from '../../src/components/RPGUIRoot';
9
9
  import { equipmentSetMock } from '../../src/mocks/equipmentSet.mocks';
10
- import { SlotContainerType } from '../components/Item/Inventory/ItemContainerTypes';
11
10
 
12
11
  const meta: Meta = {
13
12
  title: 'Equipment Set',
@@ -24,10 +23,11 @@ const onMouseOver = (event: any, slotIndex: number, item: IItem | null) => {
24
23
  };
25
24
 
26
25
  const onItemClick = (
26
+ ItemType: ItemType,
27
27
  item: IItem,
28
- slotContainerType: SlotContainerType | null
28
+ itemContainerType: ItemContainerType | null
29
29
  ) => {
30
- console.log(item, slotContainerType, 'was clicked!');
30
+ console.log(item, ItemType, itemContainerType, 'was clicked!');
31
31
  };
32
32
 
33
33
  const onSelected = (payload: string) => {
@@ -43,6 +43,7 @@ const Template: Story<IEquipmentSetProps> = args => (
43
43
  onMouseOver={onMouseOver}
44
44
  onSelected={onSelected}
45
45
  onItemClick={onItemClick}
46
+ ContainerTypes={ItemContainerType.Inventory}
46
47
  />
47
48
  </RPGUIRoot>
48
49
  );
@@ -1,4 +1,4 @@
1
- import { IItem } from '@rpg-engine/shared';
1
+ import { IItem, ItemContainerType, ItemType } from '@rpg-engine/shared';
2
2
  import { Meta, Story } from '@storybook/react';
3
3
  import React from 'react';
4
4
  import {
@@ -7,7 +7,6 @@ import {
7
7
  } from '../../src/components/Item/Inventory/ItemContainer';
8
8
  import { RPGUIRoot } from '../../src/components/RPGUIRoot';
9
9
  import { itemContainerMock } from '../../src/mocks/itemContainer.mocks';
10
- import { SlotContainerType } from '../components/Item/Inventory/ItemContainerTypes';
11
10
 
12
11
  const meta: Meta = {
13
12
  title: 'Item Container',
@@ -30,9 +29,10 @@ const onSelected = (payload: string, item: IItem) => {
30
29
 
31
30
  const onItemClick = (
32
31
  item: IItem,
33
- slotContainerType: SlotContainerType | null
32
+ ItemType: ItemType,
33
+ itemContainerType: ItemContainerType | null
34
34
  ) => {
35
- console.log(item, slotContainerType, 'was clicked!');
35
+ console.log(item, ItemType, itemContainerType, 'was clicked!');
36
36
  };
37
37
 
38
38
  const Template: Story<IItemContainerProps> = () => (
@@ -43,6 +43,7 @@ const Template: Story<IItemContainerProps> = () => (
43
43
  onMouseOver={onMouseOver}
44
44
  onSelected={onSelected}
45
45
  onItemClick={onItemClick}
46
+ ContainerType={ItemContainerType.Inventory}
46
47
  />
47
48
  </RPGUIRoot>
48
49
  );