mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Refactor rotation overview matrices
This commit is contained in:
parent
850461df8f
commit
a32c0530bb
@ -632,3 +632,54 @@ export function formatItemsPerSecond(speed, double = false, separator = T.global
|
||||
round2Digits(speed).toString().replace(".", separator)
|
||||
) + (double ? " " + T.ingame.buildingPlacement.infoTexts.itemsPerSecondDouble : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates a flat 3x3 matrix clockwise
|
||||
* Entries:
|
||||
* 0 lo
|
||||
* 1 mo
|
||||
* 2 ro
|
||||
* 3 lm
|
||||
* 4 mm
|
||||
* 5 rm
|
||||
* 6 lu
|
||||
* 7 mu
|
||||
* 8 ru
|
||||
* @param {Array<number>} flatMatrix
|
||||
*/
|
||||
|
||||
export function rotateFlatMatrix3x3(flatMatrix) {
|
||||
return [
|
||||
flatMatrix[6],
|
||||
flatMatrix[3],
|
||||
flatMatrix[0],
|
||||
flatMatrix[7],
|
||||
flatMatrix[4],
|
||||
flatMatrix[1],
|
||||
flatMatrix[8],
|
||||
flatMatrix[5],
|
||||
flatMatrix[2],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates rotated variants of the matrix
|
||||
* @param {Array<number>} originalMatrix
|
||||
* @returns {Object<number, Array<number>>}
|
||||
*/
|
||||
export function generateMatrixRotations(originalMatrix) {
|
||||
const result = {
|
||||
0: originalMatrix,
|
||||
};
|
||||
|
||||
originalMatrix = rotateFlatMatrix3x3(originalMatrix);
|
||||
result[90] = originalMatrix;
|
||||
|
||||
originalMatrix = rotateFlatMatrix3x3(originalMatrix);
|
||||
result[180] = originalMatrix;
|
||||
|
||||
originalMatrix = rotateFlatMatrix3x3(originalMatrix);
|
||||
result[270] = originalMatrix;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { formatItemsPerSecond } from "../../core/utils";
|
||||
import { formatItemsPerSecond, generateMatrixRotations } from "../../core/utils";
|
||||
import { enumAngleToDirection, enumDirection, Vector } from "../../core/vector";
|
||||
import { SOUNDS } from "../../platform/sound";
|
||||
import { T } from "../../translations";
|
||||
@ -10,26 +10,9 @@ import { GameRoot } from "../root";
|
||||
export const arrayBeltVariantToRotation = [enumDirection.top, enumDirection.left, enumDirection.right];
|
||||
|
||||
export const beltOverlayMatrices = {
|
||||
[enumDirection.top]: {
|
||||
0: [0, 1, 0, 0, 1, 0, 0, 1, 0],
|
||||
90: [0, 0, 0, 1, 1, 1, 0, 0, 0],
|
||||
180: [0, 1, 0, 0, 1, 0, 0, 1, 0],
|
||||
270: [0, 0, 0, 1, 1, 1, 0, 0, 0],
|
||||
},
|
||||
|
||||
[enumDirection.left]: {
|
||||
0: [0, 0, 0, 1, 1, 0, 0, 1, 0],
|
||||
90: [0, 1, 0, 1, 1, 0, 0, 0, 0],
|
||||
180: [0, 1, 0, 0, 1, 1, 0, 0, 0],
|
||||
270: [0, 0, 0, 0, 1, 1, 0, 1, 0],
|
||||
},
|
||||
|
||||
[enumDirection.right]: {
|
||||
0: [0, 0, 0, 0, 1, 1, 0, 1, 0],
|
||||
90: [0, 0, 0, 1, 1, 0, 0, 1, 0],
|
||||
180: [0, 1, 0, 1, 1, 0, 0, 0, 0],
|
||||
270: [0, 1, 0, 0, 1, 1, 0, 0, 0],
|
||||
},
|
||||
[enumDirection.top]: generateMatrixRotations([0, 1, 0, 0, 1, 0, 0, 1, 0]),
|
||||
[enumDirection.left]: generateMatrixRotations([0, 0, 0, 1, 1, 0, 0, 1, 0]),
|
||||
[enumDirection.right]: generateMatrixRotations([0, 0, 0, 0, 1, 1, 0, 1, 0]),
|
||||
};
|
||||
|
||||
export class MetaBeltBaseBuilding extends MetaBuilding {
|
||||
|
@ -8,7 +8,7 @@ import { MetaBuilding, defaultBuildingVariant } from "../meta_building";
|
||||
import { GameRoot, enumLayer } from "../root";
|
||||
import { globalConfig } from "../../core/config";
|
||||
import { enumHubGoalRewards } from "../tutorial_goals";
|
||||
import { formatItemsPerSecond } from "../../core/utils";
|
||||
import { formatItemsPerSecond, generateMatrixRotations } from "../../core/utils";
|
||||
import { T } from "../../translations";
|
||||
|
||||
/** @enum {string} */
|
||||
@ -27,20 +27,10 @@ export const enumUndergroundBeltVariantToTier = {
|
||||
|
||||
const overlayMatrices = [
|
||||
// Sender
|
||||
{
|
||||
0: [1, 1, 1, 0, 1, 0, 0, 1, 0],
|
||||
90: [0, 0, 1, 1, 1, 1, 0, 0, 1],
|
||||
180: [0, 1, 0, 0, 1, 0, 1, 1, 1],
|
||||
270: [1, 0, 0, 1, 1, 1, 1, 0, 0],
|
||||
},
|
||||
generateMatrixRotations([1, 1, 1, 0, 1, 0, 0, 1, 0]),
|
||||
|
||||
// Receiver
|
||||
{
|
||||
0: [0, 1, 0, 0, 1, 0, 1, 1, 1],
|
||||
90: [1, 0, 0, 1, 1, 1, 1, 0, 0],
|
||||
180: [1, 1, 1, 0, 1, 0, 0, 1, 0],
|
||||
270: [0, 0, 1, 1, 1, 1, 0, 0, 1],
|
||||
},
|
||||
generateMatrixRotations([0, 1, 0, 0, 1, 0, 1, 1, 1]),
|
||||
];
|
||||
|
||||
export class MetaUndergroundBeltBuilding extends MetaBuilding {
|
||||
|
Loading…
Reference in New Issue
Block a user