From fb5b6a1dad6d41071c5d3f8b7a390f70ed18141d Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Wed, 17 Dec 2025 05:02:34 +0100 Subject: [PATCH] Fix barrel group vertical centering calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Correct baseY calculation to account for barrel centers - baseY now positions bottom barrel so group center aligns with deck center - Remove incorrect groupHeight calculation - Both fuel and oil barrels now properly centered 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- src/scenes/ShipDeckScene.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/scenes/ShipDeckScene.js b/src/scenes/ShipDeckScene.js index a90f684..31cc0be 100644 --- a/src/scenes/ShipDeckScene.js +++ b/src/scenes/ShipDeckScene.js @@ -115,7 +115,6 @@ export default class ShipDeckScene extends Phaser.Scene { // Calculate group dimensions const groupWidth = (Math.min(barrelCount, barrelsPerRow) * horizontalSpacing); const stackLevels = Math.ceil(barrelCount / barrelsPerRow); - const groupHeight = (stackLevels * barrelHeight) + ((stackLevels - 1) * (verticalSpacing - barrelHeight)); // Center horizontally in left half of deck const leftHalfCenter = this.deckLeftX + (this.deckWidth / 4); @@ -123,7 +122,12 @@ export default class ShipDeckScene extends Phaser.Scene { // Center vertically on deck (using actual deck edges) const deckVerticalCenter = (this.deckTopEdge + this.deckBottomEdge) / 2; - const baseY = deckVerticalCenter + (groupHeight / 2); + // Calculate where bottom barrel should be so group is centered + // Top of group = baseY - (stackLevels-1)*verticalSpacing - barrelHeight/2 + // Bottom of group = baseY + barrelHeight/2 + // Center of group = (top + bottom) / 2 = baseY - ((stackLevels-1)*verticalSpacing)/2 + // We want: baseY - ((stackLevels-1)*verticalSpacing)/2 = deckVerticalCenter + const baseY = deckVerticalCenter + ((stackLevels - 1) * verticalSpacing) / 2; // Create barrels in stacking pattern for (let i = 0; i < barrelCount; i++) { @@ -191,7 +195,6 @@ export default class ShipDeckScene extends Phaser.Scene { // Calculate group dimensions const groupWidth = (Math.min(barrelCount, barrelsPerRow) * horizontalSpacing); const stackLevels = Math.ceil(barrelCount / barrelsPerRow); - const groupHeight = (stackLevels * barrelHeight) + ((stackLevels - 1) * (verticalSpacing - barrelHeight)); // Center horizontally in right half of deck const rightHalfCenter = this.deckCenterX + (this.deckWidth / 4); @@ -199,7 +202,8 @@ export default class ShipDeckScene extends Phaser.Scene { // Center vertically on deck (using actual deck edges) const deckVerticalCenter = (this.deckTopEdge + this.deckBottomEdge) / 2; - const baseY = deckVerticalCenter + (groupHeight / 2); + // Calculate where bottom barrel should be so group is centered + const baseY = deckVerticalCenter + ((stackLevels - 1) * verticalSpacing) / 2; // Create barrels in stacking pattern for (let i = 0; i < barrelCount; i++) {