@rpgjs/client 4.0.3 → 4.0.5
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/CHANGELOG.md +19 -0
- package/browser/React-ab9e74c2.js +127 -0
- package/browser/manifest.json +1 -1
- package/browser/rpg.client.js +6 -7
- package/browser/rpg.client.umd.cjs +29 -31041
- package/lib/Components/Component.js +5 -5
- package/lib/Components/Component.js.map +1 -1
- package/lib/Sprite/Character.js.map +1 -1
- package/package.json +6 -6
- package/rpg.toml +1 -1
- package/src/Components/Component.ts +5 -5
- package/src/Sprite/Character.ts +1 -1
- package/browser/React-e57feed9.js +0 -31136
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 4.0.5 (2023-10-18)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* flickering motion of an event as it moves ([b2b8832](https://github.com/RSamaium/RPG-JS/commit/b2b8832a1582933afb64c698f40d1b0e72021780))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## 4.0.4 (2023-10-13)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @rpgjs/client
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## 4.0.3 (2023-10-10)
|
|
7
26
|
|
|
8
27
|
**Note:** Version bump only for package @rpgjs/client
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import require$$0 from "react-dom";
|
|
2
|
+
import { useCallback, useSyncExternalStore, createContext, useState, useContext, useEffect, useRef, createElement } from "react";
|
|
3
|
+
import { map, tap, BehaviorSubject } from "rxjs";
|
|
4
|
+
var createRoot;
|
|
5
|
+
var m = require$$0;
|
|
6
|
+
if ({}.NODE_ENV === "production") {
|
|
7
|
+
createRoot = m.createRoot;
|
|
8
|
+
m.hydrateRoot;
|
|
9
|
+
} else {
|
|
10
|
+
var i = m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
11
|
+
createRoot = function(c, o) {
|
|
12
|
+
i.usingClientEntryPoint = true;
|
|
13
|
+
try {
|
|
14
|
+
return m.createRoot(c, o);
|
|
15
|
+
} finally {
|
|
16
|
+
i.usingClientEntryPoint = false;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function listenKeys(store, keys, listener) {
|
|
21
|
+
let keysSet = /* @__PURE__ */ new Set([...keys, void 0]);
|
|
22
|
+
return store.listen((value, changed) => {
|
|
23
|
+
if (keysSet.has(changed)) {
|
|
24
|
+
listener(value, changed);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function useStore(store, opts = {}) {
|
|
29
|
+
let subscribe = useCallback(
|
|
30
|
+
(onChange) => opts.keys ? listenKeys(store, opts.keys, onChange) : store.listen(onChange),
|
|
31
|
+
[opts.keys, store]
|
|
32
|
+
);
|
|
33
|
+
let get = store.get.bind(store);
|
|
34
|
+
return useSyncExternalStore(subscribe, get, get);
|
|
35
|
+
}
|
|
36
|
+
const RpgReactContext = createContext({});
|
|
37
|
+
const useObjects = () => {
|
|
38
|
+
const [objects, setObjects] = useState([]);
|
|
39
|
+
const {
|
|
40
|
+
rpgObjects
|
|
41
|
+
} = useContext(RpgReactContext);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
rpgObjects.pipe(map((objects2) => Object.values(objects2).map((obj) => obj.object))).subscribe(setObjects);
|
|
44
|
+
}, []);
|
|
45
|
+
return objects;
|
|
46
|
+
};
|
|
47
|
+
const useCurrentPlayer = () => {
|
|
48
|
+
const {
|
|
49
|
+
rpgCurrentPlayer
|
|
50
|
+
} = useContext(RpgReactContext);
|
|
51
|
+
const currentPlayerRef = useRef({});
|
|
52
|
+
let _onChanges;
|
|
53
|
+
const subscribe = (onChanges) => {
|
|
54
|
+
_onChanges = onChanges;
|
|
55
|
+
return () => {
|
|
56
|
+
_onChanges = null;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
const ob$ = rpgCurrentPlayer.pipe(map((player) => player.object), tap((player) => currentPlayerRef.current = player));
|
|
61
|
+
const subscription = ob$.subscribe(() => {
|
|
62
|
+
_onChanges == null ? void 0 : _onChanges();
|
|
63
|
+
});
|
|
64
|
+
return () => subscription.unsubscribe();
|
|
65
|
+
}, []);
|
|
66
|
+
return useSyncExternalStore(subscribe, () => currentPlayerRef.current);
|
|
67
|
+
};
|
|
68
|
+
class ReactGui {
|
|
69
|
+
//private _tooltips: BehaviorSubject<any[]> = new BehaviorSubject([] as any)
|
|
70
|
+
constructor(rootEl, parentGui) {
|
|
71
|
+
this._gui = new BehaviorSubject([]);
|
|
72
|
+
this.app = createRoot(rootEl);
|
|
73
|
+
this.clientEngine = parentGui.clientEngine;
|
|
74
|
+
this.renderer = this.clientEngine.renderer;
|
|
75
|
+
const GuiTooltip = (ui) => {
|
|
76
|
+
return () => {
|
|
77
|
+
const [_tooltip, setTooltip] = useState([]);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
var _a;
|
|
80
|
+
parentGui.listenTooltipObjects.subscribe(setTooltip);
|
|
81
|
+
(_a = parentGui.currentScene) == null ? void 0 : _a.objectsMoving.next({});
|
|
82
|
+
}, [parentGui.currentScene]);
|
|
83
|
+
return parentGui.tooltipFilter(_tooltip).map((sprite) => createElement("div", {
|
|
84
|
+
style: parentGui.tooltipPosition({
|
|
85
|
+
x: sprite.position.x,
|
|
86
|
+
y: sprite.position.y
|
|
87
|
+
}),
|
|
88
|
+
key: sprite.id
|
|
89
|
+
}, createElement(ui.gui, {
|
|
90
|
+
spriteData: sprite,
|
|
91
|
+
...ui.data || {}
|
|
92
|
+
})));
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
const GuiWrapper = () => {
|
|
96
|
+
const [_gui, setGui] = useState([]);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
this._gui.subscribe((gui) => setGui(gui));
|
|
99
|
+
}, []);
|
|
100
|
+
return createElement(RpgReactContext.Provider, {
|
|
101
|
+
value: parentGui.getInjectObject()
|
|
102
|
+
}, ..._gui.filter((ui) => ui.display && !ui.attachToSprite).map((ui) => createElement(ui.gui, {
|
|
103
|
+
key: ui.name,
|
|
104
|
+
...ui.data || {}
|
|
105
|
+
})), ..._gui.filter((ui) => ui.display && ui.attachToSprite).map((ui) => createElement("div", {
|
|
106
|
+
key: ui.name
|
|
107
|
+
}, createElement(GuiTooltip(ui)))));
|
|
108
|
+
};
|
|
109
|
+
this.app.render(createElement(GuiWrapper));
|
|
110
|
+
}
|
|
111
|
+
set gui(val) {
|
|
112
|
+
let array = [];
|
|
113
|
+
for (let key in val) {
|
|
114
|
+
if (!val[key].isFunction)
|
|
115
|
+
continue;
|
|
116
|
+
array.push(val[key]);
|
|
117
|
+
}
|
|
118
|
+
this._gui.next(array);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
export {
|
|
122
|
+
ReactGui,
|
|
123
|
+
RpgReactContext,
|
|
124
|
+
useCurrentPlayer,
|
|
125
|
+
useObjects,
|
|
126
|
+
useStore
|
|
127
|
+
};
|
package/browser/manifest.json
CHANGED
package/browser/rpg.client.js
CHANGED
|
@@ -36326,7 +36326,7 @@ class Gui {
|
|
|
36326
36326
|
}
|
|
36327
36327
|
if ((_a = this.clientEngine.envs) == null ? void 0 : _a["VITE_REACT"]) {
|
|
36328
36328
|
console.warn("[RPGJS] React GUI is experimental feature. So, its use may change over time. Not yet in production");
|
|
36329
|
-
COMPONENT_LIBRARIES.push(await import("./React-
|
|
36329
|
+
COMPONENT_LIBRARIES.push(await import("./React-ab9e74c2.js").then((m2) => m2.ReactGui));
|
|
36330
36330
|
}
|
|
36331
36331
|
const propagateEvents = (el) => {
|
|
36332
36332
|
const events = ["click", "mousedown", "mouseup", "mousemove", "mouseenter", "mouseleave", "mouseover", "mouseout", "contextmenu", "pointerdown", "pointerup", "pointermove", "pointerenter", "pointerleave", "pointerover", "pointerout", "pointerupoutside", "pointercancel", "touchstart", "touchend", "touchmove", "touchcancel", "wheel", "keydown", "keyup", "keypress", "keydownoutside", "keyupoutside", "keypressoutside"];
|
|
@@ -38237,9 +38237,9 @@ class RpgComponent extends Container {
|
|
|
38237
38237
|
position,
|
|
38238
38238
|
direction
|
|
38239
38239
|
} = this.data;
|
|
38240
|
-
this._x =
|
|
38241
|
-
this._y =
|
|
38242
|
-
this.z =
|
|
38240
|
+
this._x = (position == null ? void 0 : position.x) ?? 0;
|
|
38241
|
+
this._y = (position == null ? void 0 : position.y) ?? 0;
|
|
38242
|
+
this.z = (position == null ? void 0 : position.z) ?? 0;
|
|
38243
38243
|
this.direction = direction;
|
|
38244
38244
|
}
|
|
38245
38245
|
this._rotation = this.data["rotation"] ?? 0;
|
|
@@ -38289,8 +38289,7 @@ class RpgComponent extends Container {
|
|
|
38289
38289
|
speed,
|
|
38290
38290
|
teleported,
|
|
38291
38291
|
map: map2,
|
|
38292
|
-
fixed
|
|
38293
|
-
rotation
|
|
38292
|
+
fixed
|
|
38294
38293
|
} = obj;
|
|
38295
38294
|
this.data = obj;
|
|
38296
38295
|
this.setPosition();
|
|
@@ -38298,7 +38297,7 @@ class RpgComponent extends Container {
|
|
|
38298
38297
|
if (this._rotation != this.angle) {
|
|
38299
38298
|
this.angle += Math.min(renderSpeed, this._rotation - this.angle);
|
|
38300
38299
|
}
|
|
38301
|
-
let moving = false;
|
|
38300
|
+
let moving = obj.moving ?? false;
|
|
38302
38301
|
if (!fixed) {
|
|
38303
38302
|
if (teleported != this.teleported || map2 != this.map) {
|
|
38304
38303
|
this.x = this._x;
|