Files
GDevelop/GDJS/tests/tests-utils/MockedCustomObject.js
D8H a515836add Avoid to duplicate custom object data in the project files (#6904)
- Fix hot-reload of sprite object animations
2024-09-02 18:52:27 +02:00

53 lines
1.6 KiB
JavaScript

gdjs.evtsExt__MyExtension__MyCustomObject = gdjs.evtsExt__MyExtension__MyCustomObject || {};
/**
* Mocked generated custom object for MyExtension::MyCustomObject.
*/
gdjs.evtsExt__MyExtension__MyCustomObject.MyCustomObject = class MyCustomObject extends gdjs.CustomRuntimeObject2D {
constructor(parentInstanceContainer, objectData) {
super(parentInstanceContainer, objectData);
this._parentInstanceContainer = parentInstanceContainer;
this._onceTriggers = new gdjs.OnceTriggers();
this._objectData = {};
this._objectData.MyProperty = objectData.content.MyProperty !== undefined ? objectData.content.MyProperty : Number("123") || 0;
// It calls the onCreated super implementation at the end.
this.onCreated();
}
// Hot-reload:
updateFromObjectData(oldObjectData, newObjectData) {
super.updateFromObjectData(oldObjectData, newObjectData);
if (oldObjectData.content.MyProperty !== newObjectData.content.MyProperty)
this._objectData.MyProperty = newObjectData.content.MyProperty;
this.onHotReloading(this._parentInstanceContainer);
return true;
}
// Properties:
_getMyProperty() {
return this._objectData.MyProperty !== undefined ? this._objectData.MyProperty : Number("123") || 0;
}
_setMyProperty(newValue) {
this._objectData.MyProperty = newValue;
}
}
// Methods:
gdjs.evtsExt__MyExtension__MyCustomObject.MyCustomObject.prototype.doStepPreEvents = function() {
this._onceTriggers.startNewFrame();
};
gdjs.registerObject("MyExtension::MyCustomObject", gdjs.evtsExt__MyExtension__MyCustomObject.MyCustomObject);