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';
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) => {
window.flecks = flecks;
@ -32,3 +14,20 @@ export const hooks = {
{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 = {
'@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,18 +24,21 @@ export const hooks = {
flecks.humus.universe.resourceServer = express.static(resource);
debug('resource root: %s', resource);
},
'@flecks/server.up': async (flecks) => {
const {universe: path} = flecks.get('@humus/universe');
try {
const universe = await Universe.loadFrom(flecks, resolve(FLECKS_CORE_ROOT, path));
flecks.humus.universe.universe = universe;
universe.start();
debug('universe up and running!');
}
catch (error) {
throw new Error(`couldn't run universe: ${error.stack}`);
}
},
'@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));
flecks.humus.universe.universe = universe;
universe.start();
debug('universe up and running!');
}
catch (error) {
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;
}
};