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,24 +3,6 @@ import {Flecks} from '@flecks/core';
import Receiver from './receiver'; import Receiver from './receiver';
export const hooks = { export const hooks = {
'@flecks/core.mixin': (Flecks) => (
class FlecksWithHumusAppClient extends Flecks {
constructor(...args) {
super(...args);
if (!this.humus) {
this.humus = {};
}
if (!this.humus.app) {
this.humus.app = {};
}
this.humus.app.room = undefined;
this.humus.app.selfEntity = undefined;
this.humus.app.synchronizer = undefined;
}
}
),
'@flecks/web/client.up': Flecks.priority( '@flecks/web/client.up': Flecks.priority(
(flecks) => { (flecks) => {
window.flecks = flecks; window.flecks = flecks;
@ -32,3 +14,20 @@ export const hooks = {
{after: '@flecks/socket/client'}, {after: '@flecks/socket/client'},
), ),
}; };
export const mixin = (Flecks) => class FlecksWithHumusAppClient extends Flecks {
constructor(...args) {
super(...args);
if (!this.humus) {
this.humus = {};
}
if (!this.humus.app) {
this.humus.app = {};
}
this.humus.app.room = undefined;
this.humus.app.selfEntity = undefined;
this.humus.app.synchronizer = undefined;
}
};

View File

@ -3,23 +3,6 @@ import flatten from 'lodash.flatten';
export const hooks = { export const hooks = {
'@avocado/traits.traits': Flecks.provide(require.context('./traits', false, /\.js$/)), '@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': () => ({ '@humus/combat.affinities': () => ({
Void: Class, Void: Class,
Bio: Class, Bio: Class,
@ -60,3 +43,19 @@ export const hooks = {
}, },
'@flecks/socket.packets': Flecks.provide(require.context('./packets', false, /\.js$/)), '@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'); const debug = D('@humus/universe/server');
export const hooks = { 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) => { '@flecks/core.starting': async (flecks) => {
const {resource} = flecks.get('@humus/universe'); const {resource} = flecks.get('@humus/universe');
const stats = await stat(resource); const stats = await stat(resource);
@ -41,18 +24,21 @@ export const hooks = {
flecks.humus.universe.resourceServer = express.static(resource); flecks.humus.universe.resourceServer = express.static(resource);
debug('resource root: %s', resource); debug('resource root: %s', resource);
}, },
'@flecks/server.up': async (flecks) => { '@flecks/server.up': Flecks.priority(
const {universe: path} = flecks.get('@humus/universe'); async (flecks) => {
try { const {universe: path} = flecks.get('@humus/universe');
const universe = await Universe.loadFrom(flecks, resolve(FLECKS_CORE_ROOT, path)); try {
flecks.humus.universe.universe = universe; const universe = await Universe.loadFrom(flecks, resolve(FLECKS_CORE_ROOT, path));
universe.start(); flecks.humus.universe.universe = universe;
debug('universe up and running!'); universe.start();
} debug('universe up and running!');
catch (error) { }
throw new Error(`couldn't run universe: ${error.stack}`); catch (error) {
} throw new Error(`couldn't run universe: ${error.stack}`);
}, }
},
{before: '@flecks/web/server'},
),
'@flecks/web/server.request.socket': (flecks) => (req, res, next) => { '@flecks/web/server.request.socket': (flecks) => (req, res, next) => {
if (req.url.startsWith('/resource')) { if (req.url.startsWith('/resource')) {
req.url = req.url.slice('/resource'.length); req.url = req.url.slice('/resource'.length);
@ -76,3 +62,19 @@ export const hooks = {
{after: '@flecks/governor/server'}, {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;
}
};