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