refactor: mixin

This commit is contained in:
cha0s 2024-01-05 20:07:26 -06:00
parent b26fe51175
commit b72d3b5b28
11 changed files with 16 additions and 16 deletions

View File

@ -29,7 +29,7 @@ export default () => {
return undefined;
}
const onCreated = (created) => {
const {Room} = flecks.avocado.Resources;
const {Room} = flecks.avocado.resource.Resources;
switch (created.constructor.resourceId) {
// Track room.
case Room.resourceId: {

View File

@ -70,7 +70,7 @@ export default (flecks) => class Harmful extends decorate(Trait) {
listeners() {
const listeners = {
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.contextOrDefault,
harm,

View File

@ -192,7 +192,7 @@ export default (flecks) => class Vulnerable extends Trait {
}
interactions(harmed, harm) {
const {Script} = flecks.avocado.Resources;
const {Script} = flecks.avocado.resource.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.avocado.Resources;
const {Script} = flecks.avocado.resource.Resources;
const script = await Script.load(this.params.harmedScript, {
entity: this.entity,
from,

View File

@ -55,7 +55,7 @@ export default (flecks) => class Item extends decorate(Trait) {
use: () => {
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)];
if (cooldown > 0) {
promises.push(new Promise((resolve) => {

View File

@ -65,7 +65,7 @@ export default (flecks) => class Plant extends decorate(Trait) {
async load(json) {
await super.load(json);
const {Script} = flecks.avocado.Resources;
const {Script} = flecks.avocado.resource.Resources;
const {growthCheck, growthScript} = this.params;
if (growthCheck) {
this.growthCheck = await Script.load(growthCheck, {

View File

@ -180,7 +180,7 @@ export default (flecks) => class Tool extends Trait {
}
this.calculateTargets();
const promises = this.$$targets.map((target) => {
const {Script} = flecks.avocado.Resources;
const {Script} = flecks.avocado.resource.Resources;
const context = this.createTargetContext(target);
return Script.loadTickingPromise(this.params.toolScript, context);
});

View File

@ -48,7 +48,7 @@ export default (flecks) => class Receptacle extends decorate(Trait) {
break;
}
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);
break;
}
@ -195,7 +195,7 @@ export default (flecks) => class Receptacle extends decorate(Trait) {
}
async load(json) {
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.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});

View File

@ -56,7 +56,7 @@ noiseSeed(seed);
Plains.generate();
export default async (room, flecks) => {
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
room.tiles[0].stampAt(
[0, 0, w, h],
Plains.matrix,

View File

@ -1,5 +1,5 @@
const createPlayerEntity = async (flecks, name) => {
const {Entity} = flecks.avocado.Resources;
const {Entity} = flecks.avocado.resource.Resources;
const entity = await Entity.load({
extends: '/player/index.entity.json',
traits: {Named: {state: {name}}},

View File

@ -1,5 +1,5 @@
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'});
flecks.invoke('@humus/universe.player.room', room);
return room;

View File

@ -80,7 +80,7 @@ export default class Universe {
async createEntity(user) {
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});
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.avocado.Resources;
const {Room} = flecks.avocado.resource.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.avocado.Resources;
const {Entity} = this.$$flecks.avocado.resource.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.avocado.Resources;
const {Universe} = this.$$flecks.avocado.resource.Resources;
const buffer = await readFile(uri);
const json = JSON.parse(buffer.toString());
this.$$universe = await Universe.load(json);