mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-16 11:41:50 +00:00
optional belt length for acceptors/ejectors
This commit is contained in:
parent
10db2af21c
commit
88b12c685d
@ -152,16 +152,18 @@ export class MetaBalancerBuilding extends MetaBuilding {
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
directions: [enumDirection.bottom],
|
||||
beltLength: 0.5,
|
||||
},
|
||||
{
|
||||
pos: new Vector(1, 0),
|
||||
directions: [enumDirection.bottom],
|
||||
beltLength: 0.5,
|
||||
},
|
||||
]);
|
||||
|
||||
entity.components.ItemEjector.setSlots([
|
||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
||||
{ pos: new Vector(1, 0), direction: enumDirection.top },
|
||||
{ pos: new Vector(0, 0), direction: enumDirection.top, beltLength: 0.5 },
|
||||
{ pos: new Vector(1, 0), direction: enumDirection.top, beltLength: 0.5 },
|
||||
]);
|
||||
|
||||
break;
|
||||
@ -172,6 +174,7 @@ export class MetaBalancerBuilding extends MetaBuilding {
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
directions: [enumDirection.bottom],
|
||||
beltLength: 0.5,
|
||||
},
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
@ -180,11 +183,14 @@ export class MetaBalancerBuilding extends MetaBuilding {
|
||||
? enumDirection.left
|
||||
: enumDirection.right,
|
||||
],
|
||||
// distance to edge of perpendicular belt, ignoring border width
|
||||
// see generate_belt_sprites.js
|
||||
beltLength: 23.5 / 192,
|
||||
},
|
||||
]);
|
||||
|
||||
entity.components.ItemEjector.setSlots([
|
||||
{ pos: new Vector(0, 0), direction: enumDirection.top },
|
||||
{ pos: new Vector(0, 0), direction: enumDirection.top, beltLength: 0.5 },
|
||||
]);
|
||||
|
||||
break;
|
||||
@ -195,6 +201,7 @@ export class MetaBalancerBuilding extends MetaBuilding {
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
directions: [enumDirection.bottom],
|
||||
beltLength: 0.5,
|
||||
},
|
||||
]);
|
||||
|
||||
@ -202,6 +209,7 @@ export class MetaBalancerBuilding extends MetaBuilding {
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.top,
|
||||
beltLength: 0.5,
|
||||
},
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
@ -209,6 +217,7 @@ export class MetaBalancerBuilding extends MetaBuilding {
|
||||
variant === enumBalancerVariants.splitterInverse
|
||||
? enumDirection.left
|
||||
: enumDirection.right,
|
||||
beltLength: 23.5 / 192,
|
||||
},
|
||||
]);
|
||||
|
||||
|
||||
@ -75,6 +75,7 @@ export class MetaReaderBuilding extends MetaBuilding {
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
directions: [enumDirection.bottom],
|
||||
beltLength: 0.5,
|
||||
},
|
||||
],
|
||||
})
|
||||
@ -86,6 +87,7 @@ export class MetaReaderBuilding extends MetaBuilding {
|
||||
{
|
||||
pos: new Vector(0, 0),
|
||||
direction: enumDirection.top,
|
||||
beltLength: 0.5,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
@ -6,6 +6,7 @@ import { Component } from "../component";
|
||||
/** @typedef {{
|
||||
* pos: Vector,
|
||||
* directions: enumDirection[],
|
||||
* beltLength?: number,
|
||||
* filter?: ItemType
|
||||
* }} ItemAcceptorSlot */
|
||||
|
||||
@ -20,6 +21,7 @@ import { Component } from "../component";
|
||||
/** @typedef {{
|
||||
* pos: Vector,
|
||||
* directions: enumDirection[],
|
||||
* beltLength?: number,
|
||||
* filter?: ItemType
|
||||
* }} ItemAcceptorSlotConfig */
|
||||
|
||||
@ -65,6 +67,7 @@ export class ItemAcceptorComponent extends Component {
|
||||
this.slots.push({
|
||||
pos: slot.pos,
|
||||
directions: slot.directions,
|
||||
beltLength: slot.beltLength,
|
||||
|
||||
// Which type of item to accept (shape | color | all) @see ItemType
|
||||
filter: slot.filter,
|
||||
|
||||
@ -10,6 +10,7 @@ import { typeItemSingleton } from "../item_resolver";
|
||||
* @typedef {{
|
||||
* pos: Vector,
|
||||
* direction: enumDirection,
|
||||
* beltLength?: number,
|
||||
* item: BaseItem,
|
||||
* lastItem: BaseItem,
|
||||
* progress: number?,
|
||||
@ -39,7 +40,7 @@ export class ItemEjectorComponent extends Component {
|
||||
/**
|
||||
*
|
||||
* @param {object} param0
|
||||
* @param {Array<{pos: Vector, direction: enumDirection }>=} param0.slots The slots to eject on
|
||||
* @param {Array<{pos: Vector, direction: enumDirection, beltLength?: number }>=} param0.slots The slots to eject on
|
||||
* @param {boolean=} param0.renderFloatingItems Whether to render items even if they are not connected
|
||||
*/
|
||||
constructor({ slots = [], renderFloatingItems = true }) {
|
||||
@ -58,7 +59,7 @@ export class ItemEjectorComponent extends Component {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array<{pos: Vector, direction: enumDirection }>} slots The slots to eject on
|
||||
* @param {Array<{pos: Vector, direction: enumDirection, beltLength?: number }>} slots The slots to eject on
|
||||
*/
|
||||
setSlots(slots) {
|
||||
/** @type {Array<ItemEjectorSlot>} */
|
||||
@ -68,6 +69,7 @@ export class ItemEjectorComponent extends Component {
|
||||
this.slots.push({
|
||||
pos: slot.pos,
|
||||
direction: slot.direction,
|
||||
beltLength: slot.beltLength,
|
||||
item: null,
|
||||
lastItem: null,
|
||||
progress: 0,
|
||||
|
||||
@ -43,8 +43,13 @@ export class AcceptorBeltSystem extends GameSystemWithFilter {
|
||||
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
for (let i = 0; i < acceptorComp.slots.length; ++i) {
|
||||
// skips both missing and 0 belt lengths
|
||||
if (!acceptorComp.slots[i].beltLength) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract underlay parameters
|
||||
const { pos, directions } = acceptorComp.slots[i];
|
||||
const { pos, directions, beltLength } = acceptorComp.slots[i];
|
||||
const transformedPos = staticComp.localTileToWorld(pos);
|
||||
const destX = transformedPos.x * globalConfig.tileSize;
|
||||
const destY = transformedPos.y * globalConfig.tileSize;
|
||||
@ -73,7 +78,7 @@ export class AcceptorBeltSystem extends GameSystemWithFilter {
|
||||
const worldDirection = staticComp.localDirectionToWorld(direction);
|
||||
const angle = enumDirectionToAngle[enumInvertedDirections[worldDirection]];
|
||||
|
||||
const clipRect = new Rectangle(0, 0.5, 1, 0.5);
|
||||
const clipRect = new Rectangle(0, 1 - beltLength, 1, beltLength);
|
||||
|
||||
// Actually draw the sprite
|
||||
const x = destX + globalConfig.halfTileSize;
|
||||
|
||||
@ -43,8 +43,13 @@ export class EjectorBeltSystem extends GameSystemWithFilter {
|
||||
|
||||
const staticComp = entity.components.StaticMapEntity;
|
||||
for (let i = 0; i < ejectorComp.slots.length; ++i) {
|
||||
// skips both missing and 0 belt lengths
|
||||
if (!ejectorComp.slots[i].beltLength) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Extract underlay parameters
|
||||
const { pos, direction } = ejectorComp.slots[i];
|
||||
const { pos, direction, beltLength } = ejectorComp.slots[i];
|
||||
const transformedPos = staticComp.localTileToWorld(pos);
|
||||
const destX = transformedPos.x * globalConfig.tileSize;
|
||||
const destY = transformedPos.y * globalConfig.tileSize;
|
||||
@ -70,7 +75,7 @@ export class EjectorBeltSystem extends GameSystemWithFilter {
|
||||
const worldDirection = staticComp.localDirectionToWorld(direction);
|
||||
const angle = enumDirectionToAngle[worldDirection];
|
||||
|
||||
const clipRect = new Rectangle(0, 0, 1, 0.5);
|
||||
const clipRect = new Rectangle(0, 0, 1, beltLength);
|
||||
|
||||
// Actually draw the sprite
|
||||
const x = destX + globalConfig.halfTileSize;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user