@energy8platform/game-engine 0.14.4 → 0.14.6
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/dist/index.cjs.js +4 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +4 -3
- package/dist/index.esm.js.map +1 -1
- package/dist/react.cjs.js +89 -6
- package/dist/react.cjs.js.map +1 -1
- package/dist/react.esm.js +89 -6
- package/dist/react.esm.js.map +1 -1
- package/dist/ui.cjs.js +4 -3
- package/dist/ui.cjs.js.map +1 -1
- package/dist/ui.esm.js +4 -3
- package/dist/ui.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/react/applyProps.ts +47 -2
- package/src/react/reconciler.ts +37 -2
- package/src/ui/Modal.ts +3 -4
package/dist/react.esm.js
CHANGED
|
@@ -23,6 +23,11 @@ function extend(components) {
|
|
|
23
23
|
const RESERVED = new Set(['children', 'key', 'ref']);
|
|
24
24
|
/** Props handled by the reconciler as flex item config, not forwarded to components */
|
|
25
25
|
const FLEX_ITEM_PROPS$1 = new Set(['flexGrow', 'flexShrink', 'layoutWidth', 'layoutHeight', 'alignSelf', 'flexExclude', 'top', 'right', 'bottom', 'left']);
|
|
26
|
+
/** Base Container props applied directly to the instance (not via config) */
|
|
27
|
+
const CONTAINER_PROPS = new Set([
|
|
28
|
+
'x', 'y', 'alpha', 'visible', 'rotation', 'angle', 'zIndex',
|
|
29
|
+
'label', 'cursor', 'eventMode',
|
|
30
|
+
]);
|
|
26
31
|
// ─── UI Component helpers ────────────────────────────────
|
|
27
32
|
/**
|
|
28
33
|
* Extract a config object from React props.
|
|
@@ -32,7 +37,7 @@ const FLEX_ITEM_PROPS$1 = new Set(['flexGrow', 'flexShrink', 'layoutWidth', 'lay
|
|
|
32
37
|
function extractConfig(props) {
|
|
33
38
|
const config = {};
|
|
34
39
|
for (const key in props) {
|
|
35
|
-
if (RESERVED.has(key) || FLEX_ITEM_PROPS$1.has(key) || isEventProp(key))
|
|
40
|
+
if (RESERVED.has(key) || FLEX_ITEM_PROPS$1.has(key) || CONTAINER_PROPS.has(key) || isEventProp(key))
|
|
36
41
|
continue;
|
|
37
42
|
if (key.includes('-')) {
|
|
38
43
|
const parts = key.split('-');
|
|
@@ -57,7 +62,7 @@ function diffConfig(newProps, oldProps) {
|
|
|
57
62
|
const changed = {};
|
|
58
63
|
// New or changed props
|
|
59
64
|
for (const key in newProps) {
|
|
60
|
-
if (RESERVED.has(key) || FLEX_ITEM_PROPS$1.has(key) || isEventProp(key))
|
|
65
|
+
if (RESERVED.has(key) || FLEX_ITEM_PROPS$1.has(key) || CONTAINER_PROPS.has(key) || isEventProp(key))
|
|
61
66
|
continue;
|
|
62
67
|
if (newProps[key] !== oldProps[key]) {
|
|
63
68
|
if (key.includes('-')) {
|
|
@@ -153,6 +158,50 @@ function setNestedValue(target, path, value) {
|
|
|
153
158
|
}
|
|
154
159
|
obj[path[path.length - 1]] = value;
|
|
155
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Apply base Container props (x, y, alpha, visible, etc.) directly to the instance.
|
|
163
|
+
* Called for ALL elements — both UI components and standard PixiJS elements.
|
|
164
|
+
* Also handles scale, pivot, position, anchor via dash-notation.
|
|
165
|
+
*/
|
|
166
|
+
function applyContainerProps(instance, newProps, oldProps = {}) {
|
|
167
|
+
for (const key of CONTAINER_PROPS) {
|
|
168
|
+
if (key in newProps && newProps[key] !== oldProps[key]) {
|
|
169
|
+
try {
|
|
170
|
+
instance[key] = newProps[key];
|
|
171
|
+
}
|
|
172
|
+
catch { /* read-only */ }
|
|
173
|
+
}
|
|
174
|
+
else if (key in oldProps && !(key in newProps)) {
|
|
175
|
+
// Prop removed — reset to undefined (PixiJS defaults)
|
|
176
|
+
try {
|
|
177
|
+
instance[key] = undefined;
|
|
178
|
+
}
|
|
179
|
+
catch { /* read-only */ }
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Handle scale as uniform number or {x,y} object
|
|
183
|
+
if ('scale' in newProps && newProps.scale !== oldProps.scale) {
|
|
184
|
+
const s = newProps.scale;
|
|
185
|
+
if (typeof s === 'number') {
|
|
186
|
+
instance.scale?.set?.(s, s);
|
|
187
|
+
}
|
|
188
|
+
else if (s && typeof s === 'object') {
|
|
189
|
+
instance.scale?.set?.(s.x ?? 1, s.y ?? 1);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// Handle dash-notation container props: scale-x, scale-y, pivot-x, pivot-y, position-x, position-y, anchor-x, anchor-y
|
|
193
|
+
for (const key in newProps) {
|
|
194
|
+
if (!key.includes('-'))
|
|
195
|
+
continue;
|
|
196
|
+
const parts = key.split('-');
|
|
197
|
+
const root = parts[0];
|
|
198
|
+
if (root === 'scale' || root === 'pivot' || root === 'position' || root === 'anchor') {
|
|
199
|
+
if (newProps[key] !== oldProps[key]) {
|
|
200
|
+
setNestedValue(instance, parts, newProps[key]);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
156
205
|
function applyProps(instance, newProps, oldProps = {}) {
|
|
157
206
|
// Remove old props not in newProps
|
|
158
207
|
for (const key in oldProps) {
|
|
@@ -860,6 +909,7 @@ const hostConfig = {
|
|
|
860
909
|
// Config-based UI component: pass props as constructor config
|
|
861
910
|
const config = extractConfig(props);
|
|
862
911
|
instance = new Ctor(config);
|
|
912
|
+
applyContainerProps(instance, props);
|
|
863
913
|
applyEventProps(instance, props);
|
|
864
914
|
}
|
|
865
915
|
else {
|
|
@@ -875,6 +925,24 @@ const hostConfig = {
|
|
|
875
925
|
if (flexItemConfig) {
|
|
876
926
|
instance._flexConfig = { ...instance._flexConfig, ...flexItemConfig };
|
|
877
927
|
}
|
|
928
|
+
// Auto-set layoutWidth/layoutHeight from explicit width/height props for UI components.
|
|
929
|
+
// This ensures parent FlexContainers measure children correctly without relying on
|
|
930
|
+
// getLocalBounds() which may return wrong values before the first render pass
|
|
931
|
+
// (e.g. Text with unloaded fonts, Graphics with pending geometry).
|
|
932
|
+
if (typeof Ctor.prototype.updateConfig === 'function' && !(instance instanceof FlexContainer)) {
|
|
933
|
+
const w = typeof props.width === 'number' ? props.width : undefined;
|
|
934
|
+
const h = typeof props.height === 'number' ? props.height : undefined;
|
|
935
|
+
if (w !== undefined || h !== undefined) {
|
|
936
|
+
if (!instance._flexConfig)
|
|
937
|
+
instance._flexConfig = {};
|
|
938
|
+
if (w !== undefined && instance._flexConfig.layoutWidth === undefined) {
|
|
939
|
+
instance._flexConfig.layoutWidth = w;
|
|
940
|
+
}
|
|
941
|
+
if (h !== undefined && instance._flexConfig.layoutHeight === undefined) {
|
|
942
|
+
instance._flexConfig.layoutHeight = h;
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
878
946
|
return instance;
|
|
879
947
|
},
|
|
880
948
|
createTextInstance() {
|
|
@@ -952,6 +1020,7 @@ const hostConfig = {
|
|
|
952
1020
|
if (Object.keys(changed).length > 0) {
|
|
953
1021
|
instance.updateConfig(changed);
|
|
954
1022
|
}
|
|
1023
|
+
applyContainerProps(instance, newProps, oldProps);
|
|
955
1024
|
applyEventProps(instance, newProps, oldProps);
|
|
956
1025
|
}
|
|
957
1026
|
else {
|
|
@@ -962,7 +1031,20 @@ const hostConfig = {
|
|
|
962
1031
|
const oldFlexConfig = extractFlexItemConfig(oldProps);
|
|
963
1032
|
if (newFlexConfig || oldFlexConfig) {
|
|
964
1033
|
instance._flexConfig = { ...instance._flexConfig, ...newFlexConfig };
|
|
965
|
-
|
|
1034
|
+
}
|
|
1035
|
+
// Keep auto layoutWidth/layoutHeight in sync with width/height for UI components
|
|
1036
|
+
if (typeof instance.updateConfig === 'function' && !(instance instanceof FlexContainer)) {
|
|
1037
|
+
if (instance._flexConfig) {
|
|
1038
|
+
if (typeof newProps.width === 'number' && instance._flexConfig.layoutWidth !== undefined) {
|
|
1039
|
+
instance._flexConfig.layoutWidth = newProps.width;
|
|
1040
|
+
}
|
|
1041
|
+
if (typeof newProps.height === 'number' && instance._flexConfig.layoutHeight !== undefined) {
|
|
1042
|
+
instance._flexConfig.layoutHeight = newProps.height;
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
// Trigger parent relayout if flex config or dimensions changed
|
|
1047
|
+
if (newFlexConfig || oldFlexConfig || newProps.width !== oldProps.width || newProps.height !== oldProps.height) {
|
|
966
1048
|
if (instance.parent instanceof FlexContainer) {
|
|
967
1049
|
instance.parent.updateLayout();
|
|
968
1050
|
}
|
|
@@ -2155,10 +2237,11 @@ class Modal extends Container {
|
|
|
2155
2237
|
// Overlay
|
|
2156
2238
|
this._overlay = new Graphics();
|
|
2157
2239
|
this._overlay.eventMode = 'static';
|
|
2240
|
+
this._overlay.on('pointertap', () => {
|
|
2241
|
+
if (this._config.closeOnOverlay)
|
|
2242
|
+
this.hide();
|
|
2243
|
+
});
|
|
2158
2244
|
this.addChild(this._overlay);
|
|
2159
|
-
if (this._config.closeOnOverlay) {
|
|
2160
|
-
this._overlay.on('pointertap', () => this.hide());
|
|
2161
|
-
}
|
|
2162
2245
|
// Content container
|
|
2163
2246
|
this._contentContainer = new Container();
|
|
2164
2247
|
this.addChild(this._contentContainer);
|