Add display
After Width: | Height: | Size: 6.5 KiB |
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 240 KiB After Width: | Height: | Size: 232 KiB |
Before Width: | Height: | Size: 574 KiB After Width: | Height: | Size: 570 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 4.9 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.6 KiB |
After Width: | Height: | Size: 2.6 KiB |
|
@ -1,5 +1,5 @@
|
||||||
$buildings: belt, cutter, miner, mixer, painter, rotater, splitter, stacker, trash, underground_belt, wire,
|
$buildings: belt, cutter, miner, mixer, painter, rotater, splitter, stacker, trash, underground_belt, wire,
|
||||||
constant_signal, logic_gate, lever, filter, wire_tunnel;
|
constant_signal, logic_gate, lever, filter, wire_tunnel, display;
|
||||||
|
|
||||||
@each $building in $buildings {
|
@each $building in $buildings {
|
||||||
[data-icon="building_icons/#{$building}.png"] {
|
[data-icon="building_icons/#{$building}.png"] {
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
import { enumDirection, Vector } from "../../core/vector";
|
||||||
|
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
|
||||||
|
import { Entity } from "../entity";
|
||||||
|
import { MetaBuilding } from "../meta_building";
|
||||||
|
import { GameRoot } from "../root";
|
||||||
|
import { DisplayComponent } from "../components/display";
|
||||||
|
|
||||||
|
export class MetaDisplayBuilding extends MetaBuilding {
|
||||||
|
constructor() {
|
||||||
|
super("display");
|
||||||
|
}
|
||||||
|
|
||||||
|
getSilhouetteColor() {
|
||||||
|
return "#aaaaaa";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {GameRoot} root
|
||||||
|
*/
|
||||||
|
getIsUnlocked(root) {
|
||||||
|
// @todo
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
getDimensions() {
|
||||||
|
return new Vector(1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the entity at the given location
|
||||||
|
* @param {Entity} entity
|
||||||
|
*/
|
||||||
|
setupEntityComponents(entity) {
|
||||||
|
entity.addComponent(
|
||||||
|
new WiredPinsComponent({
|
||||||
|
slots: [
|
||||||
|
{
|
||||||
|
pos: new Vector(0, 0),
|
||||||
|
direction: enumDirection.bottom,
|
||||||
|
type: enumPinSlotType.logicalAcceptor,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
entity.addComponent(new DisplayComponent());
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ import { ConstantSignalComponent } from "./components/constant_signal";
|
||||||
import { LogicGateComponent } from "./components/logic_gate";
|
import { LogicGateComponent } from "./components/logic_gate";
|
||||||
import { LeverComponent } from "./components/lever";
|
import { LeverComponent } from "./components/lever";
|
||||||
import { WireTunnelComponent } from "./components/wire_tunnel";
|
import { WireTunnelComponent } from "./components/wire_tunnel";
|
||||||
|
import { DisplayComponent } from "./components/display";
|
||||||
|
|
||||||
export function initComponentRegistry() {
|
export function initComponentRegistry() {
|
||||||
gComponentRegistry.register(StaticMapEntityComponent);
|
gComponentRegistry.register(StaticMapEntityComponent);
|
||||||
|
@ -33,6 +34,7 @@ export function initComponentRegistry() {
|
||||||
gComponentRegistry.register(LogicGateComponent);
|
gComponentRegistry.register(LogicGateComponent);
|
||||||
gComponentRegistry.register(LeverComponent);
|
gComponentRegistry.register(LeverComponent);
|
||||||
gComponentRegistry.register(WireTunnelComponent);
|
gComponentRegistry.register(WireTunnelComponent);
|
||||||
|
gComponentRegistry.register(DisplayComponent);
|
||||||
|
|
||||||
// IMPORTANT ^^^^^ UPDATE ENTITY COMPONENT STORAGE AFTERWARDS
|
// IMPORTANT ^^^^^ UPDATE ENTITY COMPONENT STORAGE AFTERWARDS
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { Component } from "../component";
|
||||||
|
|
||||||
|
export class DisplayComponent extends Component {
|
||||||
|
static getId() {
|
||||||
|
return "Display";
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicateWithoutContents() {
|
||||||
|
return new DisplayComponent();
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ import { ConstantSignalComponent } from "./components/constant_signal";
|
||||||
import { LogicGateComponent } from "./components/logic_gate";
|
import { LogicGateComponent } from "./components/logic_gate";
|
||||||
import { LeverComponent } from "./components/lever";
|
import { LeverComponent } from "./components/lever";
|
||||||
import { WireTunnelComponent } from "./components/wire_tunnel";
|
import { WireTunnelComponent } from "./components/wire_tunnel";
|
||||||
|
import { DisplayComponent } from "./components/display";
|
||||||
/* typehints:end */
|
/* typehints:end */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,6 +74,9 @@ export class EntityComponentStorage {
|
||||||
/** @type {WireTunnelComponent} */
|
/** @type {WireTunnelComponent} */
|
||||||
this.WireTunnel;
|
this.WireTunnel;
|
||||||
|
|
||||||
|
/** @type {DisplayComponent} */
|
||||||
|
this.Display;
|
||||||
|
|
||||||
/* typehints:end */
|
/* typehints:end */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import { WireSystem } from "./systems/wire";
|
||||||
import { ConstantSignalSystem } from "./systems/constant_signal";
|
import { ConstantSignalSystem } from "./systems/constant_signal";
|
||||||
import { LogicGateSystem } from "./systems/logic_gate";
|
import { LogicGateSystem } from "./systems/logic_gate";
|
||||||
import { LeverSystem } from "./systems/lever";
|
import { LeverSystem } from "./systems/lever";
|
||||||
|
import { DisplaySystem } from "./systems/display";
|
||||||
|
|
||||||
const logger = createLogger("game_system_manager");
|
const logger = createLogger("game_system_manager");
|
||||||
|
|
||||||
|
@ -80,6 +81,9 @@ export class GameSystemManager {
|
||||||
/** @type {LeverSystem} */
|
/** @type {LeverSystem} */
|
||||||
lever: null,
|
lever: null,
|
||||||
|
|
||||||
|
/** @type {DisplaySystem} */
|
||||||
|
display: null,
|
||||||
|
|
||||||
/* typehints:end */
|
/* typehints:end */
|
||||||
};
|
};
|
||||||
this.systemUpdateOrder = [];
|
this.systemUpdateOrder = [];
|
||||||
|
@ -137,6 +141,8 @@ export class GameSystemManager {
|
||||||
// Wires must be after all gate, signal etc logic!
|
// Wires must be after all gate, signal etc logic!
|
||||||
add("wire", WireSystem);
|
add("wire", WireSystem);
|
||||||
|
|
||||||
|
add("display", DisplaySystem);
|
||||||
|
|
||||||
logger.log("📦 There are", this.systemUpdateOrder.length, "game systems");
|
logger.log("📦 There are", this.systemUpdateOrder.length, "game systems");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import { enumLayer } from "../../root";
|
||||||
import { HUDBaseToolbar } from "./base_toolbar";
|
import { HUDBaseToolbar } from "./base_toolbar";
|
||||||
import { MetaLeverBuilding } from "../../buildings/lever";
|
import { MetaLeverBuilding } from "../../buildings/lever";
|
||||||
import { MetaFilterBuilding } from "../../buildings/filter";
|
import { MetaFilterBuilding } from "../../buildings/filter";
|
||||||
|
import { MetaDisplayBuilding } from "../../buildings/display";
|
||||||
|
|
||||||
const supportedBuildings = [
|
const supportedBuildings = [
|
||||||
MetaBeltBaseBuilding,
|
MetaBeltBaseBuilding,
|
||||||
|
@ -26,6 +27,7 @@ const supportedBuildings = [
|
||||||
MetaTrashBuilding,
|
MetaTrashBuilding,
|
||||||
MetaLeverBuilding,
|
MetaLeverBuilding,
|
||||||
MetaFilterBuilding,
|
MetaFilterBuilding,
|
||||||
|
MetaDisplayBuilding,
|
||||||
];
|
];
|
||||||
|
|
||||||
export class HUDBuildingsToolbar extends HUDBaseToolbar {
|
export class HUDBuildingsToolbar extends HUDBaseToolbar {
|
||||||
|
|
|
@ -55,12 +55,14 @@ export const KEYMAPPINGS = {
|
||||||
painter: { keyCode: key("9") },
|
painter: { keyCode: key("9") },
|
||||||
trash: { keyCode: key("0") },
|
trash: { keyCode: key("0") },
|
||||||
|
|
||||||
|
lever: { keyCode: key("L") },
|
||||||
|
filter: { keyCode: key("B") },
|
||||||
|
display: { keyCode: key("N") },
|
||||||
|
|
||||||
wire: { keyCode: key("1") },
|
wire: { keyCode: key("1") },
|
||||||
wire_tunnel: { keyCode: key("2") },
|
wire_tunnel: { keyCode: key("2") },
|
||||||
constant_signal: { keyCode: key("3") },
|
constant_signal: { keyCode: key("3") },
|
||||||
logic_gate: { keyCode: key("4") },
|
logic_gate: { keyCode: key("4") },
|
||||||
lever: { keyCode: key("5") },
|
|
||||||
filter: { keyCode: key("6") },
|
|
||||||
},
|
},
|
||||||
|
|
||||||
placement: {
|
placement: {
|
||||||
|
|
|
@ -40,7 +40,7 @@ export class MapChunk {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Which entities this chunk contains, sorted by layer
|
* Which entities this chunk contains, sorted by layer
|
||||||
* @type {Object<enumLayer, Array<Entity>>}
|
* @type {Object<string, Array<Entity>>}
|
||||||
*/
|
*/
|
||||||
this.containedEntitiesByLayer = {
|
this.containedEntitiesByLayer = {
|
||||||
[enumLayer.regular]: [],
|
[enumLayer.regular]: [],
|
||||||
|
|
|
@ -53,6 +53,7 @@ export class MapChunkView extends MapChunk {
|
||||||
systems.miner.drawChunk(parameters, this);
|
systems.miner.drawChunk(parameters, this);
|
||||||
systems.staticMapEntities.drawChunk(parameters, this);
|
systems.staticMapEntities.drawChunk(parameters, this);
|
||||||
systems.lever.drawChunk(parameters, this);
|
systems.lever.drawChunk(parameters, this);
|
||||||
|
systems.display.drawChunk(parameters, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,6 +20,7 @@ import { MetaLogicGateBuilding, enumLogicGateVariants } from "./buildings/logic_
|
||||||
import { MetaLeverBuilding } from "./buildings/lever";
|
import { MetaLeverBuilding } from "./buildings/lever";
|
||||||
import { MetaFilterBuilding } from "./buildings/filter";
|
import { MetaFilterBuilding } from "./buildings/filter";
|
||||||
import { MetaWireTunnelBuilding } from "./buildings/wire_tunnel";
|
import { MetaWireTunnelBuilding } from "./buildings/wire_tunnel";
|
||||||
|
import { MetaDisplayBuilding } from "./buildings/display";
|
||||||
|
|
||||||
const logger = createLogger("building_registry");
|
const logger = createLogger("building_registry");
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ export function initMetaBuildingRegistry() {
|
||||||
gMetaBuildingRegistry.register(MetaLeverBuilding);
|
gMetaBuildingRegistry.register(MetaLeverBuilding);
|
||||||
gMetaBuildingRegistry.register(MetaFilterBuilding);
|
gMetaBuildingRegistry.register(MetaFilterBuilding);
|
||||||
gMetaBuildingRegistry.register(MetaWireTunnelBuilding);
|
gMetaBuildingRegistry.register(MetaWireTunnelBuilding);
|
||||||
|
gMetaBuildingRegistry.register(MetaDisplayBuilding);
|
||||||
|
|
||||||
// Belt
|
// Belt
|
||||||
registerBuildingVariant(1, MetaBeltBaseBuilding, defaultBuildingVariant, 0);
|
registerBuildingVariant(1, MetaBeltBaseBuilding, defaultBuildingVariant, 0);
|
||||||
|
@ -115,6 +117,9 @@ export function initMetaBuildingRegistry() {
|
||||||
// Wire tunnel
|
// Wire tunnel
|
||||||
registerBuildingVariant(39, MetaWireTunnelBuilding);
|
registerBuildingVariant(39, MetaWireTunnelBuilding);
|
||||||
|
|
||||||
|
// Display
|
||||||
|
registerBuildingVariant(40, MetaDisplayBuilding);
|
||||||
|
|
||||||
// Propagate instances
|
// Propagate instances
|
||||||
for (const key in gBuildingVariants) {
|
for (const key in gBuildingVariants) {
|
||||||
gBuildingVariants[key].metaInstance = gMetaBuildingRegistry.findByClass(
|
gBuildingVariants[key].metaInstance = gMetaBuildingRegistry.findByClass(
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
import { globalConfig } from "../../core/config";
|
||||||
|
import { Loader } from "../../core/loader";
|
||||||
|
import { BaseItem, enumItemType } from "../base_item";
|
||||||
|
import { enumColors } from "../colors";
|
||||||
|
import { DisplayComponent } from "../components/display";
|
||||||
|
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||||
|
import { ColorItem, COLOR_ITEM_SINGLETONS } from "../items/color_item";
|
||||||
|
import { MapChunkView } from "../map_chunk_view";
|
||||||
|
import { enumLayer } from "../root";
|
||||||
|
import { BooleanItem } from "../items/boolean_item";
|
||||||
|
|
||||||
|
export class DisplaySystem extends GameSystemWithFilter {
|
||||||
|
constructor(root) {
|
||||||
|
super(root, [DisplayComponent]);
|
||||||
|
|
||||||
|
/** @type {Object<string, import("../../core/draw_utils").AtlasSprite>} */
|
||||||
|
this.displaySprites = {};
|
||||||
|
|
||||||
|
for (const colorId in enumColors) {
|
||||||
|
if (colorId === enumColors.uncolored) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
this.displaySprites[colorId] = Loader.getSprite("sprites/wires/display/" + colorId + ".png");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the color / value a display should show
|
||||||
|
* @param {BaseItem} value
|
||||||
|
* @returns {BaseItem}
|
||||||
|
*/
|
||||||
|
getDisplayItem(value) {
|
||||||
|
if (!value) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (value.getItemType()) {
|
||||||
|
case enumItemType.boolean: {
|
||||||
|
return /** @type {BooleanItem} */ (value).value
|
||||||
|
? COLOR_ITEM_SINGLETONS[enumColors.white]
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
case enumItemType.color: {
|
||||||
|
const item = /**@type {ColorItem} */ (value);
|
||||||
|
return item.color === enumColors.uncolored ? null : item;
|
||||||
|
}
|
||||||
|
|
||||||
|
case enumItemType.shape: {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
assertAlways(false, "Unknown item type: " + value.getItemType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a given chunk
|
||||||
|
* @param {import("../../core/draw_utils").DrawParameters} parameters
|
||||||
|
* @param {MapChunkView} chunk
|
||||||
|
*/
|
||||||
|
drawChunk(parameters, chunk) {
|
||||||
|
const contents = chunk.containedEntitiesByLayer[enumLayer.regular];
|
||||||
|
for (let i = 0; i < contents.length; ++i) {
|
||||||
|
const entity = contents[i];
|
||||||
|
if (entity && entity.components.Display) {
|
||||||
|
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.getItemType() === enumItemType.color) {
|
||||||
|
this.displaySprites[/** @type {ColorItem} */ (value).color].drawCachedCentered(
|
||||||
|
parameters,
|
||||||
|
(origin.x + 0.5) * globalConfig.tileSize,
|
||||||
|
(origin.y + 0.5) * globalConfig.tileSize,
|
||||||
|
globalConfig.tileSize + 3
|
||||||
|
);
|
||||||
|
} else if (value.getItemType() === enumItemType.shape) {
|
||||||
|
// @todo
|
||||||
|
value.draw(
|
||||||
|
(origin.x + 0.5) * globalConfig.tileSize,
|
||||||
|
(origin.y + 0.5) * globalConfig.tileSize,
|
||||||
|
parameters,
|
||||||
|
30
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -581,6 +581,12 @@ buildings:
|
||||||
# TEMP
|
# TEMP
|
||||||
description: Only leaves through items who match exactly the provided shape / color. If you put in a boolean 1, it leaves everything through, if you put in a 0 it will leave nothing through.
|
description: Only leaves through items who match exactly the provided shape / color. If you put in a boolean 1, it leaves everything through, if you put in a 0 it will leave nothing through.
|
||||||
|
|
||||||
|
display:
|
||||||
|
default:
|
||||||
|
name: &display Display
|
||||||
|
# TEMP
|
||||||
|
description: Can be connected on the wires layer to show a color or shape. When inputting a boolean item, the display will be white if the value is 1.
|
||||||
|
|
||||||
storyRewards:
|
storyRewards:
|
||||||
# Those are the rewards gained from completing the store
|
# Those are the rewards gained from completing the store
|
||||||
reward_cutter_and_trash:
|
reward_cutter_and_trash:
|
||||||
|
@ -871,6 +877,7 @@ keybindings:
|
||||||
lever: *lever
|
lever: *lever
|
||||||
filter: *filter
|
filter: *filter
|
||||||
wire_tunnel: *wire_tunnel
|
wire_tunnel: *wire_tunnel
|
||||||
|
display: *display
|
||||||
# ---
|
# ---
|
||||||
|
|
||||||
pipette: Pipette
|
pipette: Pipette
|
||||||
|
|