1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-16 11:41:50 +00:00

remove belt underlays component

This commit is contained in:
EmeraldBlock 2021-11-23 23:08:49 -06:00
parent 654643c5b0
commit 10db2af21c
7 changed files with 105 additions and 216 deletions

View File

@ -8,7 +8,6 @@ import { GameRoot } from "../root";
import { enumHubGoalRewards } from "../tutorial_goals"; import { enumHubGoalRewards } from "../tutorial_goals";
import { T } from "../../translations"; import { T } from "../../translations";
import { formatItemsPerSecond, generateMatrixRotations } from "../../core/utils"; import { formatItemsPerSecond, generateMatrixRotations } from "../../core/utils";
import { BeltUnderlaysComponent } from "../components/belt_underlays";
/** @enum {string} */ /** @enum {string} */
export const enumBalancerVariants = { export const enumBalancerVariants = {
@ -138,8 +137,6 @@ export class MetaBalancerBuilding extends MetaBuilding {
renderFloatingItems: false, renderFloatingItems: false,
}) })
); );
entity.addComponent(new BeltUnderlaysComponent({ underlays: [] }));
} }
/** /**
@ -167,11 +164,6 @@ export class MetaBalancerBuilding extends MetaBuilding {
{ pos: new Vector(1, 0), direction: enumDirection.top }, { pos: new Vector(1, 0), direction: enumDirection.top },
]); ]);
entity.components.BeltUnderlays.underlays = [
{ pos: new Vector(0, 0), direction: enumDirection.top },
{ pos: new Vector(1, 0), direction: enumDirection.top },
];
break; break;
} }
case enumBalancerVariants.merger: case enumBalancerVariants.merger:
@ -195,10 +187,6 @@ export class MetaBalancerBuilding extends MetaBuilding {
{ pos: new Vector(0, 0), direction: enumDirection.top }, { pos: new Vector(0, 0), direction: enumDirection.top },
]); ]);
entity.components.BeltUnderlays.underlays = [
{ pos: new Vector(0, 0), direction: enumDirection.top },
];
break; break;
} }
case enumBalancerVariants.splitter: case enumBalancerVariants.splitter:
@ -224,10 +212,6 @@ export class MetaBalancerBuilding extends MetaBuilding {
}, },
]); ]);
entity.components.BeltUnderlays.underlays = [
{ pos: new Vector(0, 0), direction: enumDirection.top },
];
break; break;
} }
default: default:

View File

@ -1,115 +1,103 @@
import { enumDirection, Vector } from "../../core/vector"; import { enumDirection, 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";
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";
import { GameRoot } from "../root"; import { GameRoot } from "../root";
import { BeltUnderlaysComponent } from "../components/belt_underlays"; import { BeltReaderComponent } from "../components/belt_reader";
import { BeltReaderComponent } from "../components/belt_reader"; import { enumHubGoalRewards } from "../tutorial_goals";
import { enumHubGoalRewards } from "../tutorial_goals"; import { generateMatrixRotations } from "../../core/utils";
import { generateMatrixRotations } from "../../core/utils";
const overlayMatrix = generateMatrixRotations([0, 1, 0, 0, 1, 0, 0, 1, 0]);
const overlayMatrix = generateMatrixRotations([0, 1, 0, 0, 1, 0, 0, 1, 0]);
export class MetaReaderBuilding extends MetaBuilding {
export class MetaReaderBuilding extends MetaBuilding { constructor() {
constructor() { super("reader");
super("reader"); }
}
getSilhouetteColor() {
getSilhouetteColor() { return "#25fff2";
return "#25fff2"; }
}
/**
/** * @param {GameRoot} root
* @param {GameRoot} root */
*/ getIsUnlocked(root) {
getIsUnlocked(root) { return root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_belt_reader);
return root.hubGoals.isRewardUnlocked(enumHubGoalRewards.reward_belt_reader); }
}
getDimensions() {
getDimensions() { return new Vector(1, 1);
return new Vector(1, 1); }
}
getShowWiresLayerPreview() {
getShowWiresLayerPreview() { return true;
return true; }
}
/**
/** * @param {number} rotation
* @param {number} rotation * @param {number} rotationVariant
* @param {number} rotationVariant * @param {string} variant
* @param {string} variant * @param {Entity} entity
* @param {Entity} entity * @returns {Array<number>|null}
* @returns {Array<number>|null} */
*/ getSpecialOverlayRenderMatrix(rotation, rotationVariant, variant, entity) {
getSpecialOverlayRenderMatrix(rotation, rotationVariant, variant, entity) { return overlayMatrix[rotation];
return overlayMatrix[rotation]; }
}
/**
/** * Creates the entity at the given location
* Creates the entity at the given location * @param {Entity} entity
* @param {Entity} entity */
*/ setupEntityComponents(entity) {
setupEntityComponents(entity) { entity.addComponent(
entity.addComponent( new WiredPinsComponent({
new WiredPinsComponent({ slots: [
slots: [ {
{ pos: new Vector(0, 0),
pos: new Vector(0, 0), direction: enumDirection.right,
direction: enumDirection.right, type: enumPinSlotType.logicalEjector,
type: enumPinSlotType.logicalEjector, },
}, {
{ pos: new Vector(0, 0),
pos: new Vector(0, 0), direction: enumDirection.left,
direction: enumDirection.left, type: enumPinSlotType.logicalEjector,
type: enumPinSlotType.logicalEjector, },
}, ],
], })
}) );
);
entity.addComponent(
entity.addComponent( new ItemAcceptorComponent({
new ItemAcceptorComponent({ slots: [
slots: [ {
{ pos: new Vector(0, 0),
pos: new Vector(0, 0), directions: [enumDirection.bottom],
directions: [enumDirection.bottom], },
}, ],
], })
}) );
);
entity.addComponent(
entity.addComponent( new ItemEjectorComponent({
new ItemEjectorComponent({ slots: [
slots: [ {
{ pos: new Vector(0, 0),
pos: new Vector(0, 0), direction: enumDirection.top,
direction: enumDirection.top, },
}, ],
], })
}) );
);
entity.addComponent(
entity.addComponent( new ItemProcessorComponent({
new ItemProcessorComponent({ processorType: enumItemProcessorTypes.reader,
processorType: enumItemProcessorTypes.reader, inputsPerCharge: 1,
inputsPerCharge: 1, })
}) );
);
entity.addComponent(new BeltReaderComponent());
entity.addComponent( }
new BeltUnderlaysComponent({ }
underlays: [
{
pos: new Vector(0, 0),
direction: enumDirection.top,
},
],
})
);
entity.addComponent(new BeltReaderComponent());
}
}

View File

@ -9,7 +9,6 @@ import { UndergroundBeltComponent } from "./components/underground_belt";
import { HubComponent } from "./components/hub"; import { HubComponent } from "./components/hub";
import { StorageComponent } from "./components/storage"; import { StorageComponent } from "./components/storage";
import { WiredPinsComponent } from "./components/wired_pins"; import { WiredPinsComponent } from "./components/wired_pins";
import { BeltUnderlaysComponent } from "./components/belt_underlays";
import { WireComponent } from "./components/wire"; import { WireComponent } from "./components/wire";
import { ConstantSignalComponent } from "./components/constant_signal"; import { ConstantSignalComponent } from "./components/constant_signal";
import { LogicGateComponent } from "./components/logic_gate"; import { LogicGateComponent } from "./components/logic_gate";
@ -32,7 +31,6 @@ export function initComponentRegistry() {
gComponentRegistry.register(HubComponent); gComponentRegistry.register(HubComponent);
gComponentRegistry.register(StorageComponent); gComponentRegistry.register(StorageComponent);
gComponentRegistry.register(WiredPinsComponent); gComponentRegistry.register(WiredPinsComponent);
gComponentRegistry.register(BeltUnderlaysComponent);
gComponentRegistry.register(WireComponent); gComponentRegistry.register(WireComponent);
gComponentRegistry.register(ConstantSignalComponent); gComponentRegistry.register(ConstantSignalComponent);
gComponentRegistry.register(LogicGateComponent); gComponentRegistry.register(LogicGateComponent);

View File

@ -1,41 +0,0 @@
import { enumDirection, Vector } from "../../core/vector";
import { Component } from "../component";
/**
* Store which type an underlay is, this is cached so we can easily
* render it.
*
* Full: Render underlay at top and bottom of tile
* Bottom Only: Only render underlay at the bottom half
* Top Only:
* @enum {string}
*/
export const enumClippedBeltUnderlayType = {
full: "full",
bottomOnly: "bottomOnly",
topOnly: "topOnly",
none: "none",
};
/**
* @typedef {{
* pos: Vector,
* direction: enumDirection,
* cachedType?: enumClippedBeltUnderlayType
* }} BeltUnderlayTile
*/
export class BeltUnderlaysComponent extends Component {
static getId() {
return "BeltUnderlays";
}
/**
* @param {object} param0
* @param {Array<BeltUnderlayTile>=} param0.underlays Where to render belt underlays
*/
constructor({ underlays = [] }) {
super();
this.underlays = underlays;
}
}

View File

@ -1,6 +1,5 @@
/* typehints:start */ /* typehints:start */
import { BeltComponent } from "./components/belt"; import { BeltComponent } from "./components/belt";
import { BeltUnderlaysComponent } from "./components/belt_underlays";
import { HubComponent } from "./components/hub"; import { HubComponent } from "./components/hub";
import { ItemAcceptorComponent } from "./components/item_acceptor"; import { ItemAcceptorComponent } from "./components/item_acceptor";
import { ItemEjectorComponent } from "./components/item_ejector"; import { ItemEjectorComponent } from "./components/item_ejector";
@ -60,9 +59,6 @@ export class EntityComponentStorage {
/** @type {WiredPinsComponent} */ /** @type {WiredPinsComponent} */
this.WiredPins; this.WiredPins;
/** @type {BeltUnderlaysComponent} */
this.BeltUnderlays;
/** @type {WireComponent} */ /** @type {WireComponent} */
this.Wire; this.Wire;

View File

@ -2,25 +2,12 @@ import { globalConfig } from "../../core/config";
import { DrawParameters } from "../../core/draw_parameters"; import { DrawParameters } from "../../core/draw_parameters";
import { Loader } from "../../core/loader"; import { Loader } from "../../core/loader";
import { Rectangle } from "../../core/rectangle"; import { Rectangle } from "../../core/rectangle";
import { FULL_CLIP_RECT } from "../../core/sprites";
import { enumDirectionToAngle, enumInvertedDirections } from "../../core/vector"; import { enumDirectionToAngle, enumInvertedDirections } from "../../core/vector";
import { enumClippedBeltUnderlayType } from "../components/belt_underlays";
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";
import { BELT_ANIM_COUNT } from "./belt"; import { BELT_ANIM_COUNT } from "./belt";
/**
* Mapping from underlay type to clip rect
* @type {Object<enumClippedBeltUnderlayType, Rectangle>}
*/
const enumUnderlayTypeToClipRect = {
[enumClippedBeltUnderlayType.none]: null,
[enumClippedBeltUnderlayType.full]: FULL_CLIP_RECT,
[enumClippedBeltUnderlayType.topOnly]: new Rectangle(0, 0, 1, 0.5),
[enumClippedBeltUnderlayType.bottomOnly]: new Rectangle(0, 0.5, 1, 0.5),
};
export class AcceptorBeltSystem extends GameSystemWithFilter { export class AcceptorBeltSystem extends GameSystemWithFilter {
constructor(root) { constructor(root) {
super(root, [ItemAcceptorComponent]); super(root, [ItemAcceptorComponent]);
@ -86,12 +73,7 @@ export class AcceptorBeltSystem extends GameSystemWithFilter {
const worldDirection = staticComp.localDirectionToWorld(direction); const worldDirection = staticComp.localDirectionToWorld(direction);
const angle = enumDirectionToAngle[enumInvertedDirections[worldDirection]]; const angle = enumDirectionToAngle[enumInvertedDirections[worldDirection]];
const underlayType = enumClippedBeltUnderlayType.bottomOnly; const clipRect = new Rectangle(0, 0.5, 1, 0.5);
const clipRect = enumUnderlayTypeToClipRect[underlayType];
if (!clipRect) {
// Empty
continue;
}
// Actually draw the sprite // Actually draw the sprite
const x = destX + globalConfig.halfTileSize; const x = destX + globalConfig.halfTileSize;

View File

@ -2,25 +2,12 @@ import { globalConfig } from "../../core/config";
import { DrawParameters } from "../../core/draw_parameters"; import { DrawParameters } from "../../core/draw_parameters";
import { Loader } from "../../core/loader"; import { Loader } from "../../core/loader";
import { Rectangle } from "../../core/rectangle"; import { Rectangle } from "../../core/rectangle";
import { FULL_CLIP_RECT } from "../../core/sprites";
import { enumDirectionToAngle } from "../../core/vector"; import { enumDirectionToAngle } from "../../core/vector";
import { enumClippedBeltUnderlayType } from "../components/belt_underlays";
import { ItemEjectorComponent } from "../components/item_ejector"; import { ItemEjectorComponent } from "../components/item_ejector";
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";
import { BELT_ANIM_COUNT } from "./belt"; import { BELT_ANIM_COUNT } from "./belt";
/**
* Mapping from underlay type to clip rect
* @type {Object<enumClippedBeltUnderlayType, Rectangle>}
*/
const enumUnderlayTypeToClipRect = {
[enumClippedBeltUnderlayType.none]: null,
[enumClippedBeltUnderlayType.full]: FULL_CLIP_RECT,
[enumClippedBeltUnderlayType.topOnly]: new Rectangle(0, 0, 1, 0.5),
[enumClippedBeltUnderlayType.bottomOnly]: new Rectangle(0, 0.5, 1, 0.5),
};
export class EjectorBeltSystem extends GameSystemWithFilter { export class EjectorBeltSystem extends GameSystemWithFilter {
constructor(root) { constructor(root) {
super(root, [ItemEjectorComponent]); super(root, [ItemEjectorComponent]);
@ -83,12 +70,7 @@ export class EjectorBeltSystem extends GameSystemWithFilter {
const worldDirection = staticComp.localDirectionToWorld(direction); const worldDirection = staticComp.localDirectionToWorld(direction);
const angle = enumDirectionToAngle[worldDirection]; const angle = enumDirectionToAngle[worldDirection];
const underlayType = enumClippedBeltUnderlayType.topOnly; const clipRect = new Rectangle(0, 0, 1, 0.5);
const clipRect = enumUnderlayTypeToClipRect[underlayType];
if (!clipRect) {
// Empty
continue;
}
// Actually draw the sprite // Actually draw the sprite
const x = destX + globalConfig.halfTileSize; const x = destX + globalConfig.halfTileSize;