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 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)
// }
}
(async () => {
const instances = {};
createInstances(template) {
const instances = {};
log.info('Starting Collexion with ' + Object.keys(template) + ' Objects')
for(const symbol in template) {
const instTemplate = template[symbol];
const _class = instTemplate.Code;
const inst = new _class(this);
inst._data = instTemplate.Data;
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];
// 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);
// guarantee at least an object in _data
inst._data = {...instTemplate.Data};
instances[symbol] = inst;
}
}
for(const symbol in instances) {
const inst = instances[symbol];
inst.connected()
}
//call start in each instance.
for(const symbol in instances) {
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",
"dependencies": {
"aquatin": "file:.",
"rimraf": "^2.6.3",
"signale": "^1.4.0",
"typescript": "^3.5.3",

View File

@ -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'
}
}
})
});
})();

View File

@ -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();
}
}