From d2474293e31f6e2e7fffd9080eb1372cefd9a5e6 Mon Sep 17 00:00:00 2001 From: "Theunis J. Botha" Date: Fri, 24 Sep 2021 09:32:27 +0200 Subject: [PATCH] started initialize for all objects --- .r3_history | 4 +- dist/r3.js | 617 +++++++++--------- package.json | 2 +- r3.php | 9 + src/r3/r3-component/r3-component-canvas.js | 10 +- src/r3/r3-component/r3-component-code.js | 10 +- src/r3/r3-component/r3-component-d-o-m.js | 10 +- src/r3/r3-component/r3-component-graphics.js | 10 +- src/r3/r3-component/r3-component-image.js | 22 +- src/r3/r3-component/r3-component-input.js | 10 +- src/r3/r3-component/r3-component-material.js | 10 +- src/r3/r3-component/r3-component-mesh.js | 10 +- src/r3/r3-component/r3-component-texture.js | 10 +- src/r3/r3-component/r3-component-touch.js | 10 +- src/r3/r3-component/r3-component.js | 12 +- src/r3/r3-entity/r3-entity-slider.js | 44 +- src/r3/r3-entity/r3-entity.js | 112 +--- src/r3/r3-event.js | 68 +- src/r3/r3-project.js | 156 ++++- src/r3/r3-r3-object.js | 200 +++++- src/r3/r3-r3.js | 4 +- .../component_extends_constructor.template | 4 - src/templates/entity_base.template | 1 - src/templates/entity_extends.template | 5 +- .../entity_extends_constructor.template | 4 - src/templates/object_base.template | 79 +++ .../object_base_constructor.template | 41 ++ src/templates/object_extends.template | 85 +++ .../object_extends_constructor.template | 54 ++ version | 2 +- 30 files changed, 973 insertions(+), 642 deletions(-) create mode 100644 src/templates/object_base.template create mode 100644 src/templates/object_base_constructor.template create mode 100644 src/templates/object_extends.template create mode 100644 src/templates/object_extends_constructor.template diff --git a/.r3_history b/.r3_history index 120880c..77f3f66 100644 --- a/.r3_history +++ b/.r3_history @@ -11,9 +11,8 @@ r3 create ComponentTouch component_extends ComponentInput ./r3-component/ r3 create Entity entity_base ./r3-entity/ r3 create EntitySlider entity_extends Entity ./r3-entity/ r3 create Event base ./ -r3 create Project extends R3Object ./ +r3 create Project object_extends R3Object ./ r3 create R3 r3_base ./ -r3 create R3Object extends Event ./ r3 create RuntimeBullet runtime_extends RuntimePhysics ./r3-runtime/ r3 create RuntimeCodeMirror runtime_extends RuntimeCoder ./r3-runtime/ r3 create RuntimeCoder runtime_base ./r3-runtime/ @@ -41,3 +40,4 @@ r3 create RuntimeWebImage runtime_extends RuntimeImage ./r3-runtime/ r3 create RuntimeNodeJSImage runtime_extends RuntimeImage ./r3-runtime/ r3 create Runtime base ./r3-runtime/ r3 create ComponentCode component_extends Component ./r3-component/ +r3 create R3Object object_base ./ diff --git a/dist/r3.js b/dist/r3.js index 5cd79fa..d092cca 100644 --- a/dist/r3.js +++ b/dist/r3.js @@ -1,6 +1,6 @@ class R3 { - static version = '3.0.76'; - static compileDate = '2021 Sep 24 - 07:41:32 am'; + static version = '3.0.104'; + static compileDate = '2021 Sep 24 - 09:31:24 am'; } class Runtime { @@ -2442,24 +2442,23 @@ Event.MOUSE_MOVE = 0x1a; Event.MOUSE_UP = 0x1b; Event.MOUSE_WHEEL = 0x1c; Event.OBJECT_CREATED = 0x1d; -Event.OBJECT_INITIALIZED = 0x1e; -Event.PAUSE = 0x1f; -Event.PROJECT_INITIALIZED = 0x20; -Event.RESTART = 0x21; -Event.SLIDER_ENTITY_INITIALIZED = 0x22; -Event.START = 0x23; -Event.TOUCH_CANCEL = 0x24; -Event.TOUCH_COMPONENT_INITIALIZED = 0x25; -Event.TOUCH_END = 0x26; -Event.TOUCH_MOVE = 0x27; -Event.TOUCH_START = 0x28; -Event.UPDATE_FROM_INSTANCE_AFTER = 0x29; -Event.UPDATE_FROM_INSTANCE_BEFORE = 0x2a; -Event.UPDATE_INSTANCE_AFTER = 0x2b; -Event.UPDATE_INSTANCE_BEFORE = 0x2c; -Event.UPDATE_INSTANCE_PROPERTY = 0x2d; -Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x2e; -Event.MAX_EVENTS = 0x2f; +Event.PAUSE = 0x1e; +Event.PROJECT_INITIALIZED = 0x1f; +Event.RESTART = 0x20; +Event.SLIDER_ENTITY_INITIALIZED = 0x21; +Event.START = 0x22; +Event.TOUCH_CANCEL = 0x23; +Event.TOUCH_COMPONENT_INITIALIZED = 0x24; +Event.TOUCH_END = 0x25; +Event.TOUCH_MOVE = 0x26; +Event.TOUCH_START = 0x27; +Event.UPDATE_FROM_INSTANCE_AFTER = 0x28; +Event.UPDATE_FROM_INSTANCE_BEFORE = 0x29; +Event.UPDATE_INSTANCE_AFTER = 0x2a; +Event.UPDATE_INSTANCE_BEFORE = 0x2b; +Event.UPDATE_INSTANCE_PROPERTY = 0x2c; +Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x2d; +Event.MAX_EVENTS = 0x2e; Event.GetEventName = function(eventId) { @@ -2493,23 +2492,22 @@ Event.GetEventName = function(eventId) { case 0x1b : return 'mouse_up'; case 0x1c : return 'mouse_wheel'; case 0x1d : return 'object_created'; - case 0x1e : return 'object_initialized'; - case 0x1f : return 'pause'; - case 0x20 : return 'project_initialized'; - case 0x21 : return 'restart'; - case 0x22 : return 'slider_entity_initialized'; - case 0x23 : return 'start'; - case 0x24 : return 'touch_cancel'; - case 0x25 : return 'touch_component_initialized'; - case 0x26 : return 'touch_end'; - case 0x27 : return 'touch_move'; - case 0x28 : return 'touch_start'; - case 0x29 : return 'update_from_instance_after'; - case 0x2a : return 'update_from_instance_before'; - case 0x2b : return 'update_instance_after'; - case 0x2c : return 'update_instance_before'; - case 0x2d : return 'update_instance_property'; - case 0x2e : return 'update_property_from_instance'; + 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_component_initialized'; + case 0x25 : return 'touch_end'; + case 0x26 : return 'touch_move'; + case 0x27 : return 'touch_start'; + case 0x28 : return 'update_from_instance_after'; + case 0x29 : return 'update_from_instance_before'; + case 0x2a : return 'update_instance_after'; + case 0x2b : return 'update_instance_before'; + case 0x2c : return 'update_instance_property'; + case 0x2d : return 'update_property_from_instance'; default : throw new Error('Event type not defined : ' + eventId); } @@ -2559,11 +2557,7 @@ Event.GetEventName = function(eventId) { Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Static Properties: @@ -2585,6 +2579,18 @@ class R3Object extends Event { super(options); + if (typeof options.maxDepth === 'undefined') { + options.maxDepth = 0; + } + + if (typeof options.callDepth === 'undefined') { + options.callDepth = 0; + } else { + options.callDepth++; + } + + options.maxDepth = options.callDepth; + /** * id - Each Object receives an 15 digit random ID which uniquely identifies it everywhere (client and * server side) @@ -2599,133 +2605,41 @@ class R3Object extends Event { options.name = 'Object ' + options.id; } /** - * parent - All objects could have a parent + * initialized - A boolean which indicates whether or not this Object has initialized + */ + if (typeof options.initialized === 'undefined') { + options.initialized = false; + } + /** + * initializeDepth - The amount of times this Object passed through initialize() functions + */ + if (typeof options.initializeDepth === 'undefined') { + options.initializeDepth = 0; + } + /** + * parent - All Objects could have a parent */ if (typeof options.parent === 'undefined') { options.parent = null; } /** - * children - All objects could have some children + * children - All Objects could have some children */ if (typeof options.children === 'undefined') { options.children = []; } + /** + * required - All Objects could have some required Objects which need to initialize before this Object can + * initialize + */ + if (typeof options.required === 'undefined') { + options.required = {}; + } Object.assign(this, options); this.emit(Event.OBJECT_CREATED, this); - } - -} - -/** - - Class R3.Event.Object.Entity - [Inherited from Event] - - Inherited Properties: - - - - Inherited Static Properties: - - - - Inherited Methods: - - - async(eventId, data, clientCallback, clientErrorCallback) - Simply calls 'Async()' passing it the arguments - - - emit(eventId, data, clientCallback, clientErrorCallback) - Simply calls 'Emit()' passing it the arguments - - - subscribe(eventId, callback) - Simply calls 'Subscribe()' passing it the arguments - - Inherited Static Methods: - - - Async(eventId, data, clientCallback, clientErrorCallback) - Calls all subscription functions registered to eventId with data, clientCallback and clientErrorCallback as - arguments. If an error occurs during clientCallback it additionally will execute clientErrorCallback with the - error as argument. - - - Emit(eventId, data, clientCallback, clientErrorCallback) - Calls all subscription functions registered to eventId with data as arg. Calls clientCallback directly after - the event result is obtained, passing it the result. If an exception occurs during execution, the - clientErrorCallback is called with the error as argument. - - - Subscribe(eventId, callback) - Subscribes to 'eventName', ex. Event.BEFORE_RENDER and executes 'callback()' when eventName is raised - - [Inherited from R3Object] - - Inherited Properties: - - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) - - Inherited Static Properties: - - - - Inherited Methods: - - - - Inherited Static Methods: - - - - [Belonging to Entity] - - Properties: - - - - Static Properties: - - - - Methods: - - - - Static Methods: - - - - **/ - -class Entity extends R3Object { - - constructor(options) { - - super(options); - - if (typeof options === 'undefined') { - options = {}; - } - - if (typeof options.maxDepth === 'undefined') { - options.maxDepth = 0; - } - - if (typeof options.callDepth === 'undefined') { - options.callDepth = 0; - } else { - options.callDepth++; - } - - options.maxDepth = options.callDepth; - - Object.assign(this, options); - - this.emit(Event.ENTITY_CREATED, this); - if (options.callDepth === 0) { this.initialize(); } else { @@ -2736,14 +2650,11 @@ class Entity extends R3Object { /** * initialize() - * - Starts the Entity if all of its sub-Components are initialized + * - Initializes this Object if all of its required Objects are initialized */ initialize() { 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...'); @@ -2755,8 +2666,8 @@ class Entity extends R3Object { /** * setInitialized() - * - Checks whether all required components are available and if so, sets initialized to true otherwise false. By - * passing in a property and future value, it determines whether or not this component will still be initialized + * - Checks whether all required Object(s) are initialized and if so, sets initialized to true otherwise false. By + * passing in a property and future value, it determines whether or not this Object will still be initialized * after 'property' will assume 'value' * @param property=null * @param value=null @@ -2851,6 +2762,138 @@ class Entity extends R3Object { } +/** + + Class R3.Event.Object.Entity + [Inherited from Event] + + Inherited Properties: + + + + Inherited Static Properties: + + + + Inherited Methods: + + - async(eventId, data, clientCallback, clientErrorCallback) + Simply calls 'Async()' passing it the arguments + + - emit(eventId, data, clientCallback, clientErrorCallback) + Simply calls 'Emit()' passing it the arguments + + - subscribe(eventId, callback) + Simply calls 'Subscribe()' passing it the arguments + + Inherited Static Methods: + + - Async(eventId, data, clientCallback, clientErrorCallback) + Calls all subscription functions registered to eventId with data, clientCallback and clientErrorCallback as + arguments. If an error occurs during clientCallback it additionally will execute clientErrorCallback with the + error as argument. + + - Emit(eventId, data, clientCallback, clientErrorCallback) + Calls all subscription functions registered to eventId with data as arg. Calls clientCallback directly after + the event result is obtained, passing it the result. If an exception occurs during execution, the + clientErrorCallback is called with the error as argument. + + - Subscribe(eventId, callback) + Subscribes to 'eventName', ex. Event.BEFORE_RENDER and executes 'callback()' when eventName is raised + + [Inherited from R3Object] + + Inherited Properties: + + + + Inherited Static Properties: + + + + Inherited Methods: + + + + Inherited Static Methods: + + + + [Belonging to Entity] + + Properties: + + + + Static Properties: + + + + Methods: + + + + Static Methods: + + + + **/ + +class Entity extends R3Object { + + constructor(options) { + + super(options); + + if (typeof options === 'undefined') { + options = {}; + } + + if (typeof options.maxDepth === 'undefined') { + options.maxDepth = 0; + } + + if (typeof options.callDepth === 'undefined') { + options.callDepth = 0; + } else { + options.callDepth++; + } + + options.maxDepth = options.callDepth; + + Object.assign(this, options); + + this.emit(Event.ENTITY_CREATED, this); + + if (options.callDepth === 0) { + this.initialize(); + } else { + options.callDepth--; + } + + } + + /** + * initialize() + * - Starts the Entity if all of its sub-Components are initialized + */ + initialize() { + + 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...'); + } else { + this.initializeDepth++; + } + + } + +} + Entity.SLIDER = 0x0; Entity.MAX_ENTITY = 0x1; @@ -2897,11 +2940,7 @@ Entity.MAX_ENTITY = 0x1; Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -2987,13 +3026,13 @@ class EntitySlider extends Entity { options.maxDepth = options.callDepth; /** - * initialized - A boolean which indicates whether or not this entity has initialized + * initialized - A boolean which indicates whether or not this Entity has initialized */ if (typeof options.initialized === 'undefined') { options.initialized = false; } /** - * initializeDepth - The amount of times this component passed through initialize() functions + * initializeDepth - The amount of times this Entity passed through initialize() functions */ if (typeof options.initializeDepth === 'undefined') { options.initializeDepth = 0; @@ -3053,10 +3092,6 @@ class EntitySlider extends Entity { options.images = []; } - if (typeof options.required === 'undefined') { - options.required = {} - } - /** * images - We need a list of at least one Image which to slide */ @@ -3206,23 +3241,6 @@ class EntitySlider extends Entity { } - /** - * setInitialized() - * - Checks whether all required components are available and if so, sets initialized to true otherwise false. By - * passing in a property and future value, it determines whether or not this component will still be initialized - * after 'property' will assume 'value' - * @param property=null - * @param value=null - */ - setInitialized( - property=null, - value=null - ) { - - super.setInitialized(property, value); - - } - /** * start() * - Starts the entity by subscribing to all events @@ -3371,11 +3389,7 @@ class EntitySlider extends Entity { Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -3445,8 +3459,10 @@ class Component extends R3Object { */ initialize() { - this.initialized = true; - Event.Emit(Event.COMPONENT_INITIALIZED, this); + super.initialize(); + if (this.initialized) { + Event.Emit(Event.COMPONENT_INITIALIZED, this); + } if (this.initializeDepth === this.maxDepth) { throw new Error('You should not try to instantiate this base class - extend it rather...'); @@ -3592,11 +3608,7 @@ Component.MAX_COMPONENT = 0xa; Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -3689,10 +3701,6 @@ class ComponentCode extends Component { super(options); - if (typeof options.required === 'undefined') { - options.required = {} - } - this.underConstruction = true; Object.assign(this, options); @@ -3802,11 +3810,7 @@ class ComponentCode extends Component { Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -3907,10 +3911,6 @@ class ComponentDOM extends Component { options.instance = null; } - if (typeof options.required === 'undefined') { - options.required = {} - } - this.underConstruction = true; Object.assign(this, options); @@ -4052,11 +4052,7 @@ class ComponentDOM extends Component { Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -4196,10 +4192,6 @@ class ComponentCanvas extends ComponentDOM { options.style = 'border:1px solid #00bb00;'; } - if (typeof options.required === 'undefined') { - options.required = {} - } - this.underConstruction = true; Object.assign(this, options); @@ -4395,11 +4387,7 @@ class ComponentCanvas extends ComponentDOM { Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -4492,10 +4480,6 @@ class ComponentGraphics extends Component { super(options); - if (typeof options.required === 'undefined') { - options.required = {} - } - this.underConstruction = true; Object.assign(this, options); @@ -4607,11 +4591,7 @@ class ComponentGraphics extends Component { Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -4805,10 +4785,6 @@ class ComponentImage extends ComponentGraphics { options.orientation = 'square'; } - if (typeof options.required === 'undefined') { - options.required = {} - } - if (options.extension.match(/(png)$/i)) { options.contentType = 'image/png'; } @@ -4821,16 +4797,16 @@ class ComponentImage extends ComponentGraphics { options.contentType = 'image/gif'; } - if (this.width > this.height) { - this.orientation = 'landscape'; + if (options.width > options.height) { + options.orientation = 'landscape'; } - if (this.width < this.height) { - this.orientation = 'portrait'; + if (options.width < options.height) { + options.orientation = 'portrait'; } - if (this.width === this.height) { - this.orientation = 'square'; + if (options.width === options.height) { + options.orientation = 'square'; } this.underConstruction = true; @@ -5170,11 +5146,7 @@ class ComponentImage extends ComponentGraphics { Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -5285,10 +5257,6 @@ class ComponentMaterial extends ComponentGraphics { super(options); - if (typeof options.required === 'undefined') { - options.required = {} - } - this.underConstruction = true; Object.assign(this, options); @@ -5398,11 +5366,7 @@ class ComponentMaterial extends ComponentGraphics { Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -5513,10 +5477,6 @@ class ComponentMesh extends ComponentGraphics { super(options); - if (typeof options.required === 'undefined') { - options.required = {} - } - this.underConstruction = true; Object.assign(this, options); @@ -5626,11 +5586,7 @@ class ComponentMesh extends ComponentGraphics { Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -5741,10 +5697,6 @@ class ComponentTexture extends ComponentGraphics { super(options); - if (typeof options.required === 'undefined') { - options.required = {} - } - this.underConstruction = true; Object.assign(this, options); @@ -5854,11 +5806,7 @@ class ComponentTexture extends ComponentGraphics { Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -5951,10 +5899,6 @@ class ComponentInput extends Component { super(options); - if (typeof options.required === 'undefined') { - options.required = {} - } - this.underConstruction = true; Object.assign(this, options); @@ -6066,11 +6010,7 @@ class ComponentInput extends Component { Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -6190,10 +6130,6 @@ class ComponentTouch extends ComponentInput { options.canvas = null; } - if (typeof options.required === 'undefined') { - options.required = {} - } - /** * canvas - No comment */ @@ -6372,11 +6308,7 @@ class ComponentTouch extends ComponentInput { Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -6402,8 +6334,7 @@ class ComponentTouch extends ComponentInput { Methods: - - initialize() - Should raises an event(s) which indicates that this object initialized + Static Methods: @@ -6415,23 +6346,72 @@ class Project extends R3Object { constructor(options) { + if (typeof options === 'undefined') { + options = {}; + } + + if (typeof options.maxDepth === 'undefined') { + options.maxDepth = 0; + } + + if (typeof options.initialized === 'undefined') { + options.initialized = false; + } + + if (typeof options.callDepth === 'undefined') { + options.callDepth = 0; + } else { + options.callDepth++; + } + + options.maxDepth = options.callDepth; + + /** + * started - Indicates whether or not this entity is active (subscribing to events) or not + */ + if (typeof options.started === 'undefined') { + options.started = false; + } + /** + * subscriptions - An association object which hold the subscription handles for Events this system is listening + * to. The system can stop receiving events by calling remove() on a handle. + */ + if (typeof options.subscriptions === 'undefined') { + options.subscriptions = {}; + } + /** + * dirty - When dirty is true, it means that this entity is in transition from having a Component to not + * having this Component, and will probably end up in an uninitialized state. During the next few + * clock cycles this child Component will have its parent reference to this entity removed. + */ + if (typeof options.dirty === 'undefined') { + options.dirty = false; + } + super(options); + this.underConstruction = true; + Object.assign(this, options); + this.underConstruction = false; + + if (options.callDepth === 0) { + this.initialize(); + } else { + options.callDepth--; + } + } /** * initialize() - * - Should raises an event(s) which indicates that this object initialized + * - Initializes this Object if all of its required Objects are initialized */ initialize() { super.initialize(); - Event.Emit(Event.OBJECT_INITIALIZED, this); - Event.Emit(Event.PROJECT_INITIALIZED, this); - if (this.initializeDepth === this.maxDepth) { if (this instanceof R3.Component) { @@ -6448,6 +6428,37 @@ class Project extends R3Object { } + /** + * start() + * - Starts the Object by subscribing to all Events + */ + start() { + + this.started = true; + + if (this instanceof R3.Entity) { + this.emit( + Event.ENTITY_STARTED, + this + ); + } + + console.log('Started transient system: CLASS_NAME'); + + } + + /** + * stop() + * - Stops this Object by removing all subscriptions to events + */ + stop() { + + this.started = false; + + console.log('Stopped transient system: CLASS_NAME'); + + } + } class Utils { diff --git a/package.json b/package.json index 838e5ec..b9b977a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "r3", - "version" : "3.0.76", + "version" : "3.0.104", "description": "", "private": true, "dependencies": { diff --git a/r3.php b/r3.php index 14a117f..9a34cd1 100755 --- a/r3.php +++ b/r3.php @@ -497,6 +497,15 @@ function generateConstructors($file, $command) $baseExtends = 'extends'; } + if (preg_match('/\bobject_base\b/', $command)) { + $constructor = file_get_contents('src/templates/object_base_constructor.template'); + } + + if (preg_match('/\bobject_extends\b/', $command)) { + $constructor = file_get_contents('src/templates/object_extends_constructor.template'); + $baseExtends = 'extends'; + } + if (preg_match('/\bbase\b/', $command)) { $constructor = file_get_contents('src/templates/base_constructor.template'); } diff --git a/src/r3/r3-component/r3-component-canvas.js b/src/r3/r3-component/r3-component-canvas.js index 1c841ef..8f22b94 100644 --- a/src/r3/r3-component/r3-component-canvas.js +++ b/src/r3/r3-component/r3-component-canvas.js @@ -47,11 +47,7 @@ const ComponentDOM = require('.././r3-component-d-o-m.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -251,10 +247,6 @@ class ComponentCanvas extends ComponentDOM { } //GENERATED_OPTIONS_INIT_END - if (typeof options.required === 'undefined') { - options.required = {} - } - //GENERATED_REQUIRED_COMPONENTS_START //GENERATED_REQUIRED_COMPONENTS_END diff --git a/src/r3/r3-component/r3-component-code.js b/src/r3/r3-component/r3-component-code.js index 092a01c..cf3aede 100644 --- a/src/r3/r3-component/r3-component-code.js +++ b/src/r3/r3-component/r3-component-code.js @@ -47,11 +47,7 @@ const Component = require('.././r3-component.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -200,10 +196,6 @@ class ComponentCode extends Component { //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END - if (typeof options.required === 'undefined') { - options.required = {} - } - //GENERATED_REQUIRED_COMPONENTS_START //GENERATED_REQUIRED_COMPONENTS_END 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 d0cabea..bb5d0ac 100644 --- a/src/r3/r3-component/r3-component-d-o-m.js +++ b/src/r3/r3-component/r3-component-d-o-m.js @@ -47,11 +47,7 @@ const Component = require('.././r3-component.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -208,10 +204,6 @@ class ComponentDOM extends Component { } //GENERATED_OPTIONS_INIT_END - if (typeof options.required === 'undefined') { - options.required = {} - } - //GENERATED_REQUIRED_COMPONENTS_START //GENERATED_REQUIRED_COMPONENTS_END diff --git a/src/r3/r3-component/r3-component-graphics.js b/src/r3/r3-component/r3-component-graphics.js index daf1737..4899a82 100644 --- a/src/r3/r3-component/r3-component-graphics.js +++ b/src/r3/r3-component/r3-component-graphics.js @@ -47,11 +47,7 @@ const Component = require('.././r3-component.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -200,10 +196,6 @@ class ComponentGraphics extends Component { //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END - if (typeof options.required === 'undefined') { - options.required = {} - } - //GENERATED_REQUIRED_COMPONENTS_START //GENERATED_REQUIRED_COMPONENTS_END diff --git a/src/r3/r3-component/r3-component-image.js b/src/r3/r3-component/r3-component-image.js index a5686f4..df13812 100644 --- a/src/r3/r3-component/r3-component-image.js +++ b/src/r3/r3-component/r3-component-image.js @@ -47,11 +47,7 @@ const ComponentGraphics = require('.././r3-component-graphics.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -315,10 +311,6 @@ class ComponentImage extends ComponentGraphics { } //GENERATED_OPTIONS_INIT_END - if (typeof options.required === 'undefined') { - options.required = {} - } - //GENERATED_REQUIRED_COMPONENTS_START //GENERATED_REQUIRED_COMPONENTS_END @@ -340,16 +332,16 @@ class ComponentImage extends ComponentGraphics { //CUSTOM_BEFORE_INIT_START - if (this.width > this.height) { - this.orientation = 'landscape'; + if (options.width > options.height) { + options.orientation = 'landscape'; } - if (this.width < this.height) { - this.orientation = 'portrait'; + if (options.width < options.height) { + options.orientation = 'portrait'; } - if (this.width === this.height) { - this.orientation = 'square'; + if (options.width === options.height) { + options.orientation = 'square'; } //CUSTOM_BEFORE_INIT_END diff --git a/src/r3/r3-component/r3-component-input.js b/src/r3/r3-component/r3-component-input.js index 72b51ff..e2c0584 100644 --- a/src/r3/r3-component/r3-component-input.js +++ b/src/r3/r3-component/r3-component-input.js @@ -47,11 +47,7 @@ const Component = require('.././r3-component.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -200,10 +196,6 @@ class ComponentInput extends Component { //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END - if (typeof options.required === 'undefined') { - options.required = {} - } - //GENERATED_REQUIRED_COMPONENTS_START //GENERATED_REQUIRED_COMPONENTS_END diff --git a/src/r3/r3-component/r3-component-material.js b/src/r3/r3-component/r3-component-material.js index 1f4dae4..350b5ed 100644 --- a/src/r3/r3-component/r3-component-material.js +++ b/src/r3/r3-component/r3-component-material.js @@ -47,11 +47,7 @@ const ComponentGraphics = require('.././r3-component-graphics.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -218,10 +214,6 @@ class ComponentMaterial extends ComponentGraphics { //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END - if (typeof options.required === 'undefined') { - options.required = {} - } - //GENERATED_REQUIRED_COMPONENTS_START //GENERATED_REQUIRED_COMPONENTS_END diff --git a/src/r3/r3-component/r3-component-mesh.js b/src/r3/r3-component/r3-component-mesh.js index e17e250..92a5542 100644 --- a/src/r3/r3-component/r3-component-mesh.js +++ b/src/r3/r3-component/r3-component-mesh.js @@ -47,11 +47,7 @@ const ComponentGraphics = require('.././r3-component-graphics.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -218,10 +214,6 @@ class ComponentMesh extends ComponentGraphics { //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END - if (typeof options.required === 'undefined') { - options.required = {} - } - //GENERATED_REQUIRED_COMPONENTS_START //GENERATED_REQUIRED_COMPONENTS_END diff --git a/src/r3/r3-component/r3-component-texture.js b/src/r3/r3-component/r3-component-texture.js index 17004b9..118586e 100644 --- a/src/r3/r3-component/r3-component-texture.js +++ b/src/r3/r3-component/r3-component-texture.js @@ -47,11 +47,7 @@ const ComponentGraphics = require('.././r3-component-graphics.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -218,10 +214,6 @@ class ComponentTexture extends ComponentGraphics { //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END - if (typeof options.required === 'undefined') { - options.required = {} - } - //GENERATED_REQUIRED_COMPONENTS_START //GENERATED_REQUIRED_COMPONENTS_END diff --git a/src/r3/r3-component/r3-component-touch.js b/src/r3/r3-component/r3-component-touch.js index 9d61e6f..ad445dc 100644 --- a/src/r3/r3-component/r3-component-touch.js +++ b/src/r3/r3-component/r3-component-touch.js @@ -47,11 +47,7 @@ const ComponentInput = require('.././r3-component-input.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -226,10 +222,6 @@ class ComponentTouch extends ComponentInput { } //GENERATED_OPTIONS_INIT_END - if (typeof options.required === 'undefined') { - options.required = {} - } - //GENERATED_REQUIRED_COMPONENTS_START /** * canvas - No comment diff --git a/src/r3/r3-component/r3-component.js b/src/r3/r3-component/r3-component.js index e15794d..8a4a680 100644 --- a/src/r3/r3-component/r3-component.js +++ b/src/r3/r3-component/r3-component.js @@ -47,11 +47,7 @@ const R3Object = require('.././r3-r3-object.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -174,8 +170,10 @@ class Component extends R3Object { //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START - this.initialized = true; - Event.Emit(Event.COMPONENT_INITIALIZED, this); + super.initialize(); + if (this.initialized) { + Event.Emit(Event.COMPONENT_INITIALIZED, this); + } //CUSTOM_INITIALIZE_METHOD_END //GENERATED_INITIALIZE_METHOD_AFTER_START diff --git a/src/r3/r3-entity/r3-entity-slider.js b/src/r3/r3-entity/r3-entity-slider.js index d1d7502..ceab260 100644 --- a/src/r3/r3-entity/r3-entity-slider.js +++ b/src/r3/r3-entity/r3-entity-slider.js @@ -47,11 +47,7 @@ const Entity = require('.././r3-entity.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -109,8 +105,8 @@ const Entity = require('.././r3-entity.js'); GENERATED_INHERITED_END TEMPLATE_OPTIONS_START - initialized=false - A boolean which indicates whether or not this entity has initialized - initializeDepth=0 - The amount of times this component passed through initialize() functions + initialized=false - A boolean which indicates whether or not this Entity has initialized + initializeDepth=0 - The amount of times this Entity passed through initialize() functions parent=null - The parent R3.Object of this component components=[] - A list of components that this entity is composed of started=false - Indicates whether or not this entity is active (subscribing to events) or not @@ -138,7 +134,6 @@ const Entity = require('.././r3-entity.js'); TEMPLATE_METHODS_START initialize() - Starts the Entity if all of its sub-Components are initialized. Calls the parent initialize(). - setInitialized(property=null, value=null) - Checks whether all required components are available and if so, sets initialized to true otherwise false. By passing in a property and future value, it determines whether or not this component will still be initialized after 'property' will assume 'value' start() - Starts the entity by subscribing to all events stop() - Stops this entity by removing all subscriptions to events TEMPLATE_METHODS_END @@ -188,13 +183,13 @@ class EntitySlider extends Entity { //GENERATED_TEMPLATE_OPTIONS_INIT_START /** - * initialized - A boolean which indicates whether or not this entity has initialized + * initialized - A boolean which indicates whether or not this Entity has initialized */ if (typeof options.initialized === 'undefined') { options.initialized = false; } /** - * initializeDepth - The amount of times this component passed through initialize() functions + * initializeDepth - The amount of times this Entity passed through initialize() functions */ if (typeof options.initializeDepth === 'undefined') { options.initializeDepth = 0; @@ -257,10 +252,6 @@ class EntitySlider extends Entity { } //GENERATED_OPTIONS_INIT_END - if (typeof options.required === 'undefined') { - options.required = {} - } - //GENERATED_REQUIRED_COMPONENTS_START /** * images - We need a list of at least one Image which to slide @@ -429,31 +420,6 @@ class EntitySlider extends Entity { } - /** - * setInitialized() - * - Checks whether all required components are available and if so, sets initialized to true otherwise false. By - * passing in a property and future value, it determines whether or not this component will still be initialized - * after 'property' will assume 'value' - * @param property=null - * @param value=null - */ - setInitialized( - property=null, - value=null - ) { - - //GENERATED_SET_INITIALIZED_METHOD_START - super.setInitialized(property, value); - //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 - - } - /** * start() * - Starts the entity by subscribing to all events diff --git a/src/r3/r3-entity/r3-entity.js b/src/r3/r3-entity/r3-entity.js index 14ca2d2..0c6df85 100644 --- a/src/r3/r3-entity/r3-entity.js +++ b/src/r3/r3-entity/r3-entity.js @@ -47,11 +47,7 @@ const R3Object = require('.././r3-r3-object.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -99,7 +95,6 @@ const R3Object = require('.././r3-r3-object.js'); TEMPLATE_METHODS_START initialize() - Starts the Entity if all of its sub-Components are initialized - setInitialized(property=null, value=null) - Checks whether all required components are available and if so, sets initialized to true otherwise false. By passing in a property and future value, it determines whether or not this component will still be initialized after 'property' will assume 'value' TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -189,111 +184,6 @@ class Entity extends R3Object { } //GENERATED_INITIALIZE_METHOD_AFTER_END - } - - /** - * setInitialized() - * - Checks whether all required components are available and if so, sets initialized to true otherwise false. By - * passing in a property and future value, it determines whether or not this component will still be initialized - * after 'property' will assume 'value' - * @param property=null - * @param value=null - */ - setInitialized( - property=null, - value=null - ) { - - //GENERATED_SET_INITIALIZED_METHOD_START - - let isReady = function(property, value) { - - console.log('checking requirements for ' + property); - - if (this.required[property] instanceof Array) { - - /** - * First we need to check if we have this array defined - */ - if (!(value instanceof Array)) { - throw new Error('The property ' + property + ' of this object was not properly defined - it should be an array'); - } - - if (value.length === 0) { - return false; - } - - /** - * Check all properties are an instance of this.required[property] - */ - for (let i = 0; i < value.length; i++) { - this.required[property].map( - function(constructor) { - if (!(value[i] instanceof constructor)) { - throw new Error('The property ' + property + ' of this object is not of the correct type'); - } - }.bind(this) - ); - } - - for (let i = 0; i < value.length; i++) { - if (value[i].initialized !== true) { - return false; - } - } - - return true; - - } else { - - if (value === null) { - return false; - } else { - - if (typeof value === 'undefined') { - throw new Error('The ' + property + ' is not defined'); - } - - if (!(value instanceof this.required[property])) { - throw new Error('The property ' + property + ' of this object is not of the correct type') - } - - if (value.initialized !== true) { - return false; - } - - return true; - } - } - }.bind(this); - - for (let requiredProperty in this.required) { - if (this.required.hasOwnProperty(requiredProperty)) { - if (requiredProperty === property) { - if (isReady(property, value)) { - this.initialized = true; - } else { - this.initialized = false; - return; - } - } else { - if (isReady(requiredProperty, this[requiredProperty])) { - this.initialized = true; - } else { - this.initialized = false; - return; - } - } - } - } - //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 55a7f68..68af17b 100644 --- a/src/r3/r3-event.js +++ b/src/r3/r3-event.js @@ -374,24 +374,23 @@ Event.MOUSE_MOVE = 0x1a; Event.MOUSE_UP = 0x1b; Event.MOUSE_WHEEL = 0x1c; Event.OBJECT_CREATED = 0x1d; -Event.OBJECT_INITIALIZED = 0x1e; -Event.PAUSE = 0x1f; -Event.PROJECT_INITIALIZED = 0x20; -Event.RESTART = 0x21; -Event.SLIDER_ENTITY_INITIALIZED = 0x22; -Event.START = 0x23; -Event.TOUCH_CANCEL = 0x24; -Event.TOUCH_COMPONENT_INITIALIZED = 0x25; -Event.TOUCH_END = 0x26; -Event.TOUCH_MOVE = 0x27; -Event.TOUCH_START = 0x28; -Event.UPDATE_FROM_INSTANCE_AFTER = 0x29; -Event.UPDATE_FROM_INSTANCE_BEFORE = 0x2a; -Event.UPDATE_INSTANCE_AFTER = 0x2b; -Event.UPDATE_INSTANCE_BEFORE = 0x2c; -Event.UPDATE_INSTANCE_PROPERTY = 0x2d; -Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x2e; -Event.MAX_EVENTS = 0x2f; +Event.PAUSE = 0x1e; +Event.PROJECT_INITIALIZED = 0x1f; +Event.RESTART = 0x20; +Event.SLIDER_ENTITY_INITIALIZED = 0x21; +Event.START = 0x22; +Event.TOUCH_CANCEL = 0x23; +Event.TOUCH_COMPONENT_INITIALIZED = 0x24; +Event.TOUCH_END = 0x25; +Event.TOUCH_MOVE = 0x26; +Event.TOUCH_START = 0x27; +Event.UPDATE_FROM_INSTANCE_AFTER = 0x28; +Event.UPDATE_FROM_INSTANCE_BEFORE = 0x29; +Event.UPDATE_INSTANCE_AFTER = 0x2a; +Event.UPDATE_INSTANCE_BEFORE = 0x2b; +Event.UPDATE_INSTANCE_PROPERTY = 0x2c; +Event.UPDATE_PROPERTY_FROM_INSTANCE = 0x2d; +Event.MAX_EVENTS = 0x2e; Event.GetEventName = function(eventId) { @@ -425,23 +424,22 @@ Event.GetEventName = function(eventId) { case 0x1b : return 'mouse_up'; case 0x1c : return 'mouse_wheel'; case 0x1d : return 'object_created'; - case 0x1e : return 'object_initialized'; - case 0x1f : return 'pause'; - case 0x20 : return 'project_initialized'; - case 0x21 : return 'restart'; - case 0x22 : return 'slider_entity_initialized'; - case 0x23 : return 'start'; - case 0x24 : return 'touch_cancel'; - case 0x25 : return 'touch_component_initialized'; - case 0x26 : return 'touch_end'; - case 0x27 : return 'touch_move'; - case 0x28 : return 'touch_start'; - case 0x29 : return 'update_from_instance_after'; - case 0x2a : return 'update_from_instance_before'; - case 0x2b : return 'update_instance_after'; - case 0x2c : return 'update_instance_before'; - case 0x2d : return 'update_instance_property'; - case 0x2e : return 'update_property_from_instance'; + 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_component_initialized'; + case 0x25 : return 'touch_end'; + case 0x26 : return 'touch_move'; + case 0x27 : return 'touch_start'; + case 0x28 : return 'update_from_instance_after'; + case 0x29 : return 'update_from_instance_before'; + case 0x2a : return 'update_instance_after'; + case 0x2b : return 'update_instance_before'; + case 0x2c : return 'update_instance_property'; + case 0x2d : 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 935b43a..9a14746 100644 --- a/src/r3/r3-project.js +++ b/src/r3/r3-project.js @@ -47,11 +47,7 @@ const R3Object = require('./r3-r3-object.js'); Inherited Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Inherited Static Properties: @@ -77,8 +73,7 @@ const R3Object = require('./r3-r3-object.js'); Methods: - - initialize() - Should raises an event(s) which indicates that this object initialized + Static Methods: @@ -87,11 +82,17 @@ const R3Object = require('./r3-r3-object.js'); GENERATED_INHERITED_END TEMPLATE_OPTIONS_START + started=false - Indicates whether or not this entity is active (subscribing to events) or not + subscriptions={} - An association object which hold the subscription handles for Events this system is listening to. The system can stop receiving events by calling remove() on a handle. + dirty=false - When dirty is true, it means that this entity is in transition from having a Component to not having this Component, and will probably end up in an uninitialized state. During the next few clock cycles this child Component will have its parent reference to this entity removed. TEMPLATE_OPTIONS_END CUSTOM_OPTIONS_START CUSTOM_OPTIONS_END + CUSTOM_REQUIRED_COMPONENTS_START + CUSTOM_REQUIRED_COMPONENTS_END + TEMPLATE_STATIC_OPTIONS_START TEMPLATE_STATIC_OPTIONS_END @@ -99,10 +100,12 @@ const R3Object = require('./r3-r3-object.js'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START + initialize() - Initializes this Object if all of its required Objects are initialized + start() - Starts the Object by subscribing to all Events + stop() - Stops this Object by removing all subscriptions to events TEMPLATE_METHODS_END CUSTOM_METHODS_START - initialize() - Should raises an event(s) which indicates that this object initialized CUSTOM_METHODS_END TEMPLATE_STATIC_METHODS_START @@ -111,6 +114,9 @@ const R3Object = require('./r3-r3-object.js'); CUSTOM_STATIC_METHODS_START CUSTOM_STATIC_METHODS_END + CUSTOM_EVENT_LISTENERS_START + CUSTOM_EVENT_LISTENERS_END + **/ class Project extends R3Object { @@ -118,35 +124,86 @@ class Project extends R3Object { //GENERATED_CONSTRUCTOR_START constructor(options) { - super(options); + if (typeof options === 'undefined') { + options = {}; + } + + if (typeof options.maxDepth === 'undefined') { + options.maxDepth = 0; + } + + if (typeof options.initialized === 'undefined') { + options.initialized = false; + } + + if (typeof options.callDepth === 'undefined') { + options.callDepth = 0; + } else { + options.callDepth++; + } + + options.maxDepth = options.callDepth; //GENERATED_TEMPLATE_OPTIONS_INIT_START + /** + * started - Indicates whether or not this entity is active (subscribing to events) or not + */ + if (typeof options.started === 'undefined') { + options.started = false; + } + /** + * subscriptions - An association object which hold the subscription handles for Events this system is listening + * to. The system can stop receiving events by calling remove() on a handle. + */ + if (typeof options.subscriptions === 'undefined') { + options.subscriptions = {}; + } + /** + * dirty - When dirty is true, it means that this entity is in transition from having a Component to not + * having this Component, and will probably end up in an uninitialized state. During the next few + * clock cycles this child Component will have its parent reference to this entity removed. + */ + if (typeof options.dirty === 'undefined') { + options.dirty = false; + } //GENERATED_TEMPLATE_OPTIONS_INIT_END + super(options); + //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END + //GENERATED_REQUIRED_COMPONENTS_START + //GENERATED_REQUIRED_COMPONENTS_END + //CUSTOM_OPTIONS_INIT_START //CUSTOM_OPTIONS_INIT_END - Object.assign(this, options); - //CUSTOM_BEFORE_INIT_START //CUSTOM_BEFORE_INIT_END + this.underConstruction = true; + + Object.assign(this, options); + + this.underConstruction = false; + + if (options.callDepth === 0) { + this.initialize(); + } else { + options.callDepth--; + } + //CUSTOM_AFTER_INIT_START //CUSTOM_AFTER_INIT_END } //GENERATED_CONSTRUCTOR_END //GENERATED_TEMPLATE_METHODS_START - //GENERATED_TEMPLATE_METHODS_END - - //GENERATED_METHODS_START /** * initialize() - * - Should raises an event(s) which indicates that this object initialized + * - Initializes this Object if all of its required Objects are initialized */ initialize() { @@ -155,8 +212,6 @@ class Project extends R3Object { //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START - Event.Emit(Event.OBJECT_INITIALIZED, this); - Event.Emit(Event.PROJECT_INITIALIZED, this); //CUSTOM_INITIALIZE_METHOD_END //GENERATED_INITIALIZE_METHOD_AFTER_START @@ -176,8 +231,75 @@ class Project extends R3Object { //GENERATED_INITIALIZE_METHOD_AFTER_END } + + /** + * start() + * - Starts the Object by subscribing to all Events + */ + start() { + + //GENERATED_START_METHOD_START + + //GENERATED_EVENT_LISTENERS_START_START + //GENERATED_EVENT_LISTENERS_START_END + + //CUSTOM_BEFORE_SYSTEM_START_START + //CUSTOM_BEFORE_SYSTEM_START_END + + this.started = true; + + if (this instanceof R3.Entity) { + this.emit( + Event.ENTITY_STARTED, + this + ); + } + + console.log('Started transient system: CLASS_NAME'); + //GENERATED_START_METHOD_END + + //CUSTOM_START_METHOD_START + //CUSTOM_START_METHOD_END + + //GENERATED_START_METHOD_AFTER_START + //GENERATED_START_METHOD_AFTER_END + + } + + /** + * stop() + * - Stops this Object by removing all subscriptions to events + */ + stop() { + + //GENERATED_STOP_METHOD_START + + //GENERATED_EVENT_LISTENERS_STOP_START + //GENERATED_EVENT_LISTENERS_STOP_END + + //CUSTOM_BEFORE_SYSTEM_STOP_START + //CUSTOM_BEFORE_SYSTEM_STOP_END + + this.started = false; + + console.log('Stopped transient system: CLASS_NAME'); + //GENERATED_STOP_METHOD_END + + //CUSTOM_STOP_METHOD_START + //CUSTOM_STOP_METHOD_END + + //GENERATED_STOP_METHOD_AFTER_START + //GENERATED_STOP_METHOD_AFTER_END + + } + //GENERATED_TEMPLATE_METHODS_END + + //GENERATED_METHODS_START //GENERATED_METHODS_END + //GENERATED_EVENT_LISTENER_METHODS_START + //GENERATED_EVENT_LISTENER_METHODS_END + //GENERATED_TEMPLATE_STATIC_METHODS_START //GENERATED_TEMPLATE_STATIC_METHODS_END diff --git a/src/r3/r3-r3-object.js b/src/r3/r3-r3-object.js index 2cf9e3c..06129f6 100644 --- a/src/r3/r3-r3-object.js +++ b/src/r3/r3-r3-object.js @@ -1,5 +1,5 @@ +const Event = require('./r3-event'); const Utils = require('./r3-utils'); -const Event = require('./r3-event.js'); /** @@ -46,11 +46,7 @@ const Event = require('./r3-event.js'); Properties: - - id (Default value Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely - identifies it everywhere (client and server side)) - - name (Default value 'Object ' + options.id - Each Object has a name) - - parent (Default value null - All objects could have a parent) - - children (Default value [] - All objects could have some children) + Static Properties: @@ -67,13 +63,16 @@ const Event = require('./r3-event.js'); GENERATED_INHERITED_END TEMPLATE_OPTIONS_START + id=Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely identifies it everywhere (client and server side) + name='Object ' + options.id - Each Object has a name + initialized=false - A boolean which indicates whether or not this Object has initialized + initializeDepth=0 - The amount of times this Object passed through initialize() functions + parent=null - All Objects could have a parent + children=[] - All Objects could have some children + required={} - All Objects could have some required Objects which need to initialize before this Object can initialize TEMPLATE_OPTIONS_END CUSTOM_OPTIONS_START - id=Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely identifies it everywhere (client and server side) - name='Object ' + options.id - Each Object has a name - parent=null - All objects could have a parent - children=[] - All objects could have some children CUSTOM_OPTIONS_END TEMPLATE_STATIC_OPTIONS_START @@ -83,6 +82,8 @@ const Event = require('./r3-event.js'); CUSTOM_STATIC_OPTIONS_END TEMPLATE_METHODS_START + initialize() - Initializes this Object if all of its required Objects are initialized + setInitialized(property=null, value=null) - Checks whether all required Object(s) are initialized and if so, sets initialized to true otherwise false. By passing in a property and future value, it determines whether or not this Object will still be initialized after 'property' will assume 'value' TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -103,10 +104,19 @@ class R3Object extends Event { super(options); - //GENERATED_TEMPLATE_OPTIONS_INIT_START - //GENERATED_TEMPLATE_OPTIONS_INIT_END + if (typeof options.maxDepth === 'undefined') { + options.maxDepth = 0; + } - //GENERATED_OPTIONS_INIT_START + if (typeof options.callDepth === 'undefined') { + options.callDepth = 0; + } else { + options.callDepth++; + } + + options.maxDepth = options.callDepth; + + //GENERATED_TEMPLATE_OPTIONS_INIT_START /** * id - Each Object receives an 15 digit random ID which uniquely identifies it everywhere (client and * server side) @@ -121,17 +131,39 @@ class R3Object extends Event { options.name = 'Object ' + options.id; } /** - * parent - All objects could have a parent + * initialized - A boolean which indicates whether or not this Object has initialized + */ + if (typeof options.initialized === 'undefined') { + options.initialized = false; + } + /** + * initializeDepth - The amount of times this Object passed through initialize() functions + */ + if (typeof options.initializeDepth === 'undefined') { + options.initializeDepth = 0; + } + /** + * parent - All Objects could have a parent */ if (typeof options.parent === 'undefined') { options.parent = null; } /** - * children - All objects could have some children + * children - All Objects could have some children */ if (typeof options.children === 'undefined') { options.children = []; } + /** + * required - All Objects could have some required Objects which need to initialize before this Object can + * initialize + */ + if (typeof options.required === 'undefined') { + options.required = {}; + } + //GENERATED_TEMPLATE_OPTIONS_INIT_END + + //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END //CUSTOM_OPTIONS_INIT_START @@ -139,16 +171,151 @@ class R3Object extends Event { Object.assign(this, options); - //CUSTOM_BEFORE_INIT_START this.emit(Event.OBJECT_CREATED, this); + + //CUSTOM_BEFORE_INIT_START //CUSTOM_BEFORE_INIT_END + if (options.callDepth === 0) { + this.initialize(); + } else { + options.callDepth--; + } + //CUSTOM_AFTER_INIT_START //CUSTOM_AFTER_INIT_END } //GENERATED_CONSTRUCTOR_END //GENERATED_TEMPLATE_METHODS_START + + /** + * initialize() + * - Initializes this Object if all of its required Objects are initialized + */ + initialize() { + + //GENERATED_INITIALIZE_METHOD_START + //GENERATED_INITIALIZE_METHOD_END + + //CUSTOM_INITIALIZE_METHOD_START + this.setInitialized(); + //CUSTOM_INITIALIZE_METHOD_END + + //GENERATED_INITIALIZE_METHOD_AFTER_START + if (this.initializeDepth === this.maxDepth) { + throw new Error('You should not try to instantiate this base class - extend it rather...'); + } else { + this.initializeDepth++; + } + //GENERATED_INITIALIZE_METHOD_AFTER_END + + } + + /** + * setInitialized() + * - Checks whether all required Object(s) are initialized and if so, sets initialized to true otherwise false. By + * passing in a property and future value, it determines whether or not this Object will still be initialized + * after 'property' will assume 'value' + * @param property=null + * @param value=null + */ + setInitialized( + property=null, + value=null + ) { + + //GENERATED_SET_INITIALIZED_METHOD_START + + let isReady = function(property, value) { + + console.log('checking requirements for ' + property); + + if (this.required[property] instanceof Array) { + + /** + * First we need to check if we have this array defined + */ + if (!(value instanceof Array)) { + throw new Error('The property ' + property + ' of this object was not properly defined - it should be an array'); + } + + if (value.length === 0) { + return false; + } + + /** + * Check all properties are an instance of this.required[property] + */ + for (let i = 0; i < value.length; i++) { + this.required[property].map( + function(constructor) { + if (!(value[i] instanceof constructor)) { + throw new Error('The property ' + property + ' of this object is not of the correct type'); + } + }.bind(this) + ); + } + + for (let i = 0; i < value.length; i++) { + if (value[i].initialized !== true) { + return false; + } + } + + return true; + + } else { + + if (value === null) { + return false; + } else { + + if (typeof value === 'undefined') { + throw new Error('The ' + property + ' is not defined'); + } + + if (!(value instanceof this.required[property])) { + throw new Error('The property ' + property + ' of this object is not of the correct type') + } + + if (value.initialized !== true) { + return false; + } + + return true; + } + } + }.bind(this); + + for (let requiredProperty in this.required) { + if (this.required.hasOwnProperty(requiredProperty)) { + if (requiredProperty === property) { + if (isReady(property, value)) { + this.initialized = true; + } else { + this.initialized = false; + return; + } + } else { + if (isReady(requiredProperty, this[requiredProperty])) { + this.initialized = true; + } else { + this.initialized = false; + return; + } + } + } + } + //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 //GENERATED_METHODS_START @@ -162,6 +329,7 @@ class R3Object extends Event { //CUSTOM_IMPLEMENTATION_START //CUSTOM_IMPLEMENTATION_END + } //GENERATED_TEMPLATE_STATIC_OPTIONS_INIT_START diff --git a/src/r3/r3-r3.js b/src/r3/r3-r3.js index 3680197..8b68a41 100644 --- a/src/r3/r3-r3.js +++ b/src/r3/r3-r3.js @@ -1,6 +1,6 @@ class R3 { - static version = '3.0.76'; - static compileDate = '2021 Sep 24 - 07:41:32 am'; + static version = '3.0.104'; + static compileDate = '2021 Sep 24 - 09:31:24 am'; } //GENERATED_IMPORTS_START diff --git a/src/templates/component_extends_constructor.template b/src/templates/component_extends_constructor.template index 1ef286d..8ddabab 100644 --- a/src/templates/component_extends_constructor.template +++ b/src/templates/component_extends_constructor.template @@ -24,10 +24,6 @@ //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END - if (typeof options.required === 'undefined') { - options.required = {} - } - //GENERATED_REQUIRED_COMPONENTS_START //GENERATED_REQUIRED_COMPONENTS_END diff --git a/src/templates/entity_base.template b/src/templates/entity_base.template index 63e1012..3eb61c8 100644 --- a/src/templates/entity_base.template +++ b/src/templates/entity_base.template @@ -22,7 +22,6 @@ const R3Object = require('.././r3-r3-object.js'); TEMPLATE_METHODS_START initialize() - Starts the Entity if all of its sub-Components are initialized - setInitialized(property=null, value=null) - Checks whether all required components are available and if so, sets initialized to true otherwise false. By passing in a property and future value, it determines whether or not this component will still be initialized after 'property' will assume 'value' TEMPLATE_METHODS_END CUSTOM_METHODS_START diff --git a/src/templates/entity_extends.template b/src/templates/entity_extends.template index 7d82bde..d248c85 100644 --- a/src/templates/entity_extends.template +++ b/src/templates/entity_extends.template @@ -9,8 +9,8 @@ const EXTEND_CLASS = require('INCLUDE_PATH/EXTEND_CLASS_FILE_NAME'); GENERATED_INHERITED_END TEMPLATE_OPTIONS_START - initialized=false - A boolean which indicates whether or not this entity has initialized - initializeDepth=0 - The amount of times this component passed through initialize() functions + initialized=false - A boolean which indicates whether or not this Entity has initialized + initializeDepth=0 - The amount of times this Entity passed through initialize() functions parent=null - The parent R3.Object of this component components=[] - A list of components that this entity is composed of started=false - Indicates whether or not this entity is active (subscribing to events) or not @@ -32,7 +32,6 @@ const EXTEND_CLASS = require('INCLUDE_PATH/EXTEND_CLASS_FILE_NAME'); TEMPLATE_METHODS_START initialize() - Starts the Entity if all of its sub-Components are initialized. Calls the parent initialize(). - setInitialized(property=null, value=null) - Checks whether all required components are available and if so, sets initialized to true otherwise false. By passing in a property and future value, it determines whether or not this component will still be initialized after 'property' will assume 'value' 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 d3a4784..d08108c 100644 --- a/src/templates/entity_extends_constructor.template +++ b/src/templates/entity_extends_constructor.template @@ -28,10 +28,6 @@ //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END - if (typeof options.required === 'undefined') { - options.required = {} - } - //GENERATED_REQUIRED_COMPONENTS_START //GENERATED_REQUIRED_COMPONENTS_END diff --git a/src/templates/object_base.template b/src/templates/object_base.template new file mode 100644 index 0000000..46aadfa --- /dev/null +++ b/src/templates/object_base.template @@ -0,0 +1,79 @@ +const Event = require('INCLUDE_PATH/r3-event'); +const Utils = require('INCLUDE_PATH/r3-utils'); + +/** + + GENERATED_INHERITED_START + + GENERATED_INHERITED_END + + TEMPLATE_OPTIONS_START + id=Utils.RandomId(15) - Each Object receives an 15 digit random ID which uniquely identifies it everywhere (client and server side) + name='Object ' + options.id - Each Object has a name + initialized=false - A boolean which indicates whether or not this Object has initialized + initializeDepth=0 - The amount of times this Object passed through initialize() functions + parent=null - All Objects could have a parent + children=[] - All Objects could have some children + required={} - All Objects could have some required Objects which need to initialize before this Object can initialize + TEMPLATE_OPTIONS_END + + CUSTOM_OPTIONS_START + CUSTOM_OPTIONS_END + + TEMPLATE_STATIC_OPTIONS_START + TEMPLATE_STATIC_OPTIONS_END + + CUSTOM_STATIC_OPTIONS_START + CUSTOM_STATIC_OPTIONS_END + + TEMPLATE_METHODS_START + initialize() - Initializes this Object if all of its required Objects are initialized + setInitialized(property=null, value=null) - Checks whether all required Object(s) are initialized and if so, sets initialized to true otherwise false. By passing in a property and future value, it determines whether or not this Object will still be initialized after 'property' will assume 'value' + TEMPLATE_METHODS_END + + CUSTOM_METHODS_START + CUSTOM_METHODS_END + + TEMPLATE_STATIC_METHODS_START + TEMPLATE_STATIC_METHODS_END + + CUSTOM_STATIC_METHODS_START + CUSTOM_STATIC_METHODS_END + + **/ + +class CLASS_NAME extends Event { + + //GENERATED_CONSTRUCTOR_START + //GENERATED_CONSTRUCTOR_END + + //GENERATED_TEMPLATE_METHODS_START + //GENERATED_TEMPLATE_METHODS_END + + //GENERATED_METHODS_START + //GENERATED_METHODS_END + + //GENERATED_TEMPLATE_STATIC_METHODS_START + //GENERATED_TEMPLATE_STATIC_METHODS_END + + //GENERATED_STATIC_METHODS_START + //GENERATED_STATIC_METHODS_END + + //CUSTOM_IMPLEMENTATION_START + //CUSTOM_IMPLEMENTATION_END + +} + +//GENERATED_TEMPLATE_STATIC_OPTIONS_INIT_START +//GENERATED_TEMPLATE_STATIC_OPTIONS_INIT_END + +//GENERATED_STATIC_OPTIONS_INIT_START +//GENERATED_STATIC_OPTIONS_INIT_END + +//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START +//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END + +//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START +//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END + +module.exports = CLASS_NAME; diff --git a/src/templates/object_base_constructor.template b/src/templates/object_base_constructor.template new file mode 100644 index 0000000..3256c14 --- /dev/null +++ b/src/templates/object_base_constructor.template @@ -0,0 +1,41 @@ + constructor(options) { + + super(options); + + if (typeof options.maxDepth === 'undefined') { + options.maxDepth = 0; + } + + if (typeof options.callDepth === 'undefined') { + options.callDepth = 0; + } else { + options.callDepth++; + } + + options.maxDepth = options.callDepth; + + //GENERATED_TEMPLATE_OPTIONS_INIT_START + //GENERATED_TEMPLATE_OPTIONS_INIT_END + + //GENERATED_OPTIONS_INIT_START + //GENERATED_OPTIONS_INIT_END + + //CUSTOM_OPTIONS_INIT_START + //CUSTOM_OPTIONS_INIT_END + + Object.assign(this, options); + + this.emit(Event.OBJECT_CREATED, this); + + //CUSTOM_BEFORE_INIT_START + //CUSTOM_BEFORE_INIT_END + + if (options.callDepth === 0) { + this.initialize(); + } else { + options.callDepth--; + } + + //CUSTOM_AFTER_INIT_START + //CUSTOM_AFTER_INIT_END + } \ No newline at end of file diff --git a/src/templates/object_extends.template b/src/templates/object_extends.template new file mode 100644 index 0000000..f109ab2 --- /dev/null +++ b/src/templates/object_extends.template @@ -0,0 +1,85 @@ +const Event = require('INCLUDE_PATH/r3-event'); +const Utils = require('INCLUDE_PATH/r3-utils'); +const EXTEND_CLASS = require('INCLUDE_PATH/EXTEND_CLASS_FILE_NAME'); + +/** + + GENERATED_INHERITED_START + + GENERATED_INHERITED_END + + TEMPLATE_OPTIONS_START + started=false - Indicates whether or not this entity is active (subscribing to events) or not + subscriptions={} - An association object which hold the subscription handles for Events this system is listening to. The system can stop receiving events by calling remove() on a handle. + dirty=false - When dirty is true, it means that this entity is in transition from having a Component to not having this Component, and will probably end up in an uninitialized state. During the next few clock cycles this child Component will have its parent reference to this entity removed. + TEMPLATE_OPTIONS_END + + CUSTOM_OPTIONS_START + CUSTOM_OPTIONS_END + + CUSTOM_REQUIRED_COMPONENTS_START + CUSTOM_REQUIRED_COMPONENTS_END + + TEMPLATE_STATIC_OPTIONS_START + TEMPLATE_STATIC_OPTIONS_END + + CUSTOM_STATIC_OPTIONS_START + CUSTOM_STATIC_OPTIONS_END + + TEMPLATE_METHODS_START + initialize() - Initializes this Object if all of its required Objects are initialized + start() - Starts the Object by subscribing to all Events + stop() - Stops this Object by removing all subscriptions to events + TEMPLATE_METHODS_END + + CUSTOM_METHODS_START + CUSTOM_METHODS_END + + TEMPLATE_STATIC_METHODS_START + TEMPLATE_STATIC_METHODS_END + + CUSTOM_STATIC_METHODS_START + CUSTOM_STATIC_METHODS_END + + CUSTOM_EVENT_LISTENERS_START + CUSTOM_EVENT_LISTENERS_END + + **/ + +class CLASS_NAME extends EXTEND_CLASS { + + //GENERATED_CONSTRUCTOR_START + //GENERATED_CONSTRUCTOR_END + + //GENERATED_TEMPLATE_METHODS_START + //GENERATED_TEMPLATE_METHODS_END + + //GENERATED_METHODS_START + //GENERATED_METHODS_END + + //GENERATED_EVENT_LISTENER_METHODS_START + //GENERATED_EVENT_LISTENER_METHODS_END + + //GENERATED_TEMPLATE_STATIC_METHODS_START + //GENERATED_TEMPLATE_STATIC_METHODS_END + + //GENERATED_STATIC_METHODS_START + //GENERATED_STATIC_METHODS_END + + //CUSTOM_IMPLEMENTATION_START + //CUSTOM_IMPLEMENTATION_END +} + +//GENERATED_TEMPLATE_STATIC_OPTIONS_INIT_START +//GENERATED_TEMPLATE_STATIC_OPTIONS_INIT_END + +//GENERATED_STATIC_OPTIONS_INIT_START +//GENERATED_STATIC_OPTIONS_INIT_END + +//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START +//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END + +//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START +//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END + +module.exports = CLASS_NAME; diff --git a/src/templates/object_extends_constructor.template b/src/templates/object_extends_constructor.template new file mode 100644 index 0000000..d08108c --- /dev/null +++ b/src/templates/object_extends_constructor.template @@ -0,0 +1,54 @@ + constructor(options) { + + if (typeof options === 'undefined') { + options = {}; + } + + if (typeof options.maxDepth === 'undefined') { + options.maxDepth = 0; + } + + if (typeof options.initialized === 'undefined') { + options.initialized = false; + } + + if (typeof options.callDepth === 'undefined') { + options.callDepth = 0; + } else { + options.callDepth++; + } + + options.maxDepth = options.callDepth; + + //GENERATED_TEMPLATE_OPTIONS_INIT_START + //GENERATED_TEMPLATE_OPTIONS_INIT_END + + super(options); + + //GENERATED_OPTIONS_INIT_START + //GENERATED_OPTIONS_INIT_END + + //GENERATED_REQUIRED_COMPONENTS_START + //GENERATED_REQUIRED_COMPONENTS_END + + //CUSTOM_OPTIONS_INIT_START + //CUSTOM_OPTIONS_INIT_END + + //CUSTOM_BEFORE_INIT_START + //CUSTOM_BEFORE_INIT_END + + this.underConstruction = true; + + Object.assign(this, options); + + this.underConstruction = false; + + if (options.callDepth === 0) { + this.initialize(); + } else { + options.callDepth--; + } + + //CUSTOM_AFTER_INIT_START + //CUSTOM_AFTER_INIT_END + } \ No newline at end of file diff --git a/version b/version index bec157c..22aa30f 100644 --- a/version +++ b/version @@ -1 +1 @@ -3.0.76 \ No newline at end of file +3.0.104 \ No newline at end of file