|
|
|
@ -7,7 +7,7 @@ import { BaseItem } from "./base_item";
|
|
|
|
|
import { enumColors } from "./colors";
|
|
|
|
|
import { Entity } from "./entity";
|
|
|
|
|
import { COLOR_ITEM_SINGLETONS } from "./items/color_item";
|
|
|
|
|
import { enumLayer, GameRoot } from "./root";
|
|
|
|
|
import { GameRoot } from "./root";
|
|
|
|
|
import { enumSubShape } from "./shape_definition";
|
|
|
|
|
import { Rectangle } from "../core/rectangle";
|
|
|
|
|
|
|
|
|
@ -70,11 +70,11 @@ export class MapChunk {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Which entities this chunk contains, sorted by layer
|
|
|
|
|
* @type {Object<string, Array<Entity>>}
|
|
|
|
|
* @type {Record<Layer, Array<Entity>>}
|
|
|
|
|
*/
|
|
|
|
|
this.containedEntitiesByLayer = {
|
|
|
|
|
[enumLayer.regular]: [],
|
|
|
|
|
[enumLayer.wires]: [],
|
|
|
|
|
regular: [],
|
|
|
|
|
wires: [],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -362,7 +362,7 @@ export class MapChunk {
|
|
|
|
|
* Returns the contents of this chunk from the given world space coordinates
|
|
|
|
|
* @param {number} worldX
|
|
|
|
|
* @param {number} worldY
|
|
|
|
|
* @param {enumLayer} layer
|
|
|
|
|
* @param {Layer} layer
|
|
|
|
|
* @returns {Entity=}
|
|
|
|
|
*/
|
|
|
|
|
getLayerContentFromWorldCoords(worldX, worldY, layer) {
|
|
|
|
@ -372,7 +372,7 @@ export class MapChunk {
|
|
|
|
|
assert(localY >= 0, "Local Y is < 0");
|
|
|
|
|
assert(localX < globalConfig.mapChunkSize, "Local X is >= chunk size");
|
|
|
|
|
assert(localY < globalConfig.mapChunkSize, "Local Y is >= chunk size");
|
|
|
|
|
if (layer === enumLayer.regular) {
|
|
|
|
|
if (layer === "regular") {
|
|
|
|
|
return this.contents[localX][localY] || null;
|
|
|
|
|
} else {
|
|
|
|
|
return this.wireContents[localX][localY] || null;
|
|
|
|
@ -425,7 +425,7 @@ export class MapChunk {
|
|
|
|
|
* @param {number} tileX
|
|
|
|
|
* @param {number} tileY
|
|
|
|
|
* @param {Entity=} contents
|
|
|
|
|
* @param {enumLayer} layer
|
|
|
|
|
* @param {Layer} layer
|
|
|
|
|
*/
|
|
|
|
|
setLayerContentFromWorldCords(tileX, tileY, contents, layer) {
|
|
|
|
|
const localX = tileX - this.tileX;
|
|
|
|
@ -436,7 +436,7 @@ export class MapChunk {
|
|
|
|
|
assert(localY < globalConfig.mapChunkSize, "Local Y is >= chunk size");
|
|
|
|
|
|
|
|
|
|
let oldContents;
|
|
|
|
|
if (layer === enumLayer.regular) {
|
|
|
|
|
if (layer === "regular") {
|
|
|
|
|
oldContents = this.contents[localX][localY];
|
|
|
|
|
} else {
|
|
|
|
|
oldContents = this.wireContents[localX][localY];
|
|
|
|
@ -450,7 +450,7 @@ export class MapChunk {
|
|
|
|
|
fastArrayDeleteValueIfContained(this.containedEntitiesByLayer[layer], oldContents);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (layer === enumLayer.regular) {
|
|
|
|
|
if (layer === "regular") {
|
|
|
|
|
this.contents[localX][localY] = contents;
|
|
|
|
|
} else {
|
|
|
|
|
this.wireContents[localX][localY] = contents;
|
|
|
|
|