mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Replace enumDirection with string literal Direction
This commit is contained in:
parent
1dfb5f7476
commit
c1f8a3bd2e
@ -53,27 +53,6 @@ export class Rectangle {
|
|||||||
return a.left <= b.right && b.left <= a.right && a.top <= b.bottom && b.top <= a.bottom;
|
return a.left <= b.right && b.left <= a.right && a.top <= b.bottom && b.top <= a.bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a rectangle arround a rotated point
|
|
||||||
* @param {Array<Vector>} points
|
|
||||||
* @param {number} angle
|
|
||||||
* @returns {Rectangle}
|
|
||||||
*/
|
|
||||||
static getAroundPointsRotated(points, angle) {
|
|
||||||
let minX = 1e10;
|
|
||||||
let minY = 1e10;
|
|
||||||
let maxX = -1e10;
|
|
||||||
let maxY = -1e10;
|
|
||||||
for (let i = 0; i < points.length; ++i) {
|
|
||||||
const rotated = points[i].rotated(angle);
|
|
||||||
minX = Math.min(minX, rotated.x);
|
|
||||||
minY = Math.min(minY, rotated.y);
|
|
||||||
maxX = Math.max(maxX, rotated.x);
|
|
||||||
maxY = Math.max(maxY, rotated.y);
|
|
||||||
}
|
|
||||||
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies this instance
|
* Copies this instance
|
||||||
* @returns {Rectangle}
|
* @returns {Rectangle}
|
||||||
|
@ -4,53 +4,105 @@ import { safeModulo } from "./utils";
|
|||||||
const tileSize = globalConfig.tileSize;
|
const tileSize = globalConfig.tileSize;
|
||||||
const halfTileSize = globalConfig.halfTileSize;
|
const halfTileSize = globalConfig.halfTileSize;
|
||||||
|
|
||||||
/**
|
/** @type {Angle[]} **/
|
||||||
* @enum {string}
|
export const angles = [0, 90, 180, 270];
|
||||||
*/
|
|
||||||
export const enumDirection = {
|
/** @type {Direction[]} **/
|
||||||
top: "top",
|
export const directions = ["top", "right", "bottom", "left"];
|
||||||
right: "right",
|
|
||||||
bottom: "bottom",
|
/** @type {Record<Direction, Direction>} **/
|
||||||
left: "left",
|
export const inverseDirectionMap = {
|
||||||
|
top: "bottom",
|
||||||
|
right: "left",
|
||||||
|
bottom: "top",
|
||||||
|
left: "right",
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @type {Record<Direction, Angle>} **/
|
||||||
|
export const directionAngleMap = {
|
||||||
|
top: 0,
|
||||||
|
right: 90,
|
||||||
|
bottom: 180,
|
||||||
|
left: 270,
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @type {Record<Angle, Direction>} **/
|
||||||
|
export const angleDirectionMap = {
|
||||||
|
0: "top",
|
||||||
|
90: "right",
|
||||||
|
180: "bottom",
|
||||||
|
270: "left",
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @type {Record<Angle, Angle>} **/
|
||||||
|
export const inverseAngleMap = {
|
||||||
|
0: 0,
|
||||||
|
90: 270,
|
||||||
|
180: 180,
|
||||||
|
270: 90,
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @type {Record<Angle, Angle>} **/
|
||||||
|
export const clockwiseAngleMap = {
|
||||||
|
0: 90,
|
||||||
|
90: 180,
|
||||||
|
180: 270,
|
||||||
|
270: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @type {Record<Angle, Angle>} **/
|
||||||
|
export const counterClockwiseAngleMap = {
|
||||||
|
0: 270,
|
||||||
|
90: 0,
|
||||||
|
180: 90,
|
||||||
|
270: 180,
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @type {Record<Direction, Record<Angle, Direction>>} **/
|
||||||
|
export const directionRotationMap = {
|
||||||
|
top: {
|
||||||
|
0: "top",
|
||||||
|
90: "right",
|
||||||
|
180: "bottom",
|
||||||
|
270: "left",
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
0: "right",
|
||||||
|
90: "bottom",
|
||||||
|
180: "left",
|
||||||
|
270: "top",
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
0: "bottom",
|
||||||
|
90: "left",
|
||||||
|
180: "top",
|
||||||
|
270: "right",
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
0: "left",
|
||||||
|
90: "top",
|
||||||
|
180: "right",
|
||||||
|
270: "bottom",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum {string}
|
* @param {number} n
|
||||||
|
* @return {n is Angle}
|
||||||
*/
|
*/
|
||||||
export const enumInvertedDirections = {
|
function isAngle(n) {
|
||||||
[enumDirection.top]: enumDirection.bottom,
|
return angles.includes(/** @type {Angle} **/ (n));
|
||||||
[enumDirection.right]: enumDirection.left,
|
}
|
||||||
[enumDirection.bottom]: enumDirection.top,
|
|
||||||
[enumDirection.left]: enumDirection.right,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum {number}
|
* @param {number} radians
|
||||||
|
* @return {Angle}
|
||||||
*/
|
*/
|
||||||
export const enumDirectionToAngle = {
|
export function snapToAngle(radians) {
|
||||||
[enumDirection.top]: 0,
|
const angle = (Math.round(Math.degrees(radians) / 90) * 90 + 360) % 360;
|
||||||
[enumDirection.right]: 90,
|
if (!isAngle(angle)) throw new Error("invalid Angle");
|
||||||
[enumDirection.bottom]: 180,
|
return angle;
|
||||||
[enumDirection.left]: 270,
|
}
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @enum {enumDirection}
|
|
||||||
*/
|
|
||||||
export const enumAngleToDirection = {
|
|
||||||
0: enumDirection.top,
|
|
||||||
90: enumDirection.right,
|
|
||||||
180: enumDirection.bottom,
|
|
||||||
270: enumDirection.left,
|
|
||||||
};
|
|
||||||
|
|
||||||
/** @type {Array<enumDirection>} */
|
|
||||||
export const arrayAllDirections = [
|
|
||||||
enumDirection.top,
|
|
||||||
enumDirection.right,
|
|
||||||
enumDirection.bottom,
|
|
||||||
enumDirection.left,
|
|
||||||
];
|
|
||||||
|
|
||||||
export class Vector {
|
export class Vector {
|
||||||
/**
|
/**
|
||||||
@ -92,7 +144,7 @@ export class Vector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Substracts a vector and return a new vector
|
* Subtracts a vector and return a new vector
|
||||||
* @param {Vector} other
|
* @param {Vector} other
|
||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
@ -340,14 +392,6 @@ export class Vector {
|
|||||||
return new Vector(Math.floor(this.x / tileSize), Math.floor(this.y / tileSize));
|
return new Vector(Math.floor(this.x / tileSize), Math.floor(this.y / tileSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts this vector from world to street space and return a new vector
|
|
||||||
* @returns {Vector}
|
|
||||||
*/
|
|
||||||
toStreetSpace() {
|
|
||||||
return new Vector(Math.floor(this.x / halfTileSize + 0.25), Math.floor(this.y / halfTileSize + 0.25));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this vector to world space and return a new vector
|
* Converts this vector to world space and return a new vector
|
||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
@ -438,162 +482,24 @@ export class Vector {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotates this vector
|
* Rotates this vector
|
||||||
* @param {number} angle
|
* @param {Angle} angle
|
||||||
* @returns {Vector} new vector
|
* @returns {Vector} new vector
|
||||||
*/
|
*/
|
||||||
rotated(angle) {
|
rotate(angle) {
|
||||||
const sin = Math.sin(angle);
|
const { x, y } = this;
|
||||||
const cos = Math.cos(angle);
|
|
||||||
return new Vector(this.x * cos - this.y * sin, this.x * sin + this.y * cos);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rotates this vector
|
|
||||||
* @param {number} angle
|
|
||||||
* @returns {Vector} this vector
|
|
||||||
*/
|
|
||||||
rotateInplaceFastMultipleOf90(angle) {
|
|
||||||
// const sin = Math.sin(angle);
|
|
||||||
// const cos = Math.cos(angle);
|
|
||||||
// let sin = 0, cos = 1;
|
|
||||||
assert(angle >= 0 && angle <= 360, "Invalid angle, please clamp first: " + angle);
|
|
||||||
|
|
||||||
switch (angle) {
|
switch (angle) {
|
||||||
case 0:
|
|
||||||
case 360: {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
case 90: {
|
|
||||||
// sin = 1;
|
|
||||||
// cos = 0;
|
|
||||||
|
|
||||||
const x = this.x;
|
|
||||||
this.x = -this.y;
|
|
||||||
this.y = x;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
case 180: {
|
|
||||||
// sin = 0
|
|
||||||
// cos = -1
|
|
||||||
this.x = -this.x;
|
|
||||||
this.y = -this.y;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
case 270: {
|
|
||||||
// sin = -1
|
|
||||||
// cos = 0
|
|
||||||
const x = this.x;
|
|
||||||
this.x = this.y;
|
|
||||||
this.y = -x;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
assertAlways(false, "Invalid fast inplace rotation: " + angle);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// return new Vector(this.x * cos - this.y * sin, this.x * sin + this.y * cos);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rotates this vector
|
|
||||||
* @param {number} angle
|
|
||||||
* @returns {Vector} new vector
|
|
||||||
*/
|
|
||||||
rotateFastMultipleOf90(angle) {
|
|
||||||
assert(angle >= 0 && angle <= 360, "Invalid angle, please clamp first: " + angle);
|
|
||||||
|
|
||||||
switch (angle) {
|
|
||||||
case 360:
|
|
||||||
case 0: {
|
case 0: {
|
||||||
return new Vector(this.x, this.y);
|
return new Vector(x, y);
|
||||||
}
|
}
|
||||||
case 90: {
|
case 90: {
|
||||||
return new Vector(-this.y, this.x);
|
return new Vector(-y, x);
|
||||||
}
|
}
|
||||||
case 180: {
|
case 180: {
|
||||||
return new Vector(-this.x, -this.y);
|
return new Vector(-x, -y);
|
||||||
}
|
}
|
||||||
case 270: {
|
case 270: {
|
||||||
return new Vector(this.y, -this.x);
|
return new Vector(y, -x);
|
||||||
}
|
}
|
||||||
default: {
|
|
||||||
assertAlways(false, "Invalid fast inplace rotation: " + angle);
|
|
||||||
return new Vector();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to rotate a direction
|
|
||||||
* @param {enumDirection} direction
|
|
||||||
* @param {number} angle
|
|
||||||
* @returns {enumDirection}
|
|
||||||
*/
|
|
||||||
static transformDirectionFromMultipleOf90(direction, angle) {
|
|
||||||
if (angle === 0 || angle === 360) {
|
|
||||||
return direction;
|
|
||||||
}
|
|
||||||
assert(angle >= 0 && angle <= 360, "Invalid angle: " + angle);
|
|
||||||
switch (direction) {
|
|
||||||
case enumDirection.top: {
|
|
||||||
switch (angle) {
|
|
||||||
case 90:
|
|
||||||
return enumDirection.right;
|
|
||||||
case 180:
|
|
||||||
return enumDirection.bottom;
|
|
||||||
case 270:
|
|
||||||
return enumDirection.left;
|
|
||||||
default:
|
|
||||||
assertAlways(false, "Invalid angle: " + angle);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case enumDirection.right: {
|
|
||||||
switch (angle) {
|
|
||||||
case 90:
|
|
||||||
return enumDirection.bottom;
|
|
||||||
case 180:
|
|
||||||
return enumDirection.left;
|
|
||||||
case 270:
|
|
||||||
return enumDirection.top;
|
|
||||||
default:
|
|
||||||
assertAlways(false, "Invalid angle: " + angle);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case enumDirection.bottom: {
|
|
||||||
switch (angle) {
|
|
||||||
case 90:
|
|
||||||
return enumDirection.left;
|
|
||||||
case 180:
|
|
||||||
return enumDirection.top;
|
|
||||||
case 270:
|
|
||||||
return enumDirection.right;
|
|
||||||
default:
|
|
||||||
assertAlways(false, "Invalid angle: " + angle);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case enumDirection.left: {
|
|
||||||
switch (angle) {
|
|
||||||
case 90:
|
|
||||||
return enumDirection.top;
|
|
||||||
case 180:
|
|
||||||
return enumDirection.right;
|
|
||||||
case 270:
|
|
||||||
return enumDirection.bottom;
|
|
||||||
default:
|
|
||||||
assertAlways(false, "Invalid angle: " + angle);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
assertAlways(false, "Invalid angle: " + angle);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,7 +513,7 @@ export class Vector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the angle
|
* Returns the angle in radians
|
||||||
* @returns {number} 0 .. 2 PI
|
* @returns {number} 0 .. 2 PI
|
||||||
*/
|
*/
|
||||||
angle() {
|
angle() {
|
||||||
@ -680,9 +586,9 @@ export function mixVector(v1, v2, a) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapping from string direction to actual vector
|
* Mapping from string direction to actual vector
|
||||||
* @enum {Vector}
|
* @type {Record<Direction, Vector>}
|
||||||
*/
|
*/
|
||||||
export const enumDirectionToVector = {
|
export const directionVectorMap = {
|
||||||
top: new Vector(0, -1),
|
top: new Vector(0, -1),
|
||||||
right: new Vector(1, 0),
|
right: new Vector(1, 0),
|
||||||
bottom: new Vector(0, 1),
|
bottom: new Vector(0, 1),
|
||||||
|
@ -3,7 +3,7 @@ import { DrawParameters } from "../core/draw_parameters";
|
|||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
import { Rectangle } from "../core/rectangle";
|
import { Rectangle } from "../core/rectangle";
|
||||||
import { epsilonCompare, round4Digits } from "../core/utils";
|
import { epsilonCompare, round4Digits } from "../core/utils";
|
||||||
import { enumDirection, enumDirectionToVector, enumInvertedDirections, Vector } from "../core/vector";
|
import { directionVectorMap, inverseDirectionMap, Vector } from "../core/vector";
|
||||||
import { BasicSerializableObject, types } from "../savegame/serialization";
|
import { BasicSerializableObject, types } from "../savegame/serialization";
|
||||||
import { BaseItem } from "./base_item";
|
import { BaseItem } from "./base_item";
|
||||||
import { Entity } from "./entity";
|
import { Entity } from "./entity";
|
||||||
@ -186,7 +186,7 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the entity which accepts our items
|
* Finds the entity which accepts our items
|
||||||
* @return {{ entity: Entity, slot: number, direction?: enumDirection }}
|
* @return {{ entity: Entity, slot: number, direction?: Direction }}
|
||||||
*/
|
*/
|
||||||
computeAcceptingEntityAndSlot() {
|
computeAcceptingEntityAndSlot() {
|
||||||
const lastEntity = this.entityPath[this.entityPath.length - 1];
|
const lastEntity = this.entityPath[this.entityPath.length - 1];
|
||||||
@ -196,7 +196,7 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
// Figure out where and into which direction we eject items
|
// Figure out where and into which direction we eject items
|
||||||
const ejectSlotWsTile = lastStatic.localTileToWorld(new Vector(0, 0));
|
const ejectSlotWsTile = lastStatic.localTileToWorld(new Vector(0, 0));
|
||||||
const ejectSlotWsDirection = lastStatic.localDirectionToWorld(lastBeltComp.direction);
|
const ejectSlotWsDirection = lastStatic.localDirectionToWorld(lastBeltComp.direction);
|
||||||
const ejectSlotWsDirectionVector = enumDirectionToVector[ejectSlotWsDirection];
|
const ejectSlotWsDirectionVector = directionVectorMap[ejectSlotWsDirection];
|
||||||
const ejectSlotTargetWsTile = ejectSlotWsTile.add(ejectSlotWsDirectionVector);
|
const ejectSlotTargetWsTile = ejectSlotWsTile.add(ejectSlotWsDirectionVector);
|
||||||
|
|
||||||
// Try to find the given acceptor component to take the item
|
// Try to find the given acceptor component to take the item
|
||||||
@ -212,7 +212,7 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
|
|
||||||
// Check for belts (special case)
|
// Check for belts (special case)
|
||||||
if (targetBeltComp) {
|
if (targetBeltComp) {
|
||||||
const beltAcceptingDirection = targetStaticComp.localDirectionToWorld(enumDirection.top);
|
const beltAcceptingDirection = targetStaticComp.localDirectionToWorld("top");
|
||||||
if (ejectSlotWsDirection === beltAcceptingDirection) {
|
if (ejectSlotWsDirection === beltAcceptingDirection) {
|
||||||
return {
|
return {
|
||||||
entity: targetEntity,
|
entity: targetEntity,
|
||||||
@ -243,7 +243,7 @@ export class BeltPath extends BasicSerializableObject {
|
|||||||
return {
|
return {
|
||||||
entity: targetEntity,
|
entity: targetEntity,
|
||||||
slot: matchingSlot.index,
|
slot: matchingSlot.index,
|
||||||
direction: enumInvertedDirections[ejectingDirection],
|
direction: inverseDirectionMap[ejectingDirection],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { DrawParameters } from "../core/draw_parameters";
|
import { DrawParameters } from "../core/draw_parameters";
|
||||||
import { Loader } from "../core/loader";
|
|
||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
import { Vector } from "../core/vector";
|
import { clockwiseAngleMap, counterClockwiseAngleMap, Vector } from "../core/vector";
|
||||||
import { Entity } from "./entity";
|
import { Entity } from "./entity";
|
||||||
import { GameRoot } from "./root";
|
import { GameRoot } from "./root";
|
||||||
import { findNiceIntegerValue } from "../core/utils";
|
import { findNiceIntegerValue } from "../core/utils";
|
||||||
@ -102,41 +101,23 @@ export class Blueprint {
|
|||||||
*/
|
*/
|
||||||
rotateCw() {
|
rotateCw() {
|
||||||
for (let i = 0; i < this.entities.length; ++i) {
|
for (let i = 0; i < this.entities.length; ++i) {
|
||||||
const entity = this.entities[i];
|
const { components: { StaticMapEntity } } = this.entities[i];
|
||||||
const staticComp = entity.components.StaticMapEntity;
|
StaticMapEntity.rotation = clockwiseAngleMap[StaticMapEntity.rotation];
|
||||||
|
StaticMapEntity.originalRotation = clockwiseAngleMap[StaticMapEntity.originalRotation];
|
||||||
staticComp.rotation = (staticComp.rotation + 90) % 360;
|
StaticMapEntity.origin = StaticMapEntity.origin.rotate(90);
|
||||||
staticComp.originalRotation = (staticComp.originalRotation + 90) % 360;
|
|
||||||
staticComp.origin = staticComp.origin.rotateFastMultipleOf90(90);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotates the blueprint counter clock wise
|
* Rotates the blueprint counter-clockwise
|
||||||
*/
|
*/
|
||||||
rotateCcw() {
|
rotateCcw() {
|
||||||
// Well ...
|
|
||||||
for (let i = 0; i < 3; ++i) {
|
|
||||||
this.rotateCw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the blueprint can be placed at the given tile
|
|
||||||
* @param {GameRoot} root
|
|
||||||
* @param {Vector} tile
|
|
||||||
*/
|
|
||||||
canPlace(root, tile) {
|
|
||||||
let anyPlaceable = false;
|
|
||||||
|
|
||||||
for (let i = 0; i < this.entities.length; ++i) {
|
for (let i = 0; i < this.entities.length; ++i) {
|
||||||
const entity = this.entities[i];
|
const { components: { StaticMapEntity } } = this.entities[i];
|
||||||
if (root.logic.checkCanPlaceEntity(entity, tile)) {
|
StaticMapEntity.rotation = counterClockwiseAngleMap[StaticMapEntity.rotation];
|
||||||
anyPlaceable = true;
|
StaticMapEntity.originalRotation = counterClockwiseAngleMap[StaticMapEntity.originalRotation];
|
||||||
}
|
StaticMapEntity.origin = StaticMapEntity.origin.rotate(270);
|
||||||
}
|
}
|
||||||
|
|
||||||
return anyPlaceable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,7 +9,7 @@ import { Vector } from "../core/vector";
|
|||||||
* metaClass: typeof MetaBuilding,
|
* metaClass: typeof MetaBuilding,
|
||||||
* metaInstance?: MetaBuilding,
|
* metaInstance?: MetaBuilding,
|
||||||
* variant?: string,
|
* variant?: string,
|
||||||
* rotationVariant?: number,
|
* rotationVariant?: RotationVariant,
|
||||||
* tileSize?: Vector,
|
* tileSize?: Vector,
|
||||||
* sprite?: AtlasSprite,
|
* sprite?: AtlasSprite,
|
||||||
* blueprintSprite?: AtlasSprite,
|
* blueprintSprite?: AtlasSprite,
|
||||||
@ -30,7 +30,7 @@ export const gBuildingVariants = {
|
|||||||
* @param {number} id
|
* @param {number} id
|
||||||
* @param {typeof MetaBuilding} meta
|
* @param {typeof MetaBuilding} meta
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
*/
|
*/
|
||||||
export function registerBuildingVariant(
|
export function registerBuildingVariant(
|
||||||
id,
|
id,
|
||||||
@ -62,7 +62,7 @@ export function getBuildingDataFromCode(code) {
|
|||||||
* Finds the code for a given variant
|
* Finds the code for a given variant
|
||||||
* @param {MetaBuilding} metaBuilding
|
* @param {MetaBuilding} metaBuilding
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
*/
|
*/
|
||||||
export function getCodeFromBuildingData(metaBuilding, variant, rotationVariant) {
|
export function getCodeFromBuildingData(metaBuilding, variant, rotationVariant) {
|
||||||
for (const key in gBuildingVariants) {
|
for (const key in gBuildingVariants) {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { Loader } from "../../core/loader";
|
import { Loader } from "../../core/loader";
|
||||||
import { enumDirection } from "../../core/vector";
|
|
||||||
import { SOUNDS } from "../../platform/sound";
|
import { SOUNDS } from "../../platform/sound";
|
||||||
import { arrayBeltVariantToRotation, MetaBeltBaseBuilding } from "./belt_base";
|
import { arrayBeltVariantToRotation, MetaBeltBaseBuilding } from "./belt_base";
|
||||||
|
|
||||||
@ -18,13 +17,13 @@ export class MetaBeltBuilding extends MetaBeltBaseBuilding {
|
|||||||
|
|
||||||
getPreviewSprite(rotationVariant) {
|
getPreviewSprite(rotationVariant) {
|
||||||
switch (arrayBeltVariantToRotation[rotationVariant]) {
|
switch (arrayBeltVariantToRotation[rotationVariant]) {
|
||||||
case enumDirection.top: {
|
case "top": {
|
||||||
return Loader.getSprite("sprites/buildings/belt_top.png");
|
return Loader.getSprite("sprites/buildings/belt_top.png");
|
||||||
}
|
}
|
||||||
case enumDirection.left: {
|
case "left": {
|
||||||
return Loader.getSprite("sprites/buildings/belt_left.png");
|
return Loader.getSprite("sprites/buildings/belt_left.png");
|
||||||
}
|
}
|
||||||
case enumDirection.right: {
|
case "right": {
|
||||||
return Loader.getSprite("sprites/buildings/belt_right.png");
|
return Loader.getSprite("sprites/buildings/belt_right.png");
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@ -35,13 +34,13 @@ export class MetaBeltBuilding extends MetaBeltBaseBuilding {
|
|||||||
|
|
||||||
getBlueprintSprite(rotationVariant) {
|
getBlueprintSprite(rotationVariant) {
|
||||||
switch (arrayBeltVariantToRotation[rotationVariant]) {
|
switch (arrayBeltVariantToRotation[rotationVariant]) {
|
||||||
case enumDirection.top: {
|
case "top": {
|
||||||
return Loader.getSprite("sprites/blueprints/belt_top.png");
|
return Loader.getSprite("sprites/blueprints/belt_top.png");
|
||||||
}
|
}
|
||||||
case enumDirection.left: {
|
case "left": {
|
||||||
return Loader.getSprite("sprites/blueprints/belt_left.png");
|
return Loader.getSprite("sprites/blueprints/belt_left.png");
|
||||||
}
|
}
|
||||||
case enumDirection.right: {
|
case "right": {
|
||||||
return Loader.getSprite("sprites/blueprints/belt_right.png");
|
return Loader.getSprite("sprites/blueprints/belt_right.png");
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { formatItemsPerSecond, generateMatrixRotations } from "../../core/utils";
|
import { formatItemsPerSecond, generateMatrixRotations } from "../../core/utils";
|
||||||
import { enumAngleToDirection, enumDirection, Vector } from "../../core/vector";
|
import { angleDirectionMap, clockwiseAngleMap, counterClockwiseAngleMap, Vector } from "../../core/vector";
|
||||||
import { SOUNDS } from "../../platform/sound";
|
import { SOUNDS } from "../../platform/sound";
|
||||||
import { T } from "../../translations";
|
import { T } from "../../translations";
|
||||||
import { BeltComponent } from "../components/belt";
|
import { BeltComponent } from "../components/belt";
|
||||||
@ -7,12 +7,14 @@ import { Entity } from "../entity";
|
|||||||
import { MetaBuilding } from "../meta_building";
|
import { MetaBuilding } from "../meta_building";
|
||||||
import { GameRoot } from "../root";
|
import { GameRoot } from "../root";
|
||||||
|
|
||||||
export const arrayBeltVariantToRotation = [enumDirection.top, enumDirection.left, enumDirection.right];
|
/** @type {Exclude<Direction, "Bottom">[]} **/
|
||||||
|
export const arrayBeltVariantToRotation = ["top", "left", "right"];
|
||||||
|
|
||||||
export const beltOverlayMatrices = {
|
/** @type {Record<Exclude<Direction, "bottom">, Object<number, Array<number>>>} **/
|
||||||
[enumDirection.top]: generateMatrixRotations([0, 1, 0, 0, 1, 0, 0, 1, 0]),
|
const beltOverlayMatrices = {
|
||||||
[enumDirection.left]: generateMatrixRotations([0, 0, 0, 1, 1, 0, 0, 1, 0]),
|
top: generateMatrixRotations([0, 1, 0, 0, 1, 0, 0, 1, 0]),
|
||||||
[enumDirection.right]: generateMatrixRotations([0, 0, 0, 0, 1, 1, 0, 1, 0]),
|
left: generateMatrixRotations([0, 0, 0, 1, 1, 0, 0, 1, 0]),
|
||||||
|
right: generateMatrixRotations([0, 0, 0, 0, 1, 1, 0, 1, 0]),
|
||||||
};
|
};
|
||||||
|
|
||||||
export class MetaBeltBaseBuilding extends MetaBuilding {
|
export class MetaBeltBaseBuilding extends MetaBuilding {
|
||||||
@ -52,8 +54,8 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {number} rotation
|
* @param {Angle} rotation
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
*/
|
*/
|
||||||
@ -68,7 +70,7 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
|
|||||||
setupEntityComponents(entity) {
|
setupEntityComponents(entity) {
|
||||||
entity.addComponent(
|
entity.addComponent(
|
||||||
new BeltComponent({
|
new BeltComponent({
|
||||||
direction: enumDirection.top, // updated later
|
direction: "top", // updated later
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -76,7 +78,7 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant) {
|
updateVariants(entity, rotationVariant) {
|
||||||
entity.components.Belt.direction = arrayBeltVariantToRotation[rotationVariant];
|
entity.components.Belt.direction = arrayBeltVariantToRotation[rotationVariant];
|
||||||
@ -87,16 +89,16 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
|
|||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {GameRoot} param0.root
|
* @param {GameRoot} param0.root
|
||||||
* @param {Vector} param0.tile
|
* @param {Vector} param0.tile
|
||||||
* @param {number} param0.rotation
|
* @param {Angle} param0.rotation
|
||||||
* @param {string} param0.variant
|
* @param {string} param0.variant
|
||||||
* @param {Layer} param0.layer
|
* @param {Layer} param0.layer
|
||||||
* @return {{ rotation: number, rotationVariant: number, connectedEntities?: Array<Entity> }}
|
* @return {{ rotation: Angle, rotationVariant: RotationVariant, connectedEntities?: Array<Entity> }}
|
||||||
*/
|
*/
|
||||||
computeOptimalDirectionAndRotationVariantAtTile({ root, tile, rotation, variant, layer }) {
|
computeOptimalDirectionAndRotationVariantAtTile({ root, tile, rotation, variant, layer }) {
|
||||||
const topDirection = enumAngleToDirection[rotation];
|
const topDirection = angleDirectionMap[rotation];
|
||||||
const rightDirection = enumAngleToDirection[(rotation + 90) % 360];
|
const rightDirection = angleDirectionMap[(rotation + 90) % 360];
|
||||||
const bottomDirection = enumAngleToDirection[(rotation + 180) % 360];
|
const bottomDirection = angleDirectionMap[(rotation + 180) % 360];
|
||||||
const leftDirection = enumAngleToDirection[(rotation + 270) % 360];
|
const leftDirection = angleDirectionMap[(rotation + 270) % 360];
|
||||||
|
|
||||||
const { ejectors, acceptors } = root.logic.getEjectorsAndAcceptorsAtTile(tile);
|
const { ejectors, acceptors } = root.logic.getEjectorsAndAcceptorsAtTile(tile);
|
||||||
|
|
||||||
@ -141,7 +143,7 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
|
|||||||
|
|
||||||
if (hasRightEjector && !hasLeftEjector) {
|
if (hasRightEjector && !hasLeftEjector) {
|
||||||
return {
|
return {
|
||||||
rotation: (rotation + 270) % 360,
|
rotation: counterClockwiseAngleMap[rotation],
|
||||||
rotationVariant: 2,
|
rotationVariant: 2,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -150,7 +152,7 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
|
|||||||
// do a curve from the right to the top
|
// do a curve from the right to the top
|
||||||
if (hasLeftEjector && !hasRightEjector) {
|
if (hasLeftEjector && !hasRightEjector) {
|
||||||
return {
|
return {
|
||||||
rotation: (rotation + 90) % 360,
|
rotation: clockwiseAngleMap[rotation],
|
||||||
rotationVariant: 1,
|
rotationVariant: 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
|
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { MetaBuilding } from "../meta_building";
|
import { MetaBuilding } from "../meta_building";
|
||||||
@ -41,7 +41,7 @@ export class MetaConstantSignalBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.top,
|
direction: "top",
|
||||||
type: enumPinSlotType.logicalEjector,
|
type: enumPinSlotType.logicalEjector,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { formatItemsPerSecond } from "../../core/utils";
|
import { formatItemsPerSecond } from "../../core/utils";
|
||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { T } from "../../translations";
|
import { T } from "../../translations";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||||
@ -80,7 +80,7 @@ export class MetaCutterBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -91,25 +91,25 @@ export class MetaCutterBuilding extends MetaBuilding {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant, variant) {
|
updateVariants(entity, rotationVariant, variant) {
|
||||||
switch (variant) {
|
switch (variant) {
|
||||||
case defaultBuildingVariant: {
|
case defaultBuildingVariant: {
|
||||||
entity.components.ItemEjector.setSlots([
|
entity.components.ItemEjector.setSlots([
|
||||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
{ pos: new Vector(0, 0), direction: "top" },
|
||||||
{ pos: new Vector(1, 0), direction: enumDirection.top },
|
{ pos: new Vector(1, 0), direction: "top" },
|
||||||
]);
|
]);
|
||||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.cutter;
|
entity.components.ItemProcessor.type = enumItemProcessorTypes.cutter;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case enumCutterVariants.quad: {
|
case enumCutterVariants.quad: {
|
||||||
entity.components.ItemEjector.setSlots([
|
entity.components.ItemEjector.setSlots([
|
||||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
{ pos: new Vector(0, 0), direction: "top" },
|
||||||
{ pos: new Vector(1, 0), direction: enumDirection.top },
|
{ pos: new Vector(1, 0), direction: "top" },
|
||||||
{ pos: new Vector(2, 0), direction: enumDirection.top },
|
{ pos: new Vector(2, 0), direction: "top" },
|
||||||
{ pos: new Vector(3, 0), direction: enumDirection.top },
|
{ pos: new Vector(3, 0), direction: "top" },
|
||||||
]);
|
]);
|
||||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.cutterQuad;
|
entity.components.ItemProcessor.type = enumItemProcessorTypes.cutterQuad;
|
||||||
break;
|
break;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
|
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { MetaBuilding } from "../meta_building";
|
import { MetaBuilding } from "../meta_building";
|
||||||
@ -40,7 +40,7 @@ export class MetaDisplayBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.bottom,
|
direction: "bottom",
|
||||||
type: enumPinSlotType.logicalAcceptor,
|
type: enumPinSlotType.logicalAcceptor,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
|
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { MetaBuilding } from "../meta_building";
|
import { MetaBuilding } from "../meta_building";
|
||||||
@ -43,7 +43,7 @@ export class MetaFilterBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.left,
|
direction: "left",
|
||||||
type: enumPinSlotType.logicalAcceptor,
|
type: enumPinSlotType.logicalAcceptor,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -55,7 +55,7 @@ export class MetaFilterBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
@ -66,11 +66,11 @@ export class MetaFilterBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.top,
|
direction: "top",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(1, 0),
|
pos: new Vector(1, 0),
|
||||||
direction: enumDirection.right,
|
direction: "right",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { HubComponent } from "../components/hub";
|
import { HubComponent } from "../components/hub";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
||||||
@ -55,7 +55,7 @@ export class MetaHubBuilding extends MetaBuilding {
|
|||||||
{
|
{
|
||||||
pos: new Vector(0, 2),
|
pos: new Vector(0, 2),
|
||||||
type: enumPinSlotType.logicalEjector,
|
type: enumPinSlotType.logicalEjector,
|
||||||
direction: enumDirection.left,
|
direction: "left",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
@ -66,72 +66,72 @@ export class MetaHubBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.top, enumDirection.left],
|
directions: ["top", "left"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(1, 0),
|
pos: new Vector(1, 0),
|
||||||
directions: [enumDirection.top],
|
directions: ["top"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(2, 0),
|
pos: new Vector(2, 0),
|
||||||
directions: [enumDirection.top],
|
directions: ["top"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(3, 0),
|
pos: new Vector(3, 0),
|
||||||
directions: [enumDirection.top, enumDirection.right],
|
directions: ["top", "right"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 3),
|
pos: new Vector(0, 3),
|
||||||
directions: [enumDirection.bottom, enumDirection.left],
|
directions: ["bottom", "left"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(1, 3),
|
pos: new Vector(1, 3),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(2, 3),
|
pos: new Vector(2, 3),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(3, 3),
|
pos: new Vector(3, 3),
|
||||||
directions: [enumDirection.bottom, enumDirection.right],
|
directions: ["bottom", "right"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 1),
|
pos: new Vector(0, 1),
|
||||||
directions: [enumDirection.left],
|
directions: ["left"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 2),
|
pos: new Vector(0, 2),
|
||||||
directions: [enumDirection.left],
|
directions: ["left"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 3),
|
pos: new Vector(0, 3),
|
||||||
directions: [enumDirection.left],
|
directions: ["left"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(3, 1),
|
pos: new Vector(3, 1),
|
||||||
directions: [enumDirection.right],
|
directions: ["right"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(3, 2),
|
pos: new Vector(3, 2),
|
||||||
directions: [enumDirection.right],
|
directions: ["right"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(3, 3),
|
pos: new Vector(3, 3),
|
||||||
directions: [enumDirection.right],
|
directions: ["right"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
|
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { MetaBuilding } from "../meta_building";
|
import { MetaBuilding } from "../meta_building";
|
||||||
@ -49,7 +49,7 @@ export class MetaLeverBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.top,
|
direction: "top",
|
||||||
type: enumPinSlotType.logicalEjector,
|
type: enumPinSlotType.logicalEjector,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
|
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
||||||
@ -66,7 +66,7 @@ export class MetaLogicGateBuilding extends MetaBuilding {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant, variant) {
|
updateVariants(entity, rotationVariant, variant) {
|
||||||
const gateType = enumVariantToGate[variant];
|
const gateType = enumVariantToGate[variant];
|
||||||
@ -81,17 +81,17 @@ export class MetaLogicGateBuilding extends MetaBuilding {
|
|||||||
pinComp.setSlots([
|
pinComp.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.top,
|
direction: "top",
|
||||||
type: enumPinSlotType.logicalEjector,
|
type: enumPinSlotType.logicalEjector,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.left,
|
direction: "left",
|
||||||
type: enumPinSlotType.logicalAcceptor,
|
type: enumPinSlotType.logicalAcceptor,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.right,
|
direction: "right",
|
||||||
type: enumPinSlotType.logicalAcceptor,
|
type: enumPinSlotType.logicalAcceptor,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -101,17 +101,17 @@ export class MetaLogicGateBuilding extends MetaBuilding {
|
|||||||
pinComp.setSlots([
|
pinComp.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.top,
|
direction: "top",
|
||||||
type: enumPinSlotType.logicalEjector,
|
type: enumPinSlotType.logicalEjector,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.left,
|
direction: "left",
|
||||||
type: enumPinSlotType.logicalAcceptor,
|
type: enumPinSlotType.logicalAcceptor,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.bottom,
|
direction: "bottom",
|
||||||
type: enumPinSlotType.logicalAcceptor,
|
type: enumPinSlotType.logicalAcceptor,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
@ -122,12 +122,12 @@ export class MetaLogicGateBuilding extends MetaBuilding {
|
|||||||
pinComp.setSlots([
|
pinComp.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.top,
|
direction: "top",
|
||||||
type: enumPinSlotType.logicalEjector,
|
type: enumPinSlotType.logicalEjector,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.bottom,
|
direction: "bottom",
|
||||||
type: enumPinSlotType.logicalAcceptor,
|
type: enumPinSlotType.logicalAcceptor,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||||
import { MinerComponent } from "../components/miner";
|
import { MinerComponent } from "../components/miner";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
@ -44,8 +44,8 @@ export class MetaMinerBuilding extends MetaBuilding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} rotation
|
* @param {Angle} rotation
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
*/
|
*/
|
||||||
@ -61,7 +61,7 @@ export class MetaMinerBuilding extends MetaBuilding {
|
|||||||
entity.addComponent(new MinerComponent({}));
|
entity.addComponent(new MinerComponent({}));
|
||||||
entity.addComponent(
|
entity.addComponent(
|
||||||
new ItemEjectorComponent({
|
new ItemEjectorComponent({
|
||||||
slots: [{ pos: new Vector(0, 0), direction: enumDirection.top }],
|
slots: [{ pos: new Vector(0, 0), direction: "top" }],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ export class MetaMinerBuilding extends MetaBuilding {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant, variant) {
|
updateVariants(entity, rotationVariant, variant) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { formatItemsPerSecond } from "../../core/utils";
|
import { formatItemsPerSecond } from "../../core/utils";
|
||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { T } from "../../translations";
|
import { T } from "../../translations";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||||
@ -53,7 +53,7 @@ export class MetaMixerBuilding extends MetaBuilding {
|
|||||||
|
|
||||||
entity.addComponent(
|
entity.addComponent(
|
||||||
new ItemEjectorComponent({
|
new ItemEjectorComponent({
|
||||||
slots: [{ pos: new Vector(0, 0), direction: enumDirection.top }],
|
slots: [{ pos: new Vector(0, 0), direction: "top" }],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
entity.addComponent(
|
entity.addComponent(
|
||||||
@ -61,12 +61,12 @@ export class MetaMixerBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
filter: "color",
|
filter: "color",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(1, 0),
|
pos: new Vector(1, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
filter: "color",
|
filter: "color",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { formatItemsPerSecond } from "../../core/utils";
|
import { formatItemsPerSecond } from "../../core/utils";
|
||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { T } from "../../translations";
|
import { T } from "../../translations";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||||
@ -88,7 +88,7 @@ export class MetaPainterBuilding extends MetaBuilding {
|
|||||||
|
|
||||||
entity.addComponent(
|
entity.addComponent(
|
||||||
new ItemEjectorComponent({
|
new ItemEjectorComponent({
|
||||||
slots: [{ pos: new Vector(1, 0), direction: enumDirection.right }],
|
slots: [{ pos: new Vector(1, 0), direction: "right" }],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
entity.addComponent(
|
entity.addComponent(
|
||||||
@ -96,12 +96,12 @@ export class MetaPainterBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.left],
|
directions: ["left"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(1, 0),
|
pos: new Vector(1, 0),
|
||||||
directions: [enumDirection.top],
|
directions: ["top"],
|
||||||
filter: "color",
|
filter: "color",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -112,7 +112,7 @@ export class MetaPainterBuilding extends MetaBuilding {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant, variant) {
|
updateVariants(entity, rotationVariant, variant) {
|
||||||
@ -122,87 +122,77 @@ export class MetaPainterBuilding extends MetaBuilding {
|
|||||||
entity.components.ItemAcceptor.setSlots([
|
entity.components.ItemAcceptor.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.left],
|
directions: ["left"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(1, 0),
|
pos: new Vector(1, 0),
|
||||||
directions: [
|
directions: [variant === defaultBuildingVariant ? "top" : "bottom"],
|
||||||
variant === defaultBuildingVariant ? enumDirection.top : enumDirection.bottom,
|
|
||||||
],
|
|
||||||
filter: "color",
|
filter: "color",
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.painter;
|
entity.components.ItemProcessor.type = enumItemProcessorTypes.painter;
|
||||||
entity.components.ItemProcessor.inputsPerCharge = 2;
|
entity.components.ItemProcessor.inputsPerCharge = 2;
|
||||||
entity.components.ItemEjector.setSlots([
|
entity.components.ItemEjector.setSlots([{ pos: new Vector(1, 0), direction: "right" }]);
|
||||||
{ pos: new Vector(1, 0), direction: enumDirection.right },
|
|
||||||
]);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case enumPainterVariants.double: {
|
case enumPainterVariants.double: {
|
||||||
entity.components.ItemAcceptor.setSlots([
|
entity.components.ItemAcceptor.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.left],
|
directions: ["left"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 1),
|
pos: new Vector(0, 1),
|
||||||
directions: [enumDirection.left],
|
directions: ["left"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(1, 0),
|
pos: new Vector(1, 0),
|
||||||
directions: [enumDirection.top],
|
directions: ["top"],
|
||||||
filter: "color",
|
filter: "color",
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.painterDouble;
|
entity.components.ItemProcessor.type = enumItemProcessorTypes.painterDouble;
|
||||||
entity.components.ItemProcessor.inputsPerCharge = 3;
|
entity.components.ItemProcessor.inputsPerCharge = 3;
|
||||||
|
entity.components.ItemEjector.setSlots([{ pos: new Vector(1, 0), direction: "right" }]);
|
||||||
entity.components.ItemEjector.setSlots([
|
|
||||||
{ pos: new Vector(1, 0), direction: enumDirection.right },
|
|
||||||
]);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case enumPainterVariants.quad: {
|
case enumPainterVariants.quad: {
|
||||||
entity.components.ItemAcceptor.setSlots([
|
entity.components.ItemAcceptor.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.left],
|
directions: ["left"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
filter: "color",
|
filter: "color",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(1, 0),
|
pos: new Vector(1, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
filter: "color",
|
filter: "color",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(2, 0),
|
pos: new Vector(2, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
filter: "color",
|
filter: "color",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(3, 0),
|
pos: new Vector(3, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
filter: "color",
|
filter: "color",
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
entity.components.ItemProcessor.type = enumItemProcessorTypes.painterQuad;
|
entity.components.ItemProcessor.type = enumItemProcessorTypes.painterQuad;
|
||||||
entity.components.ItemProcessor.inputsPerCharge = 5;
|
entity.components.ItemProcessor.inputsPerCharge = 5;
|
||||||
|
entity.components.ItemEjector.setSlots([{ pos: new Vector(0, 0), direction: "top" }]);
|
||||||
entity.components.ItemEjector.setSlots([
|
|
||||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
|
||||||
]);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { formatItemsPerSecond } from "../../core/utils";
|
import { formatItemsPerSecond } from "../../core/utils";
|
||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { T } from "../../translations";
|
import { T } from "../../translations";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||||
@ -79,7 +79,7 @@ export class MetaRotaterBuilding extends MetaBuilding {
|
|||||||
|
|
||||||
entity.addComponent(
|
entity.addComponent(
|
||||||
new ItemEjectorComponent({
|
new ItemEjectorComponent({
|
||||||
slots: [{ pos: new Vector(0, 0), direction: enumDirection.top }],
|
slots: [{ pos: new Vector(0, 0), direction: "top" }],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
entity.addComponent(
|
entity.addComponent(
|
||||||
@ -87,7 +87,7 @@ export class MetaRotaterBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -98,7 +98,7 @@ export class MetaRotaterBuilding extends MetaBuilding {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant, variant) {
|
updateVariants(entity, rotationVariant, variant) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||||
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
||||||
@ -95,7 +95,7 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant, variant) {
|
updateVariants(entity, rotationVariant, variant) {
|
||||||
@ -104,22 +104,22 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
|||||||
entity.components.ItemAcceptor.setSlots([
|
entity.components.ItemAcceptor.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(1, 0),
|
pos: new Vector(1, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
entity.components.ItemEjector.setSlots([
|
entity.components.ItemEjector.setSlots([
|
||||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
{ pos: new Vector(0, 0), direction: "top" },
|
||||||
{ pos: new Vector(1, 0), direction: enumDirection.top },
|
{ pos: new Vector(1, 0), direction: "top" },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
entity.components.BeltUnderlays.underlays = [
|
entity.components.BeltUnderlays.underlays = [
|
||||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
{ pos: new Vector(0, 0), direction: "top" },
|
||||||
{ pos: new Vector(1, 0), direction: enumDirection.top },
|
{ pos: new Vector(1, 0), direction: "top" },
|
||||||
];
|
];
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -129,25 +129,17 @@ export class MetaSplitterBuilding extends MetaBuilding {
|
|||||||
entity.components.ItemAcceptor.setSlots([
|
entity.components.ItemAcceptor.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [
|
directions: [variant === enumSplitterVariants.compactInverse ? "left" : "right"],
|
||||||
variant === enumSplitterVariants.compactInverse
|
|
||||||
? enumDirection.left
|
|
||||||
: enumDirection.right,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
entity.components.ItemEjector.setSlots([
|
entity.components.ItemEjector.setSlots([{ pos: new Vector(0, 0), direction: "top" }]);
|
||||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
|
||||||
]);
|
|
||||||
|
|
||||||
entity.components.BeltUnderlays.underlays = [
|
entity.components.BeltUnderlays.underlays = [{ pos: new Vector(0, 0), direction: "top" }];
|
||||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
|
||||||
];
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { formatItemsPerSecond } from "../../core/utils";
|
import { formatItemsPerSecond } from "../../core/utils";
|
||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { T } from "../../translations";
|
import { T } from "../../translations";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||||
@ -53,7 +53,7 @@ export class MetaStackerBuilding extends MetaBuilding {
|
|||||||
|
|
||||||
entity.addComponent(
|
entity.addComponent(
|
||||||
new ItemEjectorComponent({
|
new ItemEjectorComponent({
|
||||||
slots: [{ pos: new Vector(0, 0), direction: enumDirection.top }],
|
slots: [{ pos: new Vector(0, 0), direction: "top" }],
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
entity.addComponent(
|
entity.addComponent(
|
||||||
@ -61,12 +61,12 @@ export class MetaStackerBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(1, 0),
|
pos: new Vector(1, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
filter: "shape",
|
filter: "shape",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { formatBigNumber } from "../../core/utils";
|
import { formatBigNumber } from "../../core/utils";
|
||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { T } from "../../translations";
|
import { T } from "../../translations";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||||
@ -86,12 +86,7 @@ export class MetaTrashBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [
|
directions: ["top", "right", "bottom", "left"],
|
||||||
enumDirection.top,
|
|
||||||
enumDirection.right,
|
|
||||||
enumDirection.bottom,
|
|
||||||
enumDirection.left,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
@ -101,7 +96,7 @@ export class MetaTrashBuilding extends MetaBuilding {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant, variant) {
|
updateVariants(entity, rotationVariant, variant) {
|
||||||
@ -125,12 +120,7 @@ export class MetaTrashBuilding extends MetaBuilding {
|
|||||||
entity.components.ItemAcceptor.setSlots([
|
entity.components.ItemAcceptor.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [
|
directions: ["top", "right", "bottom", "left"],
|
||||||
enumDirection.top,
|
|
||||||
enumDirection.right,
|
|
||||||
enumDirection.bottom,
|
|
||||||
enumDirection.left,
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
entity.components.ItemEjector.setSlots([]);
|
entity.components.ItemEjector.setSlots([]);
|
||||||
@ -150,12 +140,12 @@ export class MetaTrashBuilding extends MetaBuilding {
|
|||||||
slots: [
|
slots: [
|
||||||
{
|
{
|
||||||
pos: new Vector(1, 1),
|
pos: new Vector(1, 1),
|
||||||
direction: enumDirection.right,
|
direction: "right",
|
||||||
type: enumPinSlotType.logicalEjector,
|
type: enumPinSlotType.logicalEjector,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 1),
|
pos: new Vector(0, 1),
|
||||||
direction: enumDirection.left,
|
direction: "left",
|
||||||
type: enumPinSlotType.logicalEjector,
|
type: enumPinSlotType.logicalEjector,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@ -167,22 +157,22 @@ export class MetaTrashBuilding extends MetaBuilding {
|
|||||||
entity.components.ItemAcceptor.setSlots([
|
entity.components.ItemAcceptor.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 1),
|
pos: new Vector(0, 1),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(1, 1),
|
pos: new Vector(1, 1),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
entity.components.ItemEjector.setSlots([
|
entity.components.ItemEjector.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.top,
|
direction: "top",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
pos: new Vector(1, 0),
|
pos: new Vector(1, 0),
|
||||||
direction: enumDirection.top,
|
direction: "top",
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
break;
|
break;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Loader } from "../../core/loader";
|
import { Loader } from "../../core/loader";
|
||||||
import { enumDirection, Vector, enumAngleToDirection, enumDirectionToVector } from "../../core/vector";
|
import { Vector, angleDirectionMap, directionVectorMap, clockwiseAngleMap } from "../../core/vector";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||||
import { enumUndergroundBeltMode, UndergroundBeltComponent } from "../components/underground_belt";
|
import { enumUndergroundBeltMode, UndergroundBeltComponent } from "../components/underground_belt";
|
||||||
@ -51,8 +51,8 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} rotation
|
* @param {Angle} rotation
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
*/
|
*/
|
||||||
@ -90,7 +90,7 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
getPreviewSprite(rotationVariant, variant) {
|
getPreviewSprite(rotationVariant, variant) {
|
||||||
@ -110,7 +110,7 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
getBlueprintSprite(rotationVariant, variant) {
|
getBlueprintSprite(rotationVariant, variant) {
|
||||||
@ -130,7 +130,7 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
getSprite(rotationVariant, variant) {
|
getSprite(rotationVariant, variant) {
|
||||||
@ -169,17 +169,17 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
|||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {GameRoot} param0.root
|
* @param {GameRoot} param0.root
|
||||||
* @param {Vector} param0.tile
|
* @param {Vector} param0.tile
|
||||||
* @param {number} param0.rotation
|
* @param {Angle} param0.rotation
|
||||||
* @param {string} param0.variant
|
* @param {string} param0.variant
|
||||||
* @param {Layer} param0.layer
|
* @param {Layer} param0.layer
|
||||||
* @return {{ rotation: number, rotationVariant: number, connectedEntities?: Array<Entity> }}
|
* @return {{ rotation: Angle, rotationVariant: RotationVariant, connectedEntities?: Array<Entity> }}
|
||||||
*/
|
*/
|
||||||
computeOptimalDirectionAndRotationVariantAtTile({ root, tile, rotation, variant, layer }) {
|
computeOptimalDirectionAndRotationVariantAtTile({ root, tile, rotation, variant, layer }) {
|
||||||
const searchDirection = enumAngleToDirection[rotation];
|
const searchDirection = angleDirectionMap[rotation];
|
||||||
const searchVector = enumDirectionToVector[searchDirection];
|
const searchVector = directionVectorMap[searchDirection];
|
||||||
const tier = enumUndergroundBeltVariantToTier[variant];
|
const tier = enumUndergroundBeltVariantToTier[variant];
|
||||||
|
|
||||||
const targetRotation = (rotation + 180) % 360;
|
const targetRotation = clockwiseAngleMap[clockwiseAngleMap[rotation]];
|
||||||
const targetSenderRotation = rotation;
|
const targetSenderRotation = rotation;
|
||||||
|
|
||||||
for (
|
for (
|
||||||
@ -209,7 +209,7 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
|||||||
// Draw connections to receivers
|
// Draw connections to receivers
|
||||||
if (undergroundComp.mode === enumUndergroundBeltMode.receiver) {
|
if (undergroundComp.mode === enumUndergroundBeltMode.receiver) {
|
||||||
return {
|
return {
|
||||||
rotation: rotation,
|
rotation,
|
||||||
rotationVariant: 0,
|
rotationVariant: 0,
|
||||||
connectedEntities: [contents],
|
connectedEntities: [contents],
|
||||||
};
|
};
|
||||||
@ -230,7 +230,7 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant, variant) {
|
updateVariants(entity, rotationVariant, variant) {
|
||||||
@ -243,7 +243,7 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
|||||||
entity.components.ItemAcceptor.setSlots([
|
entity.components.ItemAcceptor.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
return;
|
return;
|
||||||
@ -254,7 +254,7 @@ export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
|||||||
entity.components.ItemEjector.setSlots([
|
entity.components.ItemEjector.setSlots([
|
||||||
{
|
{
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.top,
|
direction: "top",
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
return;
|
return;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Loader } from "../../core/loader";
|
import { Loader } from "../../core/loader";
|
||||||
import { generateMatrixRotations } from "../../core/utils";
|
import { generateMatrixRotations } from "../../core/utils";
|
||||||
import { enumDirection, enumDirectionToAngle, enumDirectionToVector, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { SOUNDS } from "../../platform/sound";
|
import { SOUNDS } from "../../platform/sound";
|
||||||
import { enumWireType, WireComponent } from "../components/wire";
|
import { enumWireType, WireComponent } from "../components/wire";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
@ -83,7 +83,7 @@ export class MetaWireBuilding extends MetaBuilding {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant) {
|
updateVariants(entity, rotationVariant) {
|
||||||
entity.components.Wire.type = arrayWireRotationVariantToType[rotationVariant];
|
entity.components.Wire.type = arrayWireRotationVariantToType[rotationVariant];
|
||||||
@ -91,8 +91,8 @@ export class MetaWireBuilding extends MetaBuilding {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {number} rotation
|
* @param {Angle} rotation
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
*/
|
*/
|
||||||
@ -145,17 +145,17 @@ export class MetaWireBuilding extends MetaBuilding {
|
|||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {GameRoot} param0.root
|
* @param {GameRoot} param0.root
|
||||||
* @param {Vector} param0.tile
|
* @param {Vector} param0.tile
|
||||||
* @param {number} param0.rotation
|
* @param {Angle} param0.rotation
|
||||||
* @param {string} param0.variant
|
* @param {string} param0.variant
|
||||||
* @param {string} param0.layer
|
* @param {string} param0.layer
|
||||||
* @return {{ rotation: number, rotationVariant: number, connectedEntities?: Array<Entity> }}
|
* @return {{ rotation: Angle, rotationVariant: RotationVariant, connectedEntities?: Array<Entity> }}
|
||||||
*/
|
*/
|
||||||
computeOptimalDirectionAndRotationVariantAtTile({ root, tile, rotation, variant, layer }) {
|
computeOptimalDirectionAndRotationVariantAtTile({ root, tile, rotation, variant, layer }) {
|
||||||
const connections = {
|
const connections = {
|
||||||
top: root.logic.computeWireEdgeStatus({ tile, rotation, edge: enumDirection.top }),
|
top: root.logic.computeWireEdgeStatus({ tile, rotation, edge: "top" }),
|
||||||
right: root.logic.computeWireEdgeStatus({ tile, rotation, edge: enumDirection.right }),
|
right: root.logic.computeWireEdgeStatus({ tile, rotation, edge: "right" }),
|
||||||
bottom: root.logic.computeWireEdgeStatus({ tile, rotation, edge: enumDirection.bottom }),
|
bottom: root.logic.computeWireEdgeStatus({ tile, rotation, edge: "bottom" }),
|
||||||
left: root.logic.computeWireEdgeStatus({ tile, rotation, edge: enumDirection.left }),
|
left: root.logic.computeWireEdgeStatus({ tile, rotation, edge: "left" }),
|
||||||
};
|
};
|
||||||
|
|
||||||
let flag = 0;
|
let flag = 0;
|
||||||
@ -176,7 +176,7 @@ export class MetaWireBuilding extends MetaBuilding {
|
|||||||
|
|
||||||
case 0x0001:
|
case 0x0001:
|
||||||
// Left
|
// Left
|
||||||
rotation += 90;
|
rotation = 90;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0010:
|
case 0x0010:
|
||||||
@ -187,17 +187,17 @@ export class MetaWireBuilding extends MetaBuilding {
|
|||||||
case 0x0011:
|
case 0x0011:
|
||||||
// Bottom | Left
|
// Bottom | Left
|
||||||
targetType = enumWireType.turn;
|
targetType = enumWireType.turn;
|
||||||
rotation += 90;
|
rotation = 90;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0100:
|
case 0x0100:
|
||||||
// Right
|
// Right
|
||||||
rotation += 90;
|
rotation = 90;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0101:
|
case 0x0101:
|
||||||
// Right | Left
|
// Right | Left
|
||||||
rotation += 90;
|
rotation = 90;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x0110:
|
case 0x0110:
|
||||||
@ -217,7 +217,7 @@ export class MetaWireBuilding extends MetaBuilding {
|
|||||||
case 0x1001:
|
case 0x1001:
|
||||||
// Top | Left
|
// Top | Left
|
||||||
targetType = enumWireType.turn;
|
targetType = enumWireType.turn;
|
||||||
rotation += 180;
|
rotation = 180;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x1010:
|
case 0x1010:
|
||||||
@ -227,25 +227,25 @@ export class MetaWireBuilding extends MetaBuilding {
|
|||||||
case 0x1011:
|
case 0x1011:
|
||||||
// Top | Bottom | Left
|
// Top | Bottom | Left
|
||||||
targetType = enumWireType.split;
|
targetType = enumWireType.split;
|
||||||
rotation += 90;
|
rotation = 90;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x1100:
|
case 0x1100:
|
||||||
// Top | Right
|
// Top | Right
|
||||||
targetType = enumWireType.turn;
|
targetType = enumWireType.turn;
|
||||||
rotation -= 90;
|
rotation = 270;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x1101:
|
case 0x1101:
|
||||||
// Top | Right | Left
|
// Top | Right | Left
|
||||||
targetType = enumWireType.split;
|
targetType = enumWireType.split;
|
||||||
rotation += 180;
|
rotation = 180;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x1110:
|
case 0x1110:
|
||||||
// Top | Right | Bottom
|
// Top | Right | Bottom
|
||||||
targetType = enumWireType.split;
|
targetType = enumWireType.split;
|
||||||
rotation -= 90;
|
rotation = 270;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x1111:
|
case 0x1111:
|
||||||
@ -254,10 +254,13 @@ export class MetaWireBuilding extends MetaBuilding {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const rotationVariant = /** @type {RotationVariant} **/ (arrayWireRotationVariantToType.indexOf(
|
||||||
|
targetType
|
||||||
|
));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// Clamp rotation
|
rotation,
|
||||||
rotation: (rotation + 360 * 10) % 360,
|
rotationVariant,
|
||||||
rotationVariant: arrayWireRotationVariantToType.indexOf(targetType),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,8 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {number} rotation
|
* @param {Angle} rotation
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
*/
|
*/
|
||||||
@ -78,7 +78,7 @@ export class MetaWireTunnelBuilding extends MetaBuilding {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant, variant) {
|
updateVariants(entity, rotationVariant, variant) {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { types } from "../../savegame/serialization";
|
|
||||||
import { BeltPath } from "../belt_path";
|
import { BeltPath } from "../belt_path";
|
||||||
import { Component } from "../component";
|
import { Component } from "../component";
|
||||||
|
|
||||||
@ -8,28 +7,28 @@ export const curvedBeltLength = /* Math.PI / 4 */ 0.78;
|
|||||||
/** @type {import("./item_acceptor").ItemAcceptorSlot} */
|
/** @type {import("./item_acceptor").ItemAcceptorSlot} */
|
||||||
export const FAKE_BELT_ACCEPTOR_SLOT = {
|
export const FAKE_BELT_ACCEPTOR_SLOT = {
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
directions: [enumDirection.bottom],
|
directions: ["bottom"],
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @type {Object<enumDirection, import("./item_ejector").ItemEjectorSlot>} */
|
/** @type {Object<Direction, import("./item_ejector").ItemEjectorSlot>} */
|
||||||
export const FAKE_BELT_EJECTOR_SLOT_BY_DIRECTION = {
|
export const FAKE_BELT_EJECTOR_SLOT_BY_DIRECTION = {
|
||||||
[enumDirection.top]: {
|
top: {
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.top,
|
direction: "top",
|
||||||
item: null,
|
item: null,
|
||||||
progress: 0,
|
progress: 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
[enumDirection.right]: {
|
right: {
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.right,
|
direction: "right",
|
||||||
item: null,
|
item: null,
|
||||||
progress: 0,
|
progress: 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
[enumDirection.left]: {
|
left: {
|
||||||
pos: new Vector(0, 0),
|
pos: new Vector(0, 0),
|
||||||
direction: enumDirection.left,
|
direction: "left",
|
||||||
item: null,
|
item: null,
|
||||||
progress: 0,
|
progress: 0,
|
||||||
},
|
},
|
||||||
@ -47,9 +46,9 @@ export class BeltComponent extends Component {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {enumDirection=} param0.direction The direction of the belt
|
* @param {Direction=} param0.direction The direction of the belt
|
||||||
*/
|
*/
|
||||||
constructor({ direction = enumDirection.top }) {
|
constructor({ direction = "top" }) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
@ -66,7 +65,7 @@ export class BeltComponent extends Component {
|
|||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
getEffectiveLengthTiles() {
|
getEffectiveLengthTiles() {
|
||||||
return this.direction === enumDirection.top ? 1.0 : curvedBeltLength;
|
return this.direction === "top" ? 1.0 : curvedBeltLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,16 +98,16 @@ export class BeltComponent extends Component {
|
|||||||
transformBeltToLocalSpace(progress) {
|
transformBeltToLocalSpace(progress) {
|
||||||
assert(progress >= 0.0, "Invalid progress ( < 0): " + progress);
|
assert(progress >= 0.0, "Invalid progress ( < 0): " + progress);
|
||||||
switch (this.direction) {
|
switch (this.direction) {
|
||||||
case enumDirection.top:
|
case "top":
|
||||||
assert(progress <= 1.02, "Invalid progress: " + progress);
|
assert(progress <= 1.02, "Invalid progress: " + progress);
|
||||||
return new Vector(0, 0.5 - progress);
|
return new Vector(0, 0.5 - progress);
|
||||||
|
|
||||||
case enumDirection.right: {
|
case "right": {
|
||||||
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 2: " + progress);
|
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 2: " + progress);
|
||||||
const arcProgress = (progress / curvedBeltLength) * 0.5 * Math.PI;
|
const arcProgress = (progress / curvedBeltLength) * 0.5 * Math.PI;
|
||||||
return new Vector(0.5 - 0.5 * Math.cos(arcProgress), 0.5 - 0.5 * Math.sin(arcProgress));
|
return new Vector(0.5 - 0.5 * Math.cos(arcProgress), 0.5 - 0.5 * Math.sin(arcProgress));
|
||||||
}
|
}
|
||||||
case enumDirection.left: {
|
case "left": {
|
||||||
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 3: " + progress);
|
assert(progress <= curvedBeltLength + 0.02, "Invalid progress 3: " + progress);
|
||||||
const arcProgress = (progress / curvedBeltLength) * 0.5 * Math.PI;
|
const arcProgress = (progress / curvedBeltLength) * 0.5 * Math.PI;
|
||||||
return new Vector(-0.5 + 0.5 * Math.cos(arcProgress), 0.5 - 0.5 * Math.sin(arcProgress));
|
return new Vector(-0.5 + 0.5 * Math.cos(arcProgress), 0.5 - 0.5 * Math.sin(arcProgress));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Component } from "../component";
|
import { Component } from "../component";
|
||||||
import { types } from "../../savegame/serialization";
|
import { types } from "../../savegame/serialization";
|
||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
|
|
||||||
export class BeltUnderlaysComponent extends Component {
|
export class BeltUnderlaysComponent extends Component {
|
||||||
static getId() {
|
static getId() {
|
||||||
@ -24,7 +24,7 @@ export class BeltUnderlaysComponent extends Component {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {Array<{pos: Vector, direction: enumDirection}>=} param0.underlays Where to render belt underlays
|
* @param {Array<{pos: Vector, direction: Direction}>=} param0.underlays Where to render belt underlays
|
||||||
*/
|
*/
|
||||||
constructor({ underlays }) {
|
constructor({ underlays }) {
|
||||||
super();
|
super();
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
import { enumDirection, enumInvertedDirections, Vector } from "../../core/vector";
|
import { inverseDirectionMap, Vector } from "../../core/vector";
|
||||||
import { types } from "../../savegame/serialization";
|
|
||||||
import { BaseItem } from "../base_item";
|
import { BaseItem } from "../base_item";
|
||||||
import { Component } from "../component";
|
import { Component } from "../component";
|
||||||
|
|
||||||
/** @typedef {{
|
/** @typedef {{
|
||||||
* pos: Vector,
|
* pos: Vector,
|
||||||
* directions: enumDirection[],
|
* directions: Direction[],
|
||||||
* filter?: ItemType
|
* filter?: ItemType
|
||||||
* }} ItemAcceptorSlot */
|
* }} ItemAcceptorSlot */
|
||||||
|
|
||||||
@ -14,12 +13,12 @@ import { Component } from "../component";
|
|||||||
* @typedef {{
|
* @typedef {{
|
||||||
* slot: ItemAcceptorSlot,
|
* slot: ItemAcceptorSlot,
|
||||||
* index: number,
|
* index: number,
|
||||||
* acceptedDirection: enumDirection
|
* acceptedDirection: Direction
|
||||||
* }} ItemAcceptorLocatedSlot */
|
* }} ItemAcceptorLocatedSlot */
|
||||||
|
|
||||||
/** @typedef {{
|
/** @typedef {{
|
||||||
* pos: Vector,
|
* pos: Vector,
|
||||||
* directions: enumDirection[],
|
* directions: Direction[],
|
||||||
* filter?: ItemType
|
* filter?: ItemType
|
||||||
* }} ItemAcceptorSlotConfig */
|
* }} ItemAcceptorSlotConfig */
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ export class ItemAcceptorComponent extends Component {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fixes belt animations
|
* Fixes belt animations
|
||||||
* @type {Array<{ item: BaseItem, slotIndex: number, animProgress: number, direction: enumDirection }>}
|
* @type {Array<{ item: BaseItem, slotIndex: number, animProgress: number, direction: Direction }>}
|
||||||
*/
|
*/
|
||||||
this.itemConsumptionAnimations = [];
|
this.itemConsumptionAnimations = [];
|
||||||
|
|
||||||
@ -93,7 +92,7 @@ export class ItemAcceptorComponent extends Component {
|
|||||||
/**
|
/**
|
||||||
* Called when an item has been accepted so that
|
* Called when an item has been accepted so that
|
||||||
* @param {number} slotIndex
|
* @param {number} slotIndex
|
||||||
* @param {enumDirection} direction
|
* @param {Direction} direction
|
||||||
* @param {BaseItem} item
|
* @param {BaseItem} item
|
||||||
*/
|
*/
|
||||||
onItemAccepted(slotIndex, direction, item) {
|
onItemAccepted(slotIndex, direction, item) {
|
||||||
@ -108,27 +107,21 @@ export class ItemAcceptorComponent extends Component {
|
|||||||
/**
|
/**
|
||||||
* Tries to find a slot which accepts the current item
|
* Tries to find a slot which accepts the current item
|
||||||
* @param {Vector} targetLocalTile
|
* @param {Vector} targetLocalTile
|
||||||
* @param {enumDirection} fromLocalDirection
|
* @param {Direction} fromLocalDirection
|
||||||
* @returns {ItemAcceptorLocatedSlot|null}
|
* @returns {ItemAcceptorLocatedSlot|null}
|
||||||
*/
|
*/
|
||||||
findMatchingSlot(targetLocalTile, fromLocalDirection) {
|
findMatchingSlot(targetLocalTile, fromLocalDirection) {
|
||||||
// We need to invert our direction since the acceptor specifies *from* which direction
|
// We need to invert our direction since the acceptor specifies *from* which direction
|
||||||
// it accepts items, but the ejector specifies *into* which direction it ejects items.
|
// it accepts items, but the ejector specifies *into* which direction it ejects items.
|
||||||
// E.g.: Ejector ejects into "right" direction but acceptor accepts from "left" direction.
|
// E.g.: Ejector ejects into "right" direction but acceptor accepts from "left" direction.
|
||||||
const desiredDirection = enumInvertedDirections[fromLocalDirection];
|
const desiredDirection = inverseDirectionMap[fromLocalDirection];
|
||||||
|
|
||||||
// Go over all slots and try to find a target slot
|
// Go over all slots and try to find a target slot
|
||||||
for (let slotIndex = 0; slotIndex < this.slots.length; ++slotIndex) {
|
for (let slotIndex = 0; slotIndex < this.slots.length; ++slotIndex) {
|
||||||
const slot = this.slots[slotIndex];
|
const slot = this.slots[slotIndex];
|
||||||
|
|
||||||
// Make sure the acceptor slot is on the right position
|
|
||||||
if (!slot.pos.equals(targetLocalTile)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the acceptor slot accepts items from our direction
|
// Check if the acceptor slot accepts items from our direction
|
||||||
for (let i = 0; i < slot.directions.length; ++i) {
|
for (let i = 0; i < slot.directions.length; ++i) {
|
||||||
// const localDirection = targetStaticComp.localDirectionToWorld(slot.directions[l]);
|
|
||||||
if (desiredDirection === slot.directions[i]) {
|
if (desiredDirection === slot.directions[i]) {
|
||||||
return {
|
return {
|
||||||
slot,
|
slot,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { enumDirection, enumDirectionToVector, Vector } from "../../core/vector";
|
import { directionVectorMap, Vector } from "../../core/vector";
|
||||||
import { types } from "../../savegame/serialization";
|
import { types } from "../../savegame/serialization";
|
||||||
import { BaseItem } from "../base_item";
|
import { BaseItem } from "../base_item";
|
||||||
import { BeltPath } from "../belt_path";
|
import { BeltPath } from "../belt_path";
|
||||||
@ -7,9 +7,10 @@ import { Entity } from "../entity";
|
|||||||
import { typeItemSingleton } from "../item_resolver";
|
import { typeItemSingleton } from "../item_resolver";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @typedef {import("./item_acceptor").ItemAcceptorLocatedSlot} ItemAcceptorLocatedSlot
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* pos: Vector,
|
* pos: Vector,
|
||||||
* direction: enumDirection,
|
* direction: Direction,
|
||||||
* item: BaseItem,
|
* item: BaseItem,
|
||||||
* progress: number?,
|
* progress: number?,
|
||||||
* cachedDestSlot?: import("./item_acceptor").ItemAcceptorLocatedSlot,
|
* cachedDestSlot?: import("./item_acceptor").ItemAcceptorLocatedSlot,
|
||||||
@ -53,7 +54,7 @@ export class ItemEjectorComponent extends Component {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {Array<{pos: Vector, direction: enumDirection }>=} param0.slots The slots to eject on
|
* @param {Array<{pos: Vector, direction: Direction }>=} param0.slots The slots to eject on
|
||||||
*/
|
*/
|
||||||
constructor({ slots = [] }) {
|
constructor({ slots = [] }) {
|
||||||
super();
|
super();
|
||||||
@ -67,7 +68,7 @@ export class ItemEjectorComponent extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array<{pos: Vector, direction: enumDirection }>} slots The slots to eject on
|
* @param {Array<{pos: Vector, direction: Direction }>} slots The slots to eject on
|
||||||
*/
|
*/
|
||||||
setSlots(slots) {
|
setSlots(slots) {
|
||||||
/** @type {Array<ItemEjectorSlot>} */
|
/** @type {Array<ItemEjectorSlot>} */
|
||||||
@ -91,7 +92,7 @@ export class ItemEjectorComponent extends Component {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
getSlotTargetLocalTile(slot) {
|
getSlotTargetLocalTile(slot) {
|
||||||
const directionVector = enumDirectionToVector[slot.direction];
|
const directionVector = directionVectorMap[slot.direction];
|
||||||
return slot.pos.add(directionVector);
|
return slot.pos.add(directionVector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import { globalConfig } from "../../core/config";
|
|||||||
import { DrawParameters } from "../../core/draw_parameters";
|
import { DrawParameters } from "../../core/draw_parameters";
|
||||||
import { Rectangle } from "../../core/rectangle";
|
import { Rectangle } from "../../core/rectangle";
|
||||||
import { AtlasSprite } from "../../core/sprites";
|
import { AtlasSprite } from "../../core/sprites";
|
||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { directionRotationMap, inverseAngleMap, Vector } from "../../core/vector";
|
||||||
import { types } from "../../savegame/serialization";
|
import { types } from "../../savegame/serialization";
|
||||||
import { getBuildingDataFromCode } from "../building_codes";
|
import { getBuildingDataFromCode } from "../building_codes";
|
||||||
import { Component } from "../component";
|
import { Component } from "../component";
|
||||||
@ -77,8 +77,8 @@ export class StaticMapEntityComponent extends Component {
|
|||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {Vector=} param0.origin Origin (Top Left corner) of the entity
|
* @param {Vector=} param0.origin Origin (Top Left corner) of the entity
|
||||||
* @param {Vector=} param0.tileSize Size of the entity in tiles
|
* @param {Vector=} param0.tileSize Size of the entity in tiles
|
||||||
* @param {number=} param0.rotation Rotation in degrees. Must be multiple of 90
|
* @param {Angle} param0.rotation Rotation in degrees. Must be multiple of 90
|
||||||
* @param {number=} param0.originalRotation Original Rotation in degrees. Must be multiple of 90
|
* @param {Angle=} param0.originalRotation Original Rotation in degrees. Must be multiple of 90
|
||||||
* @param {number=} param0.code Building code
|
* @param {number=} param0.code Building code
|
||||||
*/
|
*/
|
||||||
constructor({
|
constructor({
|
||||||
@ -126,34 +126,25 @@ export class StaticMapEntityComponent extends Component {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
applyRotationToVector(vector) {
|
applyRotationToVector(vector) {
|
||||||
return vector.rotateFastMultipleOf90(this.rotation);
|
return vector.rotate(this.rotation);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transforms the given vector/rotation from world space to local space
|
|
||||||
* @param {Vector} vector
|
|
||||||
* @returns {Vector}
|
|
||||||
*/
|
|
||||||
unapplyRotationToVector(vector) {
|
|
||||||
return vector.rotateFastMultipleOf90(360 - this.rotation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms the given direction from local space
|
* Transforms the given direction from local space
|
||||||
* @param {enumDirection} direction
|
* @param {Direction} direction
|
||||||
* @returns {enumDirection}
|
* @returns {Direction}
|
||||||
*/
|
*/
|
||||||
localDirectionToWorld(direction) {
|
localDirectionToWorld(direction) {
|
||||||
return Vector.transformDirectionFromMultipleOf90(direction, this.rotation);
|
return directionRotationMap[direction][this.rotation];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms the given direction from world to local space
|
* Transforms the given direction from world to local space
|
||||||
* @param {enumDirection} direction
|
* @param {Direction} direction
|
||||||
* @returns {enumDirection}
|
* @returns {Direction}
|
||||||
*/
|
*/
|
||||||
worldDirectionToLocal(direction) {
|
worldDirectionToLocal(direction) {
|
||||||
return Vector.transformDirectionFromMultipleOf90(direction, 360 - this.rotation);
|
return directionRotationMap[direction][inverseAngleMap[this.rotation]];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -162,10 +153,7 @@ export class StaticMapEntityComponent extends Component {
|
|||||||
* @returns {Vector}
|
* @returns {Vector}
|
||||||
*/
|
*/
|
||||||
localTileToWorld(localTile) {
|
localTileToWorld(localTile) {
|
||||||
const result = localTile.rotateFastMultipleOf90(this.rotation);
|
return localTile.rotate(this.rotation).addInplace(this.origin);
|
||||||
result.x += this.origin.x;
|
|
||||||
result.y += this.origin.y;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -173,8 +161,7 @@ export class StaticMapEntityComponent extends Component {
|
|||||||
* @param {Vector} worldTile
|
* @param {Vector} worldTile
|
||||||
*/
|
*/
|
||||||
worldToLocalTile(worldTile) {
|
worldToLocalTile(worldTile) {
|
||||||
const localUnrotated = worldTile.sub(this.origin);
|
return worldTile.sub(this.origin).rotate(inverseAngleMap[this.rotation]);
|
||||||
return this.unapplyRotationToVector(localUnrotated);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { enumDirection, Vector } from "../../core/vector";
|
import { Vector } from "../../core/vector";
|
||||||
import { BaseItem } from "../base_item";
|
import { BaseItem } from "../base_item";
|
||||||
import { Component } from "../component";
|
import { Component } from "../component";
|
||||||
import { types } from "../../savegame/serialization";
|
import { types } from "../../savegame/serialization";
|
||||||
@ -13,13 +13,13 @@ export const enumPinSlotType = {
|
|||||||
/** @typedef {{
|
/** @typedef {{
|
||||||
* pos: Vector,
|
* pos: Vector,
|
||||||
* type: enumPinSlotType,
|
* type: enumPinSlotType,
|
||||||
* direction: enumDirection
|
* direction: Direction
|
||||||
* }} WirePinSlotDefinition */
|
* }} WirePinSlotDefinition */
|
||||||
|
|
||||||
/** @typedef {{
|
/** @typedef {{
|
||||||
* pos: Vector,
|
* pos: Vector,
|
||||||
* type: enumPinSlotType,
|
* type: enumPinSlotType,
|
||||||
* direction: enumDirection,
|
* direction: Direction,
|
||||||
* value: BaseItem,
|
* value: BaseItem,
|
||||||
* linkedNetwork: import("../systems/wire").WireNetwork
|
* linkedNetwork: import("../systems/wire").WireNetwork
|
||||||
* }} WirePinSlot */
|
* }} WirePinSlot */
|
||||||
|
@ -5,7 +5,7 @@ import { Component } from "./component";
|
|||||||
|
|
||||||
import { GameRoot } from "./root";
|
import { GameRoot } from "./root";
|
||||||
import { globalConfig } from "../core/config";
|
import { globalConfig } from "../core/config";
|
||||||
import { enumDirectionToVector, enumDirectionToAngle } from "../core/vector";
|
import { directionAngleMap, directionVectorMap } from "../core/vector";
|
||||||
import { BasicSerializableObject, types } from "../savegame/serialization";
|
import { BasicSerializableObject, types } from "../savegame/serialization";
|
||||||
import { EntityComponentStorage } from "./entity_components";
|
import { EntityComponentStorage } from "./entity_components";
|
||||||
import { Loader } from "../core/loader";
|
import { Loader } from "../core/loader";
|
||||||
@ -172,8 +172,8 @@ export class Entity extends BasicSerializableObject {
|
|||||||
const slot = ejectorComp.slots[i];
|
const slot = ejectorComp.slots[i];
|
||||||
const slotTile = staticComp.localTileToWorld(slot.pos);
|
const slotTile = staticComp.localTileToWorld(slot.pos);
|
||||||
const direction = staticComp.localDirectionToWorld(slot.direction);
|
const direction = staticComp.localDirectionToWorld(slot.direction);
|
||||||
const directionVector = enumDirectionToVector[direction];
|
const directionVector = directionVectorMap[direction];
|
||||||
const angle = Math.radians(enumDirectionToAngle[direction]);
|
const angle = Math.radians(directionAngleMap[direction]);
|
||||||
|
|
||||||
context.globalAlpha = slot.item ? 1 : 0.2;
|
context.globalAlpha = slot.item ? 1 : 0.2;
|
||||||
drawRotatedSprite({
|
drawRotatedSprite({
|
||||||
@ -195,8 +195,8 @@ export class Entity extends BasicSerializableObject {
|
|||||||
const slotTile = staticComp.localTileToWorld(slot.pos);
|
const slotTile = staticComp.localTileToWorld(slot.pos);
|
||||||
for (let k = 0; k < slot.directions.length; ++k) {
|
for (let k = 0; k < slot.directions.length; ++k) {
|
||||||
const direction = staticComp.localDirectionToWorld(slot.directions[k]);
|
const direction = staticComp.localDirectionToWorld(slot.directions[k]);
|
||||||
const directionVector = enumDirectionToVector[direction];
|
const directionVector = directionVectorMap[direction];
|
||||||
const angle = Math.radians(enumDirectionToAngle[direction] + 180);
|
const angle = Math.radians(directionAngleMap[direction] + 180);
|
||||||
context.globalAlpha = 0.4;
|
context.globalAlpha = 0.4;
|
||||||
drawRotatedSprite({
|
drawRotatedSprite({
|
||||||
parameters,
|
parameters,
|
||||||
|
@ -4,13 +4,7 @@ import { DrawParameters } from "../../../core/draw_parameters";
|
|||||||
import { drawRotatedSprite } from "../../../core/draw_utils";
|
import { drawRotatedSprite } from "../../../core/draw_utils";
|
||||||
import { Loader } from "../../../core/loader";
|
import { Loader } from "../../../core/loader";
|
||||||
import { clamp, makeDiv, removeAllChildren } from "../../../core/utils";
|
import { clamp, makeDiv, removeAllChildren } from "../../../core/utils";
|
||||||
import {
|
import { directionVectorMap, directionAngleMap, inverseDirectionMap, Vector } from "../../../core/vector";
|
||||||
enumDirectionToAngle,
|
|
||||||
enumDirectionToVector,
|
|
||||||
enumInvertedDirections,
|
|
||||||
Vector,
|
|
||||||
enumDirection,
|
|
||||||
} from "../../../core/vector";
|
|
||||||
import { T } from "../../../translations";
|
import { T } from "../../../translations";
|
||||||
import { KEYMAPPINGS } from "../../key_action_mapper";
|
import { KEYMAPPINGS } from "../../key_action_mapper";
|
||||||
import { defaultBuildingVariant } from "../../meta_building";
|
import { defaultBuildingVariant } from "../../meta_building";
|
||||||
@ -208,8 +202,8 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
|||||||
const dimensions = metaBuilding.getDimensions(variant);
|
const dimensions = metaBuilding.getDimensions(variant);
|
||||||
const sprite = metaBuilding.getPreviewSprite(0, variant);
|
const sprite = metaBuilding.getPreviewSprite(0, variant);
|
||||||
const spriteWrapper = makeDiv(element, null, ["iconWrap"]);
|
const spriteWrapper = makeDiv(element, null, ["iconWrap"]);
|
||||||
spriteWrapper.setAttribute("data-tile-w", dimensions.x);
|
spriteWrapper.setAttribute("data-tile-w", `${dimensions.x}`);
|
||||||
spriteWrapper.setAttribute("data-tile-h", dimensions.y);
|
spriteWrapper.setAttribute("data-tile-h", `${dimensions.y}`);
|
||||||
|
|
||||||
spriteWrapper.innerHTML = sprite.getAsHTML(iconSize * dimensions.x, iconSize * dimensions.y);
|
spriteWrapper.innerHTML = sprite.getAsHTML(iconSize * dimensions.x, iconSize * dimensions.y);
|
||||||
|
|
||||||
@ -495,7 +489,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
|||||||
const worldDirection = staticComp.localDirectionToWorld(direction);
|
const worldDirection = staticComp.localDirectionToWorld(direction);
|
||||||
|
|
||||||
// Figure out which tile ejects to this slot
|
// Figure out which tile ejects to this slot
|
||||||
const sourceTile = acceptorSlotWsTile.add(enumDirectionToVector[worldDirection]);
|
const sourceTile = acceptorSlotWsTile.add(directionVectorMap[worldDirection]);
|
||||||
|
|
||||||
let isBlocked = false;
|
let isBlocked = false;
|
||||||
let isConnected = false;
|
let isConnected = false;
|
||||||
@ -519,7 +513,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
|||||||
} else if (
|
} else if (
|
||||||
sourceBeltComp &&
|
sourceBeltComp &&
|
||||||
sourceStaticComp.localDirectionToWorld(sourceBeltComp.direction) ===
|
sourceStaticComp.localDirectionToWorld(sourceBeltComp.direction) ===
|
||||||
enumInvertedDirections[worldDirection]
|
inverseDirectionMap[worldDirection]
|
||||||
) {
|
) {
|
||||||
// Belt connected
|
// Belt connected
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
@ -538,7 +532,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
|||||||
sprite,
|
sprite,
|
||||||
x: acceptorSlotWsPos.x,
|
x: acceptorSlotWsPos.x,
|
||||||
y: acceptorSlotWsPos.y,
|
y: acceptorSlotWsPos.y,
|
||||||
angle: Math.radians(enumDirectionToAngle[enumInvertedDirections[worldDirection]]),
|
angle: Math.radians(directionAngleMap[inverseDirectionMap[worldDirection]]),
|
||||||
size: 13,
|
size: 13,
|
||||||
offsetY: offsetShift + 13,
|
offsetY: offsetShift + 13,
|
||||||
});
|
});
|
||||||
@ -550,7 +544,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
|||||||
for (let ejectorSlotIndex = 0; ejectorSlotIndex < ejectorSlots.length; ++ejectorSlotIndex) {
|
for (let ejectorSlotIndex = 0; ejectorSlotIndex < ejectorSlots.length; ++ejectorSlotIndex) {
|
||||||
const slot = ejectorSlots[ejectorSlotIndex];
|
const slot = ejectorSlots[ejectorSlotIndex];
|
||||||
|
|
||||||
const ejectorSlotLocalTile = slot.pos.add(enumDirectionToVector[slot.direction]);
|
const ejectorSlotLocalTile = slot.pos.add(directionVectorMap[slot.direction]);
|
||||||
const ejectorSlotWsTile = staticComp.localTileToWorld(ejectorSlotLocalTile);
|
const ejectorSlotWsTile = staticComp.localTileToWorld(ejectorSlotLocalTile);
|
||||||
|
|
||||||
const ejectorSLotWsPos = ejectorSlotWsTile.toWorldSpaceCenterOfTile();
|
const ejectorSLotWsPos = ejectorSlotWsTile.toWorldSpaceCenterOfTile();
|
||||||
@ -576,7 +570,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
|||||||
if (destAcceptor && destAcceptor.findMatchingSlot(destLocalTile, destLocalDir)) {
|
if (destAcceptor && destAcceptor.findMatchingSlot(destLocalTile, destLocalDir)) {
|
||||||
// This one is connected, all good
|
// This one is connected, all good
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
} else if (destEntity.components.Belt && destLocalDir === enumDirection.top) {
|
} else if (destEntity.components.Belt && destLocalDir === "top") {
|
||||||
// Connected to a belt
|
// Connected to a belt
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
} else {
|
} else {
|
||||||
@ -594,7 +588,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
|||||||
sprite,
|
sprite,
|
||||||
x: ejectorSLotWsPos.x,
|
x: ejectorSLotWsPos.x,
|
||||||
y: ejectorSLotWsPos.y,
|
y: ejectorSLotWsPos.y,
|
||||||
angle: Math.radians(enumDirectionToAngle[ejectorSlotWsDirection]),
|
angle: Math.radians(directionAngleMap[ejectorSlotWsDirection]),
|
||||||
size: 13,
|
size: 13,
|
||||||
offsetY: offsetShift,
|
offsetY: offsetShift,
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,7 @@ import { globalConfig } from "../../../core/config";
|
|||||||
import { gMetaBuildingRegistry } from "../../../core/global_registries";
|
import { gMetaBuildingRegistry } from "../../../core/global_registries";
|
||||||
import { Signal, STOP_PROPAGATION } from "../../../core/signal";
|
import { Signal, STOP_PROPAGATION } from "../../../core/signal";
|
||||||
import { TrackedState } from "../../../core/tracked_state";
|
import { TrackedState } from "../../../core/tracked_state";
|
||||||
import { Vector } from "../../../core/vector";
|
import { clockwiseAngleMap, counterClockwiseAngleMap, snapToAngle, Vector } from "../../../core/vector";
|
||||||
import { enumMouseButton } from "../../camera";
|
import { enumMouseButton } from "../../camera";
|
||||||
import { StaticMapEntityComponent } from "../../components/static_map_entity";
|
import { StaticMapEntityComponent } from "../../components/static_map_entity";
|
||||||
import { Entity } from "../../entity";
|
import { Entity } from "../../entity";
|
||||||
@ -46,13 +46,13 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The current rotation
|
* The current rotation
|
||||||
* @type {number}
|
* @type {Angle}
|
||||||
*/
|
*/
|
||||||
this.currentBaseRotationGeneral = 0;
|
this.currentBaseRotationGeneral = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current rotation preference for each building.
|
* The current rotation preference for each building.
|
||||||
* @type{Object.<string,number>}
|
* @type{Object.<string,Angle>}
|
||||||
*/
|
*/
|
||||||
this.preferredBaseRotations = {};
|
this.preferredBaseRotations = {};
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current base rotation for the current meta-building.
|
* Returns the current base rotation for the current meta-building.
|
||||||
* @returns {number}
|
* @returns {Angle}
|
||||||
*/
|
*/
|
||||||
get currentBaseRotation() {
|
get currentBaseRotation() {
|
||||||
if (!this.root.app.settings.getAllSettings().rotationByBuilding) {
|
if (!this.root.app.settings.getAllSettings().rotationByBuilding) {
|
||||||
@ -162,7 +162,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the base rotation for the current meta-building.
|
* Sets the base rotation for the current meta-building.
|
||||||
* @param {number} rotation The new rotation/angle.
|
* @param {Angle} rotation The new rotation/angle.
|
||||||
*/
|
*/
|
||||||
set currentBaseRotation(rotation) {
|
set currentBaseRotation(rotation) {
|
||||||
if (!this.root.app.settings.getAllSettings().rotationByBuilding) {
|
if (!this.root.app.settings.getAllSettings().rotationByBuilding) {
|
||||||
@ -274,9 +274,9 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
const selectedBuilding = this.currentMetaBuilding.get();
|
const selectedBuilding = this.currentMetaBuilding.get();
|
||||||
if (selectedBuilding) {
|
if (selectedBuilding) {
|
||||||
if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateInverseModifier).pressed) {
|
if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateInverseModifier).pressed) {
|
||||||
this.currentBaseRotation = (this.currentBaseRotation + 270) % 360;
|
this.currentBaseRotation = counterClockwiseAngleMap[this.currentBaseRotation];
|
||||||
} else {
|
} else {
|
||||||
this.currentBaseRotation = (this.currentBaseRotation + 90) % 360;
|
this.currentBaseRotation = clockwiseAngleMap[this.currentBaseRotation];
|
||||||
}
|
}
|
||||||
const staticComp = this.fakeEntity.components.StaticMapEntity;
|
const staticComp = this.fakeEntity.components.StaticMapEntity;
|
||||||
staticComp.rotation = this.currentBaseRotation;
|
staticComp.rotation = this.currentBaseRotation;
|
||||||
@ -424,7 +424,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
KEYMAPPINGS.placementModifiers.placementDisableAutoOrientation
|
KEYMAPPINGS.placementModifiers.placementDisableAutoOrientation
|
||||||
).pressed
|
).pressed
|
||||||
) {
|
) {
|
||||||
this.currentBaseRotation = (180 + this.currentBaseRotation) % 360;
|
this.currentBaseRotation = clockwiseAngleMap[clockwiseAngleMap[this.currentBaseRotation]];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we should stop placement
|
// Check if we should stop placement
|
||||||
@ -508,7 +508,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the path which the current direction lock will use
|
* Finds the path which the current direction lock will use
|
||||||
* @returns {Array<{ tile: Vector, rotation: number }>}
|
* @returns {Array<{ tile: Vector, rotation: Angle }>}
|
||||||
*/
|
*/
|
||||||
computeDirectionLockPath() {
|
computeDirectionLockPath() {
|
||||||
const mousePosition = this.root.app.mousePosition;
|
const mousePosition = this.root.app.mousePosition;
|
||||||
@ -537,7 +537,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
const lengthToCorner = Math.round(pathToCorner.length());
|
const lengthToCorner = Math.round(pathToCorner.length());
|
||||||
let currentPos = startTile.copy();
|
let currentPos = startTile.copy();
|
||||||
|
|
||||||
let rotation = (Math.round(Math.degrees(deltaToCorner.angle()) / 90) * 90 + 360) % 360;
|
let rotation = snapToAngle(deltaToCorner.angle());
|
||||||
|
|
||||||
if (lengthToCorner > 0) {
|
if (lengthToCorner > 0) {
|
||||||
for (let i = 0; i < lengthToCorner; ++i) {
|
for (let i = 0; i < lengthToCorner; ++i) {
|
||||||
@ -555,7 +555,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
const lengthFromCorner = Math.round(pathFromCorner.length());
|
const lengthFromCorner = Math.round(pathFromCorner.length());
|
||||||
|
|
||||||
if (lengthFromCorner > 0) {
|
if (lengthFromCorner > 0) {
|
||||||
rotation = (Math.round(Math.degrees(deltaFromCorner.angle()) / 90) * 90 + 360) % 360;
|
rotation = snapToAngle(deltaFromCorner.angle());
|
||||||
for (let i = 0; i < lengthFromCorner + 1; ++i) {
|
for (let i = 0; i < lengthFromCorner + 1; ++i) {
|
||||||
result.push({
|
result.push({
|
||||||
tile: currentPos.copy(),
|
tile: currentPos.copy(),
|
||||||
@ -692,12 +692,12 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
|||||||
).pressed
|
).pressed
|
||||||
) {
|
) {
|
||||||
const delta = newPos.sub(oldPos);
|
const delta = newPos.sub(oldPos);
|
||||||
const angleDeg = Math.degrees(delta.angle());
|
this.currentBaseRotation = snapToAngle(delta.angle());
|
||||||
this.currentBaseRotation = (Math.round(angleDeg / 90) * 90 + 360) % 360;
|
|
||||||
|
|
||||||
// Holding alt inverts the placement
|
// Holding alt inverts the placement
|
||||||
if (this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.placeInverse).pressed) {
|
if (this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.placeInverse).pressed) {
|
||||||
this.currentBaseRotation = (180 + this.currentBaseRotation) % 360;
|
this.currentBaseRotation =
|
||||||
|
clockwiseAngleMap[clockwiseAngleMap[this.currentBaseRotation]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { createLogger } from "../core/logging";
|
import { createLogger } from "../core/logging";
|
||||||
import { STOP_PROPAGATION } from "../core/signal";
|
import { STOP_PROPAGATION } from "../core/signal";
|
||||||
import { round2Digits } from "../core/utils";
|
import { round2Digits } from "../core/utils";
|
||||||
import { enumDirection, enumDirectionToVector, enumInvertedDirections, Vector } from "../core/vector";
|
import { directionVectorMap, inverseDirectionMap, Vector } from "../core/vector";
|
||||||
import { getBuildingDataFromCode } from "./building_codes";
|
import { getBuildingDataFromCode } from "./building_codes";
|
||||||
import { Entity } from "./entity";
|
import { Entity } from "./entity";
|
||||||
import { MetaBuilding } from "./meta_building";
|
import { MetaBuilding } from "./meta_building";
|
||||||
@ -19,26 +19,23 @@ export const enumWireEdgeFlag = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Typing helper
|
* @typedef {import("./components/item_ejector").ItemEjectorSlot} ItemEjectorSlot
|
||||||
|
* @typedef {import("./components/item_acceptor").ItemAcceptorSlot} ItemAcceptorSlot
|
||||||
|
*
|
||||||
* @typedef {Array<{
|
* @typedef {Array<{
|
||||||
* entity: Entity,
|
* entity: Entity,
|
||||||
* slot: import("./components/item_ejector").ItemEjectorSlot,
|
* slot: ItemEjectorSlot,
|
||||||
* fromTile: Vector,
|
* fromTile: Vector,
|
||||||
* toDirection: enumDirection
|
* toDirection: Direction
|
||||||
* }>} EjectorsAffectingTile
|
* }>} EjectorsAffectingTile
|
||||||
*/
|
*
|
||||||
|
|
||||||
/**
|
|
||||||
* Typing helper
|
|
||||||
* @typedef {Array<{
|
* @typedef {Array<{
|
||||||
* entity: Entity,
|
* entity: Entity,
|
||||||
* slot: import("./components/item_acceptor").ItemAcceptorSlot,
|
* slot: ItemAcceptorSlot,
|
||||||
* toTile: Vector,
|
* toTile: Vector,
|
||||||
* fromDirection: enumDirection
|
* fromDirection: Direction
|
||||||
* }>} AcceptorsAffectingTile
|
* }>} AcceptorsAffectingTile
|
||||||
*/
|
*
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* acceptors: AcceptorsAffectingTile,
|
* acceptors: AcceptorsAffectingTile,
|
||||||
* ejectors: EjectorsAffectingTile
|
* ejectors: EjectorsAffectingTile
|
||||||
@ -95,9 +92,9 @@ export class GameLogic {
|
|||||||
* Attempts to place the given building
|
* Attempts to place the given building
|
||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {Vector} param0.origin
|
* @param {Vector} param0.origin
|
||||||
* @param {number} param0.rotation
|
* @param {Angle} param0.rotation
|
||||||
* @param {number} param0.originalRotation
|
* @param {Angle} param0.originalRotation
|
||||||
* @param {number} param0.rotationVariant
|
* @param {RotationVariant} param0.rotationVariant
|
||||||
* @param {string} param0.variant
|
* @param {string} param0.variant
|
||||||
* @param {MetaBuilding} param0.building
|
* @param {MetaBuilding} param0.building
|
||||||
* @returns {Entity}
|
* @returns {Entity}
|
||||||
@ -194,13 +191,12 @@ export class GameLogic {
|
|||||||
* Computes the flag for a given tile
|
* Computes the flag for a given tile
|
||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {Vector} param0.tile The tile to check at
|
* @param {Vector} param0.tile The tile to check at
|
||||||
* @param {enumDirection} param0.edge The edge to check for
|
* @param {Direction} param0.edge The edge to check for
|
||||||
* @param {number} param0.rotation The local tiles base rotation
|
* @param {Angle} param0.rotation The local tiles base rotation
|
||||||
*/
|
*/
|
||||||
computeWireEdgeStatus({ tile, edge, rotation }) {
|
computeWireEdgeStatus({ tile, edge, rotation }) {
|
||||||
const offset = enumDirectionToVector[edge];
|
const offset = directionVectorMap[edge];
|
||||||
const refTile = tile.add(offset);
|
const refTile = tile.add(offset);
|
||||||
// const angle = enumDirectionToAngle[edge];
|
|
||||||
|
|
||||||
// // First, check if this edge can be connected from locally
|
// // First, check if this edge can be connected from locally
|
||||||
// const canConnectLocally = rotation === angle || (rotation + 180) % 360 === angle;
|
// const canConnectLocally = rotation === angle || (rotation + 180) % 360 === angle;
|
||||||
@ -306,7 +302,7 @@ export class GameLogic {
|
|||||||
/**
|
/**
|
||||||
* Gets the flag at the given tile
|
* Gets the flag at the given tile
|
||||||
* @param {Vector} tile
|
* @param {Vector} tile
|
||||||
* @param {enumDirection} edge
|
* @param {Direction} edge
|
||||||
* @returns {enumWireEdgeFlag}
|
* @returns {enumWireEdgeFlag}
|
||||||
*/
|
*/
|
||||||
getWireEdgeFlag(tile, edge) {
|
getWireEdgeFlag(tile, edge) {
|
||||||
@ -337,7 +333,7 @@ export class GameLogic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the pin has the right direction
|
// Check if the pin has the right direction
|
||||||
if (pinDirection !== enumInvertedDirections[edge]) {
|
if (pinDirection !== inverseDirectionMap[edge]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,8 +358,8 @@ export class GameLogic {
|
|||||||
return enumWireEdgeFlag.connected;
|
return enumWireEdgeFlag.connected;
|
||||||
} else {
|
} else {
|
||||||
// Its a coating, check if it matches the direction
|
// Its a coating, check if it matches the direction
|
||||||
const referenceDirection = targetStaticComp.localDirectionToWorld(enumDirection.top);
|
const referenceDirection = targetStaticComp.localDirectionToWorld("top");
|
||||||
return referenceDirection === edge || enumInvertedDirections[referenceDirection] === edge
|
return referenceDirection === edge || inverseDirectionMap[referenceDirection] === edge
|
||||||
? enumWireEdgeFlag.connected
|
? enumWireEdgeFlag.connected
|
||||||
: enumWireEdgeFlag.empty;
|
: enumWireEdgeFlag.empty;
|
||||||
}
|
}
|
||||||
@ -375,10 +371,6 @@ export class GameLogic {
|
|||||||
return enumWireEdgeFlag.empty;
|
return enumWireEdgeFlag.empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
// const refAngle = enumDirectionToAngle[edge];
|
|
||||||
// const refRotation = targetEntity.components.StaticMapEntity.originalRotation;
|
|
||||||
// const canConnectRemotely = refRotation === refAngle || (refRotation + 180) % 360 === refAngle;
|
|
||||||
|
|
||||||
// Actually connected
|
// Actually connected
|
||||||
return enumWireEdgeFlag.connected;
|
return enumWireEdgeFlag.connected;
|
||||||
}
|
}
|
||||||
@ -390,9 +382,9 @@ export class GameLogic {
|
|||||||
*/
|
*/
|
||||||
getEjectorsAndAcceptorsAtTile(tile) {
|
getEjectorsAndAcceptorsAtTile(tile) {
|
||||||
/** @type {EjectorsAffectingTile} */
|
/** @type {EjectorsAffectingTile} */
|
||||||
let ejectors = [];
|
const ejectors = [];
|
||||||
/** @type {AcceptorsAffectingTile} */
|
/** @type {AcceptorsAffectingTile} */
|
||||||
let acceptors = [];
|
const acceptors = [];
|
||||||
|
|
||||||
// Well .. please ignore this code! :D
|
// Well .. please ignore this code! :D
|
||||||
for (let dx = -1; dx <= 1; ++dx) {
|
for (let dx = -1; dx <= 1; ++dx) {
|
||||||
@ -430,7 +422,7 @@ export class GameLogic {
|
|||||||
const slot = ejectorSlots[ejectorSlot];
|
const slot = ejectorSlots[ejectorSlot];
|
||||||
const wsTile = staticComp.localTileToWorld(slot.pos);
|
const wsTile = staticComp.localTileToWorld(slot.pos);
|
||||||
const wsDirection = staticComp.localDirectionToWorld(slot.direction);
|
const wsDirection = staticComp.localDirectionToWorld(slot.direction);
|
||||||
const targetTile = wsTile.add(enumDirectionToVector[wsDirection]);
|
const targetTile = wsTile.add(directionVectorMap[wsDirection]);
|
||||||
if (targetTile.equals(tile)) {
|
if (targetTile.equals(tile)) {
|
||||||
ejectors.push({
|
ejectors.push({
|
||||||
entity,
|
entity,
|
||||||
@ -448,7 +440,7 @@ export class GameLogic {
|
|||||||
const direction = slot.directions[k];
|
const direction = slot.directions[k];
|
||||||
const wsDirection = staticComp.localDirectionToWorld(direction);
|
const wsDirection = staticComp.localDirectionToWorld(direction);
|
||||||
|
|
||||||
const sourceTile = wsTile.add(enumDirectionToVector[wsDirection]);
|
const sourceTile = wsTile.add(directionVectorMap[wsDirection]);
|
||||||
if (sourceTile.equals(tile)) {
|
if (sourceTile.equals(tile)) {
|
||||||
acceptors.push({
|
acceptors.push({
|
||||||
entity,
|
entity,
|
||||||
|
@ -55,9 +55,9 @@ export class MetaBuilding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can return a special interlaved 9 elements overlay matrix for rendering
|
* Can return a special interleved 9 elements overlay matrix for rendering
|
||||||
* @param {number} rotation
|
* @param {Angle} rotation
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @returns {Array<number>|null}
|
* @returns {Array<number>|null}
|
||||||
@ -192,9 +192,9 @@ export class MetaBuilding {
|
|||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {GameRoot} param0.root
|
* @param {GameRoot} param0.root
|
||||||
* @param {Vector} param0.origin Origin tile
|
* @param {Vector} param0.origin Origin tile
|
||||||
* @param {number=} param0.rotation Rotation
|
* @param {Angle=} param0.rotation Rotation
|
||||||
* @param {number} param0.originalRotation Original Rotation
|
* @param {Angle} param0.originalRotation Original Rotation
|
||||||
* @param {number} param0.rotationVariant Rotation variant
|
* @param {RotationVariant} param0.rotationVariant Rotation variant
|
||||||
* @param {string} param0.variant
|
* @param {string} param0.variant
|
||||||
*/
|
*/
|
||||||
createEntity({ root, origin, rotation, originalRotation, rotationVariant, variant }) {
|
createEntity({ root, origin, rotation, originalRotation, rotationVariant, variant }) {
|
||||||
@ -216,7 +216,7 @@ export class MetaBuilding {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the sprite for a given variant
|
* Returns the sprite for a given variant
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
* @returns {AtlasSprite}
|
* @returns {AtlasSprite}
|
||||||
*/
|
*/
|
||||||
@ -234,10 +234,10 @@ export class MetaBuilding {
|
|||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {GameRoot} param0.root
|
* @param {GameRoot} param0.root
|
||||||
* @param {Vector} param0.tile
|
* @param {Vector} param0.tile
|
||||||
* @param {number} param0.rotation
|
* @param {Angle} param0.rotation
|
||||||
* @param {string} param0.variant
|
* @param {string} param0.variant
|
||||||
* @param {Layer} param0.layer
|
* @param {Layer} param0.layer
|
||||||
* @return {{ rotation: number, rotationVariant: number, connectedEntities?: Array<Entity> }}
|
* @return {{ rotation: Angle, rotationVariant: RotationVariant, connectedEntities?: Array<Entity> }}
|
||||||
*/
|
*/
|
||||||
computeOptimalDirectionAndRotationVariantAtTile({ root, tile, rotation, variant, layer }) {
|
computeOptimalDirectionAndRotationVariantAtTile({ root, tile, rotation, variant, layer }) {
|
||||||
if (!this.getIsRotateable(variant)) {
|
if (!this.getIsRotateable(variant)) {
|
||||||
@ -255,7 +255,7 @@ export class MetaBuilding {
|
|||||||
/**
|
/**
|
||||||
* Should update the entity to match the given variants
|
* Should update the entity to match the given variants
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
* @param {number} rotationVariant
|
* @param {RotationVariant} rotationVariant
|
||||||
* @param {string} variant
|
* @param {string} variant
|
||||||
*/
|
*/
|
||||||
updateVariants(entity, rotationVariant, variant) {}
|
updateVariants(entity, rotationVariant, variant) {}
|
||||||
|
@ -5,7 +5,7 @@ import { Loader } from "../../core/loader";
|
|||||||
import { createLogger } from "../../core/logging";
|
import { createLogger } from "../../core/logging";
|
||||||
import { AtlasSprite } from "../../core/sprites";
|
import { AtlasSprite } from "../../core/sprites";
|
||||||
import { fastArrayDeleteValue } from "../../core/utils";
|
import { fastArrayDeleteValue } from "../../core/utils";
|
||||||
import { enumDirection, enumDirectionToVector, enumInvertedDirections, Vector } from "../../core/vector";
|
import { directionVectorMap, inverseDirectionMap, Vector } from "../../core/vector";
|
||||||
import { BeltPath } from "../belt_path";
|
import { BeltPath } from "../belt_path";
|
||||||
import { arrayBeltVariantToRotation, MetaBeltBaseBuilding } from "../buildings/belt_base";
|
import { arrayBeltVariantToRotation, MetaBeltBaseBuilding } from "../buildings/belt_base";
|
||||||
import { BeltComponent } from "../components/belt";
|
import { BeltComponent } from "../components/belt";
|
||||||
@ -26,33 +26,27 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
constructor(root) {
|
constructor(root) {
|
||||||
super(root, [BeltComponent]);
|
super(root, [BeltComponent]);
|
||||||
/**
|
/**
|
||||||
* @type {Object.<enumDirection, Array<AtlasSprite>>}
|
* @type {Record<Exclude<Direction, "bottom">, AtlasSprite>}
|
||||||
*/
|
*/
|
||||||
this.beltSprites = {
|
this.beltSprites = {
|
||||||
[enumDirection.top]: Loader.getSprite("sprites/belt/built/forward_0.png"),
|
top: Loader.getSprite("sprites/belt/built/forward_0.png"),
|
||||||
[enumDirection.left]: Loader.getSprite("sprites/belt/built/left_0.png"),
|
left: Loader.getSprite("sprites/belt/built/left_0.png"),
|
||||||
[enumDirection.right]: Loader.getSprite("sprites/belt/built/right_0.png"),
|
right: Loader.getSprite("sprites/belt/built/right_0.png"),
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Object.<enumDirection, Array<AtlasSprite>>}
|
* @type {Record<Exclude<Direction, "bottom">, Array<AtlasSprite>>}
|
||||||
*/
|
*/
|
||||||
this.beltAnimations = {
|
this.beltAnimations = {
|
||||||
[enumDirection.top]: [],
|
top: [],
|
||||||
[enumDirection.left]: [],
|
left: [],
|
||||||
[enumDirection.right]: [],
|
right: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let i = 0; i < BELT_ANIM_COUNT; ++i) {
|
for (let i = 0; i < BELT_ANIM_COUNT; ++i) {
|
||||||
this.beltAnimations[enumDirection.top].push(
|
this.beltAnimations.top.push(Loader.getSprite(`sprites/belt/built/forward_${i}.png`));
|
||||||
Loader.getSprite("sprites/belt/built/forward_" + i + ".png")
|
this.beltAnimations.left.push(Loader.getSprite(`sprites/belt/built/left_${i}.png`));
|
||||||
);
|
this.beltAnimations.right.push(Loader.getSprite(`sprites/belt/built/right_${i}.png`));
|
||||||
this.beltAnimations[enumDirection.left].push(
|
|
||||||
Loader.getSprite("sprites/belt/built/left_" + i + ".png")
|
|
||||||
);
|
|
||||||
this.beltAnimations[enumDirection.right].push(
|
|
||||||
Loader.getSprite("sprites/belt/built/right_" + i + ".png")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.root.signals.entityDestroyed.add(this.onEntityDestroyed, this);
|
this.root.signals.entityDestroyed.add(this.onEntityDestroyed, this);
|
||||||
@ -355,7 +349,7 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
const beltComp = entity.components.Belt;
|
const beltComp = entity.components.Belt;
|
||||||
|
|
||||||
const followUpDirection = staticComp.localDirectionToWorld(beltComp.direction);
|
const followUpDirection = staticComp.localDirectionToWorld(beltComp.direction);
|
||||||
const followUpVector = enumDirectionToVector[followUpDirection];
|
const followUpVector = directionVectorMap[followUpDirection];
|
||||||
|
|
||||||
const followUpTile = staticComp.origin.add(followUpVector);
|
const followUpTile = staticComp.origin.add(followUpVector);
|
||||||
const followUpEntity = this.root.map.getLayerContentXY(followUpTile.x, followUpTile.y, entity.layer);
|
const followUpEntity = this.root.map.getLayerContentXY(followUpTile.x, followUpTile.y, entity.layer);
|
||||||
@ -366,7 +360,7 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
if (followUpBeltComp) {
|
if (followUpBeltComp) {
|
||||||
const followUpStatic = followUpEntity.components.StaticMapEntity;
|
const followUpStatic = followUpEntity.components.StaticMapEntity;
|
||||||
|
|
||||||
const acceptedDirection = followUpStatic.localDirectionToWorld(enumDirection.top);
|
const acceptedDirection = followUpStatic.localDirectionToWorld("top");
|
||||||
if (acceptedDirection === followUpDirection) {
|
if (acceptedDirection === followUpDirection) {
|
||||||
return followUpEntity;
|
return followUpEntity;
|
||||||
}
|
}
|
||||||
@ -384,8 +378,8 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
findSupplyingEntity(entity) {
|
findSupplyingEntity(entity) {
|
||||||
const staticComp = entity.components.StaticMapEntity;
|
const staticComp = entity.components.StaticMapEntity;
|
||||||
|
|
||||||
const supplyDirection = staticComp.localDirectionToWorld(enumDirection.bottom);
|
const supplyDirection = staticComp.localDirectionToWorld("bottom");
|
||||||
const supplyVector = enumDirectionToVector[supplyDirection];
|
const supplyVector = directionVectorMap[supplyDirection];
|
||||||
|
|
||||||
const supplyTile = staticComp.origin.add(supplyVector);
|
const supplyTile = staticComp.origin.add(supplyVector);
|
||||||
const supplyEntity = this.root.map.getLayerContentXY(supplyTile.x, supplyTile.y, entity.layer);
|
const supplyEntity = this.root.map.getLayerContentXY(supplyTile.x, supplyTile.y, entity.layer);
|
||||||
@ -396,7 +390,7 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
if (supplyBeltComp) {
|
if (supplyBeltComp) {
|
||||||
const supplyStatic = supplyEntity.components.StaticMapEntity;
|
const supplyStatic = supplyEntity.components.StaticMapEntity;
|
||||||
const otherDirection = supplyStatic.localDirectionToWorld(
|
const otherDirection = supplyStatic.localDirectionToWorld(
|
||||||
enumInvertedDirections[supplyBeltComp.direction]
|
inverseDirectionMap[supplyBeltComp.direction]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (otherDirection === supplyDirection) {
|
if (otherDirection === supplyDirection) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { globalConfig } from "../../core/config";
|
import { globalConfig } from "../../core/config";
|
||||||
import { drawRotatedSprite } from "../../core/draw_utils";
|
import { drawRotatedSprite } from "../../core/draw_utils";
|
||||||
import { Loader } from "../../core/loader";
|
import { Loader } from "../../core/loader";
|
||||||
import { enumDirectionToAngle } from "../../core/vector";
|
import { directionAngleMap } from "../../core/vector";
|
||||||
import { BeltUnderlaysComponent } from "../components/belt_underlays";
|
import { BeltUnderlaysComponent } from "../components/belt_underlays";
|
||||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||||
import { BELT_ANIM_COUNT } from "./belt";
|
import { BELT_ANIM_COUNT } from "./belt";
|
||||||
@ -62,7 +62,7 @@ export class BeltUnderlaysSystem extends GameSystemWithFilter {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const angle = enumDirectionToAngle[staticComp.localDirectionToWorld(direction)];
|
const angle = directionAngleMap[staticComp.localDirectionToWorld(direction)];
|
||||||
|
|
||||||
// SYNC with systems/belt.js:drawSingleEntity!
|
// SYNC with systems/belt.js:drawSingleEntity!
|
||||||
const animationIndex = Math.floor(
|
const animationIndex = Math.floor(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { globalConfig } from "../../core/config";
|
import { globalConfig } from "../../core/config";
|
||||||
import { DrawParameters } from "../../core/draw_parameters";
|
import { DrawParameters } from "../../core/draw_parameters";
|
||||||
import { fastArrayDelete } from "../../core/utils";
|
import { fastArrayDelete } from "../../core/utils";
|
||||||
import { enumDirectionToVector } from "../../core/vector";
|
import { directionVectorMap } from "../../core/vector";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||||
import { MapChunkView } from "../map_chunk_view";
|
import { MapChunkView } from "../map_chunk_view";
|
||||||
@ -64,7 +64,7 @@ export class ItemAcceptorSystem extends GameSystemWithFilter {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fadeOutDirection = enumDirectionToVector[staticComp.localDirectionToWorld(direction)];
|
const fadeOutDirection = directionVectorMap[staticComp.localDirectionToWorld(direction)];
|
||||||
const finalTile = realSlotPos.subScalars(
|
const finalTile = realSlotPos.subScalars(
|
||||||
fadeOutDirection.x * (animProgress / 2 - 0.5),
|
fadeOutDirection.x * (animProgress / 2 - 0.5),
|
||||||
fadeOutDirection.y * (animProgress / 2 - 0.5)
|
fadeOutDirection.y * (animProgress / 2 - 0.5)
|
||||||
|
@ -2,7 +2,7 @@ import { globalConfig } from "../../core/config";
|
|||||||
import { DrawParameters } from "../../core/draw_parameters";
|
import { DrawParameters } from "../../core/draw_parameters";
|
||||||
import { createLogger } from "../../core/logging";
|
import { createLogger } from "../../core/logging";
|
||||||
import { Rectangle } from "../../core/rectangle";
|
import { Rectangle } from "../../core/rectangle";
|
||||||
import { enumDirection, enumDirectionToVector, Vector } from "../../core/vector";
|
import { directionVectorMap } from "../../core/vector";
|
||||||
import { BaseItem } from "../base_item";
|
import { BaseItem } from "../base_item";
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
import { ItemEjectorComponent } from "../components/item_ejector";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
@ -132,7 +132,7 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
|||||||
// Figure out where and into which direction we eject items
|
// Figure out where and into which direction we eject items
|
||||||
const ejectSlotWsTile = staticComp.localTileToWorld(ejectorSlot.pos);
|
const ejectSlotWsTile = staticComp.localTileToWorld(ejectorSlot.pos);
|
||||||
const ejectSlotWsDirection = staticComp.localDirectionToWorld(ejectorSlot.direction);
|
const ejectSlotWsDirection = staticComp.localDirectionToWorld(ejectorSlot.direction);
|
||||||
const ejectSlotWsDirectionVector = enumDirectionToVector[ejectSlotWsDirection];
|
const ejectSlotWsDirectionVector = directionVectorMap[ejectSlotWsDirection];
|
||||||
const ejectSlotTargetWsTile = ejectSlotWsTile.add(ejectSlotWsDirectionVector);
|
const ejectSlotTargetWsTile = ejectSlotWsTile.add(ejectSlotWsDirectionVector);
|
||||||
|
|
||||||
// Try to find the given acceptor component to take the item
|
// Try to find the given acceptor component to take the item
|
||||||
@ -150,7 +150,7 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
// Check for belts (special case)
|
// Check for belts (special case)
|
||||||
if (targetBeltComp) {
|
if (targetBeltComp) {
|
||||||
const beltAcceptingDirection = targetStaticComp.localDirectionToWorld(enumDirection.top);
|
const beltAcceptingDirection = targetStaticComp.localDirectionToWorld("top");
|
||||||
if (ejectSlotWsDirection === beltAcceptingDirection) {
|
if (ejectSlotWsDirection === beltAcceptingDirection) {
|
||||||
ejectorSlot.cachedTargetEntity = targetEntity;
|
ejectorSlot.cachedTargetEntity = targetEntity;
|
||||||
ejectorSlot.cachedBeltPath = targetBeltComp.assignedPath;
|
ejectorSlot.cachedBeltPath = targetBeltComp.assignedPath;
|
||||||
@ -368,7 +368,7 @@ export class ItemEjectorSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const realDirection = staticComp.localDirectionToWorld(slot.direction);
|
const realDirection = staticComp.localDirectionToWorld(slot.direction);
|
||||||
const realDirectionVector = enumDirectionToVector[realDirection];
|
const realDirectionVector = directionVectorMap[realDirection];
|
||||||
|
|
||||||
const tileX = realPosition.x + 0.5 + realDirectionVector.x * 0.5 * slot.progress;
|
const tileX = realPosition.x + 0.5 + realDirectionVector.x * 0.5 * slot.progress;
|
||||||
const tileY = realPosition.y + 0.5 + realDirectionVector.y * 0.5 * slot.progress;
|
const tileY = realPosition.y + 0.5 + realDirectionVector.y * 0.5 * slot.progress;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { globalConfig } from "../../core/config";
|
import { globalConfig } from "../../core/config";
|
||||||
import { DrawParameters } from "../../core/draw_parameters";
|
import { DrawParameters } from "../../core/draw_parameters";
|
||||||
import { enumDirectionToVector } from "../../core/vector";
|
import { directionVectorMap } from "../../core/vector";
|
||||||
import { BaseItem } from "../base_item";
|
import { BaseItem } from "../base_item";
|
||||||
import { MinerComponent } from "../components/miner";
|
import { MinerComponent } from "../components/miner";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
@ -73,7 +73,7 @@ export class MinerSystem extends GameSystemWithFilter {
|
|||||||
const ejectingPos = staticComp.localTileToWorld(ejectingSlot.pos);
|
const ejectingPos = staticComp.localTileToWorld(ejectingSlot.pos);
|
||||||
const ejectingDirection = staticComp.localDirectionToWorld(ejectingSlot.direction);
|
const ejectingDirection = staticComp.localDirectionToWorld(ejectingSlot.direction);
|
||||||
|
|
||||||
const targetTile = ejectingPos.add(enumDirectionToVector[ejectingDirection]);
|
const targetTile = ejectingPos.add(directionVectorMap[ejectingDirection]);
|
||||||
const targetContents = this.root.map.getTileContent(targetTile, "regular");
|
const targetContents = this.root.map.getTileContent(targetTile, "regular");
|
||||||
|
|
||||||
// Check if we are connected to another miner and thus do not eject directly
|
// Check if we are connected to another miner and thus do not eject directly
|
||||||
|
@ -3,11 +3,10 @@ import { Loader } from "../../core/loader";
|
|||||||
import { createLogger } from "../../core/logging";
|
import { createLogger } from "../../core/logging";
|
||||||
import { Rectangle } from "../../core/rectangle";
|
import { Rectangle } from "../../core/rectangle";
|
||||||
import {
|
import {
|
||||||
enumAngleToDirection,
|
angleDirectionMap,
|
||||||
enumDirection,
|
directionAngleMap,
|
||||||
enumDirectionToAngle,
|
directionVectorMap,
|
||||||
enumDirectionToVector,
|
inverseDirectionMap,
|
||||||
enumInvertedDirections,
|
|
||||||
} from "../../core/vector";
|
} from "../../core/vector";
|
||||||
import { enumUndergroundBeltMode, UndergroundBeltComponent } from "../components/underground_belt";
|
import { enumUndergroundBeltMode, UndergroundBeltComponent } from "../components/underground_belt";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
@ -81,9 +80,9 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
|||||||
const staticComp = entity.components.StaticMapEntity;
|
const staticComp = entity.components.StaticMapEntity;
|
||||||
const tile = staticComp.origin;
|
const tile = staticComp.origin;
|
||||||
|
|
||||||
const direction = enumAngleToDirection[staticComp.rotation];
|
const direction = angleDirectionMap[staticComp.rotation];
|
||||||
const inverseDirection = enumInvertedDirections[direction];
|
const inverseDirection = inverseDirectionMap[direction];
|
||||||
const offset = enumDirectionToVector[inverseDirection];
|
const offset = directionVectorMap[inverseDirection];
|
||||||
|
|
||||||
let currentPos = tile.copy();
|
let currentPos = tile.copy();
|
||||||
|
|
||||||
@ -106,7 +105,7 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
|||||||
contentsUndergroundComp &&
|
contentsUndergroundComp &&
|
||||||
contentsUndergroundComp.tier === undergroundComp.tier &&
|
contentsUndergroundComp.tier === undergroundComp.tier &&
|
||||||
contentsUndergroundComp.mode === enumUndergroundBeltMode.sender &&
|
contentsUndergroundComp.mode === enumUndergroundBeltMode.sender &&
|
||||||
enumAngleToDirection[contentsStaticComp.rotation] === direction
|
angleDirectionMap[contentsStaticComp.rotation] === direction
|
||||||
) {
|
) {
|
||||||
matchingEntrance = {
|
matchingEntrance = {
|
||||||
entity: contents,
|
entity: contents,
|
||||||
@ -143,8 +142,8 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
// It's a belt
|
// It's a belt
|
||||||
if (
|
if (
|
||||||
contentsBeltComp.direction !== enumDirection.top ||
|
contentsBeltComp.direction !== "top" ||
|
||||||
enumAngleToDirection[contentsStaticComp.rotation] !== direction
|
angleDirectionMap[contentsStaticComp.rotation] !== direction
|
||||||
) {
|
) {
|
||||||
allBeltsMatch = false;
|
allBeltsMatch = false;
|
||||||
break;
|
break;
|
||||||
@ -207,8 +206,8 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
|||||||
const staticAfter = entityAfter.components.StaticMapEntity;
|
const staticAfter = entityAfter.components.StaticMapEntity;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
enumAngleToDirection[staticBefore.rotation] !== direction ||
|
angleDirectionMap[staticBefore.rotation] !== direction ||
|
||||||
enumAngleToDirection[staticAfter.rotation] !== direction
|
angleDirectionMap[staticAfter.rotation] !== direction
|
||||||
) {
|
) {
|
||||||
// Wrong rotation
|
// Wrong rotation
|
||||||
continue;
|
continue;
|
||||||
@ -284,9 +283,9 @@ export class UndergroundBeltSystem extends GameSystemWithFilter {
|
|||||||
findRecieverForSender(entity) {
|
findRecieverForSender(entity) {
|
||||||
const staticComp = entity.components.StaticMapEntity;
|
const staticComp = entity.components.StaticMapEntity;
|
||||||
const undergroundComp = entity.components.UndergroundBelt;
|
const undergroundComp = entity.components.UndergroundBelt;
|
||||||
const searchDirection = staticComp.localDirectionToWorld(enumDirection.top);
|
const searchDirection = staticComp.localDirectionToWorld("top");
|
||||||
const searchVector = enumDirectionToVector[searchDirection];
|
const searchVector = directionVectorMap[searchDirection];
|
||||||
const targetRotation = enumDirectionToAngle[searchDirection];
|
const targetRotation = directionAngleMap[searchDirection];
|
||||||
let currentTile = staticComp.origin;
|
let currentTile = staticComp.origin;
|
||||||
|
|
||||||
// Search in the direction of the tunnel
|
// Search in the direction of the tunnel
|
||||||
|
@ -5,13 +5,7 @@ import { createLogger } from "../../core/logging";
|
|||||||
import { Rectangle } from "../../core/rectangle";
|
import { Rectangle } from "../../core/rectangle";
|
||||||
import { StaleAreaDetector } from "../../core/stale_area_detector";
|
import { StaleAreaDetector } from "../../core/stale_area_detector";
|
||||||
import { fastArrayDeleteValueIfContained } from "../../core/utils";
|
import { fastArrayDeleteValueIfContained } from "../../core/utils";
|
||||||
import {
|
import { directions, directionVectorMap, inverseDirectionMap, Vector } from "../../core/vector";
|
||||||
arrayAllDirections,
|
|
||||||
enumDirection,
|
|
||||||
enumDirectionToVector,
|
|
||||||
enumInvertedDirections,
|
|
||||||
Vector,
|
|
||||||
} from "../../core/vector";
|
|
||||||
import { BaseItem } from "../base_item";
|
import { BaseItem } from "../base_item";
|
||||||
import { BooleanItem } from "../items/boolean_item";
|
import { BooleanItem } from "../items/boolean_item";
|
||||||
import { arrayWireRotationVariantToType, MetaWireBuilding } from "../buildings/wire";
|
import { arrayWireRotationVariantToType, MetaWireBuilding } from "../buildings/wire";
|
||||||
@ -248,7 +242,7 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
wireComp.linkedNetwork = currentNetwork;
|
wireComp.linkedNetwork = currentNetwork;
|
||||||
currentNetwork.wires.push(nextEntity);
|
currentNetwork.wires.push(nextEntity);
|
||||||
|
|
||||||
newSearchDirections = arrayAllDirections;
|
newSearchDirections = directions;
|
||||||
newSearchTile = nextEntity.components.StaticMapEntity.origin;
|
newSearchTile = nextEntity.components.StaticMapEntity.origin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -345,7 +339,7 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
/**
|
/**
|
||||||
* Finds surrounding entities which are not yet assigned to a network
|
* Finds surrounding entities which are not yet assigned to a network
|
||||||
* @param {Vector} initialTile
|
* @param {Vector} initialTile
|
||||||
* @param {Array<enumDirection>} directions
|
* @param {Array<Direction>} directions
|
||||||
* @param {WireNetwork} network
|
* @param {WireNetwork} network
|
||||||
* @returns {Array<any>}
|
* @returns {Array<any>}
|
||||||
*/
|
*/
|
||||||
@ -358,7 +352,7 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
// Go over all directions we should search for
|
// Go over all directions we should search for
|
||||||
for (let i = 0; i < directions.length; ++i) {
|
for (let i = 0; i < directions.length; ++i) {
|
||||||
const direction = directions[i];
|
const direction = directions[i];
|
||||||
const offset = enumDirectionToVector[direction];
|
const offset = directionVectorMap[direction];
|
||||||
const initialSearchTile = initialTile.add(offset);
|
const initialSearchTile = initialTile.add(offset);
|
||||||
|
|
||||||
// Store which tunnels we already visited to avoid infinite loops
|
// Store which tunnels we already visited to avoid infinite loops
|
||||||
@ -410,7 +404,7 @@ 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 !== inverseDirectionMap[direction]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,8 +432,8 @@ export class WireSystem extends GameSystemWithFilter {
|
|||||||
if (
|
if (
|
||||||
!tunnelComp.multipleDirections &&
|
!tunnelComp.multipleDirections &&
|
||||||
!(
|
!(
|
||||||
direction === staticComp.localDirectionToWorld(enumDirection.top) ||
|
direction === staticComp.localDirectionToWorld("top") ||
|
||||||
direction === staticComp.localDirectionToWorld(enumDirection.bottom)
|
direction === staticComp.localDirectionToWorld("bottom")
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
// It's a coating, and it doesn't connect here
|
// It's a coating, and it doesn't connect here
|
||||||
|
@ -3,7 +3,7 @@ import { DrawParameters } from "../../core/draw_parameters";
|
|||||||
import { drawRotatedSprite } from "../../core/draw_utils";
|
import { drawRotatedSprite } from "../../core/draw_utils";
|
||||||
import { Loader } from "../../core/loader";
|
import { Loader } from "../../core/loader";
|
||||||
import { STOP_PROPAGATION } from "../../core/signal";
|
import { STOP_PROPAGATION } from "../../core/signal";
|
||||||
import { enumDirectionToAngle, Vector } from "../../core/vector";
|
import { directionAngleMap, Vector } from "../../core/vector";
|
||||||
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
|
import { enumPinSlotType, WiredPinsComponent } from "../components/wired_pins";
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||||
@ -181,9 +181,7 @@ export class WiredPinsSystem extends GameSystemWithFilter {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const effectiveRotation = Math.radians(
|
const angle = directionAngleMap[staticComp.localDirectionToWorld(slot.direction)];
|
||||||
staticComp.rotation + enumDirectionToAngle[slot.direction]
|
|
||||||
);
|
|
||||||
|
|
||||||
if (staticComp.getMetaBuilding().getRenderPins()) {
|
if (staticComp.getMetaBuilding().getRenderPins()) {
|
||||||
drawRotatedSprite({
|
drawRotatedSprite({
|
||||||
@ -191,7 +189,7 @@ export class WiredPinsSystem extends GameSystemWithFilter {
|
|||||||
sprite: this.pinSprites[slot.type],
|
sprite: this.pinSprites[slot.type],
|
||||||
x: worldPos.x,
|
x: worldPos.x,
|
||||||
y: worldPos.y,
|
y: worldPos.y,
|
||||||
angle: effectiveRotation,
|
angle: Math.radians(angle),
|
||||||
size: globalConfig.tileSize + 2,
|
size: globalConfig.tileSize + 2,
|
||||||
offsetX: 0,
|
offsetX: 0,
|
||||||
offsetY: 0,
|
offsetY: 0,
|
||||||
@ -201,7 +199,7 @@ export class WiredPinsSystem extends GameSystemWithFilter {
|
|||||||
// Draw contained item to visualize whats emitted
|
// Draw contained item to visualize whats emitted
|
||||||
const value = slot.value;
|
const value = slot.value;
|
||||||
if (value) {
|
if (value) {
|
||||||
const offset = new Vector(0, -9).rotated(effectiveRotation);
|
const offset = new Vector(0, -9).rotate(angle);
|
||||||
value.drawItemCenteredClipped(
|
value.drawItemCenteredClipped(
|
||||||
worldPos.x + offset.x,
|
worldPos.x + offset.x,
|
||||||
worldPos.y + offset.y,
|
worldPos.y + offset.y,
|
||||||
@ -212,7 +210,7 @@ export class WiredPinsSystem extends GameSystemWithFilter {
|
|||||||
|
|
||||||
// Debug view
|
// Debug view
|
||||||
if (G_IS_DEV && globalConfig.debug.renderWireNetworkInfos) {
|
if (G_IS_DEV && globalConfig.debug.renderWireNetworkInfos) {
|
||||||
const offset = new Vector(0, -10).rotated(effectiveRotation);
|
const offset = new Vector(0, -10).rotate(angle);
|
||||||
const network = slot.linkedNetwork;
|
const network = slot.linkedNetwork;
|
||||||
parameters.context.fillStyle = "blue";
|
parameters.context.fillStyle = "blue";
|
||||||
parameters.context.font = "5px Tahoma";
|
parameters.context.font = "5px Tahoma";
|
||||||
|
5
src/js/globals.d.ts
vendored
5
src/js/globals.d.ts
vendored
@ -193,8 +193,11 @@ declare interface TypedSignal<T extends Array<any>> {
|
|||||||
removeAll();
|
removeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
declare type Layer = "regular" | "wires";
|
declare type Angle = 0 | 90 | 180 | 270;
|
||||||
|
declare type Direction = "top" | "right" | "bottom" | "left";
|
||||||
declare type ItemType = "shape" | "color" | "boolean";
|
declare type ItemType = "shape" | "color" | "boolean";
|
||||||
|
declare type Layer = "regular" | "wires";
|
||||||
|
declare type RotationVariant = 0 | 1 | 2 | 3;
|
||||||
|
|
||||||
declare module "worker-loader?inline=true&fallback=false!*" {
|
declare module "worker-loader?inline=true&fallback=false!*" {
|
||||||
class WebpackWorker extends Worker {
|
class WebpackWorker extends Worker {
|
||||||
|
@ -484,7 +484,7 @@ export class TypeEnum extends BaseDataType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
verifySerializedValue(value) {
|
verifySerializedValue(value) {
|
||||||
if (this.availableValues.indexOf(value) < 0) {
|
if (!this.availableValues.includes(value)) {
|
||||||
return "Unknown enum value: " + value;
|
return "Unknown enum value: " + value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user