mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-10 00:31:51 +00:00
Fixed Branch
This commit is contained in:
parent
b3f9354820
commit
95b4b8b50d
@ -13,7 +13,7 @@ $buildingsAndVariants: belt, balancer, underground_belt, underground_belt-tier2,
|
||||
cutter, cutter-quad, rotater, rotater-ccw, stacker, mixer, painter-double, painter-quad, trash, storage,
|
||||
reader, rotater-rotate180, display, wireless_display, wireless_display-remote_control, constant_signal, wire, wire_tunnel, logic_gate-or, logic_gate-not,
|
||||
logic_gate-xor, analyzer, virtual_processor-rotater, virtual_processor-unstacker, item_producer,
|
||||
virtual_processor-stacker, virtual_processor-painter, wire-second, wire-third, painter, painter-mirrored, comparator;
|
||||
virtual_processor-stacker, virtual_processor-painter, wire-second, painter, painter-mirrored, comparator;
|
||||
@each $building in $buildingsAndVariants {
|
||||
[data-icon="building_tutorials/#{$building}.png"] {
|
||||
/* @load-async */
|
||||
|
||||
@ -25,19 +25,16 @@ export const wireOverlayMatrices = {
|
||||
/** @enum {string} */
|
||||
export const wireVariants = {
|
||||
second: "second",
|
||||
third: "third"
|
||||
};
|
||||
|
||||
const enumWireVariantToVariant = {
|
||||
[defaultBuildingVariant]: enumWireVariant.first,
|
||||
[wireVariants.second]: enumWireVariant.second,
|
||||
[wireVariants.third]: enumWireVariant.third,
|
||||
};
|
||||
|
||||
export class MetaWireBuilding extends MetaBuilding {
|
||||
constructor() {
|
||||
super("wire");
|
||||
this.a = "a";
|
||||
}
|
||||
|
||||
getHasDirectionLockAvailable() {
|
||||
@ -49,7 +46,7 @@ export class MetaWireBuilding extends MetaBuilding {
|
||||
}
|
||||
|
||||
getAvailableVariants() {
|
||||
return [defaultBuildingVariant, wireVariants.second, wireVariants.third];
|
||||
return [defaultBuildingVariant, wireVariants.second];
|
||||
}
|
||||
|
||||
getDimensions() {
|
||||
@ -169,95 +166,96 @@ export class MetaWireBuilding extends MetaBuilding {
|
||||
};
|
||||
|
||||
let flag = 0;
|
||||
flag |= connections.top ? 0b1000 : 0;
|
||||
flag |= connections.right ? 0b100 : 0;
|
||||
flag |= connections.bottom ? 0b10 : 0;
|
||||
flag |= connections.left ? 0b1 : 0;
|
||||
flag |= connections.top ? 0x1000 : 0;
|
||||
flag |= connections.right ? 0x100 : 0;
|
||||
flag |= connections.bottom ? 0x10 : 0;
|
||||
flag |= connections.left ? 0x1 : 0;
|
||||
|
||||
let targetType = enumWireType.forward;
|
||||
|
||||
// First, reset rotation
|
||||
rotation = 0;
|
||||
|
||||
switch (flag) {
|
||||
case 0b0000:
|
||||
case 0x0000:
|
||||
// Nothing
|
||||
break;
|
||||
|
||||
case 0b0001:
|
||||
case 0x0001:
|
||||
// Left
|
||||
rotation += 90;
|
||||
break;
|
||||
|
||||
case 0b0010:
|
||||
case 0x0010:
|
||||
// Bottom
|
||||
// END
|
||||
break;
|
||||
|
||||
case 0b0011:
|
||||
case 0x0011:
|
||||
// Bottom | Left
|
||||
targetType = enumWireType.turn;
|
||||
rotation += 90;
|
||||
break;
|
||||
|
||||
case 0b0100:
|
||||
case 0x0100:
|
||||
// Right
|
||||
rotation += 90;
|
||||
break;
|
||||
|
||||
case 0b0101:
|
||||
case 0x0101:
|
||||
// Right | Left
|
||||
rotation += 90;
|
||||
break;
|
||||
|
||||
case 0b0110:
|
||||
case 0x0110:
|
||||
// Right | Bottom
|
||||
targetType = enumWireType.turn;
|
||||
break;
|
||||
|
||||
case 0b0111:
|
||||
case 0x0111:
|
||||
// Right | Bottom | Left
|
||||
targetType = enumWireType.split;
|
||||
break;
|
||||
|
||||
case 0b1000:
|
||||
case 0x1000:
|
||||
// Top
|
||||
break;
|
||||
|
||||
case 0b1001:
|
||||
case 0x1001:
|
||||
// Top | Left
|
||||
targetType = enumWireType.turn;
|
||||
rotation += 180;
|
||||
break;
|
||||
|
||||
case 0b1010:
|
||||
case 0x1010:
|
||||
// Top | Bottom
|
||||
break;
|
||||
|
||||
case 0b1011:
|
||||
case 0x1011:
|
||||
// Top | Bottom | Left
|
||||
targetType = enumWireType.split;
|
||||
rotation += 90;
|
||||
break;
|
||||
|
||||
case 0b1100:
|
||||
case 0x1100:
|
||||
// Top | Right
|
||||
targetType = enumWireType.turn;
|
||||
rotation -= 90;
|
||||
break;
|
||||
|
||||
case 0b1101:
|
||||
case 0x1101:
|
||||
// Top | Right | Left
|
||||
targetType = enumWireType.split;
|
||||
rotation += 180;
|
||||
break;
|
||||
|
||||
case 0b1110:
|
||||
case 0x1110:
|
||||
// Top | Right | Bottom
|
||||
targetType = enumWireType.split;
|
||||
rotation -= 90;
|
||||
break;
|
||||
|
||||
case 0b1111:
|
||||
case 0x1111:
|
||||
// Top | Right | Bottom | Left
|
||||
targetType = enumWireType.cross;
|
||||
break;
|
||||
@ -269,4 +267,4 @@ export class MetaWireBuilding extends MetaBuilding {
|
||||
rotationVariant: arrayWireRotationVariantToType.indexOf(targetType),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,47 +1,12 @@
|
||||
import { generateMatrixRotations } from "../../core/utils";
|
||||
import {
|
||||
arrayAllDirections,
|
||||
enumDirection,
|
||||
enumDirectionToVector,
|
||||
enumInvertedDirections,
|
||||
Vector,
|
||||
} from "../../core/vector";
|
||||
import { Vector } from "../../core/vector";
|
||||
import { WireTunnelComponent } from "../components/wire_tunnel";
|
||||
import { Entity } from "../entity";
|
||||
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
||||
import { MetaBuilding } from "../meta_building";
|
||||
import { GameRoot } from "../root";
|
||||
import { enumHubGoalRewards } from "../tutorial_goals";
|
||||
|
||||
/** @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 of Objects containing the Tunnel Variant Connections
|
||||
* @enum {Object.<string, Vector>}
|
||||
*/
|
||||
export const ConnectionDirections = {
|
||||
[defaultBuildingVariant]: BuildConnections([
|
||||
[new Vector(0, 1), new Vector(0, 1)],
|
||||
[new Vector(1, 0), new Vector(1, 0)],
|
||||
]),
|
||||
[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)]]),
|
||||
};
|
||||
const wireTunnelOverlayMatrix = generateMatrixRotations([0, 1, 0, 1, 1, 1, 0, 1, 0]);
|
||||
|
||||
export class MetaWireTunnelBuilding extends MetaBuilding {
|
||||
constructor() {
|
||||
@ -60,33 +25,18 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {GameRoot} root
|
||||
*/
|
||||
getAvailableVariants(root) {
|
||||
return [
|
||||
defaultBuildingVariant,
|
||||
enumWireTunnelVariants.Elbow,
|
||||
enumWireTunnelVariants.Straight,
|
||||
enumWireTunnelVariants.DoubleElbow,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} rotation
|
||||
* @param {number} rotationVariant
|
||||
* @param {string} variant
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
getSpecialOverlayRenderMatrix(rotation, rotationVariant, variant, entity) {
|
||||
return wireTunnelsOverlayMatrix[variant][rotation];
|
||||
return wireTunnelOverlayMatrix[rotation];
|
||||
}
|
||||
|
||||
getIsRotateable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
getStayInPlacementMode() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
getDimensions() {
|
||||
@ -103,50 +53,6 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
||||
* @param {Entity} entity
|
||||
*/
|
||||
setupEntityComponents(entity) {
|
||||
entity.addComponent(
|
||||
new WireTunnelComponent({
|
||||
Connections: ConnectionDirections[defaultBuildingVariant],
|
||||
})
|
||||
);
|
||||
entity.addComponent(new WireTunnelComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Entity} entity
|
||||
* @param {number} rotationVariant
|
||||
* @param {string} variant
|
||||
*/
|
||||
updateVariants(entity, rotationVariant, variant) {
|
||||
if (entity.components.WireTunnel) {
|
||||
entity.components.WireTunnel.UpdateConnections(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;
|
||||
}
|
||||
}
|
||||
@ -12,7 +12,6 @@ export const enumWireType = {
|
||||
export const enumWireVariant = {
|
||||
first: "first",
|
||||
second: "second",
|
||||
third: "third",
|
||||
};
|
||||
|
||||
export class WireComponent extends Component {
|
||||
@ -40,4 +39,4 @@ export class WireComponent extends Component {
|
||||
*/
|
||||
this.linkedNetwork = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,28 +1,13 @@
|
||||
import {
|
||||
arrayAllDirections,
|
||||
enumDirection,
|
||||
enumDirectionToVector,
|
||||
enumInvertedDirections,
|
||||
Vector,
|
||||
} from "../../core/vector";
|
||||
|
||||
import { Component } from "../component";
|
||||
import { defaultBuildingVariant } from "../meta_building";
|
||||
|
||||
export class WireTunnelComponent extends Component {
|
||||
static getId() {
|
||||
return "WireTunnel";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {{Connections: Object.<string, Vector>}} Elements
|
||||
*/
|
||||
constructor({ Connections = {} }) {
|
||||
constructor() {
|
||||
super();
|
||||
/**
|
||||
* @type {Object.<string, Vector>}
|
||||
*/
|
||||
this.Connections = Connections;
|
||||
|
||||
/**
|
||||
* Linked network, only if its not multiple directions
|
||||
@ -30,48 +15,4 @@ export class WireTunnelComponent extends Component {
|
||||
*/
|
||||
this.linkedNetworks = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object.<string, Vector>} Connections
|
||||
*/
|
||||
UpdateConnections(Connections) {
|
||||
this.Connections = 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()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the Tunnel accepts inputs from the given direction
|
||||
* @param {import("./static_map_entity").StaticMapEntityComponent} staticComp
|
||||
* Static Map Entity Component
|
||||
* @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) {
|
||||
const inputDir = staticComp.unapplyRotationToVector(input);
|
||||
if (this.CanConnect(inputDir)) {
|
||||
let out = this.Connections[inputDir.toString()];
|
||||
return staticComp.applyRotationToVector(out);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -124,12 +124,6 @@ export function initMetaBuildingRegistry() {
|
||||
registerBuildingVariant(53, MetaWireBuilding, enumWireVariant.second, 1);
|
||||
registerBuildingVariant(54, MetaWireBuilding, enumWireVariant.second, 2);
|
||||
registerBuildingVariant(55, MetaWireBuilding, enumWireVariant.second, 3);
|
||||
|
||||
//TODO: CHANGE BEFORE RELEASE
|
||||
registerBuildingVariant(10000002, MetaWireBuilding, enumWireVariant.third, 0); //Temporary ID to avoid id collisions in development.
|
||||
registerBuildingVariant(10000003, MetaWireBuilding, enumWireVariant.third, 1);
|
||||
registerBuildingVariant(10000004, MetaWireBuilding, enumWireVariant.third, 2);
|
||||
registerBuildingVariant(10000005, MetaWireBuilding, enumWireVariant.third, 3);
|
||||
|
||||
// Constant signal
|
||||
registerBuildingVariant(31, MetaConstantSignalBuilding);
|
||||
@ -152,9 +146,6 @@ 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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user