refactor: plantAt

This commit is contained in:
cha0s 2022-05-04 14:41:42 -05:00
parent da22ef6cb4
commit 3b3920a939

View File

@ -64,17 +64,6 @@ export default (Room) => class FarmableRoom extends Room {
this.$$waterChanges = [];
}
isPlantAt(target) {
const entities = this.entityList.visibleEntities(Rectangle.centerOn(target, [1, 1]));
for (let i = 0; i < entities.length; ++i) {
const entity = entities[i];
if (Vector.equals(entity.position, target) && entity.is('Plant')) {
return true;
}
}
return false;
}
async load(json) {
await super.load(json);
const {
@ -100,7 +89,7 @@ export default (Room) => class FarmableRoom extends Room {
return (
'web' !== process.env.FLECKS_CORE_BUILD_TARGET
&& TILLED === tiles.tileAt(target)
&& !this.isPlantAt(center)
&& !this.plantAt(center)
);
}
@ -112,6 +101,17 @@ export default (Room) => class FarmableRoom extends Room {
return packets;
}
plantAt(target) {
const entities = this.entityList.visibleEntities(Rectangle.centerOn(target, [1, 1]));
for (let i = 0; i < entities.length; ++i) {
const entity = entities[i];
if (Vector.equals(entity.position, target) && entity.is('Plant')) {
return entity;
}
}
return null;
}
prepareSoilAt(target) {
if ('web' !== process.env.FLECKS_CORE_BUILD_TARGET) {
const tiles = this.tiles[1];