mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Wireless Displays!!
This commit is contained in:
parent
5df1c330fd
commit
ee28cb8435
@ -208,7 +208,15 @@ export class FormElementItemChooser extends FormElement {
|
|||||||
canvas.width = 128;
|
canvas.width = 128;
|
||||||
canvas.height = 128;
|
canvas.height = 128;
|
||||||
const context = canvas.getContext("2d");
|
const context = canvas.getContext("2d");
|
||||||
item.drawFullSizeOnCanvas(context, 128);
|
if (typeof item == "string") {
|
||||||
|
context.fillStyle = "#000000";
|
||||||
|
context.font = "64px sans-serif"
|
||||||
|
context.textAlign = "center";
|
||||||
|
context.fillText(item, 32, 32, 128);
|
||||||
|
console.log(context);
|
||||||
|
} else {
|
||||||
|
item.drawFullSizeOnCanvas(context, 128);
|
||||||
|
}
|
||||||
this.element.appendChild(canvas);
|
this.element.appendChild(canvas);
|
||||||
|
|
||||||
const detector = new ClickDetector(canvas, {});
|
const detector = new ClickDetector(canvas, {});
|
||||||
|
@ -6,11 +6,6 @@ import { GameRoot } from "../root";
|
|||||||
import { WirelessDisplayComponent } from "../components/wireless_display";
|
import { WirelessDisplayComponent } from "../components/wireless_display";
|
||||||
import { enumHubGoalRewards } from "../tutorial_goals";
|
import { enumHubGoalRewards } from "../tutorial_goals";
|
||||||
import { formatItemsPerSecond, generateMatrixRotations } from "../../core/utils";
|
import { formatItemsPerSecond, generateMatrixRotations } from "../../core/utils";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
|
||||||
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
|
||||||
import { T } from "../../translations";
|
|
||||||
import { BeltUnderlaysComponent } from "../components/belt_underlays";
|
|
||||||
|
|
||||||
|
|
||||||
/** @enum {string} */
|
/** @enum {string} */
|
||||||
@ -65,7 +60,7 @@ export class MetaWirelessDisplayBuilding extends MetaBuilding {
|
|||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
*/
|
*/
|
||||||
setupEntityComponents(entity) {
|
setupEntityComponents(entity) {
|
||||||
|
entity.addComponent(new WirelessDisplayComponent({}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,40 @@
|
|||||||
import { Component } from "../component";
|
import { Component } from "../component";
|
||||||
|
import { types } from "../../savegame/serialization";
|
||||||
|
import { BaseItem } from "../base_item";
|
||||||
|
import { typeItemSingleton } from "../item_resolver";
|
||||||
|
|
||||||
export class WirelessDisplayComponent extends Component {
|
export class WirelessDisplayComponent extends Component {
|
||||||
static getId() {
|
static getId() {
|
||||||
return "Wiresless_Display";
|
return "WirelessDisplay";
|
||||||
|
}
|
||||||
|
|
||||||
|
static getWirelessCode() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static getSchema() {
|
||||||
|
return {
|
||||||
|
signal: types.nullable(typeItemSingleton),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy the current state to another component
|
||||||
|
* @param {WirelessDisplayComponent} otherComponent
|
||||||
|
*/
|
||||||
|
copyAdditionalStateTo(otherComponent) {
|
||||||
|
otherComponent.signal = this.signal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {object} param0
|
||||||
|
* @param {BaseItem=} param0.signal The signal to store
|
||||||
|
*/
|
||||||
|
constructor({ signal = null }) {
|
||||||
|
super();
|
||||||
|
this.signal = signal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,6 +64,11 @@ export class Entity extends BasicSerializableObject {
|
|||||||
* @type {string} */
|
* @type {string} */
|
||||||
this.destroyReason;
|
this.destroyReason;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores wireless code of this entity
|
||||||
|
*/
|
||||||
|
this.wireless_code = 0;
|
||||||
|
|
||||||
/* typehints:end */
|
/* typehints:end */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +89,9 @@ export class GameSystemManager {
|
|||||||
/** @type {DisplaySystem} */
|
/** @type {DisplaySystem} */
|
||||||
display: null,
|
display: null,
|
||||||
|
|
||||||
|
/** @type {WirelessDisplaySystem} */
|
||||||
|
wirelessDisplay: null,
|
||||||
|
|
||||||
/** @type {ItemProcessorOverlaysSystem} */
|
/** @type {ItemProcessorOverlaysSystem} */
|
||||||
itemProcessorOverlays: null,
|
itemProcessorOverlays: null,
|
||||||
|
|
||||||
@ -163,6 +166,7 @@ export class GameSystemManager {
|
|||||||
add("beltReader", BeltReaderSystem);
|
add("beltReader", BeltReaderSystem);
|
||||||
|
|
||||||
add("display", DisplaySystem);
|
add("display", DisplaySystem);
|
||||||
|
add("wirelessDisplay", WirelessDisplaySystem);
|
||||||
|
|
||||||
add("itemProcessorOverlays", ItemProcessorOverlaysSystem);
|
add("itemProcessorOverlays", ItemProcessorOverlaysSystem);
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ export class MapChunkView extends MapChunk {
|
|||||||
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);
|
systems.display.drawChunk(parameters, this);
|
||||||
|
systems.wirelessDisplay.drawChunk(parameters, this);
|
||||||
systems.storage.drawChunk(parameters, this);
|
systems.storage.drawChunk(parameters, this);
|
||||||
systems.itemProcessorOverlays.drawChunk(parameters, this);
|
systems.itemProcessorOverlays.drawChunk(parameters, this);
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,6 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (itemInput.chosenItem) {
|
if (itemInput.chosenItem) {
|
||||||
console.log(itemInput.chosenItem);
|
|
||||||
constantComp.signal = itemInput.chosenItem;
|
constantComp.signal = itemInput.chosenItem;
|
||||||
} else {
|
} else {
|
||||||
constantComp.signal = this.parseSignalCode(signalValueInput.getValue());
|
constantComp.signal = this.parseSignalCode(signalValueInput.getValue());
|
||||||
|
@ -7,11 +7,23 @@ import { GameSystemWithFilter } from "../game_system_with_filter";
|
|||||||
import { isTrueItem } from "../items/boolean_item";
|
import { isTrueItem } from "../items/boolean_item";
|
||||||
import { ColorItem, COLOR_ITEM_SINGLETONS } from "../items/color_item";
|
import { ColorItem, COLOR_ITEM_SINGLETONS } from "../items/color_item";
|
||||||
import { MapChunkView } from "../map_chunk_view";
|
import { MapChunkView } from "../map_chunk_view";
|
||||||
|
import trim from "trim";
|
||||||
|
import { THIRDPARTY_URLS } from "../../core/config";
|
||||||
|
import { DialogWithForm } from "../../core/modal_dialog_elements";
|
||||||
|
import { FormElementInput, FormElementItemChooser } from "../../core/modal_dialog_forms";
|
||||||
|
import { fillInLinkIntoTranslation } from "../../core/utils";
|
||||||
|
import { T } from "../../translations";
|
||||||
|
import { Entity } from "../entity";
|
||||||
|
import { ShapeDefinition } from "../shape_definition";
|
||||||
|
import { BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON } from "../items/boolean_item";
|
||||||
|
import { init } from "logrocket";
|
||||||
|
|
||||||
export class WirelessDisplaySystem extends GameSystemWithFilter {
|
export class WirelessDisplaySystem extends GameSystemWithFilter {
|
||||||
constructor(root) {
|
constructor(root) {
|
||||||
super(root, [WirelessDisplayComponent]);
|
super(root, [WirelessDisplayComponent]);
|
||||||
|
|
||||||
|
this.root.signals.entityManuallyPlaced.add(this.channelSignalValue, this);
|
||||||
|
|
||||||
/** @type {Object<string, import("../../core/draw_utils").AtlasSprite>} */
|
/** @type {Object<string, import("../../core/draw_utils").AtlasSprite>} */
|
||||||
this.displaySprites = {};
|
this.displaySprites = {};
|
||||||
|
|
||||||
@ -21,6 +33,88 @@ export class WirelessDisplaySystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
this.displaySprites[colorId] = Loader.getSprite("sprites/wires/display/" + colorId + ".png");
|
this.displaySprites[colorId] = Loader.getSprite("sprites/wires/display/" + colorId + ".png");
|
||||||
}
|
}
|
||||||
|
this.wirelessMachineList = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asks the entity to enter a valid signal code
|
||||||
|
* @param {Entity} entity
|
||||||
|
*/
|
||||||
|
channelSignalValue(entity) {
|
||||||
|
if (entity.components.WirelessDisplay) {
|
||||||
|
// Ok, query, but also save the uid because it could get stale
|
||||||
|
const uid = entity.uid;
|
||||||
|
|
||||||
|
const signalValueInput = new FormElementInput({
|
||||||
|
id: "channelValue",
|
||||||
|
label: fillInLinkIntoTranslation(T.dialogs.editChannel.descShortKey, THIRDPARTY_URLS.shapeViewer),
|
||||||
|
placeholder: "",
|
||||||
|
defaultValue: "",
|
||||||
|
validator: val => val,
|
||||||
|
});
|
||||||
|
|
||||||
|
const channeldialog = new DialogWithForm({
|
||||||
|
app: this.root.app,
|
||||||
|
title: T.dialogs.editChannel.title,
|
||||||
|
desc: T.dialogs.editChannel.descItems,
|
||||||
|
formElements: [signalValueInput],
|
||||||
|
buttons: ["cancel:bad:escape", "ok:good:enter"],
|
||||||
|
closeButton: false,
|
||||||
|
});
|
||||||
|
this.root.hud.parts.dialogs.internalShowDialog(channeldialog);
|
||||||
|
|
||||||
|
// When confirmed, set the signal
|
||||||
|
const closeHandler = () => {
|
||||||
|
if (!this.root || !this.root.entityMgr) {
|
||||||
|
// Game got stopped
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const entityRef = this.root.entityMgr.findByUid(uid, false);
|
||||||
|
if (!entityRef) {
|
||||||
|
// outdated
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const constantComp = entityRef.components.WirelessDisplay;
|
||||||
|
if (!constantComp) {
|
||||||
|
// no longer interesting
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (signalValueInput.getValue() && !entity.components.WiredPins){
|
||||||
|
entity.wireless_code = signalValueInput.getValue();
|
||||||
|
} else if (signalValueInput.getValue() && entity.components.WiredPins){
|
||||||
|
entity.wireless_code = signalValueInput.getValue();
|
||||||
|
this.wirelessMachineList.push(entity);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
channeldialog.buttonSignals.ok.add(closeHandler);
|
||||||
|
channeldialog.valueChosen.add(closeHandler);
|
||||||
|
|
||||||
|
// When cancelled, destroy the entity again
|
||||||
|
channeldialog.buttonSignals.cancel.add(() => {
|
||||||
|
if (!this.root || !this.root.entityMgr) {
|
||||||
|
// Game got stopped
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const entityRef = this.root.entityMgr.findByUid(uid, false);
|
||||||
|
if (!entityRef) {
|
||||||
|
// outdated
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const constantComp = entityRef.components.WirelessDisplay;
|
||||||
|
if (!constantComp) {
|
||||||
|
// no longer interesting
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.root.logic.tryDeleteBuilding(entityRef);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,38 +154,46 @@ export class WirelessDisplaySystem extends GameSystemWithFilter {
|
|||||||
drawChunk(parameters, chunk) {
|
drawChunk(parameters, chunk) {
|
||||||
const contents = chunk.containedEntitiesByLayer.regular;
|
const contents = chunk.containedEntitiesByLayer.regular;
|
||||||
for (let i = 0; i < contents.length; ++i) {
|
for (let i = 0; i < contents.length; ++i) {
|
||||||
const entity = contents[i];
|
const entity_a = contents[i];
|
||||||
if (entity && entity.components.Display) {
|
if (entity_a && !entity_a.components.WiredPins && entity_a.components.WirelessDisplay) {
|
||||||
const pinsComp = entity.components.WiredPins;
|
for (let j = 0; j < this.wirelessMachineList.length; ++j) {
|
||||||
const network = pinsComp.slots[0].linkedNetwork;
|
const entity_b = this.wirelessMachineList[j];
|
||||||
|
if (entity_a.wireless_code == entity_b.wireless_code) {
|
||||||
|
const origin = entity_a.components.StaticMapEntity.origin;
|
||||||
|
const pinsComp = entity_b.components.WiredPins;
|
||||||
|
const network = pinsComp.slots[0].linkedNetwork;
|
||||||
|
|
||||||
if (!network || !network.hasValue()) {
|
if (!network || !network.hasValue()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const value = this.getDisplayItem(network.currentValue);
|
const value = this.getDisplayItem(network.currentValue);
|
||||||
|
|
||||||
if (!value) {
|
if (!value) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const origin = entity.components.StaticMapEntity.origin;
|
if (value.getItemType()) {
|
||||||
if (value.getItemType() === "color") {
|
if (value.getItemType() === "color") {
|
||||||
this.displaySprites[/** @type {ColorItem} */ (value).color].drawCachedCentered(
|
this.displaySprites[/** @type {ColorItem} */ (value).color].drawCachedCentered(
|
||||||
parameters,
|
parameters,
|
||||||
(origin.x + 0.5) * globalConfig.tileSize,
|
(origin.x + 0.5) * globalConfig.tileSize,
|
||||||
(origin.y + 0.5) * globalConfig.tileSize,
|
(origin.y + 0.5) * globalConfig.tileSize,
|
||||||
globalConfig.tileSize
|
globalConfig.tileSize
|
||||||
);
|
);
|
||||||
} else if (value.getItemType() === "shape") {
|
} else if (value.getItemType() === "shape") {
|
||||||
value.drawItemCenteredClipped(
|
value.drawItemCenteredClipped(
|
||||||
(origin.x + 0.5) * globalConfig.tileSize,
|
(origin.x + 0.5) * globalConfig.tileSize,
|
||||||
(origin.y + 0.5) * globalConfig.tileSize,
|
(origin.y + 0.5) * globalConfig.tileSize,
|
||||||
parameters,
|
parameters,
|
||||||
30
|
30
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,6 +255,12 @@ dialogs:
|
|||||||
titleEdit: Edit Marker
|
titleEdit: Edit Marker
|
||||||
desc: Give it a meaningful name, you can also include a <strong>short key</strong> of a shape (Which you can generate <link>here</link>)
|
desc: Give it a meaningful name, you can also include a <strong>short key</strong> of a shape (Which you can generate <link>here</link>)
|
||||||
|
|
||||||
|
editChannel:
|
||||||
|
title: Set Channel
|
||||||
|
descItems: >-
|
||||||
|
Enter used <strong>channel name</strong>
|
||||||
|
descShortKey: or enter new <strong>channel name</strong>
|
||||||
|
|
||||||
editSignal:
|
editSignal:
|
||||||
title: Set Signal
|
title: Set Signal
|
||||||
descItems: >-
|
descItems: >-
|
||||||
|
Loading…
Reference in New Issue
Block a user