1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Improve wire auto-connect

This commit is contained in:
tobspr
2020-08-12 20:11:24 +02:00
parent f16ab2389a
commit f65b3728ed
34 changed files with 1051 additions and 804 deletions

View File

@@ -5,6 +5,7 @@ import { Entity } from "../entity";
import { formatBigNumber } from "../../core/utils";
import { Loader } from "../../core/loader";
import { T } from "../../translations";
import { ShapeItem } from "../items/shape_item";
export class HubSystem extends GameSystemWithFilter {
constructor(root) {
@@ -17,7 +18,14 @@ export class HubSystem extends GameSystemWithFilter {
this.forEachMatchingEntityOnScreen(parameters, this.drawEntity.bind(this));
}
update() {}
update() {
for (let i = 0; i < this.allEntities.length; ++i) {
// Set hub goal
const entity = this.allEntities[i];
const pinsComp = entity.components.WiredPins;
pinsComp.slots[0].value = new ShapeItem(this.root.hubGoals.currentGoal.definition);
}
}
/**
* @param {DrawParameters} parameters

View File

@@ -17,6 +17,7 @@ export class WireSystem extends GameSystemWithFilter {
[enumWireType.regular]: Loader.getSprite("sprites/buildings/wire.png"),
[enumWireType.turn]: Loader.getSprite("sprites/buildings/wire-turn.png"),
[enumWireType.split]: Loader.getSprite("sprites/buildings/wire-split.png"),
[enumWireType.cross]: Loader.getSprite("sprites/buildings/wire-cross.png"),
};
this.root.signals.entityDestroyed.add(this.updateSurroundingWirePlacement, this);
@@ -36,7 +37,36 @@ export class WireSystem extends GameSystemWithFilter {
if (entity && entity.components.Wire) {
const wireType = entity.components.Wire.type;
const sprite = this.wireSprites[wireType];
entity.components.StaticMapEntity.drawSpriteOnFullEntityBounds(parameters, sprite, 0);
assert(sprite, "Unknown wire type: " + wireType);
const staticComp = entity.components.StaticMapEntity;
staticComp.drawSpriteOnFullEntityBounds(parameters, sprite, 0);
if (G_IS_DEV && globalConfig.debug.renderWireRotations) {
parameters.context.fillStyle = "red";
parameters.context.font = "5px Tahoma";
parameters.context.fillText(
"" + staticComp.originalRotation,
staticComp.origin.x * globalConfig.tileSize,
staticComp.origin.y * globalConfig.tileSize + 5
);
parameters.context.fillStyle = "rgba(255, 0, 0, 0.2)";
if (staticComp.originalRotation % 180 === 0) {
parameters.context.fillRect(
(staticComp.origin.x + 0.5) * globalConfig.tileSize,
staticComp.origin.y * globalConfig.tileSize,
3,
globalConfig.tileSize
);
} else {
parameters.context.fillRect(
staticComp.origin.x * globalConfig.tileSize,
(staticComp.origin.y + 0.5) * globalConfig.tileSize,
globalConfig.tileSize,
3
);
}
}
}
}
}

View File

@@ -179,6 +179,12 @@ export class WiredPinsSystem extends GameSystemWithFilter {
offsetX: 0,
offsetY: 0,
});
// Draw contained item to visualize whats emitted
const value = slot.value;
if (value) {
value.draw(worldPos.x, worldPos.y, parameters, 12);
}
}
}
}