refactor: mixin
This commit is contained in:
parent
b26fe51175
commit
b72d3b5b28
|
@ -29,7 +29,7 @@ export default () => {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
const onCreated = (created) => {
|
const onCreated = (created) => {
|
||||||
const {Room} = flecks.avocado.Resources;
|
const {Room} = flecks.avocado.resource.Resources;
|
||||||
switch (created.constructor.resourceId) {
|
switch (created.constructor.resourceId) {
|
||||||
// Track room.
|
// Track room.
|
||||||
case Room.resourceId: {
|
case Room.resourceId: {
|
||||||
|
|
|
@ -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.avocado.Resources;
|
const {Script} = flecks.avocado.resource.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.avocado.Resources;
|
const {Script} = flecks.avocado.resource.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.avocado.Resources;
|
const {Script} = flecks.avocado.resource.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,
|
||||||
|
|
|
@ -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.avocado.Resources;
|
const {Script} = flecks.avocado.resource.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.avocado.Resources;
|
const {Script} = flecks.avocado.resource.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.avocado.Resources;
|
const {Script} = flecks.avocado.resource.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.avocado.Resources;
|
const {Entity} = flecks.avocado.resource.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.avocado.Resources;
|
const {Entity} = flecks.avocado.resource.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.avocado.Resources;
|
const {Entity} = flecks.avocado.resource.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.avocado.Resources;
|
const {Entity} = flecks.avocado.resource.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.avocado.Resources;
|
const {Room} = flecks.avocado.resource.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.avocado.Resources;
|
const {Entity} = this.$$flecks.avocado.resource.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.avocado.Resources;
|
const {Room} = flecks.avocado.resource.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.avocado.Resources;
|
const {Entity} = this.$$flecks.avocado.resource.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.avocado.Resources;
|
const {Universe} = this.$$flecks.avocado.resource.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