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,
|
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,
|
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,
|
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 {
|
@each $building in $buildingsAndVariants {
|
||||||
[data-icon="building_tutorials/#{$building}.png"] {
|
[data-icon="building_tutorials/#{$building}.png"] {
|
||||||
/* @load-async */
|
/* @load-async */
|
||||||
|
|||||||
@ -25,19 +25,16 @@ export const wireOverlayMatrices = {
|
|||||||
/** @enum {string} */
|
/** @enum {string} */
|
||||||
export const wireVariants = {
|
export const wireVariants = {
|
||||||
second: "second",
|
second: "second",
|
||||||
third: "third"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const enumWireVariantToVariant = {
|
const enumWireVariantToVariant = {
|
||||||
[defaultBuildingVariant]: enumWireVariant.first,
|
[defaultBuildingVariant]: enumWireVariant.first,
|
||||||
[wireVariants.second]: enumWireVariant.second,
|
[wireVariants.second]: enumWireVariant.second,
|
||||||
[wireVariants.third]: enumWireVariant.third,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export class MetaWireBuilding extends MetaBuilding {
|
export class MetaWireBuilding extends MetaBuilding {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("wire");
|
super("wire");
|
||||||
this.a = "a";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getHasDirectionLockAvailable() {
|
getHasDirectionLockAvailable() {
|
||||||
@ -49,7 +46,7 @@ export class MetaWireBuilding extends MetaBuilding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAvailableVariants() {
|
getAvailableVariants() {
|
||||||
return [defaultBuildingVariant, wireVariants.second, wireVariants.third];
|
return [defaultBuildingVariant, wireVariants.second];
|
||||||
}
|
}
|
||||||
|
|
||||||
getDimensions() {
|
getDimensions() {
|
||||||
@ -169,95 +166,96 @@ export class MetaWireBuilding extends MetaBuilding {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let flag = 0;
|
let flag = 0;
|
||||||
flag |= connections.top ? 0b1000 : 0;
|
flag |= connections.top ? 0x1000 : 0;
|
||||||
flag |= connections.right ? 0b100 : 0;
|
flag |= connections.right ? 0x100 : 0;
|
||||||
flag |= connections.bottom ? 0b10 : 0;
|
flag |= connections.bottom ? 0x10 : 0;
|
||||||
flag |= connections.left ? 0b1 : 0;
|
flag |= connections.left ? 0x1 : 0;
|
||||||
|
|
||||||
let targetType = enumWireType.forward;
|
let targetType = enumWireType.forward;
|
||||||
|
|
||||||
// First, reset rotation
|
// First, reset rotation
|
||||||
rotation = 0;
|
rotation = 0;
|
||||||
|
|
||||||
switch (flag) {
|
switch (flag) {
|
||||||
case 0b0000:
|
case 0x0000:
|
||||||
// Nothing
|
// Nothing
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b0001:
|
case 0x0001:
|
||||||
// Left
|
// Left
|
||||||
rotation += 90;
|
rotation += 90;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b0010:
|
case 0x0010:
|
||||||
// Bottom
|
// Bottom
|
||||||
// END
|
// END
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b0011:
|
case 0x0011:
|
||||||
// Bottom | Left
|
// Bottom | Left
|
||||||
targetType = enumWireType.turn;
|
targetType = enumWireType.turn;
|
||||||
rotation += 90;
|
rotation += 90;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b0100:
|
case 0x0100:
|
||||||
// Right
|
// Right
|
||||||
rotation += 90;
|
rotation += 90;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b0101:
|
case 0x0101:
|
||||||
// Right | Left
|
// Right | Left
|
||||||
rotation += 90;
|
rotation += 90;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b0110:
|
case 0x0110:
|
||||||
// Right | Bottom
|
// Right | Bottom
|
||||||
targetType = enumWireType.turn;
|
targetType = enumWireType.turn;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b0111:
|
case 0x0111:
|
||||||
// Right | Bottom | Left
|
// Right | Bottom | Left
|
||||||
targetType = enumWireType.split;
|
targetType = enumWireType.split;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b1000:
|
case 0x1000:
|
||||||
// Top
|
// Top
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b1001:
|
case 0x1001:
|
||||||
// Top | Left
|
// Top | Left
|
||||||
targetType = enumWireType.turn;
|
targetType = enumWireType.turn;
|
||||||
rotation += 180;
|
rotation += 180;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b1010:
|
case 0x1010:
|
||||||
// Top | Bottom
|
// Top | Bottom
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b1011:
|
case 0x1011:
|
||||||
// Top | Bottom | Left
|
// Top | Bottom | Left
|
||||||
targetType = enumWireType.split;
|
targetType = enumWireType.split;
|
||||||
rotation += 90;
|
rotation += 90;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b1100:
|
case 0x1100:
|
||||||
// Top | Right
|
// Top | Right
|
||||||
targetType = enumWireType.turn;
|
targetType = enumWireType.turn;
|
||||||
rotation -= 90;
|
rotation -= 90;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b1101:
|
case 0x1101:
|
||||||
// Top | Right | Left
|
// Top | Right | Left
|
||||||
targetType = enumWireType.split;
|
targetType = enumWireType.split;
|
||||||
rotation += 180;
|
rotation += 180;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b1110:
|
case 0x1110:
|
||||||
// Top | Right | Bottom
|
// Top | Right | Bottom
|
||||||
targetType = enumWireType.split;
|
targetType = enumWireType.split;
|
||||||
rotation -= 90;
|
rotation -= 90;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0b1111:
|
case 0x1111:
|
||||||
// Top | Right | Bottom | Left
|
// Top | Right | Bottom | Left
|
||||||
targetType = enumWireType.cross;
|
targetType = enumWireType.cross;
|
||||||
break;
|
break;
|
||||||
@ -269,4 +267,4 @@ export class MetaWireBuilding extends MetaBuilding {
|
|||||||
rotationVariant: arrayWireRotationVariantToType.indexOf(targetType),
|
rotationVariant: arrayWireRotationVariantToType.indexOf(targetType),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,47 +1,12 @@
|
|||||||
import { generateMatrixRotations } from "../../core/utils";
|
import { generateMatrixRotations } from "../../core/utils";
|
||||||
import {
|
import { Vector } from "../../core/vector";
|
||||||
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 } from "../meta_building";
|
||||||
import { GameRoot } from "../root";
|
import { GameRoot } from "../root";
|
||||||
import { enumHubGoalRewards } from "../tutorial_goals";
|
import { enumHubGoalRewards } from "../tutorial_goals";
|
||||||
|
|
||||||
/** @enum {string} */
|
const wireTunnelOverlayMatrix = generateMatrixRotations([0, 1, 0, 1, 1, 1, 0, 1, 0]);
|
||||||
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)]]),
|
|
||||||
};
|
|
||||||
|
|
||||||
export class MetaWireTunnelBuilding extends MetaBuilding {
|
export class MetaWireTunnelBuilding extends MetaBuilding {
|
||||||
constructor() {
|
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} rotation
|
||||||
* @param {number} rotationVariant
|
* @param {number} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
*/
|
*/
|
||||||
getSpecialOverlayRenderMatrix(rotation, rotationVariant, variant, entity) {
|
getSpecialOverlayRenderMatrix(rotation, rotationVariant, variant, entity) {
|
||||||
return wireTunnelsOverlayMatrix[variant][rotation];
|
return wireTunnelOverlayMatrix[rotation];
|
||||||
}
|
}
|
||||||
|
|
||||||
getIsRotateable() {
|
getIsRotateable() {
|
||||||
return true;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
getStayInPlacementMode() {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getDimensions() {
|
getDimensions() {
|
||||||
@ -103,50 +53,6 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
|||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
*/
|
*/
|
||||||
setupEntityComponents(entity) {
|
setupEntityComponents(entity) {
|
||||||
entity.addComponent(
|
entity.addComponent(new WireTunnelComponent());
|
||||||
new WireTunnelComponent({
|
|
||||||
Connections: ConnectionDirections[defaultBuildingVariant],
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @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 = {
|
export const enumWireVariant = {
|
||||||
first: "first",
|
first: "first",
|
||||||
second: "second",
|
second: "second",
|
||||||
third: "third",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export class WireComponent extends Component {
|
export class WireComponent extends Component {
|
||||||
@ -40,4 +39,4 @@ export class WireComponent extends Component {
|
|||||||
*/
|
*/
|
||||||
this.linkedNetwork = null;
|
this.linkedNetwork = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,28 +1,13 @@
|
|||||||
import {
|
|
||||||
arrayAllDirections,
|
|
||||||
enumDirection,
|
|
||||||
enumDirectionToVector,
|
|
||||||
enumInvertedDirections,
|
|
||||||
Vector,
|
|
||||||
} from "../../core/vector";
|
|
||||||
import { Component } from "../component";
|
import { Component } from "../component";
|
||||||
import { defaultBuildingVariant } from "../meta_building";
|
|
||||||
|
|
||||||
export class WireTunnelComponent extends Component {
|
export class WireTunnelComponent extends Component {
|
||||||
static getId() {
|
static getId() {
|
||||||
return "WireTunnel";
|
return "WireTunnel";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
constructor() {
|
||||||
*
|
|
||||||
* @param {{Connections: Object.<string, Vector>}} Elements
|
|
||||||
*/
|
|
||||||
constructor({ Connections = {} }) {
|
|
||||||
super();
|
super();
|
||||||
/**
|
|
||||||
* @type {Object.<string, Vector>}
|
|
||||||
*/
|
|
||||||
this.Connections = Connections;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Linked network, only if its not multiple directions
|
* Linked network, only if its not multiple directions
|
||||||
@ -30,48 +15,4 @@ export class WireTunnelComponent extends Component {
|
|||||||
*/
|
*/
|
||||||
this.linkedNetworks = [];
|
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(53, MetaWireBuilding, enumWireVariant.second, 1);
|
||||||
registerBuildingVariant(54, MetaWireBuilding, enumWireVariant.second, 2);
|
registerBuildingVariant(54, MetaWireBuilding, enumWireVariant.second, 2);
|
||||||
registerBuildingVariant(55, MetaWireBuilding, enumWireVariant.second, 3);
|
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
|
// Constant signal
|
||||||
registerBuildingVariant(31, MetaConstantSignalBuilding);
|
registerBuildingVariant(31, MetaConstantSignalBuilding);
|
||||||
@ -152,9 +146,6 @@ export function initMetaBuildingRegistry() {
|
|||||||
|
|
||||||
// Wire tunnel
|
// Wire tunnel
|
||||||
registerBuildingVariant(39, MetaWireTunnelBuilding);
|
registerBuildingVariant(39, MetaWireTunnelBuilding);
|
||||||
registerBuildingVariant(10000006, MetaWireTunnelBuilding, enumWireTunnelVariants.Elbow);
|
|
||||||
registerBuildingVariant(10000007, MetaWireTunnelBuilding, enumWireTunnelVariants.Straight);
|
|
||||||
registerBuildingVariant(10000008, MetaWireTunnelBuilding, enumWireTunnelVariants.DoubleElbow);
|
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
registerBuildingVariant(40, MetaDisplayBuilding);
|
registerBuildingVariant(40, MetaDisplayBuilding);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user