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 {
|
||||||
@ -47,19 +60,18 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param {GameRoot} root
|
* @param {GameRoot} root
|
||||||
*/
|
*/
|
||||||
getAvailableVariants(root) {
|
getAvailableVariants(root) {
|
||||||
return [defaultBuildingVariant, enumWireTunnelVariants.Elbow, enumWireTunnelVariants.Straight, enumWireTunnelVariants.DoubleElbow];
|
return [
|
||||||
// if (root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_miner_chainable)) {
|
defaultBuildingVariant,
|
||||||
// return [enumMinerVariants.chainable];
|
enumWireTunnelVariants.Elbow,
|
||||||
// }
|
enumWireTunnelVariants.Straight,
|
||||||
// return super.getAvailableVariants(root);
|
enumWireTunnelVariants.DoubleElbow,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param {number} rotation
|
* @param {number} rotation
|
||||||
* @param {number} rotationVariant
|
* @param {number} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
@ -91,7 +103,11 @@ 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],
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,8 +118,35 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
|||||||
*/
|
*/
|
||||||
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,27 +1,28 @@
|
|||||||
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";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor({ Variant, Connections = [] }) {
|
/**
|
||||||
|
*
|
||||||
|
* @param {{Connections: Object.<string, Vector>}} Elements
|
||||||
|
*/
|
||||||
|
constructor({ Connections = {} }) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.Variant = Variant;
|
|
||||||
// /**
|
|
||||||
// * All Connection Directions
|
|
||||||
// * @type {Object.<string, Array<Vector>>} Possibility for a T piece. Should be Irrelevant
|
|
||||||
// */
|
|
||||||
/**
|
/**
|
||||||
* @type {Object.<string, Vector>}
|
* @type {Object.<string, Vector>}
|
||||||
*/
|
*/
|
||||||
this.Connections = {};
|
this.Connections = Connections;
|
||||||
|
|
||||||
this.RebuildConnections(Connections);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Linked network, only if its not multiple directions
|
* Linked network, only if its not multiple directions
|
||||||
@ -31,55 +32,42 @@ export class WireTunnelComponent extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import("../buildings/wire_tunnel").ConnectionDirections} Connections
|
* @param {Object.<string, Vector>} Connections
|
||||||
*/
|
*/
|
||||||
RebuildConnections(Connections) {
|
UpdateConnections(Connections) {
|
||||||
|
this.Connections = 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;
|
|
||||||
}
|
|
||||||
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
|
* Returns if the Tunnel accepts inputs from the given direction
|
||||||
* @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
|
* @param {Vector} dir
|
||||||
|
* Local Space Vector into the Tunnel
|
||||||
*/
|
*/
|
||||||
CanConnect(dir) {
|
CanConnect(dir) {
|
||||||
return !!this.Connections[dir.toString()];
|
return !!this.Connections[dir.toString()];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Returns if the Tunnel accepts inputs from the given direction
|
||||||
* @param {import("./static_map_entity").StaticMapEntityComponent} staticComp
|
* @param {import("./static_map_entity").StaticMapEntityComponent} staticComp
|
||||||
* @param {Vector} input
|
* Static Map Entity Component
|
||||||
* LocalSpace Direction into the Tunnel
|
* @param {Vector} dir
|
||||||
|
* World space Vector into the Tunnel
|
||||||
|
*/
|
||||||
|
CanConnectWorld(staticComp, dir) {
|
||||||
|
const inputDir = staticComp.unapplyRotationToVector(dir);
|
||||||
|
return !!this.Connections[inputDir.toString()];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Worldspace Vector out from the Tunnel or Null
|
||||||
|
* @param {import("./static_map_entity").StaticMapEntityComponent} staticComp
|
||||||
|
* Static Map Entity Component
|
||||||
|
* @param {Vector|null} input
|
||||||
|
* Worldspace Direction into the Tunnel
|
||||||
*/
|
*/
|
||||||
GetOutputDirection(staticComp, input) {
|
GetOutputDirection(staticComp, input) {
|
||||||
const inputDir = staticComp.unapplyRotationToVector(input); //TODO: Fix the Wierd Shit
|
const inputDir = staticComp.unapplyRotationToVector(input);
|
||||||
if (this.CanConnect(inputDir)) {
|
if (this.CanConnect(inputDir)) {
|
||||||
let out = this.Connections[inputDir.toString()];
|
let out = this.Connections[inputDir.toString()];
|
||||||
return staticComp.applyRotationToVector(out);
|
return staticComp.applyRotationToVector(out);
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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) {
|
||||||
@ -407,7 +407,7 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,7 +512,7 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
contents.push({
|
contents.push({
|
||||||
entity: connectedContents[h],
|
entity: connectedContents[h],
|
||||||
tile: forwardedTile,
|
tile: forwardedTile,
|
||||||
dir: outputDir
|
dir: outputDir,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user