mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-16 11:41:50 +00:00
belt hover for acceptor belts
This commit is contained in:
parent
0d3a1efa67
commit
247e4dc2e0
@ -9,7 +9,9 @@ import {
|
|||||||
enumInvertedDirections,
|
enumInvertedDirections,
|
||||||
Vector,
|
Vector,
|
||||||
} from "../../core/vector";
|
} from "../../core/vector";
|
||||||
|
import { BeltPath } from "../belt_path";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
|
import { Entity } from "../entity";
|
||||||
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";
|
||||||
@ -27,15 +29,18 @@ export class AcceptorBeltSystem extends GameSystemWithFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a given tile is connected and has an ejector
|
* Gets the adjacent entity that ejects to a tile
|
||||||
* @param {Vector} tile
|
* @param {Vector} toTile
|
||||||
* @param {enumDirection} toDirection
|
* @param {enumDirection} toDirection
|
||||||
* @returns {boolean}
|
* @returns {Entity}
|
||||||
*/
|
*/
|
||||||
checkIsEjectorConnected(tile, toDirection) {
|
getSourceEntity(toTile, toDirection) {
|
||||||
|
const toDirectionVector = enumDirectionToVector[toDirection];
|
||||||
|
const tile = toTile.sub(toDirectionVector);
|
||||||
|
|
||||||
const contents = this.root.map.getLayerContentXY(tile.x, tile.y, "regular");
|
const contents = this.root.map.getLayerContentXY(tile.x, tile.y, "regular");
|
||||||
if (!contents) {
|
if (!contents) {
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const staticComp = contents.components.StaticMapEntity;
|
const staticComp = contents.components.StaticMapEntity;
|
||||||
@ -43,7 +48,7 @@ export class AcceptorBeltSystem extends GameSystemWithFilter {
|
|||||||
// Check if its a belt, since then its simple
|
// Check if its a belt, since then its simple
|
||||||
const beltComp = contents.components.Belt;
|
const beltComp = contents.components.Belt;
|
||||||
if (beltComp) {
|
if (beltComp) {
|
||||||
return staticComp.localDirectionToWorld(beltComp.direction) === toDirection;
|
return staticComp.localDirectionToWorld(beltComp.direction) === toDirection ? contents : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for an ejector
|
// Check for an ejector
|
||||||
@ -62,12 +67,12 @@ export class AcceptorBeltSystem extends GameSystemWithFilter {
|
|||||||
// Step 2: Check if the direction matches
|
// Step 2: Check if the direction matches
|
||||||
const slotDirection = staticComp.localDirectionToWorld(slot.direction);
|
const slotDirection = staticComp.localDirectionToWorld(slot.direction);
|
||||||
if (slotDirection === toDirection) {
|
if (slotDirection === toDirection) {
|
||||||
return true;
|
return contents;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,8 +82,9 @@ export class AcceptorBeltSystem extends GameSystemWithFilter {
|
|||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
* @param {number} param0.animationIndex
|
* @param {number} param0.animationIndex
|
||||||
* @param {boolean} param0.simplifiedBelts
|
* @param {boolean} param0.simplifiedBelts
|
||||||
|
* @param {BeltPath} param0.hoveredBeltPath
|
||||||
*/
|
*/
|
||||||
internalDrawChunk(parameters, chunk, { animationIndex, simplifiedBelts }) {
|
internalDrawChunk(parameters, chunk, { animationIndex, simplifiedBelts, hoveredBeltPath }) {
|
||||||
const contents = chunk.containedEntitiesByLayer.regular;
|
const contents = chunk.containedEntitiesByLayer.regular;
|
||||||
for (let i = 0; i < contents.length; ++i) {
|
for (let i = 0; i < contents.length; ++i) {
|
||||||
const entity = contents[i];
|
const entity = contents[i];
|
||||||
@ -128,15 +134,14 @@ export class AcceptorBeltSystem extends GameSystemWithFilter {
|
|||||||
const angle = enumDirectionToAngle[worldDirection];
|
const angle = enumDirectionToAngle[worldDirection];
|
||||||
|
|
||||||
// check if connected
|
// check if connected
|
||||||
if (
|
const sourceEntity = this.getSourceEntity(transformedPos, worldDirection);
|
||||||
!this.checkIsEjectorConnected(
|
if (!sourceEntity) {
|
||||||
transformedPos.sub(worldDirectionVector),
|
|
||||||
worldDirection
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sourceBeltComp = sourceEntity.components.Belt;
|
||||||
|
const sourceBeltPath = sourceBeltComp ? sourceBeltComp.assignedPath : null;
|
||||||
|
|
||||||
const clipRect = new Rectangle(0, 1 - beltLength, 1, beltLength);
|
const clipRect = new Rectangle(0, 1 - beltLength, 1, beltLength);
|
||||||
|
|
||||||
// Actually draw the sprite
|
// Actually draw the sprite
|
||||||
@ -147,7 +152,9 @@ export class AcceptorBeltSystem extends GameSystemWithFilter {
|
|||||||
parameters.context.translate(x, y);
|
parameters.context.translate(x, y);
|
||||||
parameters.context.rotate(angleRadians);
|
parameters.context.rotate(angleRadians);
|
||||||
this.underlayBeltSprites[
|
this.underlayBeltSprites[
|
||||||
!simplifiedBelts ? animationIndex % BELT_ANIM_COUNT : 0
|
!simplifiedBelts || (sourceBeltPath && sourceBeltPath === hoveredBeltPath)
|
||||||
|
? animationIndex % BELT_ANIM_COUNT
|
||||||
|
: 0
|
||||||
].drawCachedWithClipRect(
|
].drawCachedWithClipRect(
|
||||||
parameters,
|
parameters,
|
||||||
-globalConfig.halfTileSize,
|
-globalConfig.halfTileSize,
|
||||||
|
|||||||
@ -552,6 +552,7 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
this.root.systemMgr.systems.acceptorBelt.internalDrawChunk(parameters, chunk, {
|
this.root.systemMgr.systems.acceptorBelt.internalDrawChunk(parameters, chunk, {
|
||||||
animationIndex,
|
animationIndex,
|
||||||
simplifiedBelts,
|
simplifiedBelts,
|
||||||
|
hoveredBeltPath,
|
||||||
});
|
});
|
||||||
this.root.systemMgr.systems.ejectorBelt.internalDrawChunk(parameters, chunk, {
|
this.root.systemMgr.systems.ejectorBelt.internalDrawChunk(parameters, chunk, {
|
||||||
animationIndex,
|
animationIndex,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user