Compare commits

...

2 Commits

Author SHA1 Message Date
Theunis J. Botha abbce4e691 done with parent / child relationships 2021-10-02 14:55:08 +02:00
Theunis J. Botha 4e59d9f317 cannot splice 2021-10-02 10:47:22 +02:00
24 changed files with 361 additions and 373 deletions

269
dist/r3.js vendored
View File

@ -17,12 +17,12 @@ class R3 {
/**
* static Version - Current R3 version
*/
R3.Version = '3.0.245';
R3.Version = '3.0.255';
/**
* static CompileDate - Current compile date of R3
*/
R3.CompileDate = '2021 Oct 02 - 10:26:44 am';
R3.CompileDate = '2021 Oct 02 - 14:30:13 pm';
class System {
@ -482,53 +482,57 @@ class SystemLinking extends System {
value
) {
/**
* First we check if this is a required property
*/
if (!r3Object.required.hasOwnProperty(property)) {
return;
}
/**
* We know this property is required - so continue..
*/
if (r3Object.required[property] instanceof Array) {
for (let r = 0; r < r3Object.required.length; r++) {
/**
* First we need to check that this value conforms to the requirement of being an Array
* First we check if this is a required property
*/
if (!(value instanceof Array)) {
throw new TypeError('The property ' + property + ' of ' + r3Object.name + ' was not properly defined - it should be an array');
}
if (value.length === 0) {
if (!r3Object.required[r].hasOwnProperty(property)) {
return;
}
/**
* Check all items in the array are valid objects of type r3Object.required[property]
* We know this property is required - so continue..
*/
for (let i = 0; i < value.length; i++) {
r3Object.required[property].map(
function(constructor) {
if (!(value[i] instanceof constructor)) {
throw new TypeError('The property ' + property + ' of this object is not of the correct type');
if (r3Object.required[r][property] instanceof Array) {
/**
* First we need to check that this value conforms to the requirement of being an Array
*/
if (!(value instanceof Array)) {
throw new TypeError('The property ' + property + ' of ' + r3Object.name + ' was not properly defined - it should be an array');
}
if (value.length === 0) {
return;
}
/**
* Check all items in the array are valid objects of type r3Object.required[property]
*/
for (let i = 0; i < value.length; i++) {
r3Object.required[r][property].map(
function (constructor) {
if (!(value[i] instanceof constructor)) {
throw new TypeError('The property ' + property + ' of this object is not of the correct type');
}
}
}
);
}
} else {
);
}
} else {
if (value === null) {
return;
}
if (value === null) {
return;
}
if (typeof value === 'undefined') {
return;
}
if (typeof value === 'undefined') {
return;
}
if (!(value instanceof r3Object.required[r][property])) {
throw new TypeError('The property ' + property + ' of ' + r3Object.name + ' is not of the correct type')
}
if (!(value instanceof r3Object.required[property])) {
throw new TypeError('The property ' + property + ' of ' + r3Object.name + ' is not of the correct type')
}
}
@ -556,33 +560,55 @@ class SystemLinking extends System {
* In this case - we should check its existing components and have their relationships
* severed
*/
if (value.length === 0) {
// if (value.length === 0) {
//
// if (r3Object[property] instanceof Array) {
// for (let i = 0; i < r3Object[property].length; i++) {
// if (r3Object[property][i] instanceof R3Object) {
// r3Object.dirty = true;
// Utils.RemoveFromArray(r3Object[property][i].parents, r3Object);
// }
// }
// }
//
// } else {
if (r3Object[property] instanceof Array) {
for (let i = 0; i < r3Object[property].length; i++) {
if (r3Object[property][i] instanceof R3Object) {
r3Object.dirty = true;
Utils.RemoveFromArray(r3Object[property][i].parents, r3Object);
/**
* We need to check if we removed an item from the existing array
*/
if (r3Object[property].length > 0) {
/**
* Find the missing value (if any) from the old array
*/
let unlinked = r3Object[property].reduce(
function(result, object) {
if (value.indexOf(object) === -1) {
result.push(object);
}
return result;
},
[]
);
unlinked.map(
function(unlinkObject) {
Utils.RemoveFromArray(unlinkObject.parents, r3Object);
Utils.RemoveFromArray(r3Object.children, unlinkObject);
if (r3Object instanceof Entity) {
Utils.RemoveFromArray(r3Object.components, unlinkObject);
}
}
}
);
} else {
}
/**
* We need to check if we removed an item from the existing array
*/
if (r3Object[property].length > 0) {
}
for (let i = 0; i < value.length; i++) {
if (value[i] instanceof R3Object) {
Utils.PushUnique(value[i].parents, r3Object);
Utils.PushUnique(r3Object.children, value[i]);
if (r3Object instanceof Entity) {
Utils.PushUnique(r3Object.components, value[i]);
}
for (let i = 0; i < value.length; i++) {
if (value[i] instanceof R3Object) {
Utils.PushUnique(value[i].parents, r3Object);
Utils.PushUnique(r3Object.children, value[i]);
if (r3Object instanceof Entity) {
Utils.PushUnique(r3Object.components, value[i]);
}
}
}
@ -597,6 +623,18 @@ class SystemLinking extends System {
}
}
if (value === null || typeof value === 'undefined') {
if (r3Object[property] instanceof R3Object) {
Utils.RemoveFromArray(r3Object[property].parents, r3Object);
Utils.RemoveFromArray(r3Object.children, r3Object[property]);
if (r3Object instanceof Entity) {
Utils.RemoveFromArray(r3Object.components, r3Object[property]);
}
}
}
}
/**
@ -2067,6 +2105,10 @@ class R3Object extends Event {
constructor(options) {
if (typeof options === 'undefined') {
options = {};
}
if (typeof options.maxDepth === 'undefined') {
options.maxDepth = 0;
}
@ -2152,6 +2194,8 @@ class R3Object extends Event {
*/
initialize() {
this.initialized = true;
if (this.initializeDepth === this.maxDepth) {
throw new Error('You should not try to instantiate this base class - extend it rather...');
} else {
@ -2160,23 +2204,6 @@ class R3Object extends Event {
}
/**
* 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
) {
this.initialized = true;
}
}
R3Object.PROJECT = 0x0;
@ -2222,28 +2249,6 @@ class Project extends R3Object {
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;
@ -2276,45 +2281,12 @@ 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: Project');
}
/**
* stop()
* - Stops this Object by removing all subscriptions to events
*/
stop() {
this.started = false;
console.log('Stopped transient system: Project');
}
}
class Entity extends R3Object {
constructor(options) {
super(options);
if (typeof options === 'undefined') {
options = {};
}
@ -2331,6 +2303,8 @@ class Entity extends R3Object {
options.maxDepth = options.callDepth;
super(options);
Object.assign(this, options);
this.emit(Event.ENTITY_CREATED, this);
@ -2349,7 +2323,8 @@ class Entity extends R3Object {
*/
initialize() {
this.setInitialized();
super.initialize();
Event.Emit(Event.ENTITY_INITIALIZED, this);
if (this.initializeDepth === this.maxDepth) {
@ -2385,10 +2360,6 @@ class EntitySlider extends Entity {
options.maxDepth = 0;
}
if (typeof options.initialized === 'undefined') {
options.initialized = false;
}
if (typeof options.callDepth === 'undefined') {
options.callDepth = 0;
} else {
@ -2397,18 +2368,8 @@ class EntitySlider extends Entity {
options.maxDepth = options.callDepth;
/**
* 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 Entity passed through initialize() functions
*/
if (typeof options.initializeDepth === 'undefined') {
options.initializeDepth = 0;
}
super(options);
/**
* components - A list of components that this entity is composed of
*/
@ -2429,7 +2390,12 @@ class EntitySlider extends Entity {
options.subscriptions = {};
}
super(options);
/**
* We need to assign some options here to the entity
* because SystemLinking requires 'components[]' to
* exist when determining parent / child relationships
*/
Object.assign(this, options);
/**
* canvas - The Canvas Component to which this entity binds its custom code components
@ -2707,6 +2673,10 @@ class Component extends R3Object {
constructor(options) {
if (typeof options === 'undefined') {
options = {};
}
if (typeof options.maxDepth === 'undefined') {
options.maxDepth = 0;
}
@ -2740,6 +2710,7 @@ class Component extends R3Object {
initialize() {
super.initialize();
Event.Emit(Event.COMPONENT_INITIALIZED, this);
if (this.initializeDepth === this.maxDepth) {

View File

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

55
r3.php
View File

@ -1,13 +1,12 @@
#!/usr/bin/php
<?php
echo '';
echo ' _____ __ ';echo "\n";
echo ' _____|__ / ____ / /_ ____ ';echo "\n";
echo ' / ___/ /_ < / __ \/ __ \/ __ \ ';echo "\n";
echo ' / / ___/ /_ / /_/ / / / / /_/ /';echo "\n";
echo '/_/ /____/(_) .___/_/ /_/ .___/ ';echo "\n";
echo ' /_/ /_/ ';echo "\n";
echo ' _____ __ '; echo "\n";
echo ' ____|__ / ____ / /_ ____ '; echo "\n";
echo ' / ___//_ < / __ \ / __ \ / __ \ '; echo "\n";
echo ' / / ___/ /_ / /_/ // / / // /_/ /'; echo "\n";
echo '/_/ /____/(_)/ .___//_/ /_// .___/ '; echo "\n";
echo ' /_/ /_/ '; echo "\n";
echo "\n";
include "vendor/autoload.php";
@ -466,62 +465,75 @@ function generateConstructors($file, $command)
// echo $file;
global $baseExtends;
global $specificBaseExtends;
$constructor = null;
$token = 'GENERATED_CONSTRUCTOR';
if (preg_match('/\bsystem_base\b/', $command)) {
$constructor = file_get_contents('src/templates/system_base_constructor.template');
$specificBaseExtends = 'system_base';
}
if (preg_match('/\bsystem_extends\b/', $command)) {
$constructor = file_get_contents('src/templates/system_extends_constructor.template');
$baseExtends = 'extends';
$specificBaseExtends = 'system_extends';
}
if (preg_match('/\bruntime_base\b/', $command)) {
$constructor = file_get_contents('src/templates/runtime_base_constructor.template');
$specificBaseExtends = 'runtime_base';
}
if (preg_match('/\bruntime_extends\b/', $command)) {
$constructor = file_get_contents('src/templates/runtime_extends_constructor.template');
$baseExtends = 'extends';
$specificBaseExtends = 'runtime_extends';
}
if (preg_match('/\bcomponent_base\b/', $command)) {
$constructor = file_get_contents('src/templates/component_base_constructor.template');
$specificBaseExtends = 'component_base';
}
if (preg_match('/\bcomponent_extends\b/', $command)) {
$constructor = file_get_contents('src/templates/component_extends_constructor.template');
$baseExtends = 'extends';
$specificBaseExtends = 'component_extends';
}
if (preg_match('/\bentity_base\b/', $command)) {
$constructor = file_get_contents('src/templates/entity_base_constructor.template');
$specificBaseExtends = 'entity_base';
}
if (preg_match('/\bentity_extends\b/', $command)) {
$constructor = file_get_contents('src/templates/entity_extends_constructor.template');
$baseExtends = 'extends';
$specificBaseExtends = 'entity_extends';
}
if (preg_match('/\bobject_base\b/', $command)) {
$constructor = file_get_contents('src/templates/object_base_constructor.template');
$specificBaseExtends = 'object_base';
}
if (preg_match('/\bobject_extends\b/', $command)) {
$constructor = file_get_contents('src/templates/object_extends_constructor.template');
$baseExtends = 'extends';
$specificBaseExtends = 'object_extends';
}
if (preg_match('/\bbase\b/', $command)) {
$constructor = file_get_contents('src/templates/base_constructor.template');
$specificBaseExtends = 'base';
}
if (preg_match('/\bextends\b/', $command)) {
$constructor = file_get_contents('src/templates/extends_constructor.template');
$baseExtends = 'extends';
$specificBaseExtends = 'extends';
}
if (!$constructor) {
@ -1053,6 +1065,7 @@ function getMethodDetails($item)
function getMethodTemplate($token, &$updated, $methodTokenName)
{
global $baseExtends;
global $specificBaseExtends;
$staticNormal = '';
@ -1065,7 +1078,15 @@ function getMethodTemplate($token, &$updated, $methodTokenName)
/**
* Do before function
*/
$potentialTemplate = strtolower('src/templates/' . $staticNormal . $baseExtends . '_' . $methodTokenName . '.template');
$potentialTemplate = strtolower('src/templates/' . $staticNormal . $specificBaseExtends . '_' . $methodTokenName . '.template');
if (file_exists($potentialTemplate)) {
$templateFound = true;
}
if (!$templateFound) {
$potentialTemplate = strtolower('src/templates/' . $staticNormal . $baseExtends . '_' . $methodTokenName . '.template');
}
if (file_exists($potentialTemplate)) {
$templateFound = true;
@ -1091,7 +1112,15 @@ function getMethodTemplate($token, &$updated, $methodTokenName)
/**
* Do after function
*/
$potentialTemplate = strtolower('src/templates/' . $staticNormal . $baseExtends . '_' . $methodTokenName . '_after.template');
$potentialTemplate = strtolower('src/templates/' . $staticNormal . $specificBaseExtends . '_' . $methodTokenName . '_after.template');
if (file_exists($potentialTemplate)) {
$templateFound = true;
}
if (!$templateFound) {
$potentialTemplate = strtolower('src/templates/' . $staticNormal . $baseExtends . '_' . $methodTokenName . '_after.template');
}
if (file_exists($potentialTemplate)) {
$templateFound = true;
@ -1122,8 +1151,6 @@ function getMethodTemplate($token, &$updated, $methodTokenName)
*/
function doMethodUpdate($template, $tokens, $token)
{
global $baseExtends;
$store = getTokenStore($token, $tokens);
if (sizeof($store) <= 0) {
@ -1393,6 +1420,7 @@ function buildImportsAndBody(&$imports, &$body, &$tests, &$testImports, $node, $
$file = str_replace('src/r3/r3-' . str_replace('r3-', '', strtolower(from_camel_case($type,'-'))), '.', $child->file);
//if the file extends another file it is not important for testing because it will be imported from the base index
$important = true;
if (preg_match('/src\/r3/', $file)) {
@ -1407,6 +1435,11 @@ function buildImportsAndBody(&$imports, &$body, &$tests, &$testImports, $node, $
if ($important) {
array_push($testImports, "const " . $child->name . ' = require(\'../src/r3/r3-' . str_replace('r3object','object', strtolower($type)) . '/' . $file . "');");
array_push($tests, "\t\t\tconst " . lcfirst($child->name) . " = new " . $child->name . '();');
if ($type === 'Component' || $type === 'Entity') {
array_push($tests, "\t\t\tassert.isTrue(" . lcfirst($child->name) . ".initialized);");
}
}
$child->nameSpace = $nameSpace;

View File

@ -50,6 +50,10 @@ class Component extends R3Object {
//GENERATED_CONSTRUCTOR_START
constructor(options) {
if (typeof options === 'undefined') {
options = {};
}
if (typeof options.maxDepth === 'undefined') {
options.maxDepth = 0;
}
@ -100,10 +104,10 @@ class Component extends R3Object {
initialize() {
//GENERATED_INITIALIZE_METHOD_START
super.initialize();
//GENERATED_INITIALIZE_METHOD_END
//CUSTOM_INITIALIZE_METHOD_START
super.initialize();
Event.Emit(Event.COMPONENT_INITIALIZED, this);
//CUSTOM_INITIALIZE_METHOD_END

View File

@ -18,8 +18,6 @@ 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 Entity passed through initialize() functions
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
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.
@ -80,10 +78,6 @@ class EntitySlider extends Entity {
options.maxDepth = 0;
}
if (typeof options.initialized === 'undefined') {
options.initialized = false;
}
if (typeof options.callDepth === 'undefined') {
options.callDepth = 0;
} else {
@ -92,19 +86,9 @@ class EntitySlider extends Entity {
options.maxDepth = options.callDepth;
super(options);
//GENERATED_TEMPLATE_OPTIONS_INIT_START
/**
* 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 Entity passed through initialize() functions
*/
if (typeof options.initializeDepth === 'undefined') {
options.initializeDepth = 0;
}
/**
* components - A list of components that this entity is composed of
*/
@ -126,7 +110,12 @@ class EntitySlider extends Entity {
}
//GENERATED_TEMPLATE_OPTIONS_INIT_END
super(options);
/**
* We need to assign some options here to the entity
* because SystemLinking requires 'components[]' to
* exist when determining parent / child relationships
*/
Object.assign(this, options);
//GENERATED_OPTIONS_INIT_START
/**

View File

@ -46,8 +46,6 @@ class Entity extends R3Object {
//GENERATED_CONSTRUCTOR_START
constructor(options) {
super(options);
if (typeof options === 'undefined') {
options = {};
}
@ -64,6 +62,8 @@ class Entity extends R3Object {
options.maxDepth = options.callDepth;
super(options);
//GENERATED_TEMPLATE_OPTIONS_INIT_START
//GENERATED_TEMPLATE_OPTIONS_INIT_END
@ -100,10 +100,10 @@ class Entity extends R3Object {
initialize() {
//GENERATED_INITIALIZE_METHOD_START
super.initialize();
//GENERATED_INITIALIZE_METHOD_END
//CUSTOM_INITIALIZE_METHOD_START
this.setInitialized();
Event.Emit(Event.ENTITY_INITIALIZED, this);
//CUSTOM_INITIALIZE_METHOD_END

View File

@ -37,7 +37,6 @@ const Utils = require('.././r3-utils');
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
@ -56,6 +55,10 @@ class R3Object extends Event {
//GENERATED_CONSTRUCTOR_START
constructor(options) {
if (typeof options === 'undefined') {
options = {};
}
if (typeof options.maxDepth === 'undefined') {
options.maxDepth = 0;
}
@ -158,6 +161,7 @@ class R3Object extends Event {
initialize() {
//GENERATED_INITIALIZE_METHOD_START
this.initialized = true;
//GENERATED_INITIALIZE_METHOD_END
//CUSTOM_INITIALIZE_METHOD_START
@ -171,31 +175,6 @@ class R3Object extends Event {
}
//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
this.initialized = true;
//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

View File

@ -17,9 +17,6 @@ const R3Object = require('./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
@ -36,8 +33,6 @@ const R3Object = require('./r3-object.js');
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
@ -79,32 +74,11 @@ class Project extends R3Object {
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_TEMPLATE_OPTIONS_INIT_START
//GENERATED_TEMPLATE_OPTIONS_INIT_END
//GENERATED_OPTIONS_INIT_START
//GENERATED_OPTIONS_INIT_END
@ -157,67 +131,6 @@ 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: Project');
//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: Project');
//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

View File

@ -248,6 +248,20 @@ class SystemLinking extends System {
* First we need to check that this value conforms to the requirement of being an Array
*/
if (!(value instanceof Array)) {
if (r3Object.underConstruction) {
/**
* We are about to throw during a construction process. This means this r3Object will not
* be created - and so we need tell all of its children that this object is no longer their
* parent so that it can be garbage collected
*/
r3Object.children.map(
function(child) {
Utils.RemoveFromArray(child.parents, r3Object);
}
);
}
throw new TypeError('The property ' + property + ' of ' + r3Object.name + ' was not properly defined - it should be an array');
}
@ -262,6 +276,20 @@ class SystemLinking extends System {
r3Object.required[r][property].map(
function (constructor) {
if (!(value[i] instanceof constructor)) {
if (r3Object.underConstruction) {
/**
* We are about to throw during a construction process. This means this r3Object will not
* be created - and so we need tell all of its children that this object is no longer their
* parent so that it can be garbage collected
*/
r3Object.children.map(
function(child) {
Utils.RemoveFromArray(child.parents, r3Object);
}
);
}
throw new TypeError('The property ' + property + ' of this object is not of the correct type');
}
}
@ -278,6 +306,20 @@ class SystemLinking extends System {
}
if (!(value instanceof r3Object.required[r][property])) {
if (r3Object.underConstruction) {
/**
* We are about to throw during a construction process. This means this r3Object will not
* be created - and so we need tell all of its children that this object is no longer their
* parent so that it can be garbage collected
*/
r3Object.children.map(
function(child) {
Utils.RemoveFromArray(child.parents, r3Object);
}
);
}
throw new TypeError('The property ' + property + ' of ' + r3Object.name + ' is not of the correct type')
}
@ -309,60 +351,41 @@ class SystemLinking extends System {
if (value instanceof Array) {
/**
* This object could have its property set to an empty array.
* In this case - we should check its existing components and have their relationships
* severed
* We need to check if we removed an item from the existing array
*/
if (value.length === 0) {
if (r3Object[property].length > 0) {
/**
* Find the missing value (if any) from the old array
*/
if (r3Object[property] instanceof Array) {
for (let i = 0; i < r3Object[property].length; i++) {
if (r3Object[property][i] instanceof R3Object) {
r3Object.dirty = true;
Utils.RemoveFromArray(r3Object[property][i].parents, r3Object);
let unlinked = r3Object[property].reduce(
function(result, object) {
if (value.indexOf(object) === -1) {
result.push(object);
}
return result;
},
[]
);
unlinked.map(
function(unlinkObject) {
Utils.RemoveFromArray(unlinkObject.parents, r3Object);
Utils.RemoveFromArray(r3Object.children, unlinkObject);
if (r3Object instanceof Entity) {
Utils.RemoveFromArray(r3Object.components, unlinkObject);
}
}
}
);
} else {
}
/**
* We need to check if we removed an item from the existing array
*/
if (r3Object[property].length > 0) {
/**
* Find the missing value (if any) from the old array
*/
let unlinked = r3Object[property].reduce(
function(result, object) {
if (value.indexOf(object) === -1) {
result.push(object);
}
return result;
},
[]
);
unlinked.map(
function(unlinkObject) {
Utils.RemoveFromArray(unlinkObject.parents, r3Object);
Utils.RemoveFromArray(r3Object.children, unlinkObject);
if (r3Object instanceof Entity) {
Utils.RemoveFromArray(r3Object.components, unlinkObject);
}
}
);
}
for (let i = 0; i < value.length; i++) {
if (value[i] instanceof R3Object) {
Utils.PushUnique(value[i].parents, r3Object);
Utils.PushUnique(r3Object.children, value[i]);
if (r3Object instanceof Entity) {
Utils.PushUnique(r3Object.components, value[i]);
}
for (let i = 0; i < value.length; i++) {
if (value[i] instanceof R3Object) {
Utils.PushUnique(value[i].parents, r3Object);
Utils.PushUnique(r3Object.children, value[i]);
if (r3Object instanceof Entity) {
Utils.PushUnique(r3Object.components, value[i]);
}
}
}
@ -376,6 +399,19 @@ class SystemLinking extends System {
Utils.PushUnique(r3Object.components, value);
}
}
if (value === null || typeof value === 'undefined') {
if (r3Object[property] instanceof R3Object) {
Utils.RemoveFromArray(r3Object[property].parents, r3Object);
Utils.RemoveFromArray(r3Object.children, r3Object[property]);
if (r3Object instanceof Entity) {
Utils.RemoveFromArray(r3Object.components, r3Object[property]);
}
}
}
//CUSTOM_STATIC_SET_PARENT_CHILD_RELATIONSHIPS_METHOD_END
}

View File

@ -90,12 +90,12 @@ class R3 {
/**
* static Version - Current R3 version
*/
R3.Version = '3.0.245';
R3.Version = '3.0.255';
/**
* static CompileDate - Current compile date of R3
*/
R3.CompileDate = '2021 Oct 02 - 10:26:44 am';
R3.CompileDate = '2021 Oct 02 - 14:30:13 pm';
//GENERATED_STATIC_OPTIONS_INIT_END

View File

@ -1,5 +1,9 @@
constructor(options) {
if (typeof options === 'undefined') {
options = {};
}
if (typeof options.maxDepth === 'undefined') {
options.maxDepth = 0;
}

View File

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

View File

@ -1,7 +1,5 @@
constructor(options) {
super(options);
if (typeof options === 'undefined') {
options = {};
}
@ -18,6 +16,8 @@
options.maxDepth = options.callDepth;
super(options);
//GENERATED_TEMPLATE_OPTIONS_INIT_START
//GENERATED_TEMPLATE_OPTIONS_INIT_END

View File

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

View File

@ -14,8 +14,6 @@ const EXTEND_CLASS = require('./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 Entity passed through initialize() functions
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
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.

View File

@ -8,10 +8,6 @@
options.maxDepth = 0;
}
if (typeof options.initialized === 'undefined') {
options.initialized = false;
}
if (typeof options.callDepth === 'undefined') {
options.callDepth = 0;
} else {
@ -20,10 +16,17 @@
options.maxDepth = options.callDepth;
super(options);
//GENERATED_TEMPLATE_OPTIONS_INIT_START
//GENERATED_TEMPLATE_OPTIONS_INIT_END
super(options);
/**
* We need to assign some options here to the entity
* because SystemLinking requires 'components[]' to
* exist when determining parent / child relationships
*/
Object.assign(this, options);
//GENERATED_OPTIONS_INIT_START
//GENERATED_OPTIONS_INIT_END

View File

@ -35,7 +35,6 @@ const Utils = require('INCLUDE_PATH/r3-utils');
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

View File

@ -1,5 +1,9 @@
constructor(options) {
if (typeof options === 'undefined') {
options = {};
}
if (typeof options.maxDepth === 'undefined') {
options.maxDepth = 0;
}

View File

@ -15,9 +15,6 @@ const EXTEND_CLASS = require('./EXTEND_CLASS_FILE_NAME');
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
@ -34,8 +31,6 @@ const EXTEND_CLASS = require('./EXTEND_CLASS_FILE_NAME');
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

View File

@ -20,11 +20,11 @@
options.maxDepth = options.callDepth;
super(options);
//GENERATED_TEMPLATE_OPTIONS_INIT_START
//GENERATED_TEMPLATE_OPTIONS_INIT_END
super(options);
//GENERATED_OPTIONS_INIT_START
//GENERATED_OPTIONS_INIT_END

View File

@ -36,8 +36,6 @@ GENERATED_ON_TOUCH_START_METHOD_AFTER
GENERATED_OPTIONS_INIT
GENERATED_OUT_OF_CLASS_IMPLEMENTATION
GENERATED_REQUIRED_COMPONENTS
GENERATED_SET_INITIALIZED_METHOD
GENERATED_SET_INITIALIZED_METHOD_AFTER
GENERATED_SET_RUNTIME_METHOD
GENERATED_SET_RUNTIME_METHOD_AFTER
GENERATED_SOURCE
@ -128,7 +126,6 @@ CUSTOM_OPTIONS
CUSTOM_OPTIONS_INIT
CUSTOM_OUT_OF_CLASS_IMPLEMENTATION
CUSTOM_REQUIRED_COMPONENTS
CUSTOM_SET_INITIALIZED_METHOD
CUSTOM_SET_RUNTIME_METHOD
CUSTOM_START_METHOD
CUSTOM_STATIC_ACTIVATE_INSTANCES_METHOD

View File

@ -67,18 +67,31 @@ describe('R3 Tests', () => {
//GENERATED_COMPONENT_CREATE_START
const componentCode = new ComponentCode();
assert.isTrue(componentCode.initialized);
const componentDOM = new ComponentDOM();
assert.isTrue(componentDOM.initialized);
const componentCanvas = new ComponentCanvas();
assert.isTrue(componentCanvas.initialized);
const componentGeometry = new ComponentGeometry();
assert.isTrue(componentGeometry.initialized);
const componentBufferGeometry = new ComponentBufferGeometry();
assert.isTrue(componentBufferGeometry.initialized);
const componentPlaneGeometry = new ComponentPlaneGeometry();
assert.isTrue(componentPlaneGeometry.initialized);
const componentGraphics = new ComponentGraphics();
assert.isTrue(componentGraphics.initialized);
const componentImage = new ComponentImage();
assert.isTrue(componentImage.initialized);
const componentInput = new ComponentInput();
assert.isTrue(componentInput.initialized);
const componentTouch = new ComponentTouch();
assert.isTrue(componentTouch.initialized);
const componentMaterial = new ComponentMaterial();
assert.isTrue(componentMaterial.initialized);
const componentMesh = new ComponentMesh();
assert.isTrue(componentMesh.initialized);
const componentTexture = new ComponentTexture();
assert.isTrue(componentTexture.initialized);
//GENERATED_COMPONENT_CREATE_END
}
@ -90,6 +103,7 @@ describe('R3 Tests', () => {
//GENERATED_ENTITY_CREATE_START
const entitySlider = new EntitySlider();
assert.isTrue(entitySlider.initialized);
//GENERATED_ENTITY_CREATE_END
}
@ -136,7 +150,11 @@ describe('R3 Tests', () => {
'Linking system sets parent / child relationships correctly',
() => {
const slider1 = new EntitySlider();
const slider1 = new EntitySlider(
{
name : 'slider1'
}
);
const canvas = new ComponentCanvas();
const touch = new ComponentTouch();
@ -164,6 +182,7 @@ describe('R3 Tests', () => {
const slider2 = new EntitySlider(
{
name : 'slider2',
canvas : canvas,
images : [image1, image2]
}
@ -180,6 +199,7 @@ describe('R3 Tests', () => {
try {
const slider3 = new EntitySlider(
{
name: 'badSlider3',
canvas: canvas,
images: null
}
@ -188,7 +208,12 @@ describe('R3 Tests', () => {
assert.isTrue(err instanceof TypeError);
}
const slider3 = new EntitySlider({canvas});
const slider3 = new EntitySlider(
{
name : 'slider3',
canvas
}
);
slider3.images = [image1, image2, image3];
assert.deepEqual(image1.parents, [slider1, slider2, slider3]);
@ -198,9 +223,45 @@ describe('R3 Tests', () => {
//test normal re-assignment
slider3.images = [image1, image3];
assert.deepEqual(image1.parents, [slider1, slider2, slider3]);
assert.deepEqual(image2.parents, [slider2]);
assert.deepEqual(slider3.children, [canvas, image1, image3]);
assert.deepEqual(slider3.components, [canvas, image1, image3]);
//test via splice
slider3.images = [];//splice(0,2);
assert.deepEqual(image1.parents, [slider1, slider2]);
assert.deepEqual(image2.parents, [slider2]);
assert.deepEqual(image3.parents, []);
assert.deepEqual(slider3.children, [canvas]);
assert.deepEqual(slider3.components, [canvas]);
slider3.canvas = null;
assert.deepEqual(canvas.parents, [slider1, slider2]);
assert.deepEqual(slider3.children, []);
assert.deepEqual(slider3.components, []);
try {
const slider4 = new EntitySlider(
{
canvas,
images: [{}]
}
);
} catch (err) {
assert.isTrue(err instanceof TypeError);
}
assert.deepEqual(canvas.parents, [slider1, slider2]);
try {
const slider5 = new EntitySlider(
{
canvas : image1
}
);
} catch (err) {
assert.isTrue(err instanceof TypeError);
}
}
);

View File

@ -1 +1 @@
3.0.245
3.0.255