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