refactor: mixin
This commit is contained in:
parent
173e1fdb11
commit
b26fe51175
|
@ -6,6 +6,6 @@ export const hooks = {
|
|||
const Synchronizer = Receiver(flecks);
|
||||
const synchronizer = new Synchronizer();
|
||||
flecks.set('$humus/app.synchronizer', synchronizer);
|
||||
synchronizer.listenTo(flecks.get('$flecks/socket.socket'));
|
||||
synchronizer.listenTo(flecks.socket.client);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -29,7 +29,7 @@ export default () => {
|
|||
return undefined;
|
||||
}
|
||||
const onCreated = (created) => {
|
||||
const {Room} = flecks.get('$avocado/resource.resources');
|
||||
const {Room} = flecks.avocado.Resources;
|
||||
switch (created.constructor.resourceId) {
|
||||
// Track room.
|
||||
case Room.resourceId: {
|
||||
|
|
|
@ -3,7 +3,7 @@ export const hooks = {
|
|||
// if ('production' === NODE_ENV) {
|
||||
// return;
|
||||
// }
|
||||
const {User} = flecks.get('$flecks/db.models');
|
||||
const {User} = flecks.db.Models;
|
||||
if (!await User.findOne({where: {email: 'humus@cha0s.io'}})) {
|
||||
const user = await User.create({
|
||||
email: 'humus@cha0s.io',
|
||||
|
|
|
@ -70,7 +70,7 @@ export default (flecks) => class Harmful extends decorate(Trait) {
|
|||
listeners() {
|
||||
const listeners = {
|
||||
harming: async (harm, harmed) => {
|
||||
const {Script} = flecks.get('$avocado/resource.resources');
|
||||
const {Script} = flecks.avocado.Resources;
|
||||
this.entity.addTickingPromise(Script.loadTickingPromise(this.params.harmingScript, {
|
||||
...this.entity.contextOrDefault,
|
||||
harm,
|
||||
|
|
|
@ -192,7 +192,7 @@ export default (flecks) => class Vulnerable extends Trait {
|
|||
}
|
||||
|
||||
interactions(harmed, harm) {
|
||||
const {Script} = flecks.get('$avocado/resource.resources');
|
||||
const {Script} = flecks.avocado.Resources;
|
||||
const {affinity, from} = harm;
|
||||
const interactions = flecks.get('$humus/combat.interactions');
|
||||
flatten(
|
||||
|
@ -278,7 +278,7 @@ export default (flecks) => class Vulnerable extends Trait {
|
|||
},
|
||||
|
||||
harmed: async (harm, from) => {
|
||||
const {Script} = flecks.get('$avocado/resource.resources');
|
||||
const {Script} = flecks.avocado.Resources;
|
||||
const script = await Script.load(this.params.harmedScript, {
|
||||
entity: this.entity,
|
||||
from,
|
||||
|
|
|
@ -17,7 +17,7 @@ export const hooks = {
|
|||
},
|
||||
'@flecks/web/server.request.route': (flecks) => async (req, res, next) => {
|
||||
if (isElectron() && 0 === req.user.id) {
|
||||
const {User} = flecks.get('$flecks/db.models');
|
||||
const {User} = flecks.db.Models;
|
||||
req.logIn(await User.findByPk(1), next);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ export default (flecks) => class Item extends decorate(Trait) {
|
|||
|
||||
use: () => {
|
||||
const {cooldown} = this.params;
|
||||
const {Script} = flecks.get('$avocado/resource.resources');
|
||||
const {Script} = flecks.avocado.Resources;
|
||||
const promises = [Script.loadTickingPromise(this.params.useScript, this.entity.context)];
|
||||
if (cooldown > 0) {
|
||||
promises.push(new Promise((resolve) => {
|
||||
|
|
|
@ -65,7 +65,7 @@ export default (flecks) => class Plant extends decorate(Trait) {
|
|||
|
||||
async load(json) {
|
||||
await super.load(json);
|
||||
const {Script} = flecks.get('$avocado/resource.resources');
|
||||
const {Script} = flecks.avocado.Resources;
|
||||
const {growthCheck, growthScript} = this.params;
|
||||
if (growthCheck) {
|
||||
this.growthCheck = await Script.load(growthCheck, {
|
||||
|
|
|
@ -180,7 +180,7 @@ export default (flecks) => class Tool extends Trait {
|
|||
}
|
||||
this.calculateTargets();
|
||||
const promises = this.$$targets.map((target) => {
|
||||
const {Script} = flecks.get('$avocado/resource.resources');
|
||||
const {Script} = flecks.avocado.Resources;
|
||||
const context = this.createTargetContext(target);
|
||||
return Script.loadTickingPromise(this.params.toolScript, context);
|
||||
});
|
||||
|
|
|
@ -48,7 +48,7 @@ export default (flecks) => class Receptacle extends decorate(Trait) {
|
|||
break;
|
||||
}
|
||||
case 'TraitUpdateReceptacleItemFull': {
|
||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
||||
const {Entity} = flecks.avocado.Resources;
|
||||
this.entity.addItemToSlot(await Entity.load(packet.data.json), packet.data.slotIndex);
|
||||
break;
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ export default (flecks) => class Receptacle extends decorate(Trait) {
|
|||
}
|
||||
|
||||
async load(json) {
|
||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
||||
const {Entity} = flecks.avocado.Resources;
|
||||
await super.load(json);
|
||||
await Promise.all(Object.entries(this.params.slots).map(async ([slotIndex, slotSpec]) => {
|
||||
const item = await Entity.load({extends: slotSpec.extends});
|
||||
|
|
|
@ -56,7 +56,7 @@ noiseSeed(seed);
|
|||
Plains.generate();
|
||||
|
||||
export default async (room, flecks) => {
|
||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
||||
const {Entity} = flecks.avocado.Resources;
|
||||
room.tiles[0].stampAt(
|
||||
[0, 0, w, h],
|
||||
Plains.matrix,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const createPlayerEntity = async (flecks, name) => {
|
||||
const {Entity} = flecks.get('$avocado/resource.resources');
|
||||
const {Entity} = flecks.avocado.Resources;
|
||||
const entity = await Entity.load({
|
||||
extends: '/player/index.entity.json',
|
||||
traits: {Named: {state: {name}}},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const createPlayerRoom = async (flecks) => {
|
||||
const {Room} = flecks.get('$avocado/resource.resources');
|
||||
const {Room} = flecks.avocado.Resources;
|
||||
const room = await Room.load({extends: '/player/index.room.json'});
|
||||
flecks.invoke('@humus/universe.player.room', room);
|
||||
return room;
|
||||
|
|
|
@ -80,7 +80,7 @@ export default class Universe {
|
|||
|
||||
async createEntity(user) {
|
||||
const playerPath = join(this.$$root, 'players', `${user.id}`);
|
||||
const {Entity} = this.$$flecks.get('$avocado/resource.resources');
|
||||
const {Entity} = this.$$flecks.avocado.Resources;
|
||||
await mkdir(playerPath, {recursive: true});
|
||||
const entity = await createPlayerEntity(this.$$flecks, user.email);
|
||||
entity.currentRoom = `/${join('players', `${user.id}`, 'index.room.json')}`;
|
||||
|
@ -132,7 +132,7 @@ export default class Universe {
|
|||
}
|
||||
const universe = new this(flecks, path);
|
||||
await universe.loadOrCreateResource();
|
||||
const {Room} = flecks.get('$avocado/resource.resources');
|
||||
const {Room} = flecks.avocado.Resources;
|
||||
await Promise.all(
|
||||
(await pglob('**/*.room.json', {cwd: path}))
|
||||
.map(async (roomUri) => {
|
||||
|
@ -153,7 +153,7 @@ export default class Universe {
|
|||
async loadOrCreateEntity(user) {
|
||||
debugSilly('loadOrCreateEntity from user id %d', user.id);
|
||||
const playerPath = join(this.$$root, 'players', `${user.id}`);
|
||||
const {Entity} = this.$$flecks.get('$avocado/resource.resources');
|
||||
const {Entity} = this.$$flecks.avocado.Resources;
|
||||
try {
|
||||
await stat(join(playerPath, 'index.entity.json'));
|
||||
const json = JSON.parse((await readFile(join(playerPath, 'index.entity.json'))).toString());
|
||||
|
@ -183,7 +183,7 @@ export default class Universe {
|
|||
debug("resource doesn't exist, creating...");
|
||||
await writeFile(uri, '{}');
|
||||
}
|
||||
const {Universe} = this.$$flecks.get('$avocado/resource.resources');
|
||||
const {Universe} = this.$$flecks.avocado.Resources;
|
||||
const buffer = await readFile(uri);
|
||||
const json = JSON.parse(buffer.toString());
|
||||
this.$$universe = await Universe.load(json);
|
||||
|
|
Loading…
Reference in New Issue
Block a user