refactor: mixin

This commit is contained in:
cha0s 2024-01-19 03:59:28 -06:00
parent e6c8a63a04
commit 344ec9179d
3 changed files with 64 additions and 64 deletions

View File

@ -3,8 +3,19 @@ import {Flecks} from '@flecks/core';
import Receiver from './receiver';
export const hooks = {
'@flecks/core.mixin': (Flecks) => (
class FlecksWithHumusAppClient extends Flecks {
'@flecks/web/client.up': Flecks.priority(
(flecks) => {
window.flecks = flecks;
const Synchronizer = Receiver(flecks);
const synchronizer = new Synchronizer();
flecks.humus.app.synchronizer = synchronizer;
synchronizer.listenTo(flecks.socket.client);
},
{after: '@flecks/socket/client'},
),
};
export const mixin = (Flecks) => class FlecksWithHumusAppClient extends Flecks {
constructor(...args) {
super(...args);
@ -19,16 +30,4 @@ export const hooks = {
this.humus.app.synchronizer = undefined;
}
}
),
'@flecks/web/client.up': Flecks.priority(
(flecks) => {
window.flecks = flecks;
const Synchronizer = Receiver(flecks);
const synchronizer = new Synchronizer();
flecks.humus.app.synchronizer = synchronizer;
synchronizer.listenTo(flecks.socket.client);
},
{after: '@flecks/socket/client'},
),
};

View File

@ -3,23 +3,6 @@ import flatten from 'lodash.flatten';
export const hooks = {
'@avocado/traits.traits': Flecks.provide(require.context('./traits', false, /\.js$/)),
'@flecks/core.mixin': (Flecks) => (
class FlecksWithHumusCombat extends Flecks {
constructor(...args) {
super(...args);
if (!this.humus) {
this.humus = {};
}
if (!this.humus.combat) {
this.humus.combat = {};
}
this.humus.combat.Affinities = {};
this.humus.combat.interactions = () => {};
}
}
),
'@humus/combat.affinities': () => ({
Void: Class,
Bio: Class,
@ -60,3 +43,19 @@ export const hooks = {
},
'@flecks/socket.packets': Flecks.provide(require.context('./packets', false, /\.js$/)),
};
export const mixin = (Flecks) => class FlecksWithHumusCombat extends Flecks {
constructor(...args) {
super(...args);
if (!this.humus) {
this.humus = {};
}
if (!this.humus.combat) {
this.humus.combat = {};
}
this.humus.combat.Affinities = {};
this.humus.combat.interactions = () => {};
}
};

View File

@ -14,23 +14,6 @@ const {
const debug = D('@humus/universe/server');
export const hooks = {
'@flecks/core.mixin': (Flecks) => (
class FlecksWithHumusAppClient extends Flecks {
constructor(...args) {
super(...args);
if (!this.humus) {
this.humus = {};
}
if (!this.humus.universe) {
this.humus.universe = {};
}
this.humus.universe.universe = undefined;
this.humus.universe.resourceServer = undefined;
}
}
),
'@flecks/core.starting': async (flecks) => {
const {resource} = flecks.get('@humus/universe');
const stats = await stat(resource);
@ -41,7 +24,8 @@ export const hooks = {
flecks.humus.universe.resourceServer = express.static(resource);
debug('resource root: %s', resource);
},
'@flecks/server.up': async (flecks) => {
'@flecks/server.up': Flecks.priority(
async (flecks) => {
const {universe: path} = flecks.get('@humus/universe');
try {
const universe = await Universe.loadFrom(flecks, resolve(FLECKS_CORE_ROOT, path));
@ -53,6 +37,8 @@ export const hooks = {
throw new Error(`couldn't run universe: ${error.stack}`);
}
},
{before: '@flecks/web/server'},
),
'@flecks/web/server.request.socket': (flecks) => (req, res, next) => {
if (req.url.startsWith('/resource')) {
req.url = req.url.slice('/resource'.length);
@ -76,3 +62,19 @@ export const hooks = {
{after: '@flecks/governor/server'},
),
};
export const mixin = (Flecks) => class FlecksWithHumusAppClient extends Flecks {
constructor(...args) {
super(...args);
if (!this.humus) {
this.humus = {};
}
if (!this.humus.universe) {
this.humus.universe = {};
}
this.humus.universe.universe = undefined;
this.humus.universe.resourceServer = undefined;
}
};