1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Further take on logic wires

This commit is contained in:
tobspr
2020-08-11 18:40:09 +02:00
parent 5708ef385c
commit 850461df8f
46 changed files with 1308 additions and 785 deletions

View File

@@ -9,7 +9,7 @@ import { GameRoot } from "../root";
export const arrayBeltVariantToRotation = [enumDirection.top, enumDirection.left, enumDirection.right];
const overlayMatrices = {
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],
@@ -75,7 +75,7 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
* @param {Entity} entity
*/
getSpecialOverlayRenderMatrix(rotation, rotationVariant, variant, entity) {
return overlayMatrices[entity.components.Belt.direction][rotation];
return beltOverlayMatrices[entity.components.Belt.direction][rotation];
}
/**

View File

@@ -54,7 +54,7 @@ export class MetaHubBuilding extends MetaBuilding {
new WiredPinsComponent({
slots: [
{
pos: new Vector(0, 0),
pos: new Vector(3, 0),
type: enumPinSlotType.logicalEjector,
direction: enumDirection.top,
},

View File

@@ -29,17 +29,17 @@ const overlayMatrices = [
// Sender
{
0: [1, 1, 1, 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],
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],
},
// Receiver
{
0: [0, 1, 0, 0, 1, 0, 1, 1, 1],
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],
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],
},
];

View File

@@ -0,0 +1,111 @@
import { Vector } from "../../core/vector";
import { SOUNDS } from "../../platform/sound";
import { enumWireType, WireComponent } from "../components/wire";
import { Entity } from "../entity";
import { MetaBuilding } from "../meta_building";
import { enumLayer, GameRoot } from "../root";
import { beltOverlayMatrices } from "./belt_base";
export const arrayWireRotationVariantToType = [enumWireType.regular, enumWireType.turn, enumWireType.split];
export const wireOverlayMatrices = {
[enumWireType.regular]: {
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],
},
[enumWireType.split]: {
0: [0, 0, 0, 1, 1, 1, 0, 1, 0],
90: [0, 1, 0, 1, 1, 0, 0, 1, 0],
180: [0, 1, 0, 1, 1, 1, 0, 0, 0],
270: [0, 1, 0, 0, 1, 1, 0, 1, 0],
},
[enumWireType.turn]: {
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],
},
};
export class MetaWireBuilding extends MetaBuilding {
constructor() {
super("wire");
}
getHasDirectionLockAvailable() {
return true;
}
getSilhouetteColor() {
return "#25fff2";
}
getDimensions() {
return new Vector(1, 1);
}
getStayInPlacementMode() {
return true;
}
getPlacementSound() {
return SOUNDS.placeBelt;
}
getRotateAutomaticallyWhilePlacing() {
return true;
}
getLayer() {
return enumLayer.wires;
}
getSprite() {
return null;
}
getIsReplaceable() {
return true;
}
/**
* @param {GameRoot} root
*/
getIsUnlocked(root) {
// @todo
return G_IS_DEV;
}
/**
* Creates the entity at the given location
* @param {Entity} entity
*/
setupEntityComponents(entity) {
// @todo
entity.addComponent(new WireComponent({}));
}
/**
*
* @param {Entity} entity
* @param {number} rotationVariant
*/
updateVariants(entity, rotationVariant) {
entity.components.Wire.type = arrayWireRotationVariantToType[rotationVariant];
}
/**
*
* @param {number} rotation
* @param {number} rotationVariant
* @param {string} variant
* @param {Entity} entity
*/
getSpecialOverlayRenderMatrix(rotation, rotationVariant, variant, entity) {
return wireOverlayMatrices[entity.components.Wire.type][rotation];
}
}