mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-16 11:41:50 +00:00
only show acceptor belt if connected
This commit is contained in:
parent
97d45e8aa7
commit
24d6238d17
@ -2,7 +2,13 @@ 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 { enumDirectionToAngle, enumInvertedDirections } from "../../core/vector";
|
import {
|
||||||
|
enumDirection,
|
||||||
|
enumDirectionToAngle,
|
||||||
|
enumDirectionToVector,
|
||||||
|
enumInvertedDirections,
|
||||||
|
Vector,
|
||||||
|
} 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";
|
||||||
@ -20,6 +26,50 @@ export class AcceptorBeltSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a given tile is connected and has an ejector
|
||||||
|
* @param {Vector} tile
|
||||||
|
* @param {enumDirection} toDirection
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
checkIsEjectorConnected(tile, toDirection) {
|
||||||
|
const contents = this.root.map.getLayerContentXY(tile.x, tile.y, "regular");
|
||||||
|
if (!contents) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const staticComp = contents.components.StaticMapEntity;
|
||||||
|
|
||||||
|
// Check if its a belt, since then its simple
|
||||||
|
const beltComp = contents.components.Belt;
|
||||||
|
if (beltComp) {
|
||||||
|
return staticComp.localDirectionToWorld(beltComp.direction) === toDirection;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for an ejector
|
||||||
|
const ejectorComp = contents.components.ItemEjector;
|
||||||
|
if (ejectorComp) {
|
||||||
|
// Check each slot to see if its connected
|
||||||
|
for (let i = 0; i < ejectorComp.slots.length; ++i) {
|
||||||
|
const slot = ejectorComp.slots[i];
|
||||||
|
const slotTile = staticComp.localTileToWorld(slot.pos);
|
||||||
|
|
||||||
|
// Step 1: Check if the tile matches
|
||||||
|
if (!slotTile.equals(tile)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 2: Check if the direction matches
|
||||||
|
const slotDirection = staticComp.localDirectionToWorld(slot.direction);
|
||||||
|
if (slotDirection === toDirection) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws a given chunk
|
* Draws a given chunk
|
||||||
* @param {DrawParameters} parameters
|
* @param {DrawParameters} parameters
|
||||||
@ -76,8 +126,20 @@ export class AcceptorBeltSystem extends GameSystemWithFilter {
|
|||||||
const direction = directions[j];
|
const direction = directions[j];
|
||||||
|
|
||||||
// Extract direction and angle
|
// Extract direction and angle
|
||||||
const worldDirection = staticComp.localDirectionToWorld(direction);
|
const worldDirection =
|
||||||
const angle = enumDirectionToAngle[enumInvertedDirections[worldDirection]];
|
enumInvertedDirections[staticComp.localDirectionToWorld(direction)];
|
||||||
|
const worldDirectionVector = enumDirectionToVector[worldDirection];
|
||||||
|
const angle = enumDirectionToAngle[worldDirection];
|
||||||
|
|
||||||
|
// check if connected
|
||||||
|
if (
|
||||||
|
!this.checkIsEjectorConnected(
|
||||||
|
transformedPos.sub(worldDirectionVector),
|
||||||
|
worldDirection
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const clipRect = new Rectangle(0, 1 - beltLength, 1, beltLength);
|
const clipRect = new Rectangle(0, 1 - beltLength, 1, beltLength);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user