@rpg-engine/long-bow 0.2.17 → 0.2.19

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.2.17",
3
+ "version": "0.2.19",
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.4.46",
86
+ "@rpg-engine/shared": "^0.4.54",
87
87
  "dayjs": "^1.11.2",
88
88
  "fs-extra": "^10.1.0",
89
89
  "lodash": "^4.17.21",
@@ -1,5 +1,6 @@
1
1
  import React, { useEffect, useState } from 'react';
2
2
  import { v4 as uuidv4 } from 'uuid';
3
+ import { RPGUIForceRenderStart } from './RPGUIForceRenderStart';
3
4
  import { _RPGUI } from './RPGUIRoot';
4
5
 
5
6
  export interface IOptionsProps {
@@ -40,18 +41,24 @@ export const Dropdown: React.FC<IDropdownProps> = ({
40
41
  }, [selectedValue]);
41
42
 
42
43
  return (
43
- <select
44
- id={`rpgui-dropdown-${dropdownId}`}
45
- style={{ width: width }}
46
- className="rpgui-dropdown"
44
+ <RPGUIForceRenderStart
45
+ elementDOMId={`rpgui-dropdown-${dropdownId}`}
46
+ elementRenderedDOMKey='[data-rpguitype="dropdown"]'
47
+ RPGUICreateFunction="dropdown"
47
48
  >
48
- {options.map(option => {
49
- return (
50
- <option key={option.id} value={option.value}>
51
- {option.option}
52
- </option>
53
- );
54
- })}
55
- </select>
49
+ <select
50
+ id={`rpgui-dropdown-${dropdownId}`}
51
+ style={{ width: width }}
52
+ className="rpgui-dropdown"
53
+ >
54
+ {options.map(option => {
55
+ return (
56
+ <option key={option.id} value={option.value}>
57
+ {option.option}
58
+ </option>
59
+ );
60
+ })}
61
+ </select>
62
+ </RPGUIForceRenderStart>
56
63
  );
57
64
  };
@@ -26,7 +26,7 @@ const EquipmentSlotSpriteByType: any = {
26
26
  Feet: 'boots/iron-boots.png',
27
27
  Inventory: 'containers/bag.png',
28
28
  RightHand: 'shields/plate-shield.png',
29
- Accessory: 'gloves/plate-gloves.png',
29
+ Accessory: 'ranged-weapons/arrow.png',
30
30
  };
31
31
 
32
32
  interface IProps {
@@ -0,0 +1,45 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { _RPGUI } from './RPGUIRoot';
3
+
4
+ interface IProps {
5
+ elementDOMId: string;
6
+ elementRenderedDOMKey: string; // this is what "proves" the element is rendered
7
+ children: React.ReactNode;
8
+ RPGUICreateFunction:
9
+ | 'dropdown'
10
+ | 'slider'
11
+ | 'checkbox'
12
+ | 'draggable'
13
+ | 'progress'
14
+ | 'radio'
15
+ | 'list';
16
+ }
17
+
18
+ export const RPGUIForceRenderStart: React.FC<IProps> = ({
19
+ children,
20
+ elementDOMId,
21
+ elementRenderedDOMKey,
22
+ RPGUICreateFunction,
23
+ }) => {
24
+ const [isRendered, setIsRendered] = useState<boolean>(false);
25
+
26
+ useEffect(() => {
27
+ if (_RPGUI) {
28
+ const element = document.getElementById(elementDOMId);
29
+
30
+ // create an interval to wait for the element to be rendered
31
+ // if it's not, trigger the rendering forcefully
32
+ const interval = setInterval(() => {
33
+ const dropdown = document.querySelector(elementRenderedDOMKey);
34
+
35
+ if (!dropdown && !isRendered) {
36
+ _RPGUI.__create_funcs[RPGUICreateFunction](element);
37
+ setIsRendered(true);
38
+ clearInterval(interval);
39
+ }
40
+ }, 10);
41
+ }
42
+ }, []);
43
+
44
+ return <>{children}</>;
45
+ };
@@ -1,7 +1,7 @@
1
- import React, { useState } from 'react';
1
+ import React from 'react';
2
2
  import styled from 'styled-components';
3
3
  import { v4 as uuidv4 } from 'uuid';
4
- import { useEventListener } from '../hooks/useEventListener';
4
+ import { RPGUIForceRenderStart } from './RPGUIForceRenderStart';
5
5
  import { _RPGUI } from './RPGUIRoot';
6
6
 
7
7
  export enum RangeSliderType {
@@ -26,15 +26,6 @@ export const RangeSlider: React.FC<IRangeSliderProps> = ({
26
26
  }) => {
27
27
  const sliderId = uuidv4();
28
28
 
29
- const [wasMouseDownFirst, setWasMouseDownFirst] = useState<boolean>(false);
30
-
31
- useEventListener('mouseup', () => {
32
- if (wasMouseDownFirst) {
33
- onHandleMouseUp();
34
- }
35
- setWasMouseDownFirst(false);
36
- });
37
-
38
29
  const onHandleMouseUp = () => {
39
30
  const rpguiSlider = document.getElementById(`rpgui-slider-${sliderId}`);
40
31
  const value = _RPGUI.get_value(rpguiSlider);
@@ -43,23 +34,26 @@ export const RangeSlider: React.FC<IRangeSliderProps> = ({
43
34
  };
44
35
 
45
36
  return (
46
- <div
47
- onMouseUp={onHandleMouseUp}
48
- onMouseDown={() => setWasMouseDownFirst(true)}
37
+ <RPGUIForceRenderStart
38
+ elementDOMId={`rpgui-slider-${sliderId}`}
39
+ elementRenderedDOMKey="[data-rpguitype='slider']"
40
+ RPGUICreateFunction="slider"
49
41
  >
50
- <Input
51
- className={
52
- type === RangeSliderType.Slider
53
- ? RangeSliderType.Slider
54
- : RangeSliderType.GoldSlider
55
- }
56
- type="range"
57
- style={{ width: width }}
58
- min={valueMin}
59
- max={valueMax}
60
- id={`rpgui-slider-${sliderId}`}
61
- />
62
- </div>
42
+ <div onMouseUp={onHandleMouseUp}>
43
+ <Input
44
+ className={
45
+ type === RangeSliderType.Slider
46
+ ? RangeSliderType.Slider
47
+ : RangeSliderType.GoldSlider
48
+ }
49
+ type="range"
50
+ style={{ width: width }}
51
+ min={valueMin}
52
+ max={valueMax}
53
+ id={`rpgui-slider-${sliderId}`}
54
+ />
55
+ </div>
56
+ </RPGUIForceRenderStart>
63
57
  );
64
58
  };
65
59
 
@@ -9,6 +9,7 @@ import {
9
9
  export const items: IItem[] = [
10
10
  {
11
11
  _id: '629acef1c7c8e8002ff60736',
12
+ hasUseWith: false,
12
13
  type: ItemType.Weapon,
13
14
  subType: ItemSubType.Sword,
14
15
  textureAtlas: 'items',
@@ -42,6 +43,7 @@ export const items: IItem[] = [
42
43
  },
43
44
  {
44
45
  _id: '629acef1c7c8e8002ff73564',
46
+ hasUseWith: false,
45
47
  type: ItemType.Weapon,
46
48
  subType: ItemSubType.Axe,
47
49
  textureAtlas: 'items',
@@ -73,6 +75,7 @@ export const items: IItem[] = [
73
75
  },
74
76
  {
75
77
  _id: '629acef1c7c8e8002ff60723',
78
+ hasUseWith: false,
76
79
  type: ItemType.Consumable,
77
80
  subType: ItemSubType.Potion,
78
81
  textureAtlas: 'items',
@@ -105,6 +108,7 @@ export const items: IItem[] = [
105
108
  },
106
109
  {
107
110
  _id: '629acek4j7c8e8002ff60034',
111
+ hasUseWith: false,
108
112
  type: ItemType.Consumable,
109
113
  subType: ItemSubType.Food,
110
114
  textureAtlas: 'items',
@@ -137,6 +141,7 @@ export const items: IItem[] = [
137
141
  },
138
142
  {
139
143
  _id: '629acek4j7c8e8002fg60034',
144
+ hasUseWith: false,
140
145
  type: ItemType.Consumable,
141
146
  subType: ItemSubType.Accessory,
142
147
  textureAtlas: 'items',
@@ -170,6 +175,7 @@ export const items: IItem[] = [
170
175
  {
171
176
  _id: '392acek4j7c8e8002ff60403',
172
177
  type: ItemType.CraftMaterial,
178
+ hasUseWith: false,
173
179
  subType: ItemSubType.Other,
174
180
  textureAtlas: 'items',
175
181
  allowedEquipSlotType: [ItemSlotType.Inventory],
@@ -202,6 +208,7 @@ export const items: IItem[] = [
202
208
 
203
209
  {
204
210
  _id: '392acek4j7c8e8002ff60404',
211
+ hasUseWith: false,
205
212
  type: ItemType.Container,
206
213
  subType: ItemSubType.Other,
207
214
  textureAtlas: 'items',
@@ -57,4 +57,7 @@ Default.args = {
57
57
  type: RangeSliderType.Slider,
58
58
  valueMin: 0,
59
59
  valueMax: 100,
60
+ onChange: n => {
61
+ console.log('onChange', n);
62
+ },
60
63
  };