For Trevor

master
Marcus 2019-10-17 14:50:16 -04:00
parent dfbcfd7bf4
commit 39ab3cb56d
5 changed files with 59 additions and 87 deletions

14
.vscode/launch.json vendored 100644
View File

@ -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"
}
]
}

View File

@ -1,83 +1,48 @@
const {Signale} = require('signale'); const {Signale} = require('signale');
const log = new 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 { class Collexion {
constructor() { constructor(template) {
// this.cache = cache;
this.entities = {}; this.entities = {};
// for(const uuid of cache.getInstances()) { (async () => {
// this.loadEntity(uuid) const instances = {};
// }
} log.info('Starting Collexion with ' + Object.keys(template) + ' Objects')
createInstances(template) { // call constructors on objects, and give them their data
const instances = {}; for(const symbol in template) {
const instTemplate = template[symbol];
for(const symbol in template) { const _class = instTemplate.Code;
const instTemplate = template[symbol]; const inst = new _class(this);
const _class = instTemplate.Code; // guarantee at least an object in _data
const inst = new _class(this); inst._data = {...instTemplate.Data};
inst._data = instTemplate.Data; instances[symbol] = inst;
instances[symbol] = inst;
}
for(const symbol in instances) {
const inst = instances[symbol];
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) { //call start in each instance.
const inst = instances[symbol]; for(const symbol in instances) {
inst.connected() const inst = instances[symbol];
} if('start' in inst)
await inst.start()
}
for(const symbol in instances) {
const inst = instances[symbol];
for(const symbol in instances) {
inst[symbol] = instances[symbol];
}
}
for(const symbol in instances) {
const inst = instances[symbol];
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};

View File

@ -21,7 +21,6 @@
}, },
"homepage": "https://github.com/marcus13345/AquaTin#readme", "homepage": "https://github.com/marcus13345/AquaTin#readme",
"dependencies": { "dependencies": {
"aquatin": "file:.",
"rimraf": "^2.6.3", "rimraf": "^2.6.3",
"signale": "^1.4.0", "signale": "^1.4.0",
"typescript": "^3.5.3", "typescript": "^3.5.3",

View File

@ -2,27 +2,21 @@ const {Collexion, Link, LinkArray} = require('./../../core/Collexion.js');
const PingPong = require('./pingpong.js') const PingPong = require('./pingpong.js')
;(async () => { ;(async () => {
const collexion = new Collexion({}); const collexion = new Collexion({
collexion.createInstances({ A: {
'A': {
Code: PingPong, Code: PingPong,
Data: { Data: {
boop: true start: true,
}, boop: 'B'
Links: {
thing: new Link('B')
} }
}, },
'B': { B: {
Code: PingPong, Code: PingPong,
Data: { Data: {
boop: 'A'
},
Links: {
thing: new Link('B')
} }
} }
}) });
})(); })();

View File

@ -5,7 +5,7 @@ const log = new Signale({
module.exports = class module { module.exports = class module {
async start() { async start() {
console.log(this._data) // console.log(this._data)
} }
connected() { connected() {
@ -16,7 +16,7 @@ module.exports = class module {
async boop() { async boop() {
log.info(`Boop!`) log.info(`Boop!`)
await new Promise(res => setTimeout(res, 1000)); await new Promise(res => setTimeout(res, 1000));
this._links.thing.boop(); this[this.boop].boop();
} }
} }