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