fix(render): turn nuke range circle red when launch would break alliance

Wire targetingAlly through GhostPreviewData.rangeWarning so RangeCirclePass
can color the blast-radius circle red instead of white when the ghosted nuke
would trigger a traitor penalty. Restores behavior lost in the canvas→WebGL
migration.
This commit is contained in:
evanpelle
2026-05-27 16:25:34 -07:00
parent 21e42ce461
commit a5e28d81d2
4 changed files with 27 additions and 13 deletions
+13 -2
View File
@@ -1,6 +1,7 @@
/**
* RangeCirclePass — draws a translucent white circle showing the effective
* range of a structure during build-mode ghost preview.
* RangeCirclePass — draws a translucent circle showing the effective
* range of a structure during build-mode ghost preview. White by default,
* red when the ghost flags a warning (e.g. nuking would break an alliance).
*
* Single quad with circle SDF in the fragment shader.
* Active only when a ghost preview with rangeRadius > 0 is set.
@@ -20,10 +21,12 @@ export class RangeCirclePass {
private uCamera: WebGLUniformLocation;
private uCenter: WebGLUniformLocation;
private uRadius: WebGLUniformLocation;
private uColor: WebGLUniformLocation;
private centerX = 0;
private centerY = 0;
private radius = 0;
private warning = false;
constructor(gl: WebGL2RenderingContext) {
this.gl = gl;
@@ -32,6 +35,7 @@ export class RangeCirclePass {
this.uCamera = gl.getUniformLocation(this.program, "uCamera")!;
this.uCenter = gl.getUniformLocation(this.program, "uCenter")!;
this.uRadius = gl.getUniformLocation(this.program, "uRadius")!;
this.uColor = gl.getUniformLocation(this.program, "uColor")!;
// Unit quad [0,1]
this.vao = gl.createVertexArray()!;
@@ -53,8 +57,10 @@ export class RangeCirclePass {
this.centerX = data.tileX;
this.centerY = data.tileY;
this.radius = data.rangeRadius;
this.warning = data.rangeWarning;
} else {
this.radius = 0;
this.warning = false;
}
}
@@ -66,6 +72,11 @@ export class RangeCirclePass {
gl.uniformMatrix3fv(this.uCamera, false, cameraMatrix);
gl.uniform2f(this.uCenter, this.centerX, this.centerY);
gl.uniform1f(this.uRadius, this.radius);
if (this.warning) {
gl.uniform3f(this.uColor, 1.0, 0.2, 0.2);
} else {
gl.uniform3f(this.uColor, 1.0, 1.0, 1.0);
}
gl.bindVertexArray(this.vao);
gl.drawArrays(gl.TRIANGLES, 0, 6);
@@ -4,6 +4,7 @@ precision highp float;
in vec2 vLocal; // [-1, +1]
uniform float uRadius;
uniform vec3 uColor;
out vec4 fragColor;
@@ -23,5 +24,5 @@ void main() {
float alpha = fill * 0.2 + stroke * 0.5;
if (alpha < 0.001) discard;
fragColor = vec4(1.0, 1.0, 1.0, alpha);
fragColor = vec4(uColor, alpha);
}
+2
View File
@@ -166,6 +166,8 @@ export interface GhostPreviewData {
upgradeTargetTile: number | null;
/** Range radius in tiles for the placement circle (0 = no circle). */
rangeRadius: number;
/** True if placing here would carry a penalty (e.g. nuking an ally → traitor). */
rangeWarning: boolean;
}
/** Nuke trajectory preview data — Bezier control points + color thresholds. */