Skip to content

Commit 3a3f9c5

Browse files
committed
fix: code organizaion nitpicks
1 parent 92b130b commit 3a3f9c5

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/client/graphics/layers/NukeTrajectoryPreviewLayer.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class NukeTrajectoryPreviewLayer implements Layer {
1515
// Trajectory preview state
1616
private mousePos = { x: 0, y: 0 };
1717
private trajectoryPoints: TileRef[] = [];
18-
private targetableSwitchPointIndex: [number, number] = [-1, -1];
18+
private untargetableSegmentBounds: [number, number] = [-1, -1];
1919
private lastTrajectoryUpdate: number = 0;
2020
private lastTargetTile: TileRef | null = null;
2121
private currentGhostStructure: UnitType | null = null;
@@ -216,10 +216,13 @@ export class NukeTrajectoryPreviewLayer implements Layer {
216216
const targetRangeSquared =
217217
this.game.config().defaultNukeTargetableRange() ** 2;
218218

219-
this.targetableSwitchPointIndex = [-1, -1];
219+
this.untargetableSegmentBounds = [-1, -1];
220+
// Find two switch points where bomb transitions:
221+
// [0]: leaves spawn range, enters untargetable zone
222+
// [1]: enters target range, becomes targetable again
220223
for (let i = 0; i < this.trajectoryPoints.length; i++) {
221224
const tile = this.trajectoryPoints[i];
222-
if (this.targetableSwitchPointIndex[0] === -1) {
225+
if (this.untargetableSegmentBounds[0] === -1) {
223226
if (
224227
this.game.euclideanDistSquared(tile, this.cachedSpawnTile) >
225228
targetRangeSquared
@@ -228,15 +231,16 @@ export class NukeTrajectoryPreviewLayer implements Layer {
228231
this.game.euclideanDistSquared(tile, targetTile) <
229232
targetRangeSquared
230233
) {
234+
// overlapping spawn & target range
231235
break;
232236
} else {
233-
this.targetableSwitchPointIndex[0] = i;
237+
this.untargetableSegmentBounds[0] = i;
234238
}
235239
}
236240
} else if (
237241
this.game.euclideanDistSquared(tile, targetTile) < targetRangeSquared
238242
) {
239-
this.targetableSwitchPointIndex[1] = i;
243+
this.untargetableSegmentBounds[1] = i;
240244
break;
241245
}
242246
}
@@ -291,7 +295,7 @@ export class NukeTrajectoryPreviewLayer implements Layer {
291295
} else {
292296
context.lineTo(x, y);
293297
}
294-
if (i === this.targetableSwitchPointIndex[0]) {
298+
if (i === this.untargetableSegmentBounds[0]) {
295299
context.stroke();
296300

297301
context.beginPath();
@@ -302,7 +306,7 @@ export class NukeTrajectoryPreviewLayer implements Layer {
302306
context.beginPath();
303307
context.strokeStyle = untargetableLineColor;
304308
context.setLineDash([2, 6]);
305-
} else if (i === this.targetableSwitchPointIndex[1]) {
309+
} else if (i === this.untargetableSegmentBounds[1]) {
306310
context.stroke();
307311

308312
context.beginPath();

0 commit comments

Comments
 (0)