From d4cbb5b12455c7aa90e055134e9f55097ce1a845 Mon Sep 17 00:00:00 2001 From: tobspr Date: Sat, 15 Aug 2020 22:52:16 +0200 Subject: [PATCH] Fix belt underlays not rendering --- src/js/game/systems/belt_underlays.js | 84 ++++++++++++++------------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/src/js/game/systems/belt_underlays.js b/src/js/game/systems/belt_underlays.js index 61908045..5bdf2331 100644 --- a/src/js/game/systems/belt_underlays.js +++ b/src/js/game/systems/belt_underlays.js @@ -32,50 +32,52 @@ export class BeltUnderlaysSystem extends GameSystemWithFilter { for (let i = 0; i < contents.length; ++i) { const entity = contents[i]; const underlayComp = entity.components.BeltUnderlays; - if (underlayComp) { - const staticComp = entity.components.StaticMapEntity; - const underlays = underlayComp.underlays; - for (let i = 0; i < underlays.length; ++i) { - const { pos, direction } = underlays[i]; - const transformedPos = staticComp.localTileToWorld(pos); + if (!underlayComp) { + continue; + } - // Culling - if (!chunk.tileSpaceRectangle.containsPoint(transformedPos.x, transformedPos.y)) { - continue; - } + const staticComp = entity.components.StaticMapEntity; + const underlays = underlayComp.underlays; + for (let i = 0; i < underlays.length; ++i) { + const { pos, direction } = underlays[i]; + const transformedPos = staticComp.localTileToWorld(pos); - const destX = transformedPos.x * globalConfig.tileSize; - const destY = transformedPos.y * globalConfig.tileSize; - - // Culling, #2 - if ( - parameters.visibleRect.containsRect4Params( - destX, - destY, - globalConfig.tileSize, - globalConfig.tileSize - ) - ) { - continue; - } - - const angle = enumDirectionToAngle[staticComp.localDirectionToWorld(direction)]; - - // SYNC with systems/belt.js:drawSingleEntity! - const animationIndex = Math.floor( - ((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) * - globalConfig.itemSpacingOnBelts - ); - - drawRotatedSprite({ - parameters, - sprite: this.underlayBeltSprites[animationIndex % this.underlayBeltSprites.length], - x: destX + globalConfig.halfTileSize, - y: destY + globalConfig.halfTileSize, - angle: Math.radians(angle), - size: globalConfig.tileSize, - }); + // Culling + if (!chunk.tileSpaceRectangle.containsPoint(transformedPos.x, transformedPos.y)) { + continue; } + + const destX = transformedPos.x * globalConfig.tileSize; + const destY = transformedPos.y * globalConfig.tileSize; + + // Culling, #2 + if ( + !parameters.visibleRect.containsRect4Params( + destX, + destY, + globalConfig.tileSize, + globalConfig.tileSize + ) + ) { + continue; + } + + const angle = enumDirectionToAngle[staticComp.localDirectionToWorld(direction)]; + + // SYNC with systems/belt.js:drawSingleEntity! + const animationIndex = Math.floor( + ((this.root.time.realtimeNow() * speedMultiplier * BELT_ANIM_COUNT * 126) / 42) * + globalConfig.itemSpacingOnBelts + ); + + drawRotatedSprite({ + parameters, + sprite: this.underlayBeltSprites[animationIndex % this.underlayBeltSprites.length], + x: destX + globalConfig.halfTileSize, + y: destY + globalConfig.halfTileSize, + angle: Math.radians(angle), + size: globalConfig.tileSize, + }); } } }