Fix changing of variant not being applied at hot-reload (#7666)

This commit is contained in:
D8H
2025-06-24 10:41:57 +02:00
committed by GitHub
parent 00376f39d5
commit 9467caf1e9
11 changed files with 45 additions and 16 deletions

View File

@@ -14,6 +14,7 @@ namespace gdjs {
animatable?: SpriteAnimationData[];
variant: string;
childrenContent: { [objectName: string]: ObjectConfiguration & any };
isInnerAreaFollowingParentSize: boolean;
};
/**
@@ -154,10 +155,12 @@ namespace gdjs {
override reinitialize(objectData: ObjectData & CustomObjectConfiguration) {
super.reinitialize(objectData);
this._initializeFromObjectData(objectData);
this._reinitializeRenderer();
this._initializeFromObjectData(objectData);
// The generated code calls the onCreated super implementation at the end.
// When changing the variant, the instance is like a new instance.
// We call again `onCreated` at the end, like done by the constructor
// the first time it's created.
this.onCreated();
}
@@ -172,6 +175,34 @@ namespace gdjs {
newObjectData.animatable || []
);
}
if (oldObjectData.variant !== newObjectData.variant) {
const width = this.getWidth();
const height = this.getHeight();
const hasInnerAreaChanged =
oldObjectData.isInnerAreaFollowingParentSize &&
this._instanceContainer._initialInnerArea &&
this._innerArea &&
(this._instanceContainer._initialInnerArea.min[0] !==
this._innerArea.min[0] ||
this._instanceContainer._initialInnerArea.min[1] !==
this._innerArea.min[1] ||
this._instanceContainer._initialInnerArea.max[0] !==
this._innerArea.max[0] ||
this._instanceContainer._initialInnerArea.max[1] !==
this._innerArea.max[1]);
this._reinitializeRenderer();
this._initializeFromObjectData(newObjectData);
// The generated code calls the onCreated super implementation at the end.
this.onCreated();
// Keep the custom size
if (hasInnerAreaChanged) {
this.setWidth(width);
this.setHeight(height);
}
}
return true;
}

View File

@@ -8,7 +8,6 @@ namespace gdjs {
objectData: ObjectData & CustomObjectConfiguration
) {
super(parent, objectData);
this.getRenderer().reinitialize(this, parent);
}
protected override _createRender(): gdjs.CustomRuntimeObject2DRenderer {

View File

@@ -24,7 +24,7 @@ namespace gdjs {
*
* @see gdjs.CustomRuntimeObject._innerArea
**/
private _initialInnerArea: {
_initialInnerArea: {
min: [float, float, float];
max: [float, float, float];
} | null = null;
@@ -47,6 +47,9 @@ namespace gdjs {
}
addLayer(layerData: LayerData) {
if (this._layers.containsKey(layerData.name)) {
return;
}
const layer = new gdjs.RuntimeCustomObjectLayer(layerData, this);
this._layers.put(layerData.name, layer);
this._orderedLayers.push(layer);

View File

@@ -811,6 +811,8 @@ namespace gdjs {
this._objectsCtor = new Hashtable();
this._allInstancesList = [];
this._instancesRemoved = [];
this._layersCameraCoordinates = {};
this._initialBehaviorSharedData = new Hashtable();
}
}
}

View File

@@ -50,12 +50,7 @@ namespace gdjs {
) {
this._object = object;
this._isContainerDirty = true;
const layer = parent.getLayer('');
if (layer) {
layer
.getRenderer()
.addRendererObject(this._pixiContainer, object.getZOrder());
}
this._pixiContainer.removeChildren();
}
getRendererObject() {

View File

@@ -229,7 +229,7 @@ declare interface EventsBasedObjectVariantData extends InstanceContainerData {
/**
* A value shared by every object instances.
*
* @see gdjs.CustomRuntimeObjectInstanceContainer._originalInnerArea
* @see gdjs.CustomRuntimeObjectInstanceContainer._initialInnerArea
**/
_initialInnerArea: {
min: [float, float, float];

View File

@@ -16,6 +16,7 @@ describe('gdjs.CustomRuntimeObject', function () {
name: 'MyCustomObject',
type: 'MyExtension::MyEventsBasedObject',
variant: '',
isInnerAreaFollowingParentSize: false,
variables: [],
behaviors: [],
effects: [],

View File

@@ -100,6 +100,7 @@ describe('gdjs.HotReloader._hotReloadRuntimeGame', () => {
effects: [],
content: {},
childrenContent: {},
isInnerAreaFollowingParentSize: false,
};
/** @type {LayerData} */