refactor: gather

This commit is contained in:
cha0s 2021-01-22 17:58:48 -06:00
parent eb94ca31ec
commit 11dbddd47b
9 changed files with 45 additions and 16 deletions

View File

@ -19,7 +19,7 @@ const ItemSlotComponent = (props) => {
const latus = useLatus();
const [qty, setQty] = useState(undefined);
useEvent(item, 'qtyChanged', useCallback(() => setQty(item.qty), [item]));
const {Image} = latus.get('%resources.fromResourceType');
const {Image} = latus.get('%resources');
let backgroundImageUri;
let qtyClass;
if (item) {

View File

@ -3,9 +3,9 @@ import {Packet} from '@latus/socket';
export default (latus) => class HarmPacket extends Packet {
static pack(harms) {
const fromType = latus.get('%affinities.fromType');
const Affinities = latus.get('%affinities');
return harms.map((harm) => {
const {[harm.affinity]: Affinity} = fromType;
const {[harm.affinity]: Affinity} = Affinities;
// eslint-disable-next-line no-param-reassign
harm.affinity = Affinity.id;
return harm;
@ -24,9 +24,9 @@ export default (latus) => class HarmPacket extends Packet {
}
static unpack(harms) {
const fromId = latus.get('%affinities.fromId');
const Affinities = latus.get('%affinities');
return harms.map((harm) => {
const {[harm.affinity]: Affinity} = fromId;
const {[harm.affinity]: Affinity} = Affinities;
// eslint-disable-next-line no-param-reassign
harm.affinity = Affinity.type;
return harm;

View File

@ -1,4 +1,3 @@
import {resource} from '@avocado/resource';
import {useEffect, useLatus, useState} from '@latus/react/client';
import {useSocket} from '@latus/socket';
@ -25,7 +24,7 @@ export default () => {
return undefined;
}
const onCreated = (type, created) => {
const {fromResourceType: {Room}} = resource(latus);
const {Room} = latus.get('%resources');
switch (type) {
// Track room.
case Room.resourceId: {

View File

@ -0,0 +1,33 @@
import {Trait} from '@avocado/traits';
export default () => class Darkened extends Trait {
static defaultParams() {
return {
isDarkened: true,
};
}
static describeParams() {
return {
isDarkened: {
type: 'bool',
label: 'Is darkened',
},
};
}
static type() {
return 'darkened';
}
async load(json) {
await super.load(json);
this._isDarkened = this.params.isDarkened;
}
get isDarkened() {
return this._isDarkened;
}
};

View File

@ -60,7 +60,7 @@ export default (latus) => class Receptacle extends decorate(Trait) {
break;
}
case 'TraitUpdateReceptacleItemFull': {
const {Entity} = latus.get('%resources.fromResourceType');
const {Entity} = latus.get('%resources');
this.entity.addItemToSlot(await Entity.load(packet.data.json), packet.data.slotIndex);
break;
}
@ -188,7 +188,7 @@ export default (latus) => class Receptacle extends decorate(Trait) {
}
async load(json) {
const {Entity} = latus.get('%resources.fromResourceType');
const {Entity} = latus.get('%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

@ -1,7 +1,7 @@
import {dirname, join} from 'path';
import {promisify} from 'util';
import {resource, JsonResource} from '@avocado/resource';
import {JsonResource} from '@avocado/resource';
import {createLoop, destroyLoop} from '@avocado/timing';
import glob from 'glob';
@ -40,7 +40,7 @@ export default (latus) => class Universe extends JsonResource {
async load(json = {}) {
super.load(json);
const {tps = 60, uri} = json;
const {fromResourceType: {Room}} = resource(latus);
const {Room} = latus.get('%resources');
if (uri) {
const universePath = dirname(uri);
await Promise.all(

View File

@ -1,4 +1,3 @@
import {resource} from '@avocado/resource';
import {gatherWithLatus} from '@latus/core';
import UniverseInput from './packets/decorators/universe-input';
@ -11,7 +10,7 @@ export default {
return;
}
try {
const {fromResourceType: {Universe}} = resource(latus);
const {Universe} = latus.get('%resources');
const universe = await Universe.load({extends: `/universe/${running}/index.universe.json`});
latus.set('%universe', universe);
universe.start();

View File

@ -1,6 +1,5 @@
import {dirname, join} from 'path';
import {resource} from '@avocado/resource';
// import {ValidationError} from '@latus/socket';
import Join from '../../packets/join';
@ -21,7 +20,7 @@ export default (latus) => class ServerJoin extends Join() {
if (player) {
return player.entity.instanceUuid;
}
const {Entity} = latus.get('%resources.fromResourceType');
const {Entity} = latus.get('%resources');
const entity = await Entity.load(
{
extends: join(

View File

@ -1,4 +1,3 @@
import {resource} from '@avocado/resource';
import {
createAsyncThunk,
createSelector,