set / unset parents of components of entities

master
Theunis J. Botha 2021-09-23 20:17:53 +02:00
parent b0626d53fe
commit 548784393a
8 changed files with 141 additions and 6 deletions

1
dist/index.html vendored
View File

@ -40,6 +40,7 @@
slider.images = [image];
slider.canvas = null;
slider.canvas = canvas;
slider.images = [];
});
</script>
</body>

70
dist/r3.js vendored
View File

@ -1,6 +1,6 @@
class R3 {
static version = '3.0.67';
static compileDate = '2021 Sep 23 - 14:00:26 pm';
static version = '3.0.68';
static compileDate = '2021 Sep 23 - 20:16:29 pm';
}
class Runtime {
@ -1505,6 +1505,52 @@ class SystemLinking extends System {
console.log('Entity object update of property ' + object.property);
/**
* Set the parent relationships
*/
if (object.value instanceof Array) {
/**
* This entity could have its property set to an empty array.
* In this case - we should check its existing components and have their relationships
* severed
*/
if (object.value.length === 0) {
if (object.entity[object.property] instanceof Array) {
for (let i = 0; i < object.entity[object.property].length; i++) {
if (object.entity[object.property][i] instanceof R3.Component) {
object.entity.dirty = true;
object.entity[object.property][i].parent = null;
}
}
}
} else {
for (let i = 0; i < object.value.length; i++) {
if (object.value[i] instanceof R3.Component) {
object.value[i].parent = object.entity;
}
}
}
}
if (object.value instanceof R3.Component) {
object.value.parent = object.entity;
}
/**
* The value was unassigned - remove the parent relationships of the existing
* components (if available)
*/
if (object.value === null || typeof object.value === 'undefined') {
if (object.entity[object.property] instanceof R3.Component) {
object.entity.dirty = true;
object.entity[object.property].parent = null;
}
}
if (!object.entity.underConstruction) {
if (object.entity.initialized) {
@ -1530,6 +1576,18 @@ class SystemLinking extends System {
static OnEntityPropertyUpdated(object) {
if (!object.entity.underConstruction) {
/**
* At this point - the object entity would have been brought to a stop
* if it had been transitioned into an uninitialized state by setting one of
* its required properties.
* We can safely clear the dirty state
*/
if (object.entity.dirty) {
object.entity.dirty = false;
}
object.entity.initializeDepth = 0;
object.entity.initialize();
}
@ -2953,6 +3011,14 @@ class EntitySlider extends Entity {
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);

View File

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

View File

@ -113,6 +113,7 @@ const Entity = require('.././r3-entity.js');
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.
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
@ -219,6 +220,14 @@ class EntitySlider extends Entity {
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);

View File

@ -1,6 +1,6 @@
class R3 {
static version = '3.0.67';
static compileDate = '2021 Sep 23 - 14:00:26 pm';
static version = '3.0.68';
static compileDate = '2021 Sep 23 - 20:16:29 pm';
}
//GENERATED_IMPORTS_START

View File

@ -368,6 +368,52 @@ class SystemLinking extends System {
//CUSTOM_STATIC_ON_ENTITY_PROPERTY_UPDATE_METHOD_START
console.log('Entity object update of property ' + object.property);
/**
* Set the parent relationships
*/
if (object.value instanceof Array) {
/**
* This entity could have its property set to an empty array.
* In this case - we should check its existing components and have their relationships
* severed
*/
if (object.value.length === 0) {
if (object.entity[object.property] instanceof Array) {
for (let i = 0; i < object.entity[object.property].length; i++) {
if (object.entity[object.property][i] instanceof R3.Component) {
object.entity.dirty = true;
object.entity[object.property][i].parent = null;
}
}
}
} else {
for (let i = 0; i < object.value.length; i++) {
if (object.value[i] instanceof R3.Component) {
object.value[i].parent = object.entity;
}
}
}
}
if (object.value instanceof R3.Component) {
object.value.parent = object.entity;
}
/**
* The value was unassigned - remove the parent relationships of the existing
* components (if available)
*/
if (object.value === null || typeof object.value === 'undefined') {
if (object.entity[object.property] instanceof R3.Component) {
object.entity.dirty = true;
object.entity[object.property].parent = null;
}
}
if (!object.entity.underConstruction) {
if (object.entity.initialized) {
@ -399,6 +445,18 @@ class SystemLinking extends System {
//CUSTOM_STATIC_ON_ENTITY_PROPERTY_UPDATED_METHOD_START
if (!object.entity.underConstruction) {
/**
* At this point - the object entity would have been brought to a stop
* if it had been transitioned into an uninitialized state by setting one of
* its required properties.
* We can safely clear the dirty state
*/
if (object.entity.dirty) {
object.entity.dirty = false;
}
object.entity.initializeDepth = 0;
object.entity.initialize();
}

View File

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

View File

@ -1 +1 @@
3.0.67
3.0.68