mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Fixed bug with Transistors and Formatted Code
This commit is contained in:
parent
c2983a9770
commit
fbd8e2e7e7
@ -1,5 +1,11 @@
|
|||||||
import { generateMatrixRotations } from "../../core/utils";
|
import { generateMatrixRotations } from "../../core/utils";
|
||||||
import { Vector } from "../../core/vector";
|
import {
|
||||||
|
arrayAllDirections,
|
||||||
|
enumDirection,
|
||||||
|
enumDirectionToVector,
|
||||||
|
enumInvertedDirections,
|
||||||
|
Vector,
|
||||||
|
} from "../../core/vector";
|
||||||
import { WireTunnelComponent } from "../components/wire_tunnel";
|
import { WireTunnelComponent } from "../components/wire_tunnel";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
||||||
@ -21,13 +27,20 @@ const wireTunnelsOverlayMatrix = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum {Array<Array<Vector>>}
|
* Enum of Objects containing the Tunnel Variant Connections
|
||||||
|
* @enum {Object.<string, Vector>}
|
||||||
*/
|
*/
|
||||||
export const ConnectionDirections = {
|
export const ConnectionDirections = {
|
||||||
[defaultBuildingVariant]: [[new Vector(0, 1), new Vector(0, 1)], [new Vector(1, 0), new Vector(1, 0)]],
|
[defaultBuildingVariant]: BuildConnections([
|
||||||
[enumWireTunnelVariants.DoubleElbow]: [[new Vector(0, 1), new Vector(1, 0)], [new Vector(0, -1), new Vector(-1, 0)]],
|
[new Vector(0, 1), new Vector(0, 1)],
|
||||||
[enumWireTunnelVariants.Elbow]: [[new Vector(0, 1), new Vector(1, 0)]],
|
[new Vector(1, 0), new Vector(1, 0)],
|
||||||
[enumWireTunnelVariants.Straight]: [[new Vector(0, 1), new Vector(0, 1)]],
|
]),
|
||||||
|
[enumWireTunnelVariants.DoubleElbow]: BuildConnections([
|
||||||
|
[new Vector(0, 1), new Vector(1, 0)],
|
||||||
|
[new Vector(0, -1), new Vector(-1, 0)],
|
||||||
|
]),
|
||||||
|
[enumWireTunnelVariants.Elbow]: BuildConnections([[new Vector(0, 1), new Vector(1, 0)]]),
|
||||||
|
[enumWireTunnelVariants.Straight]: BuildConnections([[new Vector(0, 1), new Vector(0, 1)]]),
|
||||||
};
|
};
|
||||||
|
|
||||||
export class MetaWireTunnelBuilding extends MetaBuilding {
|
export class MetaWireTunnelBuilding extends MetaBuilding {
|
||||||
@ -44,22 +57,21 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
|||||||
*/
|
*/
|
||||||
getIsUnlocked(root) {
|
getIsUnlocked(root) {
|
||||||
return root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_wires_painter_and_levers);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @param {GameRoot} root
|
||||||
|
*/
|
||||||
|
getAvailableVariants(root) {
|
||||||
|
return [
|
||||||
|
defaultBuildingVariant,
|
||||||
|
enumWireTunnelVariants.Elbow,
|
||||||
|
enumWireTunnelVariants.Straight,
|
||||||
|
enumWireTunnelVariants.DoubleElbow,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* @param {number} rotation
|
* @param {number} rotation
|
||||||
* @param {number} rotationVariant
|
* @param {number} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
@ -73,10 +85,10 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
getStayInPlacementMode() {
|
getStayInPlacementMode() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDimensions() {
|
getDimensions() {
|
||||||
return new Vector(1, 1);
|
return new Vector(1, 1);
|
||||||
}
|
}
|
||||||
@ -91,19 +103,50 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
|||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
*/
|
*/
|
||||||
setupEntityComponents(entity) {
|
setupEntityComponents(entity) {
|
||||||
entity.addComponent(new WireTunnelComponent({Variant: defaultBuildingVariant, Connections: ConnectionDirections[defaultBuildingVariant]}));
|
entity.addComponent(
|
||||||
}
|
new WireTunnelComponent({
|
||||||
|
Connections: ConnectionDirections[defaultBuildingVariant],
|
||||||
/**
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {number} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant, variant) {
|
updateVariants(entity, rotationVariant, variant) {
|
||||||
if(entity.components.WireTunnel){
|
if (entity.components.WireTunnel) {
|
||||||
//a.rotateInplaceFastMultipleOf90(rotationVariant);
|
entity.components.WireTunnel.UpdateConnections(ConnectionDirections[variant]);
|
||||||
entity.components.WireTunnel.UpdateConnections(variant, ConnectionDirections[variant])
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the Connection Graph object from the input Array
|
||||||
|
* @param {Array<Array<Vector>>} Connections
|
||||||
|
* @returns {Object.<string, Vector>}
|
||||||
|
*/
|
||||||
|
function BuildConnections(Connections) {
|
||||||
|
/**
|
||||||
|
* @type {Object.<string, Vector>}
|
||||||
|
*/
|
||||||
|
let res = {};
|
||||||
|
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 (!res[ahash]) {
|
||||||
|
res[ahash] = b;
|
||||||
|
}
|
||||||
|
let alta = a.rotateFastMultipleOf90(180);
|
||||||
|
let altb = b.rotateFastMultipleOf90(180);
|
||||||
|
const bhash = altb.toString();
|
||||||
|
if (!res[bhash]) {
|
||||||
|
res[bhash] = alta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -1,89 +1,77 @@
|
|||||||
import { Vector } from "../../core/vector";
|
import {
|
||||||
|
arrayAllDirections,
|
||||||
|
enumDirection,
|
||||||
|
enumDirectionToVector,
|
||||||
|
enumInvertedDirections,
|
||||||
|
Vector,
|
||||||
|
} from "../../core/vector";
|
||||||
import { Component } from "../component";
|
import { Component } from "../component";
|
||||||
import { defaultBuildingVariant } from "../meta_building";
|
import { defaultBuildingVariant } from "../meta_building";
|
||||||
|
|
||||||
export class WireTunnelComponent extends Component {
|
export class WireTunnelComponent extends Component {
|
||||||
static getId() {
|
static getId() {
|
||||||
return "WireTunnel";
|
return "WireTunnel";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
*
|
||||||
|
* @param {{Connections: Object.<string, Vector>}} Elements
|
||||||
|
*/
|
||||||
|
constructor({ Connections = {} }) {
|
||||||
|
super();
|
||||||
|
/**
|
||||||
|
* @type {Object.<string, Vector>}
|
||||||
|
*/
|
||||||
|
this.Connections = Connections;
|
||||||
|
|
||||||
constructor({ Variant, Connections = [] }) {
|
/**
|
||||||
super();
|
* Linked network, only if its not multiple directions
|
||||||
|
* @type {Array<import("../systems/wire").WireNetwork>}
|
||||||
|
*/
|
||||||
|
this.linkedNetworks = [];
|
||||||
|
}
|
||||||
|
|
||||||
this.Variant = Variant;
|
/**
|
||||||
// /**
|
* @param {Object.<string, Vector>} Connections
|
||||||
// * All Connection Directions
|
*/
|
||||||
// * @type {Object.<string, Array<Vector>>} Possibility for a T piece. Should be Irrelevant
|
UpdateConnections(Connections) {
|
||||||
// */
|
this.Connections = Connections;
|
||||||
/**
|
}
|
||||||
* @type {Object.<string, Vector>}
|
|
||||||
*/
|
|
||||||
this.Connections = {};
|
|
||||||
|
|
||||||
this.RebuildConnections(Connections);
|
/**
|
||||||
|
* Returns if the Tunnel accepts inputs from the given direction
|
||||||
|
* @param {Vector} dir
|
||||||
|
* Local Space Vector into the Tunnel
|
||||||
|
*/
|
||||||
|
CanConnect(dir) {
|
||||||
|
return !!this.Connections[dir.toString()];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Linked network, only if its not multiple directions
|
* Returns if the Tunnel accepts inputs from the given direction
|
||||||
* @type {Array<import("../systems/wire").WireNetwork>}
|
* @param {import("./static_map_entity").StaticMapEntityComponent} staticComp
|
||||||
*/
|
* Static Map Entity Component
|
||||||
this.linkedNetworks = [];
|
* @param {Vector} dir
|
||||||
}
|
* World space Vector into the Tunnel
|
||||||
|
*/
|
||||||
|
CanConnectWorld(staticComp, dir) {
|
||||||
|
const inputDir = staticComp.unapplyRotationToVector(dir);
|
||||||
|
return !!this.Connections[inputDir.toString()];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import("../buildings/wire_tunnel").ConnectionDirections} Connections
|
* Returns the Worldspace Vector out from the Tunnel or Null
|
||||||
*/
|
* @param {import("./static_map_entity").StaticMapEntityComponent} staticComp
|
||||||
RebuildConnections(Connections) {
|
* Static Map Entity Component
|
||||||
|
* @param {Vector|null} input
|
||||||
this.Connections = {};
|
* Worldspace Direction into the Tunnel
|
||||||
for(let i = 0; i < Connections.length; ++i) {
|
*/
|
||||||
assert(Connections[i].length == 2, "Connection Wasn't Continuos");
|
GetOutputDirection(staticComp, input) {
|
||||||
let [a, b] = Connections[i];
|
const inputDir = staticComp.unapplyRotationToVector(input);
|
||||||
|
if (this.CanConnect(inputDir)) {
|
||||||
const ahash = a.toString();
|
let out = this.Connections[inputDir.toString()];
|
||||||
if(!this.Connections[ahash]) {
|
return staticComp.applyRotationToVector(out);
|
||||||
this.Connections[ahash] = b;
|
}
|
||||||
}
|
return null;
|
||||||
let alta = a.rotateFastMultipleOf90(180);
|
}
|
||||||
let altb = b.rotateFastMultipleOf90(180);
|
|
||||||
const bhash = altb.toString();
|
|
||||||
if(!this.Connections[bhash]) {
|
|
||||||
this.Connections[bhash] = alta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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)){
|
|
||||||
let out = this.Connections[inputDir.toString()];
|
|
||||||
return staticComp.applyRotationToVector(out);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -193,9 +193,9 @@ export class GameLogic {
|
|||||||
* @param {enumDirection} param0.edge The edge to check for
|
* @param {enumDirection} param0.edge The edge to check for
|
||||||
*/
|
*/
|
||||||
computeWireEdgeStatus({ wireVariant, tile, edge }) {
|
computeWireEdgeStatus({ wireVariant, tile, edge }) {
|
||||||
/**
|
/**
|
||||||
* @type {Vector}
|
* @type {Vector}
|
||||||
*/
|
*/
|
||||||
const offset = enumDirectionToVector[edge];
|
const offset = enumDirectionToVector[edge];
|
||||||
const targetTile = tile.add(offset);
|
const targetTile = tile.add(offset);
|
||||||
|
|
||||||
@ -246,8 +246,7 @@ export class GameLogic {
|
|||||||
// Check if its a tunnel
|
// Check if its a tunnel
|
||||||
const wireTunnelComp = targetEntity.components.WireTunnel;
|
const wireTunnelComp = targetEntity.components.WireTunnel;
|
||||||
if (wireTunnelComp) {
|
if (wireTunnelComp) {
|
||||||
const inputDir = targetStaticComp.unapplyRotationToVector(offset);
|
return wireTunnelComp.CanConnectWorld(targetStaticComp, offset);
|
||||||
return wireTunnelComp.CanConnect(inputDir);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if its a wire
|
// Check if its a wire
|
||||||
|
@ -314,12 +314,12 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
newSearchDirections = [staticComp.localDirectionToWorld(slot.direction)];
|
newSearchDirections = [staticComp.localDirectionToWorld(slot.direction)];
|
||||||
newSearchTile = staticComp.localTileToWorld(slot.pos);
|
newSearchTile = staticComp.localTileToWorld(slot.pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const tunnelComp = nextEntity.components.WireTunnel;
|
const tunnelComp = nextEntity.components.WireTunnel;
|
||||||
if(tunnelComp){
|
if (tunnelComp) {
|
||||||
//const outputDir = tunnelComp.GetOutputDirection(staticComp, offset);
|
//const outputDir = tunnelComp.GetOutputDirection(staticComp, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newSearchTile) {
|
if (newSearchTile) {
|
||||||
// Find new surrounding wire targets
|
// Find new surrounding wire targets
|
||||||
@ -369,7 +369,7 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
* @param {Vector} initialTile
|
* @param {Vector} initialTile
|
||||||
* @param {Array<enumDirection>} directions
|
* @param {Array<enumDirection>} directions
|
||||||
* @param {WireNetwork} network
|
* @param {WireNetwork} network
|
||||||
* @param {enumWireVariant=} variantMask Only accept connections to this mask
|
* @param {enumWireVariant} variantMask Only accept connections to this mask
|
||||||
* @returns {Array<any>}
|
* @returns {Array<any>}
|
||||||
*/
|
*/
|
||||||
findSurroundingWireTargets(initialTile, directions, network, variantMask = null) {
|
findSurroundingWireTargets(initialTile, directions, network, variantMask = null) {
|
||||||
@ -406,8 +406,8 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
for (let j = 0; j < initialContents.length; ++j) {
|
for (let j = 0; j < initialContents.length; ++j) {
|
||||||
contents.push({
|
contents.push({
|
||||||
entity: initialContents[j],
|
entity: initialContents[j],
|
||||||
tile: initialSearchTile,
|
tile: initialSearchTile,
|
||||||
dir: offset
|
dir: offset,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,8 +444,17 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the direction (inverted) matches
|
// Check if the direction (inverted) matches
|
||||||
const pinDirection = staticComp.localDirectionToWorld(slot.direction);
|
// const pinDirection = staticComp.localDirectionToWorld(slot.direction);
|
||||||
if (pinDirection !== enumInvertedDirections[direction]) {
|
// if (pinDirection !== enumInvertedDirections[direction]) {
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// /**
|
||||||
|
// * @type {Vector}
|
||||||
|
// */
|
||||||
|
const worldDir = staticComp.localDirectionToWorld(slot.direction);
|
||||||
|
const invDir = enumInvertedDirections[worldDir];
|
||||||
|
const pinDirection = enumDirectionToVector[invDir];
|
||||||
|
if (!pinDirection.equals(dir)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,15 +478,15 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const staticComp = entity.components.StaticMapEntity;
|
const staticComp = entity.components.StaticMapEntity;
|
||||||
|
|
||||||
//const localDir = staticComp.worldToLocalTile(tile.sub(offset));
|
//const localDir = staticComp.worldToLocalTile(tile.sub(offset));
|
||||||
//staticComp.localDirectionToWorld();
|
//staticComp.localDirectionToWorld();
|
||||||
const outputDir = tunnelComp.GetOutputDirection(staticComp, dir);
|
const outputDir = tunnelComp.GetOutputDirection(staticComp, dir);
|
||||||
if(!outputDir){
|
if (!outputDir) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const forwardedTile = staticComp.origin.add(outputDir);
|
const forwardedTile = staticComp.origin.add(outputDir);
|
||||||
|
|
||||||
//TODO: Alter to Allow for different tunnel Types
|
//TODO: Alter to Allow for different tunnel Types
|
||||||
// Compute where this tunnel connects to
|
// Compute where this tunnel connects to
|
||||||
@ -497,15 +506,15 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
forwardedTile.x,
|
forwardedTile.x,
|
||||||
forwardedTile.y
|
forwardedTile.y
|
||||||
);
|
);
|
||||||
|
|
||||||
// Attach the entities and the tile we search at, because it may change
|
// Attach the entities and the tile we search at, because it may change
|
||||||
for (let h = 0; h < connectedContents.length; ++h) {
|
for (let h = 0; h < connectedContents.length; ++h) {
|
||||||
contents.push({
|
contents.push({
|
||||||
entity: connectedContents[h],
|
entity: connectedContents[h],
|
||||||
tile: forwardedTile,
|
tile: forwardedTile,
|
||||||
dir: outputDir
|
dir: outputDir,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the tunnel to the network
|
// Add the tunnel to the network
|
||||||
if (tunnelComp.linkedNetworks.indexOf(network) < 0) {
|
if (tunnelComp.linkedNetworks.indexOf(network) < 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user