From 823dcdbf14f1e52e152b61f4c3ae94a965469156 Mon Sep 17 00:00:00 2001 From: "Theunis J. Botha" Date: Wed, 22 Sep 2021 14:43:33 +0200 Subject: [PATCH] starting requirement components --- dist/r3.js | 64 ++++++++++++++++++- package.json | 2 +- r3.php | 21 ++++++ src/r3/r3-entity/r3-entity-slider.js | 44 ++++++++++++- src/r3/r3-entity/r3-entity.js | 22 ++++++- src/r3/r3-r3.js | 4 +- src/r3/r3-system/r3-system-input.js | 25 ++++++++ .../base_check_requirements.template | 1 + src/templates/entity_base.template | 1 + src/templates/entity_extends.template | 4 ++ .../entity_extends_constructor.template | 11 +++- .../extends_check_requirements.template | 1 + .../generated_required_components.template | 4 ++ src/templates/token.db | 7 ++ version | 2 +- 15 files changed, 201 insertions(+), 12 deletions(-) create mode 100644 src/templates/base_check_requirements.template create mode 100644 src/templates/extends_check_requirements.template create mode 100644 src/templates/generated_required_components.template diff --git a/dist/r3.js b/dist/r3.js index 029c126..7b2a81a 100644 --- a/dist/r3.js +++ b/dist/r3.js @@ -1,6 +1,6 @@ class R3 { - static version = '2.0.877'; - static compileDate = '2021 Sep 22 - 13:55:35 pm'; + static version = '3.0.17'; + static compileDate = '2021 Sep 22 - 14:41:58 pm'; } class Runtime { @@ -1038,6 +1038,11 @@ class SystemInput extends System { */ static Start(options) { + SystemInput.Subscriptions['SLIDER_ENTITY_INITIALIZED'] = Event.Subscribe( + Event.SLIDER_ENTITY_INITIALIZED, + SystemInput.OnSliderEntityInitialized + ); + SystemInput.Subscriptions['TOUCH_START'] = Event.Subscribe( Event.TOUCH_START, SystemInput.OnTouchStart @@ -1101,6 +1106,9 @@ class SystemInput extends System { */ static Stop(options) { + SystemInput.Subscriptions['SLIDER_ENTITY_INITIALIZED'].remove(); + delete SystemInput.Subscriptions['SLIDER_ENTITY_INITIALIZED']; + SystemInput.Subscriptions['TOUCH_START'].remove(); delete SystemInput.Subscriptions['TOUCH_START']; @@ -1137,6 +1145,16 @@ class SystemInput extends System { } + /** + * OnSliderEntityInitialized() + * - Listens to events of type Event.SLIDER_ENTITY_INITIALIZED and executes this function. + * @param object (The event data passed as argument - typically an R3Object) + * @return + */ + static OnSliderEntityInitialized(object) { + + } + /** * OnTouchStart() * - Listens to events of type Event.TOUCH_START and executes this function. @@ -2594,7 +2612,7 @@ class Entity extends R3Object { this.initialized = true; - Event.Emit(Event.ENTITY_INITIALIZED, this); + this.checkRequirements(); if (this.initializeDepth === this.maxDepth) { throw new Error('You should not try to instantiate this base class - extend it rather...'); @@ -2604,6 +2622,18 @@ class Entity extends R3Object { } + /** + * checkRequirements() + * - Checks whether all required components are initialized before triggering an Event.ENTITY_INITIALIZED + */ + checkRequirements() { + + //TODO: Check all required components have initialized - once this is the case - fire an Event.ENTITY_INITIALIZED + + Event.Emit(Event.ENTITY_INITIALIZED, this); + + } + } Entity.SLIDER = 0x0; @@ -2709,6 +2739,9 @@ Entity.MAX_ENTITY = 0x1; + images=[R3.Image] - We need a list of at least one image which to slide + canvas=R3.Canvas - We need a canvas to attach our Input events + **/ class EntitySlider extends Entity { @@ -2788,6 +2821,19 @@ 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 + */ + options.required.images = [R3.Image]; + /** + * canvas - We need a canvas to attach our Input events + */ + options.required.canvas = R3.Canvas; + Object.assign(this, options); if (options.callDepth === 0) { @@ -2824,6 +2870,18 @@ class EntitySlider extends Entity { } + /** + * checkRequirements() + * - Checks all required Components for this Entity initialized and can perform some custom actions + */ + checkRequirements() { + + super.checkRequirements(); + + Event.Emit(Event.SLIDER_ENTITY_INITIALIZED, this); + + } + /** * start() * - Starts the entity by subscribing to all events diff --git a/package.json b/package.json index 237e06d..2c45da6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "r3", - "version" : "2.0.877", + "version" : "3.0.17", "description": "", "private": true, "dependencies": { diff --git a/r3.php b/r3.php index 7a66539..58fb37e 100755 --- a/r3.php +++ b/r3.php @@ -558,6 +558,26 @@ function extractOption($item, $template) } +function generateRequiredComponents($file, $tokens, $token, $section) +{ + + $store = getTokenStore($token, $tokens); + + if (sizeof($store) <= 0) { + return; + } + + $template = file_get_contents('src/templates/generated_required_components.template'); + + $updates = ''; + + foreach ($store as $item) { + $updates .= extractOption($item, $template); + } + + updateSection($file, $section , $updates); +} + function generateInitOptions($file, $tokens, $token, $section) { @@ -1931,6 +1951,7 @@ foreach ($files as $file) { generateInitStaticOptions($file, $tokens, 'TEMPLATE_STATIC_OPTIONS', 'GENERATED_TEMPLATE_STATIC_OPTIONS_INIT'); + generateRequiredComponents($file, $tokens, 'CUSTOM_REQUIRED_COMPONENTS', 'GENERATED_REQUIRED_COMPONENTS'); // generateCreateInstanceOptions($file, $tokens); generateUpdateInstanceOptions($file, $tokens, 'CUSTOM_OPTIONS', 'GENERATED_UPDATE_INSTANCE_OPTIONS', 'CUSTOM_INSTANCE_OPTIONS_MAPPING', 'CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS'); diff --git a/src/r3/r3-entity/r3-entity-slider.js b/src/r3/r3-entity/r3-entity-slider.js index 1a75096..2c9057b 100644 --- a/src/r3/r3-entity/r3-entity-slider.js +++ b/src/r3/r3-entity/r3-entity-slider.js @@ -128,6 +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 start() - Starts the entity by subscribing to all events stop() - Stops this entity by removing all subscriptions to events TEMPLATE_METHODS_END @@ -135,6 +136,11 @@ const Entity = require('.././r3-entity.js'); CUSTOM_METHODS_START CUSTOM_METHODS_END + CUSTOM_REQUIRED_COMPONENTS_START + images=[R3.Image] - We need a list of at least one image which to slide + canvas=R3.Canvas - We need a canvas to attach our Input events + CUSTOM_REQUIRED_COMPONENTS_END + TEMPLATE_STATIC_METHODS_START TEMPLATE_STATIC_METHODS_END @@ -232,11 +238,26 @@ class EntitySlider extends Entity { } //GENERATED_OPTIONS_INIT_END - //CUSTOM_OPTIONS_INIT_START - //CUSTOM_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 + */ + options.required.images = [R3.Image]; + /** + * canvas - We need a canvas to attach our Input events + */ + options.required.canvas = R3.Canvas; + //GENERATED_REQUIRED_COMPONENTS_END Object.assign(this, options); + //CUSTOM_OPTIONS_INIT_START + //CUSTOM_OPTIONS_INIT_END + //CUSTOM_BEFORE_INIT_START //CUSTOM_BEFORE_INIT_END @@ -285,6 +306,25 @@ class EntitySlider extends Entity { } + /** + * checkRequirements() + * - Checks all required Components for this Entity initialized and can perform some custom actions + */ + checkRequirements() { + + //GENERATED_CHECK_REQUIREMENTS_METHOD_START + super.checkRequirements(); + //GENERATED_CHECK_REQUIREMENTS_METHOD_END + + //CUSTOM_CHECK_REQUIREMENTS_METHOD_START + Event.Emit(Event.SLIDER_ENTITY_INITIALIZED, this); + //CUSTOM_CHECK_REQUIREMENTS_METHOD_END + + //GENERATED_CHECK_REQUIREMENTS_METHOD_AFTER_START + //GENERATED_CHECK_REQUIREMENTS_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 696c062..e6e45f1 100644 --- a/src/r3/r3-entity/r3-entity.js +++ b/src/r3/r3-entity/r3-entity.js @@ -99,6 +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 TEMPLATE_METHODS_END CUSTOM_METHODS_START @@ -175,7 +176,7 @@ class Entity extends R3Object { //GENERATED_INITIALIZE_METHOD_END //CUSTOM_INITIALIZE_METHOD_START - Event.Emit(Event.ENTITY_INITIALIZED, this); + this.checkRequirements(); //CUSTOM_INITIALIZE_METHOD_END //GENERATED_INITIALIZE_METHOD_AFTER_START @@ -186,6 +187,25 @@ class Entity extends R3Object { } //GENERATED_INITIALIZE_METHOD_AFTER_END + } + + /** + * checkRequirements() + * - Checks whether all required components are initialized before triggering an Event.ENTITY_INITIALIZED + */ + checkRequirements() { + + //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 + + //CUSTOM_CHECK_REQUIREMENTS_METHOD_START + Event.Emit(Event.ENTITY_INITIALIZED, this); + //CUSTOM_CHECK_REQUIREMENTS_METHOD_END + + //GENERATED_CHECK_REQUIREMENTS_METHOD_AFTER_START + //GENERATED_CHECK_REQUIREMENTS_METHOD_AFTER_END + } //GENERATED_TEMPLATE_METHODS_END diff --git a/src/r3/r3-r3.js b/src/r3/r3-r3.js index 223b4a4..cad9122 100644 --- a/src/r3/r3-r3.js +++ b/src/r3/r3-r3.js @@ -1,6 +1,6 @@ class R3 { - static version = '2.0.877'; - static compileDate = '2021 Sep 22 - 13:55:35 pm'; + static version = '3.0.17'; + static compileDate = '2021 Sep 22 - 14:41:58 pm'; } //GENERATED_IMPORTS_START diff --git a/src/r3/r3-system/r3-system-input.js b/src/r3/r3-system/r3-system-input.js index d32ee9b..41ced03 100644 --- a/src/r3/r3-system/r3-system-input.js +++ b/src/r3/r3-system/r3-system-input.js @@ -63,6 +63,7 @@ const System = require('.././r3-system.js'); CUSTOM_EVENT_LISTENERS_END CUSTOM_STATIC_EVENT_LISTENERS_START + Event.SLIDER_ENTITY_INITIALIZED Event.TOUCH_START Event.TOUCH_END Event.TOUCH_MOVE @@ -136,6 +137,11 @@ class SystemInput extends System { //GENERATED_STATIC_START_METHOD_START //GENERATED_STATIC_EVENT_LISTENERS_START_START + SystemInput.Subscriptions['SLIDER_ENTITY_INITIALIZED'] = Event.Subscribe( + Event.SLIDER_ENTITY_INITIALIZED, + SystemInput.OnSliderEntityInitialized + ); + SystemInput.Subscriptions['TOUCH_START'] = Event.Subscribe( Event.TOUCH_START, SystemInput.OnTouchStart @@ -212,6 +218,9 @@ class SystemInput extends System { //GENERATED_STATIC_STOP_METHOD_START //GENERATED_STATIC_EVENT_LISTENERS_STOP_START + SystemInput.Subscriptions['SLIDER_ENTITY_INITIALIZED'].remove(); + delete SystemInput.Subscriptions['SLIDER_ENTITY_INITIALIZED']; + SystemInput.Subscriptions['TOUCH_START'].remove(); delete SystemInput.Subscriptions['TOUCH_START']; @@ -267,6 +276,22 @@ class SystemInput extends System { //GENERATED_STATIC_EVENT_LISTENER_METHODS_START + /** + * OnSliderEntityInitialized() + * - Listens to events of type Event.SLIDER_ENTITY_INITIALIZED and executes this function. + * @param object (The event data passed as argument - typically an R3Object) + * @return + */ + static OnSliderEntityInitialized(object) { + + //GENERATED_STATIC_ON_SLIDER_ENTITY_INITIALIZED_METHOD_START + //GENERATED_STATIC_ON_SLIDER_ENTITY_INITIALIZED_METHOD_END + + //CUSTOM_STATIC_ON_SLIDER_ENTITY_INITIALIZED_METHOD_START + //CUSTOM_STATIC_ON_SLIDER_ENTITY_INITIALIZED_METHOD_END + + } + /** * OnTouchStart() * - Listens to events of type Event.TOUCH_START and executes this function. diff --git a/src/templates/base_check_requirements.template b/src/templates/base_check_requirements.template new file mode 100644 index 0000000..5e08c7c --- /dev/null +++ b/src/templates/base_check_requirements.template @@ -0,0 +1 @@ + //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/entity_base.template b/src/templates/entity_base.template index ab589da..e85b5bc 100644 --- a/src/templates/entity_base.template +++ b/src/templates/entity_base.template @@ -22,6 +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 TEMPLATE_METHODS_END CUSTOM_METHODS_START diff --git a/src/templates/entity_extends.template b/src/templates/entity_extends.template index be27089..6900a5d 100644 --- a/src/templates/entity_extends.template +++ b/src/templates/entity_extends.template @@ -28,6 +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 start() - Starts the entity by subscribing to all events stop() - Stops this entity by removing all subscriptions to events TEMPLATE_METHODS_END @@ -35,6 +36,9 @@ const EXTEND_CLASS = require('INCLUDE_PATH/EXTEND_CLASS_FILE_NAME'); CUSTOM_METHODS_START CUSTOM_METHODS_END + CUSTOM_REQUIRED_COMPONENTS_START + CUSTOM_REQUIRED_COMPONENTS_END + TEMPLATE_STATIC_METHODS_START TEMPLATE_STATIC_METHODS_END diff --git a/src/templates/entity_extends_constructor.template b/src/templates/entity_extends_constructor.template index 9b9289a..d2defea 100644 --- a/src/templates/entity_extends_constructor.template +++ b/src/templates/entity_extends_constructor.template @@ -28,11 +28,18 @@ //GENERATED_OPTIONS_INIT_START //GENERATED_OPTIONS_INIT_END - //CUSTOM_OPTIONS_INIT_START - //CUSTOM_OPTIONS_INIT_END + if (typeof options.required === 'undefined') { + options.required = {} + } + + //GENERATED_REQUIRED_COMPONENTS_START + //GENERATED_REQUIRED_COMPONENTS_END Object.assign(this, options); + //CUSTOM_OPTIONS_INIT_START + //CUSTOM_OPTIONS_INIT_END + //CUSTOM_BEFORE_INIT_START //CUSTOM_BEFORE_INIT_END diff --git a/src/templates/extends_check_requirements.template b/src/templates/extends_check_requirements.template new file mode 100644 index 0000000..134bb6c --- /dev/null +++ b/src/templates/extends_check_requirements.template @@ -0,0 +1 @@ + super.checkRequirements(); \ No newline at end of file diff --git a/src/templates/generated_required_components.template b/src/templates/generated_required_components.template new file mode 100644 index 0000000..5558aa1 --- /dev/null +++ b/src/templates/generated_required_components.template @@ -0,0 +1,4 @@ + /** + * KEY - COMMENT + */ + options.required.KEY = VALUE; diff --git a/src/templates/token.db b/src/templates/token.db index 99c122e..281fc55 100644 --- a/src/templates/token.db +++ b/src/templates/token.db @@ -2,6 +2,8 @@ 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 @@ -35,6 +37,7 @@ GENERATED_ON_TOUCH_START_METHOD GENERATED_ON_TOUCH_START_METHOD_AFTER GENERATED_OPTIONS_INIT GENERATED_OUT_OF_CLASS_IMPLEMENTATION +GENERATED_REQUIRED_COMPONENTS GENERATED_SET_RUNTIME_METHOD GENERATED_SET_RUNTIME_METHOD_AFTER GENERATED_START_METHOD @@ -62,6 +65,7 @@ GENERATED_STATIC_ON_MOUSE_UP_METHOD GENERATED_STATIC_ON_MOUSE_WHEEL_METHOD GENERATED_STATIC_ON_OBJECT_CREATED_METHOD GENERATED_STATIC_ON_PROJECT_INITIALIZED_METHOD +GENERATED_STATIC_ON_SLIDER_ENTITY_INITIALIZED_METHOD GENERATED_STATIC_ON_TOUCH_CANCEL_METHOD GENERATED_STATIC_ON_TOUCH_END_METHOD GENERATED_STATIC_ON_TOUCH_MOVE_METHOD @@ -94,6 +98,7 @@ 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 @@ -113,6 +118,7 @@ CUSTOM_ON_TOUCH_START_METHOD CUSTOM_OPTIONS CUSTOM_OPTIONS_INIT CUSTOM_OUT_OF_CLASS_IMPLEMENTATION +CUSTOM_REQUIRED_COMPONENTS CUSTOM_SET_RUNTIME_METHOD CUSTOM_START_METHOD CUSTOM_STATIC_ASYNC_METHOD @@ -136,6 +142,7 @@ CUSTOM_STATIC_ON_MOUSE_UP_METHOD CUSTOM_STATIC_ON_MOUSE_WHEEL_METHOD CUSTOM_STATIC_ON_OBJECT_CREATED_METHOD CUSTOM_STATIC_ON_PROJECT_INITIALIZED_METHOD +CUSTOM_STATIC_ON_SLIDER_ENTITY_INITIALIZED_METHOD CUSTOM_STATIC_ON_TOUCH_CANCEL_METHOD CUSTOM_STATIC_ON_TOUCH_END_METHOD CUSTOM_STATIC_ON_TOUCH_MOVE_METHOD diff --git a/version b/version index 14b7e26..a99de22 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.0.877 \ No newline at end of file +3.0.17 \ No newline at end of file