mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Add wire coating
This commit is contained in:
@@ -318,9 +318,9 @@ input {
|
||||
|
||||
canvas {
|
||||
pointer-events: all;
|
||||
image-rendering: pixelated;
|
||||
// image-rendering: pixelated;
|
||||
// &.smoothed {
|
||||
// }
|
||||
// }1
|
||||
// &.unsmoothed {
|
||||
// }
|
||||
letter-spacing: 0 !important;
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
import { Vector } from "../../core/vector";
|
||||
import { Entity } from "../entity";
|
||||
import { MetaBuilding } from "../meta_building";
|
||||
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
||||
import { GameRoot, enumLayer } from "../root";
|
||||
import { WireTunnelComponent } from "../components/wire_tunnel";
|
||||
import { generateMatrixRotations } from "../../core/utils";
|
||||
|
||||
/** @enum {string} */
|
||||
export const enumWireTunnelVariants = {
|
||||
coating: "coating",
|
||||
};
|
||||
|
||||
const wireTunnelOverlayMatrices = {
|
||||
[defaultBuildingVariant]: generateMatrixRotations([0, 1, 0, 1, 1, 1, 0, 1, 0]),
|
||||
[enumWireTunnelVariants.coating]: generateMatrixRotations([0, 1, 0, 0, 1, 0, 0, 1, 0]),
|
||||
};
|
||||
|
||||
export class MetaWireTunnelBuilding extends MetaBuilding {
|
||||
constructor() {
|
||||
@@ -10,7 +21,7 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
||||
}
|
||||
|
||||
getSilhouetteColor() {
|
||||
return "#25fff2";
|
||||
return "#777a86";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -21,23 +32,55 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
||||
return true;
|
||||
}
|
||||
|
||||
getIsRotateable() {
|
||||
return false;
|
||||
/**
|
||||
*
|
||||
* @param {number} rotation
|
||||
* @param {number} rotationVariant
|
||||
* @param {string} variant
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
getSpecialOverlayRenderMatrix(rotation, rotationVariant, variant, entity) {
|
||||
return wireTunnelOverlayMatrices[variant][rotation];
|
||||
}
|
||||
|
||||
getIsRotateable(variant) {
|
||||
return variant !== defaultBuildingVariant;
|
||||
}
|
||||
|
||||
getDimensions() {
|
||||
return new Vector(1, 1);
|
||||
}
|
||||
|
||||
getAvailableVariants() {
|
||||
return [defaultBuildingVariant, enumWireTunnelVariants.coating];
|
||||
}
|
||||
|
||||
getLayer() {
|
||||
return enumLayer.wires;
|
||||
}
|
||||
|
||||
getRotateAutomaticallyWhilePlacing() {
|
||||
return true;
|
||||
}
|
||||
|
||||
getStayInPlacementMode() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the entity at the given location
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
setupEntityComponents(entity) {
|
||||
entity.addComponent(new WireTunnelComponent());
|
||||
entity.addComponent(new WireTunnelComponent({}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Entity} entity
|
||||
* @param {number} rotationVariant
|
||||
* @param {string} variant
|
||||
*/
|
||||
updateVariants(entity, rotationVariant, variant) {
|
||||
entity.components.WireTunnel.multipleDirections = variant === defaultBuildingVariant;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,15 @@ export class WireTunnelComponent extends Component {
|
||||
}
|
||||
|
||||
duplicateWithoutContents() {
|
||||
return new WireTunnelComponent();
|
||||
return new WireTunnelComponent({ multipleDirections: this.multipleDirections });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {object} param0
|
||||
* @param {boolean=} param0.multipleDirections
|
||||
*/
|
||||
constructor({ multipleDirections = true }) {
|
||||
super();
|
||||
this.multipleDirections = multipleDirections;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { createLogger } from "../core/logging";
|
||||
import { STOP_PROPAGATION } from "../core/signal";
|
||||
import { round2Digits } from "../core/utils";
|
||||
import {
|
||||
enumDirection,
|
||||
enumDirectionToAngle,
|
||||
enumDirectionToVector,
|
||||
enumInvertedDirections,
|
||||
Vector,
|
||||
} from "../core/vector";
|
||||
import { enumDirection, enumDirectionToVector, enumInvertedDirections, Vector } from "../core/vector";
|
||||
import { Entity } from "./entity";
|
||||
import { MetaBuilding } from "./meta_building";
|
||||
import { enumLayer, GameRoot } from "./root";
|
||||
@@ -17,7 +11,6 @@ const logger = createLogger("ingame/logic");
|
||||
/** @enum {number} */
|
||||
export const enumWireEdgeFlag = {
|
||||
empty: 0,
|
||||
filled: 1,
|
||||
connected: 2,
|
||||
};
|
||||
|
||||
@@ -215,10 +208,6 @@ export class GameLogic {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (neighbourStatus === enumWireEdgeFlag.filled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (neighbourStatus === enumWireEdgeFlag.connected) {
|
||||
return true;
|
||||
}
|
||||
@@ -273,10 +262,21 @@ export class GameLogic {
|
||||
return enumWireEdgeFlag.empty;
|
||||
}
|
||||
|
||||
const targetStaticComp = targetEntity.components.StaticMapEntity;
|
||||
|
||||
// Check if its a crossing
|
||||
const wireTunnelComp = targetEntity.components.WireTunnel;
|
||||
if (wireTunnelComp) {
|
||||
return enumWireEdgeFlag.filled;
|
||||
// Check if the crossing is connected
|
||||
if (wireTunnelComp.multipleDirections) {
|
||||
return enumWireEdgeFlag.connected;
|
||||
} else {
|
||||
// Its a coating, check if it matches the direction
|
||||
const referenceDirection = targetStaticComp.localDirectionToWorld(enumDirection.top);
|
||||
return referenceDirection === edge || enumInvertedDirections[referenceDirection] === edge
|
||||
? enumWireEdgeFlag.connected
|
||||
: enumWireEdgeFlag.empty;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if its a wire
|
||||
@@ -285,15 +285,9 @@ export class GameLogic {
|
||||
return enumWireEdgeFlag.empty;
|
||||
}
|
||||
|
||||
const refAngle = enumDirectionToAngle[edge];
|
||||
const refRotation = targetEntity.components.StaticMapEntity.originalRotation;
|
||||
const canConnectRemotely = refRotation === refAngle || (refRotation + 180) % 360 === refAngle;
|
||||
|
||||
// Check if the wire points towards the right direction
|
||||
if (!canConnectRemotely) {
|
||||
// Seems its not the right direction - well, still its filled
|
||||
return enumWireEdgeFlag.filled;
|
||||
}
|
||||
// const refAngle = enumDirectionToAngle[edge];
|
||||
// const refRotation = targetEntity.components.StaticMapEntity.originalRotation;
|
||||
// const canConnectRemotely = refRotation === refAngle || (refRotation + 180) % 360 === refAngle;
|
||||
|
||||
// Actually connected
|
||||
return enumWireEdgeFlag.connected;
|
||||
|
||||
@@ -19,7 +19,7 @@ import { MetaConstantSignalBuilding } from "./buildings/constant_signal";
|
||||
import { MetaLogicGateBuilding, enumLogicGateVariants } from "./buildings/logic_gate";
|
||||
import { MetaLeverBuilding } from "./buildings/lever";
|
||||
import { MetaFilterBuilding } from "./buildings/filter";
|
||||
import { MetaWireTunnelBuilding } from "./buildings/wire_tunnel";
|
||||
import { MetaWireTunnelBuilding, enumWireTunnelVariants } from "./buildings/wire_tunnel";
|
||||
import { MetaDisplayBuilding } from "./buildings/display";
|
||||
|
||||
const logger = createLogger("building_registry");
|
||||
@@ -116,6 +116,7 @@ export function initMetaBuildingRegistry() {
|
||||
|
||||
// Wire tunnel
|
||||
registerBuildingVariant(39, MetaWireTunnelBuilding);
|
||||
registerBuildingVariant(41, MetaWireTunnelBuilding, enumWireTunnelVariants.coating);
|
||||
|
||||
// Display
|
||||
registerBuildingVariant(40, MetaDisplayBuilding);
|
||||
|
||||
@@ -125,7 +125,7 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
if (!this.root.gameInitialized) {
|
||||
return;
|
||||
}
|
||||
if (entity.components.Wire || entity.components.WiredPins) {
|
||||
if (entity.components.Wire || entity.components.WiredPins || entity.components.WireTunnel) {
|
||||
this.needsRecompute = true;
|
||||
this.networks = [];
|
||||
}
|
||||
@@ -335,6 +335,7 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
);
|
||||
|
||||
// Link the initial tile to the initial entities, since it may change
|
||||
/** @type {Array<{entity: Entity, tile: Vector}>} */
|
||||
const contents = [];
|
||||
for (let j = 0; j < initialContents.length; ++j) {
|
||||
contents.push({
|
||||
@@ -384,40 +385,59 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Pin slots mean it can be nothing else
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if its a tunnel, if so, go to the forwarded item
|
||||
if (entity.components.WireTunnel) {
|
||||
if (!visitedTunnels.has(entity.uid)) {
|
||||
// Compute where this tunnel connects to
|
||||
const forwardedTile = entity.components.StaticMapEntity.origin.add(offset);
|
||||
VERBOSE_WIRES &&
|
||||
logger.log(
|
||||
" Found tunnel",
|
||||
entity.uid,
|
||||
"at",
|
||||
tile,
|
||||
"-> forwarding to",
|
||||
forwardedTile
|
||||
);
|
||||
const tunnelComp = entity.components.WireTunnel;
|
||||
if (tunnelComp) {
|
||||
if (visitedTunnels.has(entity.uid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Figure out which entities are connected
|
||||
const connectedContents = this.root.map.getLayersContentsMultipleXY(
|
||||
forwardedTile.x,
|
||||
forwardedTile.y
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
|
||||
if (
|
||||
!tunnelComp.multipleDirections &&
|
||||
!(
|
||||
direction === staticComp.localDirectionToWorld(enumDirection.top) ||
|
||||
direction === staticComp.localDirectionToWorld(enumDirection.bottom)
|
||||
)
|
||||
) {
|
||||
// It's a coating, and it doesn't connect here
|
||||
continue;
|
||||
}
|
||||
|
||||
// Compute where this tunnel connects to
|
||||
const forwardedTile = staticComp.origin.add(offset);
|
||||
VERBOSE_WIRES &&
|
||||
logger.log(
|
||||
" Found tunnel",
|
||||
entity.uid,
|
||||
"at",
|
||||
tile,
|
||||
"-> forwarding to",
|
||||
forwardedTile
|
||||
);
|
||||
|
||||
// Attach the entities and the tile we search at, because it may change
|
||||
for (let h = 0; h < connectedContents.length; ++h) {
|
||||
contents.push({
|
||||
entity: connectedContents[h],
|
||||
tile: forwardedTile,
|
||||
});
|
||||
}
|
||||
// Figure out which entities are connected
|
||||
const connectedContents = this.root.map.getLayersContentsMultipleXY(
|
||||
forwardedTile.x,
|
||||
forwardedTile.y
|
||||
);
|
||||
|
||||
// Remember this tunnel
|
||||
visitedTunnels.add(entity.uid);
|
||||
// Attach the entities and the tile we search at, because it may change
|
||||
for (let h = 0; h < connectedContents.length; ++h) {
|
||||
contents.push({
|
||||
entity: connectedContents[h],
|
||||
tile: forwardedTile,
|
||||
});
|
||||
}
|
||||
|
||||
// Remember this tunnel
|
||||
visitedTunnels.add(entity.uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user