starting requirement components

master
Theunis J. Botha 2021-09-22 14:43:33 +02:00
parent aaf4ef4a4c
commit 823dcdbf14
15 changed files with 201 additions and 12 deletions

64
dist/r3.js vendored
View File

@ -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;
<no static methods>
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

View File

@ -1,6 +1,6 @@
{
"name": "r3",
"version" : "2.0.877",
"version" : "3.0.17",
"description": "",
"private": true,
"dependencies": {

21
r3.php
View File

@ -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');

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -0,0 +1 @@
//TODO: Check all required components have initialized - once this is the case - fire an Event.ENTITY_INITIALIZED

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
super.checkRequirements();

View File

@ -0,0 +1,4 @@
/**
* KEY - COMMENT
*/
options.required.KEY = VALUE;

View File

@ -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

View File

@ -1 +1 @@
2.0.877
3.0.17