From d96164a82c690fc63bf349b9c0bb940868c9883f Mon Sep 17 00:00:00 2001 From: "Theunis J. Botha" Date: Thu, 9 Sep 2021 13:20:20 +0200 Subject: [PATCH] fix systems --- r3.php | 34 +++++++++- .../system_base_constructor.template | 20 ++++++ src/templates/system_extends.template | 66 +++++++++++++++++++ .../system_extends_constructor.template | 22 +++++++ src/templates/token.db | 1 + version | 2 +- 6 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 src/templates/system_base_constructor.template create mode 100644 src/templates/system_extends.template create mode 100644 src/templates/system_extends_constructor.template diff --git a/r3.php b/r3.php index 2d915f3..3f63368 100755 --- a/r3.php +++ b/r3.php @@ -428,6 +428,34 @@ function generateInherited($file, $restoreTokens) updateSection($file, 'GENERATED_INHERITED' , $updates); } +function generateConstructors($file, $command) +{ + echo $file; + + $token = 'GENERATED_CONSTRUCTOR'; + + if (preg_match('/system_base/', $command)) { + $constructor = file_get_contents('src/templates/system_base_constructor.template'); + } + + if (preg_match('/\bsystem\b/', $command)) { + $constructor = file_get_contents('src/templates/system_extends_constructor.template'); + $token = 'GENERATED_CONSTRUCTOR_EXTENDS'; + } + + if (preg_match('/\bnormal\b/', $command)) { + $constructor = file_get_contents('src/templates/constructor.template'); + } + + if (preg_match('/\bextends\b/', $command)) { + $constructor = file_get_contents('src/templates/constructor_extends.template'); + $token = 'GENERATED_CONSTRUCTOR_EXTENDS'; + } + + updateSection($file, $token , $constructor); + +} + function generateInitOptions($file, $tokens) { $token = 'CUSTOM_OPTIONS'; @@ -1168,7 +1196,7 @@ function generateR3($nodes, $graph) $tokens = loadSaved($r3File, getTokens('CUSTOM')); - $template = file_get_contents('src/templates/r3-base.template'); + $template = file_get_contents('src/templates/r3_base.template'); $version = file_get_contents('version'); @@ -1302,7 +1330,7 @@ function generateR3Dist($nodes) { $r3jsFile = 'dist/r3.js'; $r3jsSource = 'src/r3/r3-r3.js'; - $r3jsBaseTemplate = 'src/templates/r3-base.template'; + $r3jsBaseTemplate = 'src/templates/r3_base.template'; $r3js = fopen($r3jsFile, "w"); ftruncate($r3js, 0); @@ -1615,6 +1643,8 @@ foreach ($files as $file) { } } + generateConstructors($file, $argv[3]); + generateMethods($file, $tokens); generateStaticMethods($file, $tokens); diff --git a/src/templates/system_base_constructor.template b/src/templates/system_base_constructor.template new file mode 100644 index 0000000..1ac1361 --- /dev/null +++ b/src/templates/system_base_constructor.template @@ -0,0 +1,20 @@ + constructor(options) { + + if (typeof options === 'undefined') { + 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 + + //CUSTOM_AFTER_INIT_START + //CUSTOM_AFTER_INIT_END + } \ No newline at end of file diff --git a/src/templates/system_extends.template b/src/templates/system_extends.template new file mode 100644 index 0000000..8a9531c --- /dev/null +++ b/src/templates/system_extends.template @@ -0,0 +1,66 @@ +const Event = require('INCLUDE_PATH/r3-event'); +const Utils = require('INCLUDE_PATH/r3-utils'); +const EXTEND_CLASS = require('./EXTEND_CLASS_FILE_NAME'); + +/** + + GENERATED_INHERITED_START + + GENERATED_INHERITED_END + + CUSTOM_OPTIONS_START + CUSTOM_OPTIONS_END + + CUSTOM_STATIC_OPTIONS_START + Started=false + Subscriptions={} + CUSTOM_STATIC_OPTIONS_END + + CUSTOM_EVENT_LISTENERS_START + CUSTOM_EVENT_LISTENERS_END + + CUSTOM_STATIC_EVENT_LISTENERS_START + CUSTOM_STATIC_EVENT_LISTENERS_END + + CUSTOM_METHODS_START + CUSTOM_METHODS_END + + CUSTOM_STATIC_METHODS_START + Start(options) - Starts the system by registering subscriptions to events + Stop(options) - Stops the system by removing these subscriptions to events + CUSTOM_STATIC_METHODS_END + + **/ + +class CLASS_NAME extends EXTEND_CLASS { + + //GENERATED_CONSTRUCTOR_EXTENDS_START + //GENERATED_CONSTRUCTOR_EXTENDS_END + + //GENERATED_METHODS_START + //GENERATED_METHODS_END + + //GENERATED_STATIC_METHODS_START + //GENERATED_STATIC_METHODS_END + + //GENERATED_EVENT_LISTENER_METHODS_START + //GENERATED_EVENT_LISTENER_METHODS_END + + //GENERATED_STATIC_EVENT_LISTENER_METHODS_START + //GENERATED_STATIC_EVENT_LISTENER_METHODS_END + + //CUSTOM_IMPLEMENTATION_START + //CUSTOM_IMPLEMENTATION_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/system_extends_constructor.template b/src/templates/system_extends_constructor.template new file mode 100644 index 0000000..e2ab17d --- /dev/null +++ b/src/templates/system_extends_constructor.template @@ -0,0 +1,22 @@ + constructor(options) { + + if (typeof options === 'undefined') { + options = {}; + } + + 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 + + //CUSTOM_AFTER_INIT_START + //CUSTOM_AFTER_INIT_END + } \ No newline at end of file diff --git a/src/templates/token.db b/src/templates/token.db index 8273253..f9d4b2a 100644 --- a/src/templates/token.db +++ b/src/templates/token.db @@ -57,6 +57,7 @@ CUSTOM_ASYNC_METHOD CUSTOM_BEFORE_INIT CUSTOM_BEFORE_STATIC_SYSTEM_START CUSTOM_BEFORE_STATIC_SYSTEM_STOP +CUSTOM_BEFORE_SYSTEM CUSTOM_BEFORE_SYSTEM_START CUSTOM_BEFORE_SYSTEM_STOP CUSTOM_CONVENIENT_DEFINES diff --git a/version b/version index 6a391bc..c884a2f 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.0.228 \ No newline at end of file +2.0.440 \ No newline at end of file