refactor: tilling

This commit is contained in:
cha0s 2021-05-10 03:55:52 -05:00
parent 6f5f3715e6
commit c1ab345a47
2 changed files with 11 additions and 15 deletions

View File

@ -7,7 +7,6 @@ import {
import Renderable from './room/renderable';
const DIRT = 6;
const GRASS = [1, 2, 3, 4, 10, 11, 12];
const TILLED = 7;
export default (Room) => class FarmableRoom extends Room {
@ -34,7 +33,7 @@ export default (Room) => class FarmableRoom extends Room {
}
adjustWaterAt(target, increase) {
const [tiles] = this.tiles;
const tiles = this.tiles[1];
if (
'client' === process.env.SIDE
|| TILLED !== tiles.tileAt(target)
@ -92,15 +91,11 @@ export default (Room) => class FarmableRoom extends Room {
}
mayPrepareSoilAt(target) {
const [tiles] = this.tiles;
return (
DIRT === tiles.tileAt(target)
|| -1 !== GRASS.indexOf(tiles.tileAt(target))
);
return 0 === this.tiles[1].tileAt(target);
}
maySowAt(center) {
const [tiles] = this.tiles;
const tiles = this.tiles[1];
const {tileSize} = tiles;
const target = Vector.floor(Vector.div(center, tileSize));
return (
@ -120,8 +115,8 @@ export default (Room) => class FarmableRoom extends Room {
prepareSoilAt(target) {
if ('client' !== process.env.SIDE) {
const [tiles] = this.tiles;
tiles.setTileAt(target, DIRT === tiles.tileAt(target) ? TILLED : DIRT);
const tiles = this.tiles[1];
tiles.setTileAt(target, TILLED);
this.adjustWaterAt(target, 0);
}
}
@ -163,7 +158,7 @@ export default (Room) => class FarmableRoom extends Room {
}
waterAt(target) {
const [tiles] = this.tiles;
const tiles = this.tiles[1];
if (TILLED !== tiles.tileAt(target)) {
return 0;
}

View File

@ -14,12 +14,13 @@ export default (Room) => class extends Room.Renderable {
onWaterChange() {
const water = Object.entries(this.room.water);
const [tiles] = this.room.tiles;
const [renderable] = this.tilesRenderables;
const tiles = this.room.tiles[1];
const [tw, th] = tiles.tileSize;
const renderable = this.tilesRenderables[1];
for (let i = 0; i < water.length; i++) {
const [hash, amount] = water[i];
const [tw, th] = tiles.tileSize;
const [x, y] = Vector.mul(Vector.unpackFromUint32(hash), [tw, th]);
const position = Vector.unpackFromUint32(hash);
const [x, y] = Vector.mul(position, [tw, th]);
const primitives = this.primitivesFor(hash);
renderable.addChild(primitives);
primitives.clear();