Added Blueprint sprites and overhauled Wire logic. needs more work to get direction's Reliable
BIN
res_raw/sprites/blueprints/wire_tunnel-double_elbow.png
Executable file
After Width: | Height: | Size: 4.2 KiB |
BIN
res_raw/sprites/blueprints/wire_tunnel-elbow.png
Executable file
After Width: | Height: | Size: 2.8 KiB |
BIN
res_raw/sprites/blueprints/wire_tunnel-straight.png
Executable file
After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 5.4 KiB |
BIN
res_raw/sprites/buildings/wire_tunnel-elbow.png
Executable file
After Width: | Height: | Size: 5.1 KiB |
BIN
res_raw/sprites/buildings/wire_tunnel-straight.png
Executable file
After Width: | Height: | Size: 4.6 KiB |
@ -168,10 +168,10 @@ export class MetaWireBuilding extends MetaBuilding {
|
||||
};
|
||||
|
||||
let flag = 0;
|
||||
flag |= connections.top ? 0x1000 : 0;
|
||||
flag |= connections.right ? 0x100 : 0;
|
||||
flag |= connections.bottom ? 0x10 : 0;
|
||||
flag |= connections.left ? 0x1 : 0;
|
||||
flag |= connections.top ? 0b1000 : 0;
|
||||
flag |= connections.right ? 0b100 : 0;
|
||||
flag |= connections.bottom ? 0b10 : 0;
|
||||
flag |= connections.left ? 0b1 : 0;
|
||||
|
||||
let targetType = enumWireType.forward;
|
||||
|
||||
@ -179,85 +179,85 @@ export class MetaWireBuilding extends MetaBuilding {
|
||||
rotation = 0;
|
||||
|
||||
switch (flag) {
|
||||
case 0x0000:
|
||||
case 0b0000:
|
||||
// Nothing
|
||||
break;
|
||||
|
||||
case 0x0001:
|
||||
case 0b0001:
|
||||
// Left
|
||||
rotation += 90;
|
||||
break;
|
||||
|
||||
case 0x0010:
|
||||
case 0b0010:
|
||||
// Bottom
|
||||
// END
|
||||
break;
|
||||
|
||||
case 0x0011:
|
||||
case 0b0011:
|
||||
// Bottom | Left
|
||||
targetType = enumWireType.turn;
|
||||
rotation += 90;
|
||||
break;
|
||||
|
||||
case 0x0100:
|
||||
case 0b0100:
|
||||
// Right
|
||||
rotation += 90;
|
||||
break;
|
||||
|
||||
case 0x0101:
|
||||
case 0b0101:
|
||||
// Right | Left
|
||||
rotation += 90;
|
||||
break;
|
||||
|
||||
case 0x0110:
|
||||
case 0b0110:
|
||||
// Right | Bottom
|
||||
targetType = enumWireType.turn;
|
||||
break;
|
||||
|
||||
case 0x0111:
|
||||
case 0b0111:
|
||||
// Right | Bottom | Left
|
||||
targetType = enumWireType.split;
|
||||
break;
|
||||
|
||||
case 0x1000:
|
||||
case 0b1000:
|
||||
// Top
|
||||
break;
|
||||
|
||||
case 0x1001:
|
||||
case 0b1001:
|
||||
// Top | Left
|
||||
targetType = enumWireType.turn;
|
||||
rotation += 180;
|
||||
break;
|
||||
|
||||
case 0x1010:
|
||||
case 0b1010:
|
||||
// Top | Bottom
|
||||
break;
|
||||
|
||||
case 0x1011:
|
||||
case 0b1011:
|
||||
// Top | Bottom | Left
|
||||
targetType = enumWireType.split;
|
||||
rotation += 90;
|
||||
break;
|
||||
|
||||
case 0x1100:
|
||||
case 0b1100:
|
||||
// Top | Right
|
||||
targetType = enumWireType.turn;
|
||||
rotation -= 90;
|
||||
break;
|
||||
|
||||
case 0x1101:
|
||||
case 0b1101:
|
||||
// Top | Right | Left
|
||||
targetType = enumWireType.split;
|
||||
rotation += 180;
|
||||
break;
|
||||
|
||||
case 0x1110:
|
||||
case 0b1110:
|
||||
// Top | Right | Bottom
|
||||
targetType = enumWireType.split;
|
||||
rotation -= 90;
|
||||
break;
|
||||
|
||||
case 0x1111:
|
||||
case 0b1111:
|
||||
// Top | Right | Bottom | Left
|
||||
targetType = enumWireType.cross;
|
||||
break;
|
||||
|
@ -2,11 +2,33 @@ import { generateMatrixRotations } from "../../core/utils";
|
||||
import { Vector } from "../../core/vector";
|
||||
import { WireTunnelComponent } from "../components/wire_tunnel";
|
||||
import { Entity } from "../entity";
|
||||
import { MetaBuilding } from "../meta_building";
|
||||
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
||||
import { GameRoot } from "../root";
|
||||
import { enumHubGoalRewards } from "../tutorial_goals";
|
||||
|
||||
const wireTunnelOverlayMatrix = generateMatrixRotations([0, 1, 0, 1, 1, 1, 0, 1, 0]);
|
||||
/** @enum {string} */
|
||||
export const enumWireTunnelVariants = {
|
||||
Elbow: "elbow",
|
||||
Straight: "straight",
|
||||
DoubleElbow: "double_elbow",
|
||||
};
|
||||
|
||||
const wireTunnelsOverlayMatrix = {
|
||||
[defaultBuildingVariant]: generateMatrixRotations([0, 1, 0, 1, 1, 1, 0, 1, 0]),
|
||||
[enumWireTunnelVariants.DoubleElbow]: generateMatrixRotations([0, 1, 0, 1, 1, 1, 0, 1, 0]),
|
||||
[enumWireTunnelVariants.Elbow]: generateMatrixRotations([0, 1, 0, 0, 1, 1, 0, 0, 0]),
|
||||
[enumWireTunnelVariants.Straight]: generateMatrixRotations([0, 1, 0, 0, 1, 0, 0, 1, 0]),
|
||||
};
|
||||
|
||||
/**
|
||||
* @enum {Array<Array<Vector>>}
|
||||
*/
|
||||
export const ConnectionDirections = {
|
||||
[defaultBuildingVariant]: [[new Vector(0, 1), new Vector(0, -1)], [new Vector(-1, 0), new Vector(1, 0)]],
|
||||
[enumWireTunnelVariants.DoubleElbow]: [[new Vector(0, 1), new Vector(1, 0)], [new Vector(0, -1), new Vector(-1, 0)]],
|
||||
[enumWireTunnelVariants.Elbow]: [[new Vector(0, 1), new Vector(1, 0)]],
|
||||
[enumWireTunnelVariants.Straight]: [[new Vector(0, 1), new Vector(0, -1)]],
|
||||
};
|
||||
|
||||
export class MetaWireTunnelBuilding extends MetaBuilding {
|
||||
constructor() {
|
||||
@ -22,6 +44,18 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
||||
*/
|
||||
getIsUnlocked(root) {
|
||||
return root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_wires_painter_and_levers);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {GameRoot} root
|
||||
*/
|
||||
getAvailableVariants(root) {
|
||||
return [defaultBuildingVariant, enumWireTunnelVariants.Elbow, enumWireTunnelVariants.Straight, enumWireTunnelVariants.DoubleElbow];
|
||||
// if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_miner_chainable)) {
|
||||
// return [enumMinerVariants.chainable];
|
||||
// }
|
||||
// return super.getAvailableVariants(root);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -32,13 +66,17 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
getSpecialOverlayRenderMatrix(rotation, rotationVariant, variant, entity) {
|
||||
return wireTunnelOverlayMatrix[rotation];
|
||||
return wireTunnelsOverlayMatrix[variant][rotation];
|
||||
}
|
||||
|
||||
getIsRotateable() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
getStayInPlacementMode() {
|
||||
return true;
|
||||
}
|
||||
|
||||
getDimensions() {
|
||||
return new Vector(1, 1);
|
||||
}
|
||||
@ -53,6 +91,20 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
setupEntityComponents(entity) {
|
||||
entity.addComponent(new WireTunnelComponent());
|
||||
}
|
||||
entity.addComponent(new WireTunnelComponent({Variant: defaultBuildingVariant, Connections: ConnectionDirections[defaultBuildingVariant]}));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Entity} entity
|
||||
* @param {number} rotationVariant
|
||||
* @param {string} variant
|
||||
*/
|
||||
updateVariants(entity, rotationVariant, variant) {
|
||||
if(entity.components.WireTunnel){
|
||||
let a = new Vector(1, 0);
|
||||
//a.rotateInplaceFastMultipleOf90(rotationVariant);
|
||||
entity.components.WireTunnel.UpdateConnections(variant, ConnectionDirections[variant])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,87 @@
|
||||
import { Vector } from "../../core/vector";
|
||||
import { Component } from "../component";
|
||||
import { defaultBuildingVariant } from "../meta_building";
|
||||
|
||||
export class WireTunnelComponent extends Component {
|
||||
static getId() {
|
||||
return "WireTunnel";
|
||||
}
|
||||
static getId() {
|
||||
return "WireTunnel";
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Linked network, only if its not multiple directions
|
||||
* @type {Array<import("../systems/wire").WireNetwork>}
|
||||
*/
|
||||
this.linkedNetworks = [];
|
||||
}
|
||||
constructor({ Variant, Connections = [] }) {
|
||||
super();
|
||||
|
||||
this.Variant = Variant;
|
||||
// /**
|
||||
// * All Connection Directions
|
||||
// * @type {Object.<string, Array<Vector>>} Possibility for a T piece. Should be Irrelevant
|
||||
// */
|
||||
/**
|
||||
* @type {Object.<string, Vector>}
|
||||
*/
|
||||
this.Connections = {};
|
||||
|
||||
this.RebuildConnections(Connections);
|
||||
|
||||
/**
|
||||
* Linked network, only if its not multiple directions
|
||||
* @type {Array<import("../systems/wire").WireNetwork>}
|
||||
*/
|
||||
this.linkedNetworks = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../buildings/wire_tunnel").ConnectionDirections} Connections
|
||||
*/
|
||||
RebuildConnections(Connections) {
|
||||
|
||||
this.Connections = {};
|
||||
for(let i = 0; i < Connections.length; ++i) {
|
||||
assert(Connections[i].length == 2, "Connection Wasn't Continuos");
|
||||
let [a, b] = Connections[i];
|
||||
|
||||
const ahash = a.toString();
|
||||
if(!this.Connections[ahash]) {
|
||||
this.Connections[ahash] = b;
|
||||
}
|
||||
|
||||
const bhash = b.toString();
|
||||
if(!this.Connections[bhash]) {
|
||||
this.Connections[bhash] = a;
|
||||
}
|
||||
}
|
||||
console.log(this.Connections);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} Variant
|
||||
* @param {import("../buildings/wire_tunnel").ConnectionDirections} Connections
|
||||
*/
|
||||
UpdateConnections(Variant, Connections) {
|
||||
if(this.Variant !== Variant){
|
||||
this.Variant = Variant;
|
||||
this.RebuildConnections(Connections)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Space Direction the connection is coming from
|
||||
* @param {Vector} dir
|
||||
*/
|
||||
CanConnect(dir) {
|
||||
return !!this.Connections[dir.toString()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./static_map_entity").StaticMapEntityComponent} staticComp
|
||||
* @param {Vector} input
|
||||
* LocalSpace Direction into the Tunnel
|
||||
*/
|
||||
GetOutputDirection(staticComp, input) {
|
||||
const inputDir = staticComp.unapplyRotationToVector(input); //TODO: Fix the Wierd Shit
|
||||
if(this.CanConnect(inputDir)){
|
||||
return staticComp.applyRotationToVector(this.Connections[inputDir.toString()]);;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -193,6 +193,9 @@ export class GameLogic {
|
||||
* @param {enumDirection} param0.edge The edge to check for
|
||||
*/
|
||||
computeWireEdgeStatus({ wireVariant, tile, edge }) {
|
||||
/**
|
||||
* @type {Vector}
|
||||
*/
|
||||
const offset = enumDirectionToVector[edge];
|
||||
const targetTile = tile.add(offset);
|
||||
|
||||
@ -243,7 +246,8 @@ export class GameLogic {
|
||||
// Check if its a crossing
|
||||
const wireTunnelComp = targetEntity.components.WireTunnel;
|
||||
if (wireTunnelComp) {
|
||||
return true;
|
||||
const inputDir = targetStaticComp.unapplyRotationToVector(offset.rotateFastMultipleOf90(270));
|
||||
return wireTunnelComp.CanConnect(inputDir);
|
||||
}
|
||||
|
||||
// Check if its a wire
|
||||
|
@ -25,7 +25,7 @@ import { MetaTrashBuilding } from "./buildings/trash";
|
||||
import { enumUndergroundBeltVariants, MetaUndergroundBeltBuilding } from "./buildings/underground_belt";
|
||||
import { enumVirtualProcessorVariants, MetaVirtualProcessorBuilding } from "./buildings/virtual_processor";
|
||||
import { MetaWireBuilding } from "./buildings/wire";
|
||||
import { MetaWireTunnelBuilding } from "./buildings/wire_tunnel";
|
||||
import { MetaWireTunnelBuilding, enumWireTunnelVariants } from "./buildings/wire_tunnel";
|
||||
import { buildBuildingCodeCache, gBuildingVariants, registerBuildingVariant } from "./building_codes";
|
||||
import { enumWireVariant } from "./components/wire";
|
||||
import { KEYMAPPINGS } from "./key_action_mapper";
|
||||
@ -150,6 +150,9 @@ export function initMetaBuildingRegistry() {
|
||||
|
||||
// Wire tunnel
|
||||
registerBuildingVariant(39, MetaWireTunnelBuilding);
|
||||
registerBuildingVariant(10000006, MetaWireTunnelBuilding, enumWireTunnelVariants.Elbow);
|
||||
registerBuildingVariant(10000007, MetaWireTunnelBuilding, enumWireTunnelVariants.Straight);
|
||||
registerBuildingVariant(10000008, MetaWireTunnelBuilding, enumWireTunnelVariants.DoubleElbow);
|
||||
|
||||
// Display
|
||||
registerBuildingVariant(40, MetaDisplayBuilding);
|
||||
|
@ -314,7 +314,12 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
newSearchDirections = [staticComp.localDirectionToWorld(slot.direction)];
|
||||
newSearchTile = staticComp.localTileToWorld(slot.pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const tunnelComp = nextEntity.components.WireTunnel;
|
||||
if(tunnelComp){
|
||||
//const outputDir = tunnelComp.GetOutputDirection(staticComp, offset);
|
||||
}
|
||||
|
||||
if (newSearchTile) {
|
||||
// Find new surrounding wire targets
|
||||
@ -396,17 +401,18 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
);
|
||||
|
||||
// Link the initial tile to the initial entities, since it may change
|
||||
/** @type {Array<{entity: Entity, tile: Vector}>} */
|
||||
/** @type {Array<{entity: Entity, tile: Vector, dir: Vector}>} */
|
||||
const contents = [];
|
||||
for (let j = 0; j < initialContents.length; ++j) {
|
||||
contents.push({
|
||||
entity: initialContents[j],
|
||||
tile: initialSearchTile,
|
||||
tile: initialSearchTile,
|
||||
dir: offset
|
||||
});
|
||||
}
|
||||
|
||||
for (let k = 0; k < contents.length; ++k) {
|
||||
const { entity, tile } = contents[k];
|
||||
const { entity, tile, dir } = contents[k];
|
||||
const wireComp = entity.components.Wire;
|
||||
|
||||
// Check for wire
|
||||
@ -458,14 +464,24 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
// Check if it's a tunnel, if so, go to the forwarded item
|
||||
const tunnelComp = entity.components.WireTunnel;
|
||||
if (tunnelComp) {
|
||||
//TODO: Add Additional Tunnel Variants
|
||||
if (visitedTunnels.has(entity.uid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
|
||||
//const localDir = staticComp.worldToLocalTile(tile.sub(offset));
|
||||
//staticComp.localDirectionToWorld();
|
||||
const outputDir = tunnelComp.GetOutputDirection(staticComp, dir);
|
||||
if(!outputDir){
|
||||
continue;
|
||||
}
|
||||
const forwardedTile = staticComp.origin.add(outputDir);
|
||||
|
||||
//TODO: Alter to Allow for different tunnel Types
|
||||
// Compute where this tunnel connects to
|
||||
const forwardedTile = staticComp.origin.add(offset);
|
||||
//const forwardedTile = staticComp.origin.add(offset);
|
||||
VERBOSE_WIRES &&
|
||||
logger.log(
|
||||
" Found tunnel",
|
||||
@ -481,14 +497,15 @@ export class WireSystem extends GameSystemWithFilter {
|
||||
forwardedTile.x,
|
||||
forwardedTile.y
|
||||
);
|
||||
|
||||
|
||||
// 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,
|
||||
tile: forwardedTile,
|
||||
dir: outputDir
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Add the tunnel to the network
|
||||
if (tunnelComp.linkedNetworks.indexOf(network) < 0) {
|
||||
|
@ -642,8 +642,17 @@ buildings:
|
||||
|
||||
wire_tunnel:
|
||||
default:
|
||||
name: &wire_tunnel Wire Crossing
|
||||
name: &wire_tunnel Wire Tunnel
|
||||
description: Allows two wires to cross without connecting to each other.
|
||||
elbow:
|
||||
name: Elbow Tunnel
|
||||
description: Allows a wire to turn a corner without connecting to anything else
|
||||
straight:
|
||||
name: Straight tunnel
|
||||
description: Allows a wire to go straight without connecting to anything else
|
||||
double_elbow:
|
||||
name: Double Elbow Tunnel
|
||||
description: Allows two wires to turn corners without connecting to each other.
|
||||
|
||||
constant_signal:
|
||||
default:
|
||||
|