From f6978c091e472827905cbd66ebef5dab64fdcf28 Mon Sep 17 00:00:00 2001 From: "Theunis J. Botha" Date: Thu, 23 Sep 2021 11:39:21 +0200 Subject: [PATCH] entities become self-aware of init state --- dist/index.html | 9 +- dist/r3.js | 355 +++++++++++++----- package.json | 2 +- r3.php | 53 +++ src/r3/r3-component-code.js | 2 +- src/r3/r3-component/r3-component-canvas.js | 2 +- src/r3/r3-component/r3-component-d-o-m.js | 2 +- src/r3/r3-component/r3-component-graphics.js | 2 +- src/r3/r3-component/r3-component-image.js | 2 +- src/r3/r3-component/r3-component-input.js | 2 +- src/r3/r3-component/r3-component-material.js | 2 +- src/r3/r3-component/r3-component-mesh.js | 2 +- src/r3/r3-component/r3-component-texture.js | 2 +- src/r3/r3-component/r3-component-touch.js | 2 +- src/r3/r3-component/r3-component.js | 2 +- src/r3/r3-entity/r3-entity-slider.js | 81 +++- src/r3/r3-entity/r3-entity.js | 98 ++++- src/r3/r3-event.js | 136 +++---- src/r3/r3-project.js | 2 +- src/r3/r3-r3.js | 4 +- src/r3/r3-system/r3-system-input.js | 1 + src/r3/r3-system/r3-system-linking.js | 46 +++ .../base_check_requirements.template | 1 - src/templates/base_initialize.template | 1 - src/templates/base_set_initialized.template | 72 ++++ src/templates/entity_base.template | 2 +- src/templates/entity_extends.template | 2 +- .../entity_extends_constructor.template | 4 + .../extends_check_requirements.template | 1 - .../extends_set_initialized.template | 1 + .../generated_required_components.template | 24 ++ src/templates/initialize_after.template | 2 +- src/templates/token.db | 8 +- version | 2 +- 34 files changed, 712 insertions(+), 217 deletions(-) delete mode 100644 src/templates/base_check_requirements.template delete mode 100644 src/templates/base_initialize.template create mode 100644 src/templates/base_set_initialized.template delete mode 100644 src/templates/extends_check_requirements.template create mode 100644 src/templates/extends_set_initialized.template diff --git a/dist/index.html b/dist/index.html index 5e06083..9a936c9 100644 --- a/dist/index.html +++ b/dist/index.html @@ -32,10 +32,15 @@ let image = new R3.Image(); let slider = new R3.Entity.Slider( { - canvas : canvas, - images : [image] + canvas : null } ); + + slider.canvas = canvas; + slider.images = [image]; + slider.canvas = null; + slider.canvas = canvas; + slider.images = [image]; }); diff --git a/dist/r3.js b/dist/r3.js index 7b2a81a..876915a 100644 --- a/dist/r3.js +++ b/dist/r3.js @@ -1,6 +1,6 @@ class R3 { - static version = '3.0.17'; - static compileDate = '2021 Sep 22 - 14:41:58 pm'; + static version = '3.0.58'; + static compileDate = '2021 Sep 23 - 11:36:17 am'; } class Runtime { @@ -1153,6 +1153,8 @@ class SystemInput extends System { */ static OnSliderEntityInitialized(object) { + console.log('Slider Entity Initialized'); + } /** @@ -1356,6 +1358,11 @@ class SystemLinking extends System { SystemLinking.OnCreateInstanceBefore ); + SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATE'] = Event.Subscribe( + Event.ENTITY_PROPERTY_UPDATE, + SystemLinking.OnEntityPropertyUpdate + ); + SystemLinking.Started = true; console.log('Started system: SystemLinking'); @@ -1384,6 +1391,9 @@ class SystemLinking extends System { SystemLinking.Subscriptions['CREATE_INSTANCE_BEFORE'].remove(); delete SystemLinking.Subscriptions['CREATE_INSTANCE_BEFORE']; + SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATE'].remove(); + delete SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATE']; + SystemLinking.Started = false; console.log('Stopped system: SystemLinking'); @@ -1477,6 +1487,37 @@ class SystemLinking extends System { } + /** + * OnEntityPropertyUpdate() + * - Listens to events of type Event.ENTITY_PROPERTY_UPDATE and executes this function. + * @param object (The event data passed as argument - typically an R3Object) + * @return + */ + static OnEntityPropertyUpdate(object) { + + console.log('Entity object update', object); + console.log('canvas = ' + object.entity.canvas); + console.log('images = ' + object.entity.images); + + if (!object.entity.underConstruction) { + object.entity.initializeDepth = 0; + object.entity.initialize(); + + if (object.entity.started && !object.entity.initialized) { + object.entity.stop(); + } + + } + + // if (!object.entity.initialized) { + // object.entity.initialize(); + // } else { + // object.entity.stop(); + // } + // object.entity.initialize(); + + } + } /** @@ -2299,40 +2340,41 @@ Event.DISPOSE_OBJECT = 0x7; Event.DOM_COMPONENT_INITIALIZED = 0x8; Event.ENTITY_CREATED = 0x9; Event.ENTITY_INITIALIZED = 0xa; -Event.ENTITY_STARTED = 0xb; -Event.GET_API_URL = 0xc; -Event.GET_RUNTIME = 0xd; -Event.GET_WINDOW_SIZE = 0xe; -Event.GRAPHICS_COMPONENT_INITIALIZED = 0xf; -Event.IMAGE_COMPONENT_INITIALIZED = 0x10; -Event.IMAGE_INSTANCE_CREATED = 0x11; -Event.INPUT_COMPONENT_INITIALIZED = 0x12; -Event.INSTANCE_CREATED = 0x13; -Event.INSTANCE_DISPOSED = 0x14; -Event.KEYBOARD_DOWN = 0x15; -Event.KEYBOARD_UP = 0x16; -Event.MOUSE_DOWN = 0x17; -Event.MOUSE_MOVE = 0x18; -Event.MOUSE_UP = 0x19; -Event.MOUSE_WHEEL = 0x1a; -Event.OBJECT_CREATED = 0x1b; -Event.OBJECT_INITIALIZED = 0x1c; -Event.PAUSE = 0x1d; -Event.PROJECT_INITIALIZED = 0x1e; -Event.RESTART = 0x1f; -Event.SLIDER_ENTITY_INITIALIZED = 0x20; -Event.START = 0x21; -Event.TOUCH_CANCEL = 0x22; -Event.TOUCH_END = 0x23; -Event.TOUCH_MOVE = 0x24; -Event.TOUCH_START = 0x25; -Event.UPDATE_FROM_INSTANCE_AFTER = 0x26; -Event.UPDATE_FROM_INSTANCE_BEFORE = 0x27; -Event.UPDATE_INSTANCE_AFTER = 0x28; -Event.UPDATE_INSTANCE_BEFORE = 0x29; -Event.UPDATE_INSTANCE_PROPERTY = 0x2a; -Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x2b; -Event.MAX_EVENTS = 0x2c; +Event.ENTITY_PROPERTY_UPDATE = 0xb; +Event.ENTITY_STARTED = 0xc; +Event.GET_API_URL = 0xd; +Event.GET_RUNTIME = 0xe; +Event.GET_WINDOW_SIZE = 0xf; +Event.GRAPHICS_COMPONENT_INITIALIZED = 0x10; +Event.IMAGE_COMPONENT_INITIALIZED = 0x11; +Event.IMAGE_INSTANCE_CREATED = 0x12; +Event.INPUT_COMPONENT_INITIALIZED = 0x13; +Event.INSTANCE_CREATED = 0x14; +Event.INSTANCE_DISPOSED = 0x15; +Event.KEYBOARD_DOWN = 0x16; +Event.KEYBOARD_UP = 0x17; +Event.MOUSE_DOWN = 0x18; +Event.MOUSE_MOVE = 0x19; +Event.MOUSE_UP = 0x1a; +Event.MOUSE_WHEEL = 0x1b; +Event.OBJECT_CREATED = 0x1c; +Event.OBJECT_INITIALIZED = 0x1d; +Event.PAUSE = 0x1e; +Event.PROJECT_INITIALIZED = 0x1f; +Event.RESTART = 0x20; +Event.SLIDER_ENTITY_INITIALIZED = 0x21; +Event.START = 0x22; +Event.TOUCH_CANCEL = 0x23; +Event.TOUCH_END = 0x24; +Event.TOUCH_MOVE = 0x25; +Event.TOUCH_START = 0x26; +Event.UPDATE_FROM_INSTANCE_AFTER = 0x27; +Event.UPDATE_FROM_INSTANCE_BEFORE = 0x28; +Event.UPDATE_INSTANCE_AFTER = 0x29; +Event.UPDATE_INSTANCE_BEFORE = 0x2a; +Event.UPDATE_INSTANCE_PROPERTY = 0x2b; +Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x2c; +Event.MAX_EVENTS = 0x2d; Event.GetEventName = function(eventId) { @@ -2347,39 +2389,40 @@ Event.GetEventName = function(eventId) { case 0x8 : return 'dom_component_initialized'; case 0x9 : return 'entity_created'; case 0xa : return 'entity_initialized'; - case 0xb : return 'entity_started'; - case 0xc : return 'get_api_url'; - case 0xd : return 'get_runtime'; - case 0xe : return 'get_window_size'; - case 0xf : return 'graphics_component_initialized'; - case 0x10 : return 'image_component_initialized'; - case 0x11 : return 'image_instance_created'; - case 0x12 : return 'input_component_initialized'; - case 0x13 : return 'instance_created'; - case 0x14 : return 'instance_disposed'; - case 0x15 : return 'keyboard_down'; - case 0x16 : return 'keyboard_up'; - case 0x17 : return 'mouse_down'; - case 0x18 : return 'mouse_move'; - case 0x19 : return 'mouse_up'; - case 0x1a : return 'mouse_wheel'; - case 0x1b : return 'object_created'; - case 0x1c : return 'object_initialized'; - case 0x1d : return 'pause'; - case 0x1e : return 'project_initialized'; - case 0x1f : return 'restart'; - case 0x20 : return 'slider_entity_initialized'; - case 0x21 : return 'start'; - case 0x22 : return 'touch_cancel'; - case 0x23 : return 'touch_end'; - case 0x24 : return 'touch_move'; - case 0x25 : return 'touch_start'; - case 0x26 : return 'update_from_instance_after'; - case 0x27 : return 'update_from_instance_before'; - case 0x28 : return 'update_instance_after'; - case 0x29 : return 'update_instance_before'; - case 0x2a : return 'update_instance_property'; - case 0x2b : return 'update_property_from_instance'; + case 0xb : return 'entity_property_update'; + case 0xc : return 'entity_started'; + case 0xd : return 'get_api_url'; + case 0xe : return 'get_runtime'; + case 0xf : return 'get_window_size'; + case 0x10 : return 'graphics_component_initialized'; + case 0x11 : return 'image_component_initialized'; + case 0x12 : return 'image_instance_created'; + case 0x13 : return 'input_component_initialized'; + case 0x14 : return 'instance_created'; + case 0x15 : return 'instance_disposed'; + case 0x16 : return 'keyboard_down'; + case 0x17 : return 'keyboard_up'; + case 0x18 : return 'mouse_down'; + case 0x19 : return 'mouse_move'; + case 0x1a : return 'mouse_up'; + case 0x1b : return 'mouse_wheel'; + case 0x1c : return 'object_created'; + case 0x1d : return 'object_initialized'; + case 0x1e : return 'pause'; + case 0x1f : return 'project_initialized'; + case 0x20 : return 'restart'; + case 0x21 : return 'slider_entity_initialized'; + case 0x22 : return 'start'; + case 0x23 : return 'touch_cancel'; + case 0x24 : return 'touch_end'; + case 0x25 : return 'touch_move'; + case 0x26 : return 'touch_start'; + case 0x27 : return 'update_from_instance_after'; + case 0x28 : return 'update_from_instance_before'; + case 0x29 : return 'update_instance_after'; + case 0x2a : return 'update_instance_before'; + case 0x2b : return 'update_instance_property'; + case 0x2c : return 'update_property_from_instance'; default : throw new Error('Event type not defined : ' + eventId); } @@ -2610,9 +2653,10 @@ class Entity extends R3Object { */ initialize() { - this.initialized = true; - - this.checkRequirements(); + this.setInitialized(); + if (this.initialized) { + Event.Emit(Event.ENTITY_INITIALIZED, this); + } if (this.initializeDepth === this.maxDepth) { throw new Error('You should not try to instantiate this base class - extend it rather...'); @@ -2623,14 +2667,82 @@ class Entity extends R3Object { } /** - * checkRequirements() + * setInitialized() * - Checks whether all required components are initialized before triggering an Event.ENTITY_INITIALIZED */ - checkRequirements() { + setInitialized() { - //TODO: Check all required components have initialized - once this is the case - fire an Event.ENTITY_INITIALIZED + let ready = true; + for (let property in this.required) { + if (this.required.hasOwnProperty(property)) { - Event.Emit(Event.ENTITY_INITIALIZED, this); + console.log('checking requirements for ' + property); + + let initialized = true; + + if (this.required[property] instanceof Array) { + + /** + * First we need to check if we have this array defined + */ + if (!(this[property] instanceof Array)) { + throw new Error('The property ' + property + ' of this object was not properly defined'); + } + + if (this[property].length === 0) { + initialized = false; + } + + let isInstance = false; + + /** + * Check all properties are an instance of this.required[property] + */ + for (let i = 0; i < this[property].length; i++) { + this.required[property].map( + function(constructor) { + if (this[property][i] instanceof constructor) { + isInstance = true; + } + }.bind(this) + ); + + if (!isInstance) { + throw new Error('The property ' + property + ' of this object is not of the correct type'); + } + } + + for (let i = 0; i < this[property].length; i++) { + if (this[property][i].initialized !== true) { + initialized = false; + } + } + + } else { + + if (this[property] === null) { + initialized = false; + } else { + + if (typeof this[property] === 'undefined') { + throw new Error('The ' + property + ' was not properly defined'); + } + + if (this[property].initialized !== true) { + initialized = false; + } + } + } + + if (!initialized) { + ready = false; + console.log('This property ' + property + ' is not yet initialized'); + } + + } + } + + this.initialized = ready; } @@ -2829,13 +2941,64 @@ class EntitySlider extends Entity { * images - We need a list of at least one image which to slide */ options.required.images = [R3.Image]; - /** + this.imagesBackup = options.images; + Object.defineProperty( + this, + 'images', + { + configurable : true, + enumerable : true, + set: function(x) { + this.imagesBackup = x; + Event.Emit( + Event.ENTITY_PROPERTY_UPDATE, + { + entity : this, + property : 'images', + value : x + } + ); + return x; + }, + get : function() { + return this.imagesBackup; + } + } + ) /** * canvas - We need a canvas to attach our Input events */ options.required.canvas = R3.Canvas; + this.canvasBackup = options.canvas; + Object.defineProperty( + this, + 'canvas', + { + configurable : true, + enumerable : true, + set: function(x) { + this.canvasBackup = x; + Event.Emit( + Event.ENTITY_PROPERTY_UPDATE, + { + entity : this, + property : 'canvas', + value : x + } + ); + return x; + }, + get : function() { + return this.canvasBackup; + } + } + ) + + this.underConstruction = true; Object.assign(this, options); + this.underConstruction = false; + if (options.callDepth === 0) { this.initialize(); } else { @@ -2852,7 +3015,10 @@ class EntitySlider extends Entity { super.initialize(); - Event.Emit(Event.SLIDER_ENTITY_INITIALIZED, this); + if (this.initialized) { + Event.Emit(Event.SLIDER_ENTITY_INITIALIZED, this); + } + //TODO: stop() entity if it is no longer ready if (this.initializeDepth === this.maxDepth) { @@ -2860,7 +3026,7 @@ class EntitySlider extends Entity { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } @@ -2871,14 +3037,12 @@ class EntitySlider extends Entity { } /** - * checkRequirements() + * setInitialized() * - Checks all required Components for this Entity initialized and can perform some custom actions */ - checkRequirements() { + setInitialized() { - super.checkRequirements(); - - Event.Emit(Event.SLIDER_ENTITY_INITIALIZED, this); + super.setInitialized(); } @@ -3105,7 +3269,6 @@ class Component extends R3Object { initialize() { this.initialized = true; - Event.Emit(Event.COMPONENT_INITIALIZED, this); if (this.initializeDepth === this.maxDepth) { @@ -3383,7 +3546,7 @@ class ComponentDOM extends Component { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } @@ -3662,7 +3825,7 @@ class ComponentCanvas extends ComponentDOM { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } @@ -3952,7 +4115,7 @@ class ComponentGraphics extends Component { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } @@ -4281,7 +4444,7 @@ class ComponentImage extends ComponentGraphics { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } @@ -4727,7 +4890,7 @@ class ComponentMaterial extends ComponentGraphics { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } @@ -4947,7 +5110,7 @@ class ComponentMesh extends ComponentGraphics { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } @@ -5167,7 +5330,7 @@ class ComponentTexture extends ComponentGraphics { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } @@ -5371,7 +5534,7 @@ class ComponentInput extends Component { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } @@ -5591,7 +5754,7 @@ class ComponentTouch extends ComponentInput { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } @@ -5793,7 +5956,7 @@ class ComponentCode extends Component { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } @@ -5940,7 +6103,7 @@ class Project extends R3Object { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } diff --git a/package.json b/package.json index 2c45da6..64d90dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "r3", - "version" : "3.0.17", + "version" : "3.0.58", "description": "", "private": true, "dependencies": { diff --git a/r3.php b/r3.php index 58fb37e..14a117f 100755 --- a/r3.php +++ b/r3.php @@ -578,11 +578,64 @@ function generateRequiredComponents($file, $tokens, $token, $section) updateSection($file, $section , $updates); } +function stripRequiredComponents(&$store, $tokens) +{ + $excluded = getTokenStore('CUSTOM_REQUIRED_COMPONENTS', $tokens); + + if (sizeof($excluded) >= 0) { + + $newStore = []; + $excludedIndexes = []; + + foreach ($excluded as $excludedItem) { + $excludedItem = trim($excludedItem); + $matches = []; + + $key_value = preg_match('/^(\s*\w+)=(.*)$/', $excludedItem, $matches); + if ($key_value === false) { + return ''; + } + + $excludedKey = $matches[1]; + + for ($i = 0; $i < sizeof($store); $i++) { + $item = trim($store[$i]); + + $matches = []; + $key_value = preg_match('/^(\s*\w+)=(.*)$/', $item, $matches); + if ($key_value === false) { + continue; + } + + $actualKey = $matches[1]; + + if ($actualKey === $excludedKey) { + array_push($excludedIndexes, $i); + } + } + + + } + + for ($i = 0; $i < sizeof($store); $i++) { + if (!in_array($i, $excludedIndexes)){ + array_push($newStore, $store[$i]); + } + } + + $store = $newStore; + + } + +} + function generateInitOptions($file, $tokens, $token, $section) { $store = getTokenStore($token, $tokens); +// stripRequiredComponents($store, $tokens); + if (sizeof($store) <= 0) { return; } diff --git a/src/r3/r3-component-code.js b/src/r3/r3-component-code.js index 833e350..f154cf9 100644 --- a/src/r3/r3-component-code.js +++ b/src/r3/r3-component-code.js @@ -238,7 +238,7 @@ class ComponentCode extends Component { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } diff --git a/src/r3/r3-component/r3-component-canvas.js b/src/r3/r3-component/r3-component-canvas.js index 20c4576..3d10136 100644 --- a/src/r3/r3-component/r3-component-canvas.js +++ b/src/r3/r3-component/r3-component-canvas.js @@ -289,7 +289,7 @@ class ComponentCanvas extends ComponentDOM { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } diff --git a/src/r3/r3-component/r3-component-d-o-m.js b/src/r3/r3-component/r3-component-d-o-m.js index 2ae54a8..9ac01a5 100644 --- a/src/r3/r3-component/r3-component-d-o-m.js +++ b/src/r3/r3-component/r3-component-d-o-m.js @@ -247,7 +247,7 @@ class ComponentDOM extends Component { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } diff --git a/src/r3/r3-component/r3-component-graphics.js b/src/r3/r3-component/r3-component-graphics.js index 3bf5f81..0cb04da 100644 --- a/src/r3/r3-component/r3-component-graphics.js +++ b/src/r3/r3-component/r3-component-graphics.js @@ -239,7 +239,7 @@ class ComponentGraphics extends Component { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } diff --git a/src/r3/r3-component/r3-component-image.js b/src/r3/r3-component/r3-component-image.js index 6733cef..d4096c7 100644 --- a/src/r3/r3-component/r3-component-image.js +++ b/src/r3/r3-component/r3-component-image.js @@ -380,7 +380,7 @@ class ComponentImage extends ComponentGraphics { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } diff --git a/src/r3/r3-component/r3-component-input.js b/src/r3/r3-component/r3-component-input.js index 15c85f7..cc64aaa 100644 --- a/src/r3/r3-component/r3-component-input.js +++ b/src/r3/r3-component/r3-component-input.js @@ -239,7 +239,7 @@ class ComponentInput extends Component { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } diff --git a/src/r3/r3-component/r3-component-material.js b/src/r3/r3-component/r3-component-material.js index 96703ce..4d46cc2 100644 --- a/src/r3/r3-component/r3-component-material.js +++ b/src/r3/r3-component/r3-component-material.js @@ -256,7 +256,7 @@ class ComponentMaterial extends ComponentGraphics { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } diff --git a/src/r3/r3-component/r3-component-mesh.js b/src/r3/r3-component/r3-component-mesh.js index 50a1892..c62d4b1 100644 --- a/src/r3/r3-component/r3-component-mesh.js +++ b/src/r3/r3-component/r3-component-mesh.js @@ -256,7 +256,7 @@ class ComponentMesh extends ComponentGraphics { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } diff --git a/src/r3/r3-component/r3-component-texture.js b/src/r3/r3-component/r3-component-texture.js index e39e31e..be3b348 100644 --- a/src/r3/r3-component/r3-component-texture.js +++ b/src/r3/r3-component/r3-component-texture.js @@ -256,7 +256,7 @@ class ComponentTexture extends ComponentGraphics { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } diff --git a/src/r3/r3-component/r3-component-touch.js b/src/r3/r3-component/r3-component-touch.js index 745faee..2b2c41a 100644 --- a/src/r3/r3-component/r3-component-touch.js +++ b/src/r3/r3-component/r3-component-touch.js @@ -256,7 +256,7 @@ class ComponentTouch extends ComponentInput { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } diff --git a/src/r3/r3-component/r3-component.js b/src/r3/r3-component/r3-component.js index 9120a6e..bfafc3d 100644 --- a/src/r3/r3-component/r3-component.js +++ b/src/r3/r3-component/r3-component.js @@ -171,10 +171,10 @@ class Component extends R3Object { initialize() { //GENERATED_INITIALIZE_METHOD_START - this.initialized = true; //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START + this.initialized = true; Event.Emit(Event.COMPONENT_INITIALIZED, this); //CUSTOM_INITIALIZE_METHOD_END diff --git a/src/r3/r3-entity/r3-entity-slider.js b/src/r3/r3-entity/r3-entity-slider.js index 2c9057b..17a193f 100644 --- a/src/r3/r3-entity/r3-entity-slider.js +++ b/src/r3/r3-entity/r3-entity-slider.js @@ -128,7 +128,7 @@ const Entity = require('.././r3-entity.js'); TEMPLATE_METHODS_START initialize() - Notifies all systems listening that this component initialized. - checkRequirements() - Checks all required Components for this Entity initialized and can perform some custom actions + setInitialized() - Checks all required Components for this Entity initialized and can perform some custom actions start() - Starts the entity by subscribing to all events stop() - Stops this entity by removing all subscriptions to events TEMPLATE_METHODS_END @@ -247,14 +247,65 @@ class EntitySlider extends Entity { * images - We need a list of at least one image which to slide */ options.required.images = [R3.Image]; - /** + this.imagesBackup = options.images; + Object.defineProperty( + this, + 'images', + { + configurable : true, + enumerable : true, + set: function(x) { + this.imagesBackup = x; + Event.Emit( + Event.ENTITY_PROPERTY_UPDATE, + { + entity : this, + property : 'images', + value : x + } + ); + return x; + }, + get : function() { + return this.imagesBackup; + } + } + ) /** * canvas - We need a canvas to attach our Input events */ options.required.canvas = R3.Canvas; + this.canvasBackup = options.canvas; + Object.defineProperty( + this, + 'canvas', + { + configurable : true, + enumerable : true, + set: function(x) { + this.canvasBackup = x; + Event.Emit( + Event.ENTITY_PROPERTY_UPDATE, + { + entity : this, + property : 'canvas', + value : x + } + ); + return x; + }, + get : function() { + return this.canvasBackup; + } + } + ) //GENERATED_REQUIRED_COMPONENTS_END + this.underConstruction = true; + Object.assign(this, options); + this.underConstruction = false; + //CUSTOM_OPTIONS_INIT_START //CUSTOM_OPTIONS_INIT_END @@ -285,7 +336,10 @@ class EntitySlider extends Entity { //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START - Event.Emit(Event.SLIDER_ENTITY_INITIALIZED, this); + if (this.initialized) { + Event.Emit(Event.SLIDER_ENTITY_INITIALIZED, this); + } + //TODO: stop() entity if it is no longer ready //CUSTOM_INITIALIZE_METHOD_END //GENERATED_INITIALIZE_METHOD_AFTER_START @@ -295,7 +349,7 @@ class EntitySlider extends Entity { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } @@ -307,21 +361,20 @@ class EntitySlider extends Entity { } /** - * checkRequirements() + * setInitialized() * - Checks all required Components for this Entity initialized and can perform some custom actions */ - checkRequirements() { + setInitialized() { - //GENERATED_CHECK_REQUIREMENTS_METHOD_START - super.checkRequirements(); - //GENERATED_CHECK_REQUIREMENTS_METHOD_END + //GENERATED_SET_INITIALIZED_METHOD_START + super.setInitialized(); + //GENERATED_SET_INITIALIZED_METHOD_END - //CUSTOM_CHECK_REQUIREMENTS_METHOD_START - Event.Emit(Event.SLIDER_ENTITY_INITIALIZED, this); - //CUSTOM_CHECK_REQUIREMENTS_METHOD_END + //CUSTOM_SET_INITIALIZED_METHOD_START + //CUSTOM_SET_INITIALIZED_METHOD_END - //GENERATED_CHECK_REQUIREMENTS_METHOD_AFTER_START - //GENERATED_CHECK_REQUIREMENTS_METHOD_AFTER_END + //GENERATED_SET_INITIALIZED_METHOD_AFTER_START + //GENERATED_SET_INITIALIZED_METHOD_AFTER_END } diff --git a/src/r3/r3-entity/r3-entity.js b/src/r3/r3-entity/r3-entity.js index e6e45f1..2769e56 100644 --- a/src/r3/r3-entity/r3-entity.js +++ b/src/r3/r3-entity/r3-entity.js @@ -99,7 +99,7 @@ const R3Object = require('.././r3-r3-object.js'); TEMPLATE_METHODS_START initialize() - Should raises an event(s) which indicates that this object initialized - checkRequirements() - Checks whether all required components are initialized before triggering an Event.ENTITY_INITIALIZED + setInitialized() - Checks whether all required components are initialized before triggering an Event.ENTITY_INITIALIZED TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -172,11 +172,13 @@ class Entity extends R3Object { initialize() { //GENERATED_INITIALIZE_METHOD_START - this.initialized = true; //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START - this.checkRequirements(); + this.setInitialized(); + if (this.initialized) { + Event.Emit(Event.ENTITY_INITIALIZED, this); + } //CUSTOM_INITIALIZE_METHOD_END //GENERATED_INITIALIZE_METHOD_AFTER_START @@ -190,21 +192,91 @@ class Entity extends R3Object { } /** - * checkRequirements() + * setInitialized() * - Checks whether all required components are initialized before triggering an Event.ENTITY_INITIALIZED */ - checkRequirements() { + setInitialized() { - //GENERATED_CHECK_REQUIREMENTS_METHOD_START - //TODO: Check all required components have initialized - once this is the case - fire an Event.ENTITY_INITIALIZED - //GENERATED_CHECK_REQUIREMENTS_METHOD_END + //GENERATED_SET_INITIALIZED_METHOD_START + let ready = true; + for (let property in this.required) { + if (this.required.hasOwnProperty(property)) { - //CUSTOM_CHECK_REQUIREMENTS_METHOD_START - Event.Emit(Event.ENTITY_INITIALIZED, this); - //CUSTOM_CHECK_REQUIREMENTS_METHOD_END + console.log('checking requirements for ' + property); - //GENERATED_CHECK_REQUIREMENTS_METHOD_AFTER_START - //GENERATED_CHECK_REQUIREMENTS_METHOD_AFTER_END + let initialized = true; + + if (this.required[property] instanceof Array) { + + /** + * First we need to check if we have this array defined + */ + if (!(this[property] instanceof Array)) { + throw new Error('The property ' + property + ' of this object was not properly defined'); + } + + if (this[property].length === 0) { + initialized = false; + } + + let isInstance = false; + + /** + * Check all properties are an instance of this.required[property] + */ + for (let i = 0; i < this[property].length; i++) { + this.required[property].map( + function(constructor) { + if (this[property][i] instanceof constructor) { + isInstance = true; + } + }.bind(this) + ); + + if (!isInstance) { + throw new Error('The property ' + property + ' of this object is not of the correct type'); + } + } + + for (let i = 0; i < this[property].length; i++) { + if (this[property][i].initialized !== true) { + initialized = false; + } + } + + } else { + + if (this[property] === null) { + initialized = false; + } else { + + if (typeof this[property] === 'undefined') { + throw new Error('The ' + property + ' was not properly defined'); + } + + if (this[property].initialized !== true) { + initialized = false; + } + } + } + + if (!initialized) { + ready = false; + console.log('This property ' + property + ' is not yet initialized'); + } + + + } + } + + this.initialized = ready; + //GENERATED_SET_INITIALIZED_METHOD_END + + //CUSTOM_SET_INITIALIZED_METHOD_START + //CUSTOM_SET_INITIALIZED_METHOD_END + + //GENERATED_SET_INITIALIZED_METHOD_AFTER_START + //GENERATED_SET_INITIALIZED_METHOD_AFTER_END } //GENERATED_TEMPLATE_METHODS_END diff --git a/src/r3/r3-event.js b/src/r3/r3-event.js index 51bcdf1..76e6fa9 100644 --- a/src/r3/r3-event.js +++ b/src/r3/r3-event.js @@ -355,40 +355,41 @@ Event.DISPOSE_OBJECT = 0x7; Event.DOM_COMPONENT_INITIALIZED = 0x8; Event.ENTITY_CREATED = 0x9; Event.ENTITY_INITIALIZED = 0xa; -Event.ENTITY_STARTED = 0xb; -Event.GET_API_URL = 0xc; -Event.GET_RUNTIME = 0xd; -Event.GET_WINDOW_SIZE = 0xe; -Event.GRAPHICS_COMPONENT_INITIALIZED = 0xf; -Event.IMAGE_COMPONENT_INITIALIZED = 0x10; -Event.IMAGE_INSTANCE_CREATED = 0x11; -Event.INPUT_COMPONENT_INITIALIZED = 0x12; -Event.INSTANCE_CREATED = 0x13; -Event.INSTANCE_DISPOSED = 0x14; -Event.KEYBOARD_DOWN = 0x15; -Event.KEYBOARD_UP = 0x16; -Event.MOUSE_DOWN = 0x17; -Event.MOUSE_MOVE = 0x18; -Event.MOUSE_UP = 0x19; -Event.MOUSE_WHEEL = 0x1a; -Event.OBJECT_CREATED = 0x1b; -Event.OBJECT_INITIALIZED = 0x1c; -Event.PAUSE = 0x1d; -Event.PROJECT_INITIALIZED = 0x1e; -Event.RESTART = 0x1f; -Event.SLIDER_ENTITY_INITIALIZED = 0x20; -Event.START = 0x21; -Event.TOUCH_CANCEL = 0x22; -Event.TOUCH_END = 0x23; -Event.TOUCH_MOVE = 0x24; -Event.TOUCH_START = 0x25; -Event.UPDATE_FROM_INSTANCE_AFTER = 0x26; -Event.UPDATE_FROM_INSTANCE_BEFORE = 0x27; -Event.UPDATE_INSTANCE_AFTER = 0x28; -Event.UPDATE_INSTANCE_BEFORE = 0x29; -Event.UPDATE_INSTANCE_PROPERTY = 0x2a; -Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x2b; -Event.MAX_EVENTS = 0x2c; +Event.ENTITY_PROPERTY_UPDATE = 0xb; +Event.ENTITY_STARTED = 0xc; +Event.GET_API_URL = 0xd; +Event.GET_RUNTIME = 0xe; +Event.GET_WINDOW_SIZE = 0xf; +Event.GRAPHICS_COMPONENT_INITIALIZED = 0x10; +Event.IMAGE_COMPONENT_INITIALIZED = 0x11; +Event.IMAGE_INSTANCE_CREATED = 0x12; +Event.INPUT_COMPONENT_INITIALIZED = 0x13; +Event.INSTANCE_CREATED = 0x14; +Event.INSTANCE_DISPOSED = 0x15; +Event.KEYBOARD_DOWN = 0x16; +Event.KEYBOARD_UP = 0x17; +Event.MOUSE_DOWN = 0x18; +Event.MOUSE_MOVE = 0x19; +Event.MOUSE_UP = 0x1a; +Event.MOUSE_WHEEL = 0x1b; +Event.OBJECT_CREATED = 0x1c; +Event.OBJECT_INITIALIZED = 0x1d; +Event.PAUSE = 0x1e; +Event.PROJECT_INITIALIZED = 0x1f; +Event.RESTART = 0x20; +Event.SLIDER_ENTITY_INITIALIZED = 0x21; +Event.START = 0x22; +Event.TOUCH_CANCEL = 0x23; +Event.TOUCH_END = 0x24; +Event.TOUCH_MOVE = 0x25; +Event.TOUCH_START = 0x26; +Event.UPDATE_FROM_INSTANCE_AFTER = 0x27; +Event.UPDATE_FROM_INSTANCE_BEFORE = 0x28; +Event.UPDATE_INSTANCE_AFTER = 0x29; +Event.UPDATE_INSTANCE_BEFORE = 0x2a; +Event.UPDATE_INSTANCE_PROPERTY = 0x2b; +Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x2c; +Event.MAX_EVENTS = 0x2d; Event.GetEventName = function(eventId) { @@ -403,39 +404,40 @@ Event.GetEventName = function(eventId) { case 0x8 : return 'dom_component_initialized'; case 0x9 : return 'entity_created'; case 0xa : return 'entity_initialized'; - case 0xb : return 'entity_started'; - case 0xc : return 'get_api_url'; - case 0xd : return 'get_runtime'; - case 0xe : return 'get_window_size'; - case 0xf : return 'graphics_component_initialized'; - case 0x10 : return 'image_component_initialized'; - case 0x11 : return 'image_instance_created'; - case 0x12 : return 'input_component_initialized'; - case 0x13 : return 'instance_created'; - case 0x14 : return 'instance_disposed'; - case 0x15 : return 'keyboard_down'; - case 0x16 : return 'keyboard_up'; - case 0x17 : return 'mouse_down'; - case 0x18 : return 'mouse_move'; - case 0x19 : return 'mouse_up'; - case 0x1a : return 'mouse_wheel'; - case 0x1b : return 'object_created'; - case 0x1c : return 'object_initialized'; - case 0x1d : return 'pause'; - case 0x1e : return 'project_initialized'; - case 0x1f : return 'restart'; - case 0x20 : return 'slider_entity_initialized'; - case 0x21 : return 'start'; - case 0x22 : return 'touch_cancel'; - case 0x23 : return 'touch_end'; - case 0x24 : return 'touch_move'; - case 0x25 : return 'touch_start'; - case 0x26 : return 'update_from_instance_after'; - case 0x27 : return 'update_from_instance_before'; - case 0x28 : return 'update_instance_after'; - case 0x29 : return 'update_instance_before'; - case 0x2a : return 'update_instance_property'; - case 0x2b : return 'update_property_from_instance'; + case 0xb : return 'entity_property_update'; + case 0xc : return 'entity_started'; + case 0xd : return 'get_api_url'; + case 0xe : return 'get_runtime'; + case 0xf : return 'get_window_size'; + case 0x10 : return 'graphics_component_initialized'; + case 0x11 : return 'image_component_initialized'; + case 0x12 : return 'image_instance_created'; + case 0x13 : return 'input_component_initialized'; + case 0x14 : return 'instance_created'; + case 0x15 : return 'instance_disposed'; + case 0x16 : return 'keyboard_down'; + case 0x17 : return 'keyboard_up'; + case 0x18 : return 'mouse_down'; + case 0x19 : return 'mouse_move'; + case 0x1a : return 'mouse_up'; + case 0x1b : return 'mouse_wheel'; + case 0x1c : return 'object_created'; + case 0x1d : return 'object_initialized'; + case 0x1e : return 'pause'; + case 0x1f : return 'project_initialized'; + case 0x20 : return 'restart'; + case 0x21 : return 'slider_entity_initialized'; + case 0x22 : return 'start'; + case 0x23 : return 'touch_cancel'; + case 0x24 : return 'touch_end'; + case 0x25 : return 'touch_move'; + case 0x26 : return 'touch_start'; + case 0x27 : return 'update_from_instance_after'; + case 0x28 : return 'update_from_instance_before'; + case 0x29 : return 'update_instance_after'; + case 0x2a : return 'update_instance_before'; + case 0x2b : return 'update_instance_property'; + case 0x2c : return 'update_property_from_instance'; default : throw new Error('Event type not defined : ' + eventId); } diff --git a/src/r3/r3-project.js b/src/r3/r3-project.js index b986c81..f6c84ea 100644 --- a/src/r3/r3-project.js +++ b/src/r3/r3-project.js @@ -166,7 +166,7 @@ class Project extends R3Object { this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } diff --git a/src/r3/r3-r3.js b/src/r3/r3-r3.js index cad9122..f153653 100644 --- a/src/r3/r3-r3.js +++ b/src/r3/r3-r3.js @@ -1,6 +1,6 @@ class R3 { - static version = '3.0.17'; - static compileDate = '2021 Sep 22 - 14:41:58 pm'; + static version = '3.0.58'; + static compileDate = '2021 Sep 23 - 11:36:17 am'; } //GENERATED_IMPORTS_START diff --git a/src/r3/r3-system/r3-system-input.js b/src/r3/r3-system/r3-system-input.js index 41ced03..01cd9d2 100644 --- a/src/r3/r3-system/r3-system-input.js +++ b/src/r3/r3-system/r3-system-input.js @@ -288,6 +288,7 @@ class SystemInput extends System { //GENERATED_STATIC_ON_SLIDER_ENTITY_INITIALIZED_METHOD_END //CUSTOM_STATIC_ON_SLIDER_ENTITY_INITIALIZED_METHOD_START + console.log('Slider Entity Initialized'); //CUSTOM_STATIC_ON_SLIDER_ENTITY_INITIALIZED_METHOD_END } diff --git a/src/r3/r3-system/r3-system-linking.js b/src/r3/r3-system/r3-system-linking.js index eec1a3e..e72f033 100644 --- a/src/r3/r3-system/r3-system-linking.js +++ b/src/r3/r3-system/r3-system-linking.js @@ -70,6 +70,7 @@ const System = require('.././r3-system.js'); Event.ENTITY_INITIALIZED Event.INSTANCE_CREATED Event.CREATE_INSTANCE_BEFORE - @returns boolean delayInstance which indicates whether or not instance creation is delayed (handled) by another system. (i.e. where instance creation order is of importance) + Event.ENTITY_PROPERTY_UPDATE CUSTOM_STATIC_EVENT_LISTENERS_END TEMPLATE_METHODS_START @@ -158,6 +159,11 @@ class SystemLinking extends System { SystemLinking.OnCreateInstanceBefore ); + SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATE'] = Event.Subscribe( + Event.ENTITY_PROPERTY_UPDATE, + SystemLinking.OnEntityPropertyUpdate + ); + //GENERATED_STATIC_EVENT_LISTENERS_START_END //CUSTOM_BEFORE_STATIC_SYSTEM_START_START @@ -199,6 +205,9 @@ class SystemLinking extends System { SystemLinking.Subscriptions['CREATE_INSTANCE_BEFORE'].remove(); delete SystemLinking.Subscriptions['CREATE_INSTANCE_BEFORE']; + SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATE'].remove(); + delete SystemLinking.Subscriptions['ENTITY_PROPERTY_UPDATE']; + //GENERATED_STATIC_EVENT_LISTENERS_STOP_END //CUSTOM_BEFORE_STATIC_SYSTEM_STOP_START @@ -334,6 +343,43 @@ class SystemLinking extends System { return false; //CUSTOM_STATIC_ON_CREATE_INSTANCE_BEFORE_METHOD_END + } + + /** + * OnEntityPropertyUpdate() + * - Listens to events of type Event.ENTITY_PROPERTY_UPDATE and executes this function. + * @param object (The event data passed as argument - typically an R3Object) + * @return + */ + static OnEntityPropertyUpdate(object) { + + //GENERATED_STATIC_ON_ENTITY_PROPERTY_UPDATE_METHOD_START + //GENERATED_STATIC_ON_ENTITY_PROPERTY_UPDATE_METHOD_END + + //CUSTOM_STATIC_ON_ENTITY_PROPERTY_UPDATE_METHOD_START + console.log('Entity object update', object); + console.log('canvas = ' + object.entity.canvas); + console.log('images = ' + object.entity.images); + + if (!object.entity.underConstruction) { + object.entity.initializeDepth = 0; + object.entity.initialize(); + + if (object.entity.started && !object.entity.initialized) { + object.entity.stop(); + } + + } + + + // if (!object.entity.initialized) { + // object.entity.initialize(); + // } else { + // object.entity.stop(); + // } + // object.entity.initialize(); + //CUSTOM_STATIC_ON_ENTITY_PROPERTY_UPDATE_METHOD_END + } //GENERATED_STATIC_EVENT_LISTENER_METHODS_END diff --git a/src/templates/base_check_requirements.template b/src/templates/base_check_requirements.template deleted file mode 100644 index 5e08c7c..0000000 --- a/src/templates/base_check_requirements.template +++ /dev/null @@ -1 +0,0 @@ - //TODO: Check all required components have initialized - once this is the case - fire an Event.ENTITY_INITIALIZED \ No newline at end of file diff --git a/src/templates/base_initialize.template b/src/templates/base_initialize.template deleted file mode 100644 index 01d226d..0000000 --- a/src/templates/base_initialize.template +++ /dev/null @@ -1 +0,0 @@ - this.initialized = true; \ No newline at end of file diff --git a/src/templates/base_set_initialized.template b/src/templates/base_set_initialized.template new file mode 100644 index 0000000..a10c6c1 --- /dev/null +++ b/src/templates/base_set_initialized.template @@ -0,0 +1,72 @@ + let ready = true; + for (let property in this.required) { + if (this.required.hasOwnProperty(property)) { + + console.log('checking requirements for ' + property); + + let initialized = true; + + if (this.required[property] instanceof Array) { + + /** + * First we need to check if we have this array defined + */ + if (!(this[property] instanceof Array)) { + throw new Error('The property ' + property + ' of this object was not properly defined'); + } + + if (this[property].length === 0) { + initialized = false; + } + + let isInstance = false; + + /** + * Check all properties are an instance of this.required[property] + */ + for (let i = 0; i < this[property].length; i++) { + this.required[property].map( + function(constructor) { + if (this[property][i] instanceof constructor) { + isInstance = true; + } + }.bind(this) + ); + + if (!isInstance) { + throw new Error('The property ' + property + ' of this object is not of the correct type'); + } + } + + for (let i = 0; i < this[property].length; i++) { + if (this[property][i].initialized !== true) { + initialized = false; + } + } + + } else { + + if (this[property] === null) { + initialized = false; + } else { + + if (typeof this[property] === 'undefined') { + throw new Error('The ' + property + ' was not properly defined'); + } + + if (this[property].initialized !== true) { + initialized = false; + } + } + } + + if (!initialized) { + ready = false; + console.log('This property ' + property + ' is not yet initialized'); + } + + + } + } + + this.initialized = ready; \ No newline at end of file diff --git a/src/templates/entity_base.template b/src/templates/entity_base.template index e85b5bc..e4ceca4 100644 --- a/src/templates/entity_base.template +++ b/src/templates/entity_base.template @@ -22,7 +22,7 @@ const R3Object = require('.././r3-r3-object.js'); TEMPLATE_METHODS_START initialize() - Should raises an event(s) which indicates that this object initialized - checkRequirements() - Checks whether all required components are initialized before triggering an Event.ENTITY_INITIALIZED + setInitialized() - Checks whether all required components are initialized before triggering an Event.ENTITY_INITIALIZED TEMPLATE_METHODS_END CUSTOM_METHODS_START diff --git a/src/templates/entity_extends.template b/src/templates/entity_extends.template index 6900a5d..93a67cd 100644 --- a/src/templates/entity_extends.template +++ b/src/templates/entity_extends.template @@ -28,7 +28,7 @@ const EXTEND_CLASS = require('INCLUDE_PATH/EXTEND_CLASS_FILE_NAME'); TEMPLATE_METHODS_START initialize() - Notifies all systems listening that this component initialized. - checkRequirements() - Checks all required Components for this Entity initialized and can perform some custom actions + setInitialized() - Checks all required Components for this Entity initialized and can perform some custom actions start() - Starts the entity by subscribing to all events stop() - Stops this entity by removing all subscriptions to events TEMPLATE_METHODS_END diff --git a/src/templates/entity_extends_constructor.template b/src/templates/entity_extends_constructor.template index d2defea..2d6ef89 100644 --- a/src/templates/entity_extends_constructor.template +++ b/src/templates/entity_extends_constructor.template @@ -35,8 +35,12 @@ //GENERATED_REQUIRED_COMPONENTS_START //GENERATED_REQUIRED_COMPONENTS_END + this.underConstruction = true; + Object.assign(this, options); + this.underConstruction = false; + //CUSTOM_OPTIONS_INIT_START //CUSTOM_OPTIONS_INIT_END diff --git a/src/templates/extends_check_requirements.template b/src/templates/extends_check_requirements.template deleted file mode 100644 index 134bb6c..0000000 --- a/src/templates/extends_check_requirements.template +++ /dev/null @@ -1 +0,0 @@ - super.checkRequirements(); \ No newline at end of file diff --git a/src/templates/extends_set_initialized.template b/src/templates/extends_set_initialized.template new file mode 100644 index 0000000..c125a28 --- /dev/null +++ b/src/templates/extends_set_initialized.template @@ -0,0 +1 @@ + super.setInitialized(); \ No newline at end of file diff --git a/src/templates/generated_required_components.template b/src/templates/generated_required_components.template index 5558aa1..1e9433f 100644 --- a/src/templates/generated_required_components.template +++ b/src/templates/generated_required_components.template @@ -2,3 +2,27 @@ * KEY - COMMENT */ options.required.KEY = VALUE; + this.KEYBackup = options.KEY; + Object.defineProperty( + this, + 'KEY', + { + configurable : true, + enumerable : true, + set: function(x) { + this.KEYBackup = x; + Event.Emit( + Event.ENTITY_PROPERTY_UPDATE, + { + entity : this, + property : 'KEY', + value : x + } + ); + return x; + }, + get : function() { + return this.KEYBackup; + } + } + ) \ No newline at end of file diff --git a/src/templates/initialize_after.template b/src/templates/initialize_after.template index 4b89970..c19d2c6 100644 --- a/src/templates/initialize_after.template +++ b/src/templates/initialize_after.template @@ -4,7 +4,7 @@ this.createInstance(); } - if (this instanceof R3.Entity) { + if (this instanceof R3.Entity && this.initialized) { this.start(); } diff --git a/src/templates/token.db b/src/templates/token.db index 281fc55..bed9873 100644 --- a/src/templates/token.db +++ b/src/templates/token.db @@ -2,8 +2,6 @@ GENERATED_ASYNC_METHOD GENERATED_ASYNC_METHOD_AFTER GENERATED_BUILD_INSTANCE_METHOD GENERATED_BUILD_INSTANCE_METHOD_AFTER -GENERATED_CHECK_REQUIREMENTS_METHOD -GENERATED_CHECK_REQUIREMENTS_METHOD_AFTER GENERATED_CONSTRUCTOR GENERATED_CREATE_INSTANCE_METHOD GENERATED_CREATE_INSTANCE_METHOD_AFTER @@ -38,6 +36,8 @@ GENERATED_ON_TOUCH_START_METHOD_AFTER GENERATED_OPTIONS_INIT GENERATED_OUT_OF_CLASS_IMPLEMENTATION GENERATED_REQUIRED_COMPONENTS +GENERATED_SET_INITIALIZED_METHOD +GENERATED_SET_INITIALIZED_METHOD_AFTER GENERATED_SET_RUNTIME_METHOD GENERATED_SET_RUNTIME_METHOD_AFTER GENERATED_START_METHOD @@ -53,6 +53,7 @@ GENERATED_STATIC_ON_COMPONENT_INITIALIZED_METHOD GENERATED_STATIC_ON_CREATE_INSTANCE_BEFORE_METHOD GENERATED_STATIC_ON_DOM_COMPONENT_INITIALIZED_METHOD GENERATED_STATIC_ON_ENTITY_INITIALIZED_METHOD +GENERATED_STATIC_ON_ENTITY_PROPERTY_UPDATE_METHOD GENERATED_STATIC_ON_GET_API_URL_METHOD GENERATED_STATIC_ON_GET_RUNTIME_METHOD GENERATED_STATIC_ON_IMAGE_INSTANCE_CREATED_METHOD @@ -98,7 +99,6 @@ CUSTOM_BEFORE_STATIC_SYSTEM_STOP CUSTOM_BEFORE_SYSTEM_START CUSTOM_BEFORE_SYSTEM_STOP CUSTOM_BUILD_INSTANCE_METHOD -CUSTOM_CHECK_REQUIREMENTS_METHOD CUSTOM_CONVENIENT_DEFINES CUSTOM_CREATE_INSTANCE_METHOD CUSTOM_DISPOSE_INSTANCE_METHOD @@ -119,6 +119,7 @@ CUSTOM_OPTIONS CUSTOM_OPTIONS_INIT CUSTOM_OUT_OF_CLASS_IMPLEMENTATION CUSTOM_REQUIRED_COMPONENTS +CUSTOM_SET_INITIALIZED_METHOD CUSTOM_SET_RUNTIME_METHOD CUSTOM_START_METHOD CUSTOM_STATIC_ASYNC_METHOD @@ -130,6 +131,7 @@ CUSTOM_STATIC_ON_COMPONENT_INITIALIZED_METHOD CUSTOM_STATIC_ON_CREATE_INSTANCE_BEFORE_METHOD CUSTOM_STATIC_ON_DOM_COMPONENT_INITIALIZED_METHOD CUSTOM_STATIC_ON_ENTITY_INITIALIZED_METHOD +CUSTOM_STATIC_ON_ENTITY_PROPERTY_UPDATE_METHOD CUSTOM_STATIC_ON_GET_API_URL_METHOD CUSTOM_STATIC_ON_GET_RUNTIME_METHOD CUSTOM_STATIC_ON_IMAGE_INSTANCE_CREATED_METHOD diff --git a/version b/version index a99de22..3041e12 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.0.17 \ No newline at end of file +3.0.58 \ No newline at end of file