index generation for components and system

master
Theunis J. Botha 2021-07-03 16:11:19 +02:00
parent 40c9c55009
commit ad211bb5b5
11 changed files with 110 additions and 420 deletions

View File

@ -1,6 +1,15 @@
//GENERATE_IMPORTS_START
const R3 = require('./r3-r3.js');
const System = require('./r3-system/r3-system.js');
const Event = require('./r3-event.js');
const Utils = require('./r3-utils.js');
//GENERATE_IMPORTS_END
R3.System.Linking.start();
R3.System.Socket.start();
module.exports = R3;
module.exports = {
//GENERATE_EXPORTS_START
R3,
System,
Event,
Utils
//GENERATE_EXPORTS_END
}

View File

@ -0,0 +1,11 @@
//GENERATE_IMPORTS_START
const Component = require('./r3-component.js');
const Image = require('./r3-image.js');
//GENERATE_IMPORTS_END
module.exports = {
//GENERATE_EXPORTS_START
Component,
Image
//GENERATE_EXPORTS_END
}

View File

@ -46,28 +46,7 @@ const R3Object = require('.././r3-r3-object.js');
Methods:
- createInstance()
Creates an instance of this object based on the runtime.
- updateInstance(property)
Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object
property(ies)
- updateFromInstance(property)
Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the
value of the instance property(ies)
- dispose()
Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's
instance, because an object instance should not exist without an object parent (except maybe for particles)
- disposeInstance()
This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event
will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to
dispose the object parent this instance.
- toApiObject()
Transforms the current object into JSON ready to be stored to the back-end.
<no inherited methods>
Static Methods:

View File

@ -46,28 +46,7 @@ const Component = require('.././r3-component.js');
Methods:
- createInstance()
Creates an instance of this object based on the runtime.
- updateInstance(property)
Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object
property(ies)
- updateFromInstance(property)
Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the
value of the instance property(ies)
- dispose()
Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's
instance, because an object instance should not exist without an object parent (except maybe for particles)
- disposeInstance()
This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event
will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to
dispose the object parent this instance.
- toApiObject()
Transforms the current object into JSON ready to be stored to the back-end.
<no inherited methods>
Static Methods:

View File

@ -46,28 +46,7 @@ const R3Object = require('./r3-r3-object.js');
Methods:
- createInstance()
Creates an instance of this object based on the runtime.
- updateInstance(property)
Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object
property(ies)
- updateFromInstance(property)
Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the
value of the instance property(ies)
- dispose()
Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's
instance, because an object instance should not exist without an object parent (except maybe for particles)
- disposeInstance()
This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event
will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to
dispose the object parent this instance.
- toApiObject()
Transforms the current object into JSON ready to be stored to the back-end.
<no inherited methods>
Static Methods:
@ -81,28 +60,7 @@ const R3Object = require('./r3-r3-object.js');
Methods:
- createInstance()
Creates an instance of this object based on the runtime.
- updateInstance(property)
Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object
property(ies)
- updateFromInstance(property)
Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the
value of the instance property(ies)
- dispose()
Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's
instance, because an object instance should not exist without an object parent (except maybe for particles)
- disposeInstance()
This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event
will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to
dispose the object parent this instance.
- toApiObject()
Transforms the current object into JSON ready to be stored to the back-end.
<no methods>
Static Methods:
@ -125,12 +83,6 @@ const R3Object = require('./r3-r3-object.js');
CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS_END
CUSTOM_METHODS_START
createInstance() - Creates an instance of this object based on the runtime.
updateInstance(property) - Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object property(ies)
updateFromInstance(property) - Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the value of the instance property(ies)
dispose() - Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's instance, because an object instance should not exist without an object parent (except maybe for particles)
disposeInstance() - This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to dispose the object parent this instance.
toApiObject() - Transforms the current object into JSON ready to be stored to the back-end. @returns JSON
CUSTOM_METHODS_END
CUSTOM_STATIC_METHODS_START
@ -170,132 +122,6 @@ class Project extends R3Object {
//GENERATE_CONSTRUCTOR_EXTENDS_END
//GENERATE_METHODS_START
/**
* createInstance()
* - Creates an instance of this object based on the runtime.
*/
createInstance() {
//GENERATE_CREATE_INSTANCE_METHOD_START
this.emit(Event.CREATE_INSTANCE_BEFORE, this);
this[this.runtime].createInstance(
this,
{
//GENERATE_CREATE_INSTANCE_OPTIONS_START
//GENERATE_CREATE_INSTANCE_OPTIONS_END
}
)
this.emit(Event.INSTANCE_CREATED, this);
//GENERATE_CREATE_INSTANCE_METHOD_END
//CUSTOM_CREATE_INSTANCE_METHOD_START
//CUSTOM_CREATE_INSTANCE_METHOD_END
}
/**
* updateInstance()
* - Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object
* property(ies)
* @param property
*/
updateInstance(property) {
//GENERATE_UPDATE_INSTANCE_METHOD_START
this.emit(Event.UPDATE_INSTANCE_BEFORE, this);
//GENERATE_UPDATE_INSTANCE_OPTIONS_START
//GENERATE_UPDATE_INSTANCE_OPTIONS_END
this.emit(Event.UPDATE_INSTANCE_AFTER, this);
//GENERATE_UPDATE_INSTANCE_METHOD_END
//CUSTOM_UPDATE_INSTANCE_METHOD_START
//CUSTOM_UPDATE_INSTANCE_METHOD_END
}
/**
* updateFromInstance()
* - Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the
* value of the instance property(ies)
* @param property
*/
updateFromInstance(property) {
//GENERATE_UPDATE_FROM_INSTANCE_METHOD_START
this.emit(Event.UPDATE_FROM_INSTANCE_BEFORE, this);
//GENERATE_UPDATE_FROM_INSTANCE_OPTIONS_START
//GENERATE_UPDATE_FROM_INSTANCE_OPTIONS_END
this.emit(Event.UPDATE_FROM_INSTANCE_AFTER, this);
//GENERATE_UPDATE_FROM_INSTANCE_METHOD_END
//CUSTOM_UPDATE_FROM_INSTANCE_METHOD_START
//CUSTOM_UPDATE_FROM_INSTANCE_METHOD_END
}
/**
* dispose()
* - Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's
* instance, because an object instance should not exist without an object parent (except maybe for particles)
*/
dispose() {
//GENERATE_DISPOSE_METHOD_START
this.subscribe(
Event.INSTANCE_DISPOSED,
function(object) {
if (object === this) {
this.emit(Event.DISPOSE_OBJECT, this);
}
}
);
this.disposeInstance();
//GENERATE_DISPOSE_METHOD_END
//CUSTOM_DISPOSE_METHOD_START
//CUSTOM_DISPOSE_METHOD_END
}
/**
* disposeInstance()
* - This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event
* will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to
* dispose the object parent this instance.
*/
disposeInstance() {
//GENERATE_DISPOSE_INSTANCE_METHOD_START
console.log('Disposing instance of ' + this.name);
this.emit(Event.DISPOSE_INSTANCE, this);
//GENERATE_DISPOSE_INSTANCE_METHOD_END
//CUSTOM_DISPOSE_INSTANCE_METHOD_START
//CUSTOM_DISPOSE_INSTANCE_METHOD_END
}
/**
* toApiObject()
* - Transforms the current object into JSON ready to be stored to the back-end. \n * @returns JSON
*/
toApiObject() {
//GENERATE_TO_API_OBJECT_METHOD_START
//GENERATE_TO_API_OBJECT_METHOD_END
//CUSTOM_TO_API_OBJECT_METHOD_START
//CUSTOM_TO_API_OBJECT_METHOD_END
}
//GENERATE_METHODS_END
//GENERATE_STATIC_METHODS_START

View File

@ -45,28 +45,7 @@ const Event = require('./r3-event.js');
Methods:
- createInstance()
Creates an instance of this object based on the runtime.
- updateInstance(property)
Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object
property(ies)
- updateFromInstance(property)
Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the
value of the instance property(ies)
- dispose()
Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's
instance, because an object instance should not exist without an object parent (except maybe for particles)
- disposeInstance()
This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event
will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to
dispose the object parent this instance.
- toApiObject()
Transforms the current object into JSON ready to be stored to the back-end.
<no methods>
Static Methods:
@ -90,12 +69,6 @@ const Event = require('./r3-event.js');
CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS_END
CUSTOM_METHODS_START
createInstance() - Creates an instance of this object based on the runtime.
updateInstance(property) - Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object property(ies)
updateFromInstance(property) - Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the value of the instance property(ies)
dispose() - Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's instance, because an object instance should not exist without an object parent (except maybe for particles)
disposeInstance() - This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to dispose the object parent this instance.
toApiObject() - Transforms the current object into JSON ready to be stored to the back-end. @returns JSON
CUSTOM_METHODS_END
CUSTOM_STATIC_METHODS_START
@ -141,147 +114,6 @@ class R3Object extends Event {
//GENERATE_CONSTRUCTOR_EXTENDS_END
//GENERATE_METHODS_START
/**
* createInstance()
* - Creates an instance of this object based on the runtime.
*/
createInstance() {
//GENERATE_CREATE_INSTANCE_METHOD_START
this.emit(Event.CREATE_INSTANCE_BEFORE, this);
this[this.runtime].createInstance(
this,
{
//GENERATE_CREATE_INSTANCE_OPTIONS_START
'register': this.register
//GENERATE_CREATE_INSTANCE_OPTIONS_END
}
)
this.emit(Event.INSTANCE_CREATED, this);
//GENERATE_CREATE_INSTANCE_METHOD_END
//CUSTOM_CREATE_INSTANCE_METHOD_START
//CUSTOM_CREATE_INSTANCE_METHOD_END
}
/**
* updateInstance()
* - Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object
* property(ies)
* @param property
*/
updateInstance(property) {
//GENERATE_UPDATE_INSTANCE_METHOD_START
this.emit(Event.UPDATE_INSTANCE_BEFORE, this);
//GENERATE_UPDATE_INSTANCE_OPTIONS_START
if (property === 'register') {
this.instance.register = this.register;
if (property !== 'all') {
this.emit(Event.UPDATE_INSTANCE_AFTER, this);
return;
}
}
//GENERATE_UPDATE_INSTANCE_OPTIONS_END
this.emit(Event.UPDATE_INSTANCE_AFTER, this);
//GENERATE_UPDATE_INSTANCE_METHOD_END
//CUSTOM_UPDATE_INSTANCE_METHOD_START
//CUSTOM_UPDATE_INSTANCE_METHOD_END
}
/**
* updateFromInstance()
* - Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the
* value of the instance property(ies)
* @param property
*/
updateFromInstance(property) {
//GENERATE_UPDATE_FROM_INSTANCE_METHOD_START
this.emit(Event.UPDATE_FROM_INSTANCE_BEFORE, this);
//GENERATE_UPDATE_FROM_INSTANCE_OPTIONS_START
if (property === 'register' || property === 'all') {
this.register = this.instance.register;
if (property !== 'all') {
this.emit(Event.UPDATE_FROM_INSTANCE_AFTER, this);
return;
}
}
//GENERATE_UPDATE_FROM_INSTANCE_OPTIONS_END
this.emit(Event.UPDATE_FROM_INSTANCE_AFTER, this);
//GENERATE_UPDATE_FROM_INSTANCE_METHOD_END
//CUSTOM_UPDATE_FROM_INSTANCE_METHOD_START
//CUSTOM_UPDATE_FROM_INSTANCE_METHOD_END
}
/**
* dispose()
* - Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's
* instance, because an object instance should not exist without an object parent (except maybe for particles)
*/
dispose() {
//GENERATE_DISPOSE_METHOD_START
this.subscribe(
Event.INSTANCE_DISPOSED,
function(object) {
if (object === this) {
this.emit(Event.DISPOSE_OBJECT, this);
}
}
);
this.disposeInstance();
//GENERATE_DISPOSE_METHOD_END
//CUSTOM_DISPOSE_METHOD_START
//CUSTOM_DISPOSE_METHOD_END
}
/**
* disposeInstance()
* - This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event
* will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to
* dispose the object parent this instance.
*/
disposeInstance() {
//GENERATE_DISPOSE_INSTANCE_METHOD_START
console.log('Disposing instance of ' + this.name);
this.emit(Event.DISPOSE_INSTANCE, this);
//GENERATE_DISPOSE_INSTANCE_METHOD_END
//CUSTOM_DISPOSE_INSTANCE_METHOD_START
//CUSTOM_DISPOSE_INSTANCE_METHOD_END
}
/**
* toApiObject()
* - Transforms the current object into JSON ready to be stored to the back-end. \n * @returns JSON
*/
toApiObject() {
//GENERATE_TO_API_OBJECT_METHOD_START
//GENERATE_TO_API_OBJECT_METHOD_END
//CUSTOM_TO_API_OBJECT_METHOD_START
//CUSTOM_TO_API_OBJECT_METHOD_END
}
//GENERATE_METHODS_END
//GENERATE_STATIC_METHODS_START

View File

@ -1,9 +1,15 @@
//GENERATE_IMPORTS_START
const System = require('./r3-system.js');
const SystemLinking = require('./r3-system-linking.js');
const SystemSocket = require('./r3-system-socket.js');
const SystemTest = require('./r3-system-test.js');
//GENERATE_IMPORTS_END
module.exports = {
//GENERATE_EXPORTS_START
System,
SystemLinking,
SystemSocket
SystemSocket,
SystemTest
//GENERATE_EXPORTS_END
}

View File

@ -23,12 +23,6 @@ const EXTEND_CLASS = require('INCLUDE_PATH/EXTEND_CLASS_FILE_NAME');
CUSTOM_EXCLUDED_FROM_INSTANCE_OPTIONS_END
CUSTOM_METHODS_START
createInstance() - Creates an instance of this object based on the runtime.
updateInstance(property) - Updates the instance property, ex. 'x', or specify 'all' to update all properties based on the current object property(ies)
updateFromInstance(property) - Updates the object property, ex. 'x', or specify 'all' to update all properties of this object based on the value of the instance property(ies)
dispose() - Sends out a notification that this object wants to be deleted. It will first send out a message to delete it's instance, because an object instance should not exist without an object parent (except maybe for particles)
disposeInstance() - This will signal all systems that an instance wants to be deleted. Once it has been deleted, another event will be triggered to notify listeners of the deletion of this instance. This can give 'dispose()' a chance to dispose the object parent this instance.
toApiObject() - Transforms the current object into JSON ready to be stored to the back-end. @returns JSON
CUSTOM_METHODS_END
CUSTOM_STATIC_METHODS_START

View File

@ -0,0 +1,7 @@
//GENERATE_IMPORTS_START
//GENERATE_IMPORTS_END
module.exports = {
//GENERATE_EXPORTS_START
//GENERATE_EXPORTS_END
}

View File

@ -1,49 +1,37 @@
GENERATE_ASYNC_METHOD
GENERATE_CONSTRUCTOR
GENERATE_CONSTRUCTOR_EXTENDS
GENERATE_CREATE_INSTANCE
GENERATE_CREATE_INSTANCE_AFTER
GENERATE_CREATE_INSTANCE_BEFORE
GENERATE_CREATE_INSTANCE_METHOD
GENERATE_CREATE_INSTANCE_OPTIONS
GENERATE_DISPOSE
GENERATE_DISPOSE_AFTER
GENERATE_DISPOSE_BEFORE
GENERATE_DISPOSE_INSTANCE
GENERATE_DISPOSE_INSTANCE_AFTER
GENERATE_DISPOSE_INSTANCE_BEFORE
GENERATE_DISPOSE_INSTANCE_METHOD
GENERATE_DISPOSE_METHOD
GENERATE_EMIT_METHOD
GENERATE_EVENT_LISTENERS
GENERATE_EXPORTS
GENERATE_IMPORTS
GENERATE_INHERITED
GENERATE_METHOD_NAME_UPPERCASE_METHOD
GENERATE_METHODS
GENERATE_OPTIONS_INIT
GENERATE_START_METHOD
GENERATE_STATIC_ASYNC_METHOD
GENERATE_STATIC_EMIT_METHOD
GENERATE_STATIC_METHOD_NAME_UPPERCASE_METHOD
GENERATE_STATIC_METHODS
GENERATE_STATIC_START_METHOD
GENERATE_STATIC_STOP_METHOD
GENERATE_STATIC_SUBSCRIBE_METHOD
GENERATE_STOP_METHOD
GENERATE_SUBSCRIBE_METHOD
GENERATE_TO_API_OBJECT_METHOD
GENERATE_UPDATE_FROM_INSTANCE
GENERATE_UPDATE_FROM_INSTANCE_AFTER
GENERATE_UPDATE_FROM_INSTANCE_BEFORE
GENERATE_UPDATE_FROM_INSTANCE_METHOD
GENERATE_UPDATE_FROM_INSTANCE_OPTIONS
GENERATE_UPDATE_INSTANCE
GENERATE_UPDATE_INSTANCE_AFTER
GENERATE_UPDATE_INSTANCE_BEFORE
GENERATE_UPDATE_INSTANCE_METHOD
GENERATE_UPDATE_INSTANCE_OPTIONS
CUSTOM_AFTER_INIT
CUSTOM_ASYNC_METHOD
CUSTOM_BEFORE_INIT
CUSTOM_CREATE_INSTANCE
CUSTOM_CREATE_INSTANCE_METHOD
CUSTOM_DISPOSE
CUSTOM_DISPOSE_INSTANCE
CUSTOM_DISPOSE_INSTANCE_METHOD
CUSTOM_DISPOSE_METHOD
CUSTOM_EMIT_METHOD
@ -68,7 +56,5 @@ CUSTOM_STATIC_SUBSCRIBE_METHOD
CUSTOM_STOP_METHOD
CUSTOM_SUBSCRIBE_METHOD
CUSTOM_TO_API_OBJECT_METHOD
CUSTOM_UPDATE_FROM_INSTANCE
CUSTOM_UPDATE_FROM_INSTANCE_METHOD
CUSTOM_UPDATE_INSTANCE
CUSTOM_UPDATE_INSTANCE_METHOD

View File

@ -881,6 +881,59 @@ foreach ($files as $file) {
}
}
function generateIndex($types)
{
/**
* Graph $graph
*/
global $graph;
foreach ($types as $type) {
$systemNode = $graph->search('name', $type);
$template = file_get_contents('src/templates/index.template');
$imports = [];
$exports = [];
$nodes = array_merge([$systemNode], $systemNode->children);
foreach ($nodes as $child) {
if ($type === 'System') {
$file = str_replace('src/r3/r3-system', '.', $child->file);
}
if ($type === 'Component') {
$file = str_replace('src/r3/r3-component', '.', $child->file);
}
if ($type === 'R3') {
$file = str_replace('src/r3', '.', $child->file);
}
array_push($imports, "const " . $child->name . ' = require(\'' . $file . "');");
array_push($exports, $child->name);
}
$indexFile = 'src/r3/index.js';
if ($type === 'System') {
$indexFile = 'src/r3/r3-system/index.js';
}
if ($type === 'Component') {
$indexFile = 'src/r3/r3-component/index.js';
}
file_put_contents($indexFile, $template);
updateSection($indexFile, 'GENERATE_IMPORTS', implode("\n", $imports));
updateSection($indexFile, 'GENERATE_EXPORTS', " " . implode(",\n ", $exports));
}
}
if ($argv[2] == 'build-graph') {
global $nodeList;
@ -905,6 +958,14 @@ if ($argv[2] == 'build-graph') {
}
generateIndex(
[
'System',
'Component',
'R3'
]
);
foreach ($files as $file) {
$saveFile = $file . '.saved';