From b384d331acdb3b6e08f6376ab09d507ad4447f9e Mon Sep 17 00:00:00 2001 From: "Theunis J. Botha" Date: Fri, 10 Sep 2021 07:18:08 +0200 Subject: [PATCH] new entities --- .r3_history | 2 + dist/r3.js | 158 ++++++++++++++++++++++++---- package.json | 2 +- r3.php | 26 +++-- src/r3/r3-component/r3-component.js | 2 +- src/r3/r3-entity/index.js | 12 +++ src/r3/r3-entity/r3-entity.js | 101 ++++++++++++++++++ src/r3/r3-entity/r3-slider.js | 124 ++++++++++++++++++++++ src/r3/r3-event.js | 28 ++--- src/r3/r3-r3.js | 6 +- src/r3/r3-runtime/r3-runtime.js | 2 +- src/r3/r3-system/r3-system.js | 2 +- utils.php | 60 +++++------ version | 2 +- 14 files changed, 443 insertions(+), 84 deletions(-) create mode 100644 src/r3/r3-entity/index.js create mode 100644 src/r3/r3-entity/r3-entity.js create mode 100644 src/r3/r3-entity/r3-slider.js diff --git a/.r3_history b/.r3_history index ce8e038..5909611 100644 --- a/.r3_history +++ b/.r3_history @@ -28,3 +28,5 @@ r3 create Canvas extends DOM ./r3-component/ r3 create SystemDOM system r3 create Document extends Default ./r3-runtime/ r3 create SystemRuntime system +r3 create Entity normal ./r3-entity/ +r3 create Slider extends Entity ./r3-entity/ diff --git a/dist/r3.js b/dist/r3.js index 6272c14..9667897 100644 --- a/dist/r3.js +++ b/dist/r3.js @@ -1,8 +1,56 @@ class R3 { - static version = '2.0.454'; - static compileDate = '2021 Sep 09 - 18:08:03 pm'; + static version = '2.0.464'; + static compileDate = '2021 Sep 10 - 07:16:56 am'; } +class Entity { + + constructor(options) { + + Event.Emit(Event.OBJECT_CREATED, this); + + if (typeof options === 'undefined') { + options = {}; + } + + if (typeof options.callDepth === 'undefined') { + options.callDepth = 0; + } else { + options.callDepth++; + } + + Object.assign(this, options); + + if (options.callDepth === 0) { + this.initialized(); + } else { + options.callDepth--; + } + + } + + /** + * initialized() + * - Should raise an event(s) which indicates that this object initialized + */ + initialized() { + + if (this.hasOwnProperty('callDepth')) { + delete this.callDepth; + } else { + console.warn('Multiple calls to initialized() - check your callstack'); + } + + Event.Emit(Event.OBJECT_INITIALIZED, this); + Event.Emit(Event.ENTITY_INITIALIZED, this); + + } + +} + +Entity.SLIDER = 0x0; +Entity.MAX_ENTITY = 0x1; + class System { constructor(options) { @@ -22,7 +70,7 @@ System.SYSTEM_INPUT = 0x1; System.SYSTEM_LINKING = 0x2; System.SYSTEM_RUNTIME = 0x3; System.SYSTEM_SOCKET = 0x4; -System.MAX_SYSTEMS = 0x5; +System.MAX_SYSTEM = 0x5; class Event { @@ -278,13 +326,13 @@ class Event { } -Event.BEFORE_RENDER = 0x1; -Event.COMPONENT_CREATED = 0x2; -Event.COMPONENT_INITIALIZED = 0x3; -Event.CREATE_INSTANCE_BEFORE = 0x4; -Event.DISPOSE_INSTANCE = 0x5; -Event.DISPOSE_OBJECT = 0x6; -Event.DOM_COMPONENT_INITIALIZED = 0x7; +Event.COMPONENT_CREATED = 0x1; +Event.COMPONENT_INITIALIZED = 0x2; +Event.CREATE_INSTANCE_BEFORE = 0x3; +Event.DISPOSE_INSTANCE = 0x4; +Event.DISPOSE_OBJECT = 0x5; +Event.DOM_COMPONENT_INITIALIZED = 0x6; +Event.ENTITY_INITIALIZED = 0x7; Event.GET_RUNTIME = 0x8; Event.GET_WINDOW_SIZE = 0x9; Event.INPUT_COMPONENT_INITIALIZED = 0xa; @@ -313,13 +361,13 @@ Event.MAX_EVENTS = 0x1f; Event.GetEventName = function(eventId) { switch(eventId) { - case 0x1 : return 'before_render'; - case 0x2 : return 'component_created'; - case 0x3 : return 'component_initialized'; - case 0x4 : return 'create_instance_before'; - case 0x5 : return 'dispose_instance'; - case 0x6 : return 'dispose_object'; - case 0x7 : return 'dom_component_initialized'; + case 0x1 : return 'component_created'; + case 0x2 : return 'component_initialized'; + case 0x3 : return 'create_instance_before'; + case 0x4 : return 'dispose_instance'; + case 0x5 : return 'dispose_object'; + case 0x6 : return 'dom_component_initialized'; + case 0x7 : return 'entity_initialized'; case 0x8 : return 'get_runtime'; case 0x9 : return 'get_window_size'; case 0xa : return 'input_component_initialized'; @@ -1621,6 +1669,76 @@ class Utils { } +/** + + Class R3.Entity.Slider + [Inherited from Entity] + + Inherited Properties: + + + + Inherited Static Properties: + + + + Inherited Methods: + + - initialized() + Should raise an event(s) which indicates that this object initialized + + Inherited Static Methods: + + + + [Belonging to Slider] + + Properties: + + + + Static Properties: + + + + Methods: + + + + Static Methods: + + + + **/ + +class Slider extends Entity { + + constructor(options) { + + if (typeof options === 'undefined') { + options = {}; + } + + if (typeof options.callDepth === 'undefined') { + options.callDepth = 0; + } else { + options.callDepth++; + } + + super(options); + + Object.assign(this, options); + + if (options.callDepth === 0) { + this.initialized(); + } else { + options.callDepth--; + } + + } + +} + /** Class R3.System.DOM @@ -2450,7 +2568,7 @@ Runtime.BULLET = 0x9; Runtime.SOCKET = 0xa; Runtime.STATISTICS = 0xb; Runtime.STATS = 0xc; -Runtime.MAX_RUNTIMES = 0xd; +Runtime.MAX_RUNTIME = 0xd; /** @@ -3553,7 +3671,7 @@ Component.DOM = 0x0; Component.CANVAS = 0x1; Component.INPUT = 0x2; Component.TOUCH = 0x3; -Component.MAX_COMPONENTS = 0x4; +Component.MAX_COMPONENT = 0x4; /** @@ -5101,6 +5219,7 @@ class Touch extends Input { } +R3.Entity = Entity; R3.System = System; R3.Event = Event; R3.Utils = Utils; @@ -5134,6 +5253,7 @@ Runtime.Physics.Bullet = Bullet; Runtime.Socket = Socket; Runtime.Statistics = Statistics; Runtime.Statistics.Stats = Stats; +Entity.Slider = Slider; console.log('r3.js - version ' + R3.version + ' compiled ' + R3.compileDate); R3.System.DOM.Start(); R3.System.Input.Start(); diff --git a/package.json b/package.json index fa15a51..f69af1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "r3", - "version" : "2.0.454", + "version" : "2.0.464", "description": "", "private": true, "dependencies": { diff --git a/r3.php b/r3.php index 91317fb..f139399 100755 --- a/r3.php +++ b/r3.php @@ -286,7 +286,7 @@ function doGetInheritedTemplateUpdates($node, $restoreTokens, $inherited = true, } catch (ErrorException $e) { echo $e->getMessage(); - exit(1); + exit(0); } $updates = ''; @@ -454,7 +454,8 @@ function generateConstructors($file, $command) } if (!$constructor) { - throw new Exception('Constructor not found for file : ' . $file); + console.log('No constructor found for : ' . $file); + return; } updateSection($file, $token , $constructor); @@ -1378,6 +1379,7 @@ function generateR3Dist($nodes) 'src/r3/r3-system/index.js', 'src/r3/r3-component/index.js', 'src/r3/r3-runtime/index.js', + 'src/r3/r3-entity/index.js', ]; foreach ($indexFiles as $indexFile) { @@ -1561,7 +1563,7 @@ function generateOutOfClassImplementationDefines($graph, $types) $i++; } - array_push($updateList, $parent->name . '.MAX_' . strtoupper($parent->name) . 'S = 0x' . dechex($i) . ";\n"); + array_push($updateList, $parent->name . '.MAX_' . strtoupper($parent->name) . ' = 0x' . dechex($i) . ";\n"); updateSection($parent->file, 'GENERATED_OUT_OF_CLASS_IMPLEMENTATION' , $updateList); } @@ -1603,14 +1605,14 @@ foreach ($files as $file) { echo "Remove easily with:\n"; echo "rm $saveFile\n"; - exit(1); + exit(0); } $tokens = getTokens('CUSTOM'); $result = save($file, $tokens); - exit(0); + exit(1); } else if ($argv[2] == 'restore') { @@ -1624,7 +1626,7 @@ foreach ($files as $file) { $tokens = loadSaved($file, $restoreTokens); } catch (ErrorException $e) { echo $e->getMessage(); - exit(1); + exit(0); } $skipped = []; @@ -1696,10 +1698,10 @@ foreach ($files as $file) { print_r($skipped); echo "Please restore them manually from the saved file :$saveFile\n"; echo "If you do not do it now - on the next template update code will be overwritten and you could lose code!!!\n"; - exit(1); + exit(0); } else { deleteSavedFile($saveFile); - exit(0); + exit(1); } } else if ($argv[2] == 'build-dist') { buildNodeList($file); @@ -1738,7 +1740,8 @@ if ($argv[2] == 'build-dist') { [ 'System', 'Component', - 'Runtime' + 'Runtime', + 'Entity' ] ); @@ -1753,7 +1756,8 @@ if ($argv[2] == 'build-dist') { [ 'System', 'Component', - 'Runtime' + 'Runtime', + 'Entity' ] ); @@ -1770,6 +1774,6 @@ if ($argv[2] == 'build-dist') { } -exit(0); +exit(1); ?> \ No newline at end of file diff --git a/src/r3/r3-component/r3-component.js b/src/r3/r3-component/r3-component.js index 4ac1a08..ebb4197 100644 --- a/src/r3/r3-component/r3-component.js +++ b/src/r3/r3-component/r3-component.js @@ -312,7 +312,7 @@ Component.DOM = 0x0; Component.CANVAS = 0x1; Component.INPUT = 0x2; Component.TOUCH = 0x3; -Component.MAX_COMPONENTS = 0x4; +Component.MAX_COMPONENT = 0x4; //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END //CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START diff --git a/src/r3/r3-entity/index.js b/src/r3/r3-entity/index.js new file mode 100644 index 0000000..0d5d3a5 --- /dev/null +++ b/src/r3/r3-entity/index.js @@ -0,0 +1,12 @@ +//GENERATED_IMPORTS_START +const Entity = require('./r3-entity.js'); +const Slider = require('./r3-slider.js'); +//GENERATED_IMPORTS_END + +//GENERATED_INDEX_BODY_START +Entity.Slider = Slider; +//GENERATED_INDEX_BODY_END + +//GENERATED_EXPORTS_START +module.exports = Entity; +//GENERATED_EXPORTS_END diff --git a/src/r3/r3-entity/r3-entity.js b/src/r3/r3-entity/r3-entity.js new file mode 100644 index 0000000..493e832 --- /dev/null +++ b/src/r3/r3-entity/r3-entity.js @@ -0,0 +1,101 @@ +const Event = require('.././r3-event'); +const Utils = require('.././r3-utils'); + +/** + + GENERATED_INHERITED_START + + GENERATED_INHERITED_END + + CUSTOM_OPTIONS_START + CUSTOM_OPTIONS_END + + CUSTOM_METHODS_START + initialized() - Should raise an event(s) which indicates that this object initialized + CUSTOM_METHODS_END + + CUSTOM_STATIC_METHODS_START + CUSTOM_STATIC_METHODS_END + + **/ + +class Entity { + + //GENERATED_CONSTRUCTOR_START + constructor(options) { + + Event.Emit(Event.OBJECT_CREATED, this); + + if (typeof options === 'undefined') { + options = {}; + } + + if (typeof options.callDepth === 'undefined') { + options.callDepth = 0; + } else { + options.callDepth++; + } + + //GENERATED_OPTIONS_INIT_START + //GENERATED_OPTIONS_INIT_END + + //CUSTOM_OPTIONS_INIT_START + //CUSTOM_OPTIONS_INIT_END + + Object.assign(this, options); + + //CUSTOM_BEFORE_INIT_START + //CUSTOM_BEFORE_INIT_END + + if (options.callDepth === 0) { + this.initialized(); + } else { + options.callDepth--; + } + + //CUSTOM_AFTER_INIT_START + //CUSTOM_AFTER_INIT_END + } + //GENERATED_CONSTRUCTOR_END + + //CUSTOM_IMPLEMENTATION_START + //CUSTOM_IMPLEMENTATION_END + + //GENERATED_METHODS_START + + /** + * initialized() + * - Should raise an event(s) which indicates that this object initialized + */ + initialized() { + + //GENERATED_INITIALIZED_METHOD_START + if (this.hasOwnProperty('callDepth')) { + delete this.callDepth; + } else { + console.warn('Multiple calls to initialized() - check your callstack'); + } + //GENERATED_INITIALIZED_METHOD_END + + //CUSTOM_INITIALIZED_METHOD_START + Event.Emit(Event.OBJECT_INITIALIZED, this); + Event.Emit(Event.ENTITY_INITIALIZED, this); + //CUSTOM_INITIALIZED_METHOD_END + + } + //GENERATED_METHODS_END + + //GENERATED_STATIC_METHODS_START + //GENERATED_STATIC_METHODS_END + +} + +//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_START +Entity.SLIDER = 0x0; +Entity.MAX_ENTITY = 0x1; +//GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END + +//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START +//CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_END + +module.exports = Entity; diff --git a/src/r3/r3-entity/r3-slider.js b/src/r3/r3-entity/r3-slider.js new file mode 100644 index 0000000..3534d7b --- /dev/null +++ b/src/r3/r3-entity/r3-slider.js @@ -0,0 +1,124 @@ +const Event = require('.././r3-event'); +const Utils = require('.././r3-utils'); +const Entity = require('.././r3-entity.js'); + +/** + + GENERATED_INHERITED_START + + Class R3.Entity.Slider + [Inherited from Entity] + + Inherited Properties: + + + + Inherited Static Properties: + + + + Inherited Methods: + + - initialized() + Should raise an event(s) which indicates that this object initialized + + Inherited Static Methods: + + + + [Belonging to Slider] + + Properties: + + + + Static Properties: + + + + Methods: + + + + Static Methods: + + + + GENERATED_INHERITED_END + + CUSTOM_OPTIONS_START + CUSTOM_OPTIONS_END + + CUSTOM_INSTANCE_OPTIONS_MAPPING_START + CUSTOM_INSTANCE_OPTIONS_MAPPING_END + + CUSTOM_LINKED_OBJECTS_START + CUSTOM_LINKED_OBJECTS_END + + CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS_START + CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS_END + + CUSTOM_METHODS_START + CUSTOM_METHODS_END + + CUSTOM_STATIC_METHODS_START + CUSTOM_STATIC_METHODS_END + + **/ + +class Slider extends Entity { + + //GENERATED_CONSTRUCTOR_EXTENDS_START + constructor(options) { + + if (typeof options === 'undefined') { + options = {}; + } + + if (typeof options.callDepth === 'undefined') { + options.callDepth = 0; + } else { + options.callDepth++; + } + + super(options); + + //GENERATED_OPTIONS_INIT_START + //GENERATED_OPTIONS_INIT_END + + //CUSTOM_OPTIONS_INIT_START + //CUSTOM_OPTIONS_INIT_END + + Object.assign(this, options); + + //CUSTOM_BEFORE_INIT_START + //CUSTOM_BEFORE_INIT_END + + if (options.callDepth === 0) { + this.initialized(); + } else { + options.callDepth--; + } + + //CUSTOM_AFTER_INIT_START + //CUSTOM_AFTER_INIT_END + } + //GENERATED_CONSTRUCTOR_EXTENDS_END + + //GENERATED_METHODS_START + //GENERATED_METHODS_END + + //GENERATED_STATIC_METHODS_START + //GENERATED_STATIC_METHODS_END + + //CUSTOM_IMPLEMENTATION_START + //CUSTOM_IMPLEMENTATION_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 = Slider; diff --git a/src/r3/r3-event.js b/src/r3/r3-event.js index 5b56873..3901214 100644 --- a/src/r3/r3-event.js +++ b/src/r3/r3-event.js @@ -341,13 +341,13 @@ class Event { //CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START //GENERATED_EVENTS_START -Event.BEFORE_RENDER = 0x1; -Event.COMPONENT_CREATED = 0x2; -Event.COMPONENT_INITIALIZED = 0x3; -Event.CREATE_INSTANCE_BEFORE = 0x4; -Event.DISPOSE_INSTANCE = 0x5; -Event.DISPOSE_OBJECT = 0x6; -Event.DOM_COMPONENT_INITIALIZED = 0x7; +Event.COMPONENT_CREATED = 0x1; +Event.COMPONENT_INITIALIZED = 0x2; +Event.CREATE_INSTANCE_BEFORE = 0x3; +Event.DISPOSE_INSTANCE = 0x4; +Event.DISPOSE_OBJECT = 0x5; +Event.DOM_COMPONENT_INITIALIZED = 0x6; +Event.ENTITY_INITIALIZED = 0x7; Event.GET_RUNTIME = 0x8; Event.GET_WINDOW_SIZE = 0x9; Event.INPUT_COMPONENT_INITIALIZED = 0xa; @@ -376,13 +376,13 @@ Event.MAX_EVENTS = 0x1f; Event.GetEventName = function(eventId) { switch(eventId) { - case 0x1 : return 'before_render'; - case 0x2 : return 'component_created'; - case 0x3 : return 'component_initialized'; - case 0x4 : return 'create_instance_before'; - case 0x5 : return 'dispose_instance'; - case 0x6 : return 'dispose_object'; - case 0x7 : return 'dom_component_initialized'; + case 0x1 : return 'component_created'; + case 0x2 : return 'component_initialized'; + case 0x3 : return 'create_instance_before'; + case 0x4 : return 'dispose_instance'; + case 0x5 : return 'dispose_object'; + case 0x6 : return 'dom_component_initialized'; + case 0x7 : return 'entity_initialized'; case 0x8 : return 'get_runtime'; case 0x9 : return 'get_window_size'; case 0xa : return 'input_component_initialized'; diff --git a/src/r3/r3-r3.js b/src/r3/r3-r3.js index 4b03652..3557e45 100644 --- a/src/r3/r3-r3.js +++ b/src/r3/r3-r3.js @@ -1,9 +1,10 @@ class R3 { - static version = '2.0.454'; - static compileDate = '2021 Sep 09 - 18:08:03 pm'; + static version = '2.0.464'; + static compileDate = '2021 Sep 10 - 07:16:56 am'; } //GENERATED_IMPORTS_START +const Entity = require('./r3-entity/r3-entity.js'); const System = require('./r3-system/r3-system.js'); const Event = require('./r3-event.js'); const Utils = require('./r3-utils.js'); @@ -14,6 +15,7 @@ const Project = require('./r3-project.js'); //GENERATED_IMPORTS_END //GENERATED_DEFINES_START +R3.Entity = Entity; R3.System = System; R3.Event = Event; R3.Utils = Utils; diff --git a/src/r3/r3-runtime/r3-runtime.js b/src/r3/r3-runtime/r3-runtime.js index 359bf04..891f25a 100644 --- a/src/r3/r3-runtime/r3-runtime.js +++ b/src/r3/r3-runtime/r3-runtime.js @@ -148,7 +148,7 @@ Runtime.BULLET = 0x9; Runtime.SOCKET = 0xa; Runtime.STATISTICS = 0xb; Runtime.STATS = 0xc; -Runtime.MAX_RUNTIMES = 0xd; +Runtime.MAX_RUNTIME = 0xd; //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END //CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START diff --git a/src/r3/r3-system/r3-system.js b/src/r3/r3-system/r3-system.js index 6d9c3a9..3181645 100644 --- a/src/r3/r3-system/r3-system.js +++ b/src/r3/r3-system/r3-system.js @@ -74,7 +74,7 @@ System.SYSTEM_INPUT = 0x1; System.SYSTEM_LINKING = 0x2; System.SYSTEM_RUNTIME = 0x3; System.SYSTEM_SOCKET = 0x4; -System.MAX_SYSTEMS = 0x5; +System.MAX_SYSTEM = 0x5; //GENERATED_OUT_OF_CLASS_IMPLEMENTATION_END //CUSTOM_OUT_OF_CLASS_IMPLEMENTATION_START diff --git a/utils.php b/utils.php index 7e39620..94afb7b 100644 --- a/utils.php +++ b/utils.php @@ -32,11 +32,27 @@ else { $files = []; +function addFiles($folder, &$newFiles) +{ + + $files = scandir($folder, SCANDIR_SORT_DESCENDING); + + for ($i = 0; $i < sizeof($files); $i++) { + + if (preg_match('/index\.js$/', $files[$i])) { + continue; + } + + if (preg_match('/\.js$/', $files[$i])) { + array_push($newFiles, $folder . $files[$i]); + } + } + +} + if ($argv[1] == 'all') { + $files = scandir('src/r3/', SCANDIR_SORT_DESCENDING); - $systemFiles = scandir('src/r3/r3-system', SCANDIR_SORT_DESCENDING); - $componentFiles = scandir('src/r3/r3-component', SCANDIR_SORT_DESCENDING); - $runtimeFiles = scandir('src/r3/r3-runtime', SCANDIR_SORT_DESCENDING); $newFiles = []; @@ -51,37 +67,15 @@ if ($argv[1] == 'all') { } } - for ($i = 0; $i < sizeof($systemFiles); $i++) { + $folders = [ + 'src/r3/r3-system/', + 'src/r3/r3-component/', + 'src/r3/r3-runtime/', + 'src/r3/r3-entity/' + ]; - if (preg_match('/index\.js$/', $systemFiles[$i])) { - continue; - } - - if (preg_match('/\.js$/', $systemFiles[$i])) { - array_push($newFiles, 'src/r3/r3-system/' . $systemFiles[$i]); - } - } - - for ($i = 0; $i < sizeof($componentFiles); $i++) { - - if (preg_match('/index\.js$/', $componentFiles[$i])) { - continue; - } - - if (preg_match('/\.js$/', $componentFiles[$i])) { - array_push($newFiles, 'src/r3/r3-component/' . $componentFiles[$i]); - } - } - - for ($i = 0; $i < sizeof($runtimeFiles); $i++) { - - if (preg_match('/index\.js$/', $runtimeFiles[$i])) { - continue; - } - - if (preg_match('/\.js$/', $runtimeFiles[$i])) { - array_push($newFiles, 'src/r3/r3-runtime/' . $runtimeFiles[$i]); - } + foreach ($folders as $folder) { + addFiles($folder, $newFiles); } $files = $newFiles; diff --git a/version b/version index 4e6e09e..920df30 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.0.454 \ No newline at end of file +2.0.464 \ No newline at end of file