mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-16 03:31:52 +00:00
slightly refactor belt drawing
This commit is contained in:
parent
a7a2aad2b6
commit
8344f8ad68
@ -496,51 +496,41 @@ export class BeltSystem extends GameSystemWithFilter {
|
|||||||
drawChunk(parameters, chunk) {
|
drawChunk(parameters, chunk) {
|
||||||
// Limit speed to avoid belts going backwards
|
// Limit speed to avoid belts going backwards
|
||||||
const speedMultiplier = Math.min(this.root.hubGoals.getBeltBaseSpeed(), 10);
|
const speedMultiplier = Math.min(this.root.hubGoals.getBeltBaseSpeed(), 10);
|
||||||
|
// SYNC with systems/belt_underlays.js:drawChunk!
|
||||||
// SYNC with systems/item_acceptor.js:drawEntityUnderlays!
|
|
||||||
// 126 / 42 is the exact animation speed of the png animation
|
// 126 / 42 is the exact animation speed of the png animation
|
||||||
const animationIndex = Math.floor(
|
const animationIndex = Math.floor(
|
||||||
((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) *
|
((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) *
|
||||||
globalConfig.itemSpacingOnBelts
|
globalConfig.itemSpacingOnBelts
|
||||||
);
|
);
|
||||||
const contents = chunk.containedEntitiesByLayer.regular;
|
|
||||||
|
|
||||||
if (this.root.app.settings.getAllSettings().simplifiedBelts) {
|
const simplifiedBelts = this.root.app.settings.getAllSettings().simplifiedBelts;
|
||||||
|
|
||||||
|
let hoveredBeltPath = null;
|
||||||
|
if (simplifiedBelts) {
|
||||||
// POTATO Mode: Only show items when belt is hovered
|
// POTATO Mode: Only show items when belt is hovered
|
||||||
let hoveredBeltPath = null;
|
|
||||||
const mousePos = this.root.app.mousePosition;
|
const mousePos = this.root.app.mousePosition;
|
||||||
if (mousePos && this.root.currentLayer === "regular") {
|
if (mousePos && this.root.currentLayer === "regular") {
|
||||||
const tile = this.root.camera.screenToWorld(mousePos).toTileSpace();
|
const tile = this.root.camera.screenToWorld(mousePos).toTileSpace();
|
||||||
const contents = this.root.map.getLayerContentXY(tile.x, tile.y, "regular");
|
const entity = this.root.map.getLayerContentXY(tile.x, tile.y, "regular");
|
||||||
if (contents && contents.components.Belt) {
|
if (entity && entity.components.Belt) {
|
||||||
hoveredBeltPath = contents.components.Belt.assignedPath;
|
hoveredBeltPath = entity.components.Belt.assignedPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < contents.length; ++i) {
|
const contents = chunk.containedEntitiesByLayer.regular;
|
||||||
const entity = contents[i];
|
for (let i = 0; i < contents.length; ++i) {
|
||||||
if (entity.components.Belt) {
|
const entity = contents[i];
|
||||||
const direction = entity.components.Belt.direction;
|
if (entity.components.Belt) {
|
||||||
let sprite = this.beltAnimations[direction][0];
|
const { direction, assignedPath } = entity.components.Belt;
|
||||||
|
const sprite = this.beltAnimations[direction][
|
||||||
|
!simplifiedBelts || assignedPath === hoveredBeltPath
|
||||||
|
? animationIndex % BELT_ANIM_COUNT
|
||||||
|
: 0
|
||||||
|
];
|
||||||
|
|
||||||
if (entity.components.Belt.assignedPath === hoveredBeltPath) {
|
// Culling happens within the static map entity component
|
||||||
sprite = this.beltAnimations[direction][animationIndex % BELT_ANIM_COUNT];
|
entity.components.StaticMapEntity.drawSpriteOnBoundsClipped(parameters, sprite, 0);
|
||||||
}
|
|
||||||
|
|
||||||
// Culling happens within the static map entity component
|
|
||||||
entity.components.StaticMapEntity.drawSpriteOnBoundsClipped(parameters, sprite, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i < contents.length; ++i) {
|
|
||||||
const entity = contents[i];
|
|
||||||
if (entity.components.Belt) {
|
|
||||||
const direction = entity.components.Belt.direction;
|
|
||||||
const sprite = this.beltAnimations[direction][animationIndex % BELT_ANIM_COUNT];
|
|
||||||
|
|
||||||
// Culling happens within the static map entity component
|
|
||||||
entity.components.StaticMapEntity.drawSpriteOnBoundsClipped(parameters, sprite, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -224,6 +224,11 @@ export class BeltUnderlaysSystem extends GameSystemWithFilter {
|
|||||||
drawChunk(parameters, chunk) {
|
drawChunk(parameters, chunk) {
|
||||||
// Limit speed to avoid belts going backwards
|
// Limit speed to avoid belts going backwards
|
||||||
const speedMultiplier = Math.min(this.root.hubGoals.getBeltBaseSpeed(), 10);
|
const speedMultiplier = Math.min(this.root.hubGoals.getBeltBaseSpeed(), 10);
|
||||||
|
// SYNC with systems/belt.js:drawChunk!
|
||||||
|
const animationIndex = Math.floor(
|
||||||
|
((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) *
|
||||||
|
globalConfig.itemSpacingOnBelts
|
||||||
|
);
|
||||||
|
|
||||||
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) {
|
||||||
@ -275,16 +280,9 @@ export class BeltUnderlaysSystem extends GameSystemWithFilter {
|
|||||||
const y = destY + globalConfig.halfTileSize;
|
const y = destY + globalConfig.halfTileSize;
|
||||||
const angleRadians = Math.radians(angle);
|
const angleRadians = Math.radians(angle);
|
||||||
|
|
||||||
// SYNC with systems/belt.js:drawSingleEntity!
|
|
||||||
const animationIndex = Math.floor(
|
|
||||||
((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) *
|
|
||||||
globalConfig.itemSpacingOnBelts
|
|
||||||
);
|
|
||||||
parameters.context.translate(x, y);
|
parameters.context.translate(x, y);
|
||||||
parameters.context.rotate(angleRadians);
|
parameters.context.rotate(angleRadians);
|
||||||
this.underlayBeltSprites[
|
this.underlayBeltSprites[animationIndex % BELT_ANIM_COUNT].drawCachedWithClipRect(
|
||||||
animationIndex % this.underlayBeltSprites.length
|
|
||||||
].drawCachedWithClipRect(
|
|
||||||
parameters,
|
parameters,
|
||||||
-globalConfig.halfTileSize,
|
-globalConfig.halfTileSize,
|
||||||
-globalConfig.halfTileSize,
|
-globalConfig.halfTileSize,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user