Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 9 additions & 29 deletions src/entities/Building.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ export class Building extends Phaser.GameObjects.Container {
private selectionOutline: Phaser.GameObjects.Graphics
private rallyLine: Phaser.GameObjects.Graphics
private constructionOverlay: Phaser.GameObjects.Graphics
private constructionMaskShape: Phaser.GameObjects.Graphics
private constructionMask: Phaser.Display.Masks.GeometryMask
private labelText: Phaser.GameObjects.Text
private isSelected: boolean
private factionColor: number
Expand Down Expand Up @@ -86,7 +84,6 @@ export class Building extends Phaser.GameObjects.Container {
this.selectionOutline = scene.add.graphics()
this.rallyLine = scene.add.graphics()
this.constructionOverlay = scene.add.graphics()
this.constructionMaskShape = scene.add.graphics().setAlpha(0)
this.bodyGraphic = scene.add.graphics()
this.healthBar = scene.add.graphics()
this.labelText = scene.add.text(0, 0, '', {
Expand All @@ -102,7 +99,6 @@ export class Building extends Phaser.GameObjects.Container {
this.selectionOutline,
this.rallyLine,
this.constructionOverlay,
this.constructionMaskShape,
this.bodyGraphic,
this.healthBar,
this.labelText,
Expand All @@ -112,8 +108,6 @@ export class Building extends Phaser.GameObjects.Container {
this.drawBody()
this.drawHealthBar()
this.drawSelectionOutline()
this.constructionMask = this.constructionMaskShape.createGeometryMask()
this.bodyGraphic.setMask(this.constructionMask)

scene.add.existing(this)
this.updateRenderTransform()
Expand Down Expand Up @@ -205,15 +199,12 @@ export class Building extends Phaser.GameObjects.Container {
}

// State was externally promoted to 'active' (e.g. GameScene sets building.state = 'active'
// right after creation). The construction mask was never cleared, so bodyGraphic is invisible.
// Finalize construction visuals now.
// right after creation). Finalize construction visuals now.
if (this.constructionProgress < 1) {
this.constructionProgress = 1
this.setAlpha(1)
this.visualRoot.y = 0
this.bodyGraphic.clearMask(false)
this.bodyGraphic.setAlpha(1)
this.constructionOverlay.clear()
this.constructionMaskShape.clear()
this.drawBody()
}

Expand Down Expand Up @@ -319,25 +310,25 @@ export class Building extends Phaser.GameObjects.Container {
private playConstructionAnimation(): void {
this.setAlpha(0.3)
this.constructionProgress = 0
this.visualRoot.y = 14
this.updateConstructionMask()
this.bodyGraphic.setAlpha(0)
this.drawConstructionOverlay()
}

private updateConstruction(delta: number): void {
const buildTime = this.def.stats.buildTime * 1000 || 100
this.constructionProgress = Math.min(1, this.constructionProgress + delta / buildTime)
this.setAlpha(0.3 + this.constructionProgress * 0.7)
this.visualRoot.y = (1 - this.constructionProgress) * 14
this.updateConstructionMask()
// Fade body in as construction progresses (alpha 0→1)
this.bodyGraphic.setAlpha(this.constructionProgress)
// Slide-in effect: ADD downward offset on top of the iso base position set by updateRenderTransform()
this.visualRoot.y += (1 - this.constructionProgress) * 14
this.drawConstructionOverlay()

if (this.constructionProgress >= 1) {
this.state = 'active'
this.visualRoot.y = 0
this.bodyGraphic.clearMask(false)
// updateRenderTransform() already set the correct base position; don't override y
this.bodyGraphic.setAlpha(1)
this.constructionOverlay.clear()
this.constructionMaskShape.clear()
this.drawBody()
this.emit('construction_complete', this)
}
Expand All @@ -357,17 +348,6 @@ export class Building extends Phaser.GameObjects.Container {
)
}

private updateConstructionMask(): void {
const dims = this.getBoxDims()
const totalH = dims.wallH + dims.halfH * 2 + 10
const totalW = dims.halfW * 2 + 10
const revealH = totalH * this.constructionProgress
const bottomY = dims.baseY + dims.halfH + 5
this.constructionMaskShape.clear()
this.constructionMaskShape.fillStyle(0xffffff, 1)
this.constructionMaskShape.fillRect(-totalW / 2, bottomY - revealH, totalW, revealH)
}

// ── Private: simple 3D box rendering ────────────────────────

/** Compute box dimensions from footprint size */
Expand Down