chore: gardening
This commit is contained in:
parent
81f9c64bd0
commit
8bb14b287f
|
@ -175,7 +175,6 @@ export default (latus) => {
|
|||
}
|
||||
|
||||
cleanPackets() {
|
||||
super.cleanPackets();
|
||||
if (!this.#markedAsDirty) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
import {Vector} from '@avocado/math';
|
||||
import {StateProperty, Trait} from '@avocado/traits';
|
||||
import {compose} from '@latus/core';
|
||||
import {Trait} from '@avocado/traits';
|
||||
|
||||
import BodyView from '../body-view';
|
||||
|
||||
const decorate = compose(
|
||||
StateProperty('addedToPhysics', {
|
||||
track: true,
|
||||
}),
|
||||
);
|
||||
|
||||
export default () => class Physical extends decorate(Trait) {
|
||||
export default () => class Physical extends Trait {
|
||||
|
||||
#body;
|
||||
|
||||
|
@ -71,27 +64,12 @@ export default () => class Physical extends decorate(Trait) {
|
|||
};
|
||||
}
|
||||
|
||||
static defaultState() {
|
||||
return {
|
||||
addedToPhysics: true,
|
||||
};
|
||||
}
|
||||
|
||||
static dependencies() {
|
||||
return [
|
||||
'Shaped',
|
||||
];
|
||||
}
|
||||
|
||||
static describeState() {
|
||||
return {
|
||||
addedToPhysics: {
|
||||
type: 'bool',
|
||||
label: 'Added to physics',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
destroy() {
|
||||
super.destroy();
|
||||
this.world = undefined;
|
||||
|
@ -104,19 +82,8 @@ export default () => class Physical extends decorate(Trait) {
|
|||
this.entity.world = this.entity.room.world;
|
||||
},
|
||||
|
||||
addedToPhysicsChanged: () => {
|
||||
if (this.entity.addedToPhysics) {
|
||||
if (!this.#body) {
|
||||
this.addToWorld();
|
||||
}
|
||||
}
|
||||
else if (this.#body) {
|
||||
this.removeFromWorld();
|
||||
}
|
||||
},
|
||||
|
||||
startedDying: () => {
|
||||
this.entity.addedToPhysics = false;
|
||||
this.removeFromWorld();
|
||||
},
|
||||
|
||||
positionChanged: () => {
|
||||
|
|
|
@ -26,8 +26,6 @@ export default class LayerView extends Container {
|
|||
|
||||
destroy() {
|
||||
super.destroy();
|
||||
this.layer.off('entityAdded', this.onLayerEntityAdded);
|
||||
this.layer.off('entityRemoved', this.onLayerEntityRemoved);
|
||||
this.layer.off('tileDataChanged', this.onLayerTileDataChanged);
|
||||
this.layer.off('tilesetChanged', this.onLayerTilesetChanged);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ export default (latus) => {
|
|||
|
||||
constructor() {
|
||||
super();
|
||||
this.tileEntities = {};
|
||||
this.tileGeometry = [];
|
||||
const {EntityList, Tiles} = latus.get('%resources');
|
||||
this.setEntityList(new EntityList());
|
||||
|
@ -28,22 +27,6 @@ export default (latus) => {
|
|||
this.entityList.addEntity(entity);
|
||||
}
|
||||
|
||||
addTileEntity(entity, index) {
|
||||
if (!this.tileEntities[index]) {
|
||||
this.tileEntities[index] = [];
|
||||
}
|
||||
if (-1 !== this.tileEntities[index].indexOf(entity)) {
|
||||
return;
|
||||
}
|
||||
this.tileEntities[index].push(entity);
|
||||
}
|
||||
|
||||
cleanPackets() {
|
||||
super.cleanPackets();
|
||||
this.entityList.cleanPackets();
|
||||
this.tiles.cleanPackets();
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.entityList.destroy();
|
||||
this.entityList.off('entityAdded', this.onEntityAddedToLayer);
|
||||
|
@ -62,15 +45,6 @@ export default (latus) => {
|
|||
return this.entityList.findEntity(uuid);
|
||||
}
|
||||
|
||||
hasTileEntityWithUriAt(tilePosition, uri) {
|
||||
const tileEntities = this.tileEntitiesAt(tilePosition);
|
||||
if (0 === tileEntities.length) {
|
||||
return false;
|
||||
}
|
||||
const entitiesWithUri = tileEntities.filter((entity) => entity.uri === uri);
|
||||
return entitiesWithUri.length > 0;
|
||||
}
|
||||
|
||||
indexAt(position) {
|
||||
return this.tiles.indexAt(position);
|
||||
}
|
||||
|
@ -120,17 +94,6 @@ export default (latus) => {
|
|||
this.entityList.removeEntity(entity);
|
||||
}
|
||||
|
||||
removeTileEntity(entity, index) {
|
||||
if (!this.tileEntities[index]) {
|
||||
return;
|
||||
}
|
||||
const entityIndex = this.tileEntities[index].indexOf(entity);
|
||||
if (-1 === entityIndex) {
|
||||
return;
|
||||
}
|
||||
this.tileEntities[index].splice(entityIndex, 1);
|
||||
}
|
||||
|
||||
get s13nId() {
|
||||
return this.#s13nId;
|
||||
}
|
||||
|
@ -179,14 +142,6 @@ export default (latus) => {
|
|||
return this.tiles.tileAt(position);
|
||||
}
|
||||
|
||||
tileEntitiesAt(tilePosition) {
|
||||
const index = this.indexAt(tilePosition);
|
||||
if (!this.tileEntities[index]) {
|
||||
return [];
|
||||
}
|
||||
return this.tileEntities[index];
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
entities: this.entityList.toJSON(),
|
||||
|
@ -207,9 +162,5 @@ export default (latus) => {
|
|||
return this.entityList.visibleEntities(query);
|
||||
}
|
||||
|
||||
// visibleEntitiesWithUri(query, uri) {
|
||||
// return this.entityList.visibleEntitiesWithUri(query, uri);
|
||||
// }
|
||||
|
||||
};
|
||||
};
|
||||
|
|
|
@ -32,13 +32,6 @@ export default (latus) => {
|
|||
this.emit('layerAdded', layer);
|
||||
}
|
||||
|
||||
cleanPackets() {
|
||||
super.cleanPackets();
|
||||
for (let i = 0; i < this.layers.length; i++) {
|
||||
this.layers[i].cleanPackets();
|
||||
}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
for (let i = 0; i < this.layers.length; i++) {
|
||||
const layer = this.layers[i];
|
||||
|
|
|
@ -48,9 +48,7 @@ export default (latus) => {
|
|||
async load(json = {}) {
|
||||
await super.load(json);
|
||||
const {layers, size} = json;
|
||||
if (size) {
|
||||
this.size = size;
|
||||
}
|
||||
this.size = size || [0, 0];
|
||||
const {Layers} = latus.get('%resources');
|
||||
this.setLayers(
|
||||
layers
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
import {StateProperty, Trait} from '@avocado/traits';
|
||||
import {Vector} from '@avocado/math';
|
||||
import {compose} from '@latus/core';
|
||||
|
||||
const decorate = compose(
|
||||
StateProperty('tileIndex', {
|
||||
track: true,
|
||||
}),
|
||||
);
|
||||
|
||||
export default () => class TileEntity extends decorate(Trait) {
|
||||
|
||||
static defaultState() {
|
||||
return {
|
||||
tileIndex: 0,
|
||||
};
|
||||
}
|
||||
|
||||
static describeState() {
|
||||
return {
|
||||
tileIndex: {
|
||||
type: 'number',
|
||||
label: 'Tile index',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
destroy() {
|
||||
super.destroy();
|
||||
this.removeTileEntity(this.entity.tileIndex);
|
||||
}
|
||||
|
||||
addTileEntity(tileIndex) {
|
||||
const {layer} = this.entity;
|
||||
if (!layer) {
|
||||
return;
|
||||
}
|
||||
layer.addTileEntity(this.entity, tileIndex);
|
||||
}
|
||||
|
||||
listeners() {
|
||||
return {
|
||||
|
||||
addedToLayer: () => {
|
||||
this.setTileIndex();
|
||||
},
|
||||
|
||||
removedFromLayer: (layer) => {
|
||||
layer.removeTileEntity(this.entity, Vector.floor(this.entity.tile));
|
||||
},
|
||||
|
||||
tileChanged: () => {
|
||||
this.setTileIndex();
|
||||
},
|
||||
|
||||
tileIndexChanged: (oldTileIndex, newTileIndex) => {
|
||||
this.removeTileEntity(oldTileIndex);
|
||||
this.addTileEntity(newTileIndex);
|
||||
},
|
||||
|
||||
traitAdded: () => {
|
||||
this.setTileIndex();
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
removeTileEntity(tileIndex) {
|
||||
const {layer} = this.entity;
|
||||
if (!layer) {
|
||||
return;
|
||||
}
|
||||
layer.removeTileEntity(this.entity, tileIndex);
|
||||
}
|
||||
|
||||
setTileIndex() {
|
||||
if (!this.entity.layer) {
|
||||
return;
|
||||
}
|
||||
this.entity.tileIndex = this.entity.layer.indexAt(
|
||||
Vector.floor(this.entity.tile),
|
||||
);
|
||||
}
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user