mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Map view for displays and levers
This commit is contained in:
parent
c4f2379010
commit
94434a1d4a
@ -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
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user