diff --git a/src/js/game/map_chunk_view.js b/src/js/game/map_chunk_view.js index d1b5cb4e..50bec4aa 100644 --- a/src/js/game/map_chunk_view.js +++ b/src/js/game/map_chunk_view.js @@ -103,6 +103,8 @@ export class MapChunkView extends MapChunk { originalH: overlaySize, }); + this.root.systemMgr.systems.lever.drawChunkOverlay(parameters, this); + this.root.systemMgr.systems.display.drawChunkOverlay(parameters, this); parameters.context.imageSmoothingEnabled = true; // Draw patch items diff --git a/src/js/game/systems/display.js b/src/js/game/systems/display.js index f11091b9..7fb8be6b 100644 --- a/src/js/game/systems/display.js +++ b/src/js/game/systems/display.js @@ -1,7 +1,7 @@ import { globalConfig } from "../../core/config"; import { Loader } from "../../core/loader"; import { BaseItem } from "../base_item"; -import { enumColors } from "../colors"; +import { enumColors, enumColorsToHexCode } from "../colors"; import { DisplayComponent } from "../components/display"; import { GameSystemWithFilter } from "../game_system_with_filter"; import { isTrueItem } from "../items/boolean_item"; @@ -94,4 +94,50 @@ export class DisplaySystem extends GameSystemWithFilter { } } } + + /** + * Draws overlay of a given chunk + * @param {import("../../core/draw_utils").DrawParameters} parameters + * @param {MapChunkView} chunk + */ + drawChunkOverlay(parameters, chunk) { + const contents = chunk.containedEntitiesByLayer.regular; + for (let i = 0; i < contents.length; ++i) { + const entity = contents[i]; + if (!entity || !entity.components.Display) { + continue; + } + + const pinsComp = entity.components.WiredPins; + const network = pinsComp.slots[0].linkedNetwork; + + if (!network || !network.currentValue) { + continue; + } + + const value = this.getDisplayItem(network.currentValue); + + if (!value) { + continue; + } + + const origin = entity.components.StaticMapEntity.origin; + if (value instanceof ColorItem) { + this.displaySprites[value.color].drawCachedCentered( + parameters, + (origin.x + 0.5) * globalConfig.tileSize, + (origin.y + 0.5) * globalConfig.tileSize, + globalConfig.tileSize + ); + + parameters.context.fillStyle = enumColorsToHexCode[value.color]; + parameters.context.fillRect( + origin.x * globalConfig.tileSize, + origin.y * globalConfig.tileSize, + globalConfig.tileSize, + globalConfig.tileSize + ); + } + } + } } diff --git a/src/js/game/systems/lever.js b/src/js/game/systems/lever.js index 75b6cf28..82866797 100644 --- a/src/js/game/systems/lever.js +++ b/src/js/game/systems/lever.js @@ -41,4 +41,28 @@ export class LeverSystem extends GameSystemWithFilter { } } } + + /** + * Draws overlay of a given chunk + * @param {import("../../core/draw_utils").DrawParameters} parameters + * @param {MapChunkView} chunk + */ + drawChunkOverlay(parameters, chunk) { + const contents = chunk.containedEntitiesByLayer.regular; + for (let i = 0; i < contents.length; ++i) { + const entity = contents[i]; + + if (entity && entity.components.Lever && entity.components.Lever.toggled) { + const origin = entity.components.StaticMapEntity.origin; + + parameters.context.fillStyle = "#54ee54"; + parameters.context.fillRect( + origin.x * globalConfig.tileSize, + origin.y * globalConfig.tileSize, + globalConfig.tileSize, + globalConfig.tileSize + ); + } + } + } }