For Trevor
parent
dfbcfd7bf4
commit
39ab3cb56d
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Test",
|
||||
"program": "${workspaceFolder}\\tests\\pingpong\\index.js"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,83 +1,48 @@
|
|||
const {Signale} = require('signale');
|
||||
const log = new Signale({
|
||||
scope: 'COLLEXION'
|
||||
scope: 'CORE'
|
||||
});
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const uuid = require('uuid');
|
||||
const root = (typeof window === 'undefined' ? global : window)
|
||||
const {Entity} = require('./entity.js')
|
||||
|
||||
class Link {
|
||||
constructor(symbol) {
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return "" + this.symbol;
|
||||
}
|
||||
}
|
||||
|
||||
class Collexion {
|
||||
constructor() {
|
||||
// this.cache = cache;
|
||||
constructor(template) {
|
||||
this.entities = {};
|
||||
// for(const uuid of cache.getInstances()) {
|
||||
// this.loadEntity(uuid)
|
||||
// }
|
||||
}
|
||||
|
||||
createInstances(template) {
|
||||
(async () => {
|
||||
const instances = {};
|
||||
|
||||
log.info('Starting Collexion with ' + Object.keys(template) + ' Objects')
|
||||
|
||||
// call constructors on objects, and give them their data
|
||||
for(const symbol in template) {
|
||||
const instTemplate = template[symbol];
|
||||
const _class = instTemplate.Code;
|
||||
const inst = new _class(this);
|
||||
inst._data = instTemplate.Data;
|
||||
// guarantee at least an object in _data
|
||||
inst._data = {...instTemplate.Data};
|
||||
instances[symbol] = inst;
|
||||
}
|
||||
|
||||
//call start in each instance.
|
||||
for(const symbol in instances) {
|
||||
const inst = instances[symbol];
|
||||
inst.start()
|
||||
if('start' in inst)
|
||||
await inst.start()
|
||||
}
|
||||
|
||||
for(const symbol in instances) {
|
||||
const inst = instances[symbol];
|
||||
const instTemplate = template[symbol];
|
||||
inst._links = instTemplate.Links;
|
||||
|
||||
for (const linkKey in inst._links) {
|
||||
const link = inst._links[linkKey];
|
||||
inst._links[linkKey] = instances[link];
|
||||
for(const symbol in instances) {
|
||||
inst[symbol] = instances[symbol];
|
||||
}
|
||||
}
|
||||
|
||||
for(const symbol in instances) {
|
||||
const inst = instances[symbol];
|
||||
inst.connected()
|
||||
if('connected' in inst)
|
||||
await inst.connected()
|
||||
}
|
||||
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
loadEntity(uuid) {
|
||||
// log.debug(`spinning up ${uuid}`);
|
||||
log.debug(uuid)
|
||||
if(typeof require === 'function') {
|
||||
let codePath = this.cache.getEntityCodePathFromUuid(uuid);
|
||||
// log.debug(codePath)
|
||||
let data = this.cache.getDataFromUuid(uuid);
|
||||
let instanceData = this.cache.getInstanceFromUuid(uuid);
|
||||
let userCode = require(codePath).entity;
|
||||
this.entities[uuid] = new Entity(userCode, instanceData, this);
|
||||
this.entities[uuid].start();
|
||||
log.debug('starting', uuid)
|
||||
} else {
|
||||
//TODO COMPLICATED EVAL SHIT, MIRRORING REQUIRE FUNCTIONALITY
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
module.exports = {Collexion, Link};
|
||||
module.exports = {Collexion, Link, Component};
|
||||
|
|
@ -21,7 +21,6 @@
|
|||
},
|
||||
"homepage": "https://github.com/marcus13345/AquaTin#readme",
|
||||
"dependencies": {
|
||||
"aquatin": "file:.",
|
||||
"rimraf": "^2.6.3",
|
||||
"signale": "^1.4.0",
|
||||
"typescript": "^3.5.3",
|
||||
|
|
|
|||
|
|
@ -2,27 +2,21 @@ const {Collexion, Link, LinkArray} = require('./../../core/Collexion.js');
|
|||
const PingPong = require('./pingpong.js')
|
||||
|
||||
;(async () => {
|
||||
const collexion = new Collexion({});
|
||||
collexion.createInstances({
|
||||
'A': {
|
||||
const collexion = new Collexion({
|
||||
A: {
|
||||
Code: PingPong,
|
||||
Data: {
|
||||
boop: true
|
||||
},
|
||||
Links: {
|
||||
thing: new Link('B')
|
||||
start: true,
|
||||
boop: 'B'
|
||||
}
|
||||
},
|
||||
'B': {
|
||||
B: {
|
||||
Code: PingPong,
|
||||
Data: {
|
||||
|
||||
},
|
||||
Links: {
|
||||
thing: new Link('B')
|
||||
boop: 'A'
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ const log = new Signale({
|
|||
|
||||
module.exports = class module {
|
||||
async start() {
|
||||
console.log(this._data)
|
||||
// console.log(this._data)
|
||||
}
|
||||
|
||||
connected() {
|
||||
|
|
@ -16,7 +16,7 @@ module.exports = class module {
|
|||
async boop() {
|
||||
log.info(`Boop!`)
|
||||
await new Promise(res => setTimeout(res, 1000));
|
||||
this._links.thing.boop();
|
||||
this[this.boop].boop();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue