Skip to content

Commit e86733b

Browse files
hyperpolymathclaude
andcommitted
refactor: migrate Js.Math to Math across src/ (33 files, 118 occurrences)
Replace deprecated Js.Math API with modern Math equivalents: - Js.Math.floor_float -> Math.floor - Js.Math.sqrt/sin/cos/atan2 -> Math.* - Js.Math.max_float/min_float -> Math.max/min - Js.Math._PI -> Math.Constants.pi - Js.Math.random -> Math.random - Js.Math.abs_float -> Math.abs Part of #28. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4a58316 commit e86733b

33 files changed

+118
-118
lines changed

src/app/GameLoop.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ let update = (
677677
// Countdown the startup grace period
678678
let inGracePeriod = state.gracePeriodSec > 0.0
679679
if inGracePeriod {
680-
state.gracePeriodSec = Js.Math.max_float(0.0, state.gracePeriodSec -. dt)
680+
state.gracePeriodSec = Math.max(0.0, state.gracePeriodSec -. dt)
681681
}
682682

683683
let alertLevel = DetectionSystem.getAlertInt(state.detection)
@@ -786,7 +786,7 @@ let update = (
786786
)
787787

788788
// DistractionExpired has weight 0 apply the per-type suspicion directly
789-
state.detection.alertScore = Js.Math.min_float(
789+
state.detection.alertScore = Math.min(
790790
120.0,
791791
state.detection.alertScore +. d.spec.suspicionOnExpiry,
792792
)

src/app/combat/PlayerHP.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let isAlive = (hp: t): bool => hp.current > 0.0
4949
// Take damage from a source position. No-op if invincible.
5050
let takeDamage = (hp: t, ~amount: float, ~fromX: float, ~playerX: float): unit => {
5151
if !isInvincible(hp) {
52-
hp.current = Js.Math.max_float(0.0, hp.current -. amount)
52+
hp.current = Math.max(0.0, hp.current -. amount)
5353
hp.invincibleTimer = Knockback.iFrames
5454

5555
// Knockback direction: push player away from source
@@ -69,12 +69,12 @@ let takeDamage = (hp: t, ~amount: float, ~fromX: float, ~playerX: float): unit =
6969
let update = (hp: t, ~dt: float): (float, float) => {
7070
// Decay invincibility
7171
if hp.invincibleTimer > 0.0 {
72-
hp.invincibleTimer = Js.Math.max_float(0.0, hp.invincibleTimer -. dt)
72+
hp.invincibleTimer = Math.max(0.0, hp.invincibleTimer -. dt)
7373
}
7474

7575
// Decay knockback
7676
if hp.knockbackTimer > 0.0 {
77-
hp.knockbackTimer = Js.Math.max_float(0.0, hp.knockbackTimer -. dt)
77+
hp.knockbackTimer = Math.max(0.0, hp.knockbackTimer -. dt)
7878
let vel = (hp.knockbackVelX, hp.knockbackVelY)
7979
if hp.knockbackTimer <= 0.0 {
8080
hp.knockbackVelX = 0.0

src/app/companions/Moletaire.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ let update = (mole: t, ~dt: float): option<moleEvent> => {
758758

759759
// Hunger increases over time
760760
if mole.alive {
761-
mole.hunger = Js.Math.min_float(1.0, mole.hunger +. Tuning.hungerRate *. dt)
761+
mole.hunger = Math.min(1.0, mole.hunger +. Tuning.hungerRate *. dt)
762762

763763
// When hungry, periodically resist player control
764764
if mole.hunger > Tuning.hungerThreshold {

src/app/devices/NetworkTransfer.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ let updateTransfers = (deltaSeconds: float): unit => {
8989
switch t.status {
9090
| Active => {
9191
let bytesThisFrame = t.bandwidthMBps *. 1_000_000.0 *. deltaSeconds
92-
t.transferredBytes = Js.Math.min_float(t.transferredBytes +. bytesThisFrame, t.totalBytes)
92+
t.transferredBytes = Math.min(t.transferredBytes +. bytesThisFrame, t.totalBytes)
9393

9494
// Accumulate router traffic (source = upload, dest = download)
9595
let currentUp = Dict.get(routerUpload, t.sourceIp)->Belt.Option.getWithDefault(0.0)

src/app/enemies/DetectionSystem.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ let reportDetection = (system: t, ~source: detectionSource, ~gameTime: float): u
134134
sourceWeight(source)
135135
}
136136

137-
system.alertScore = Js.Math.min_float(120.0, system.alertScore +. weight)
137+
system.alertScore = Math.min(120.0, system.alertScore +. weight)
138138
system.totalDetections = system.totalDetections + 1
139139

140140
let event = {source, timestamp: gameTime, weight}
@@ -153,7 +153,7 @@ let update = (system: t, ~dt: float): unit => {
153153
// Natural decay security relaxes over time if nothing happens
154154
if system.alertScore > 0.0 {
155155
let decay = system.decayRate *. dt
156-
system.alertScore = Js.Math.max_float(0.0, system.alertScore -. decay)
156+
system.alertScore = Math.max(0.0, system.alertScore -. decay)
157157
}
158158
}
159159

src/app/enemies/Distraction.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ type distractionEvent =
257257
let update = (pbx: pbxState, ~dt: float): array<distractionEvent> => {
258258
// Tick cooldown
259259
if pbx.cooldownSec > 0.0 {
260-
pbx.cooldownSec = Js.Math.max_float(0.0, pbx.cooldownSec -. dt)
260+
pbx.cooldownSec = Math.max(0.0, pbx.cooldownSec -. dt)
261261
}
262262

263263
// Tick active distractions, collect events

src/app/enemies/Drone.res

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ let detectPlayer = (
175175
let dx = playerX -. drone.x
176176
// Y difference between drone altitude and player on ground
177177
let dy = playerY -. drone.groundY
178-
let groundDist = Js.Math.sqrt(dx *. dx +. dy *. dy)
178+
let groundDist = Math.sqrt(dx *. dx +. dy *. dy)
179179

180180
let effectiveRadius = if playerCrouching {
181181
drone.detectionRadius *. 0.6 // Harder to spot crouching from above
@@ -247,7 +247,7 @@ let updateState = (
247247
} else if (
248248
drone.state != Charging &&
249249
drone.state != Disabled && {
250-
drone.battery = Js.Math.max_float(0.0, drone.battery -. drone.batteryDrainRate *. dt)
250+
drone.battery = Math.max(0.0, drone.battery -. drone.batteryDrainRate *. dt)
251251
drone.battery <= 0.0
252252
}
253253
) {
@@ -300,7 +300,7 @@ let updateState = (
300300
drone.hoverTimer = 0.0
301301
}
302302
}
303-
| _ => drone.suspicion = Js.Math.max_float(0.0, drone.suspicion -. dt *. 0.1)
303+
| _ => drone.suspicion = Math.max(0.0, drone.suspicion -. dt *. 0.1)
304304
}
305305
Some(detection)
306306
}
@@ -312,7 +312,7 @@ let updateState = (
312312
switch detection {
313313
| InDetectionZone(proximity) if proximity > 0.3 => {
314314
drone.lastKnownPlayerX = Some(playerX)
315-
drone.suspicion = Js.Math.min_float(1.0, drone.suspicion +. dt *. 0.3)
315+
drone.suspicion = Math.min(1.0, drone.suspicion +. dt *. 0.3)
316316
if drone.suspicion > 0.7 {
317317
drone.state = Tracking
318318
}
@@ -342,7 +342,7 @@ let updateState = (
342342
// Pursuit drones activate spotlight
343343
if drone.variant == Pursuit && alertLevel >= 2 {
344344
drone.spotlightActive = true
345-
drone.spotlightIntensity = Js.Math.min_float(1.0, drone.spotlightIntensity +. dt *. 0.5)
345+
drone.spotlightIntensity = Math.min(1.0, drone.spotlightIntensity +. dt *. 0.5)
346346
drone.state = Spotlighting
347347
}
348348

@@ -386,7 +386,7 @@ let updateState = (
386386
drone.spotlightIntensity = 1.0
387387
}
388388
| NotDetected => {
389-
drone.spotlightIntensity = Js.Math.max_float(0.0, drone.spotlightIntensity -. dt *. 0.3)
389+
drone.spotlightIntensity = Math.max(0.0, drone.spotlightIntensity -. dt *. 0.3)
390390
if drone.spotlightIntensity <= 0.0 {
391391
drone.spotlightActive = false
392392
drone.state = Tracking
@@ -429,7 +429,7 @@ let updateState = (
429429
}
430430

431431
| Charging => {
432-
drone.battery = Js.Math.min_float(1.0, drone.battery +. drone.chargeRate *. dt)
432+
drone.battery = Math.min(1.0, drone.battery +. drone.chargeRate *. dt)
433433
if drone.battery >= 0.95 {
434434
drone.state = Patrolling
435435
}

src/app/enemies/GuardNPC.res

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ let make = (
447447
let isInVisionCone = (guard: t, ~targetX: float, ~targetY: float): bool => {
448448
let dx = targetX -. guard.x
449449
let dy = targetY -. guard.y
450-
let distance = Js.Math.sqrt(dx *. dx +. dy *. dy)
450+
let distance = Math.sqrt(dx *. dx +. dy *. dy)
451451

452452
let facingRight = guard.facing == Right
453453
let isBehind = (facingRight && dx < 0.0) || (!facingRight && dx > 0.0)
@@ -459,15 +459,15 @@ let isInVisionCone = (guard: t, ~targetX: float, ~targetY: float): bool => {
459459
let guardAngle = if facingRight {
460460
0.0
461461
} else {
462-
Js.Math._PI
462+
Math.Constants.pi
463463
}
464464
// SafeAngle.fromAtan2 guards against non-finite dy/dx inputs
465465
// (NaN/Infinity from degenerate positions would poison the entire
466466
// vision cone calculation and cause guards to never/always detect).
467467
let targetAngle = SafeAngle.fromAtan2(~y=dy, ~x=dx)
468468
let angleDiff = absFloat(targetAngle -. guardAngle)
469-
let normalised = if angleDiff > Js.Math._PI {
470-
2.0 *. Js.Math._PI -. angleDiff
469+
let normalised = if angleDiff > Math.Constants.pi {
470+
2.0 *. Math.Constants.pi -. angleDiff
471471
} else {
472472
angleDiff
473473
}
@@ -491,7 +491,7 @@ let detectPlayer = (
491491
} else {
492492
let dx = playerX -. guard.x
493493
let dy = playerY -. guard.y
494-
let distance = Js.Math.sqrt(dx *. dx +. dy *. dy)
494+
let distance = Math.sqrt(dx *. dx +. dy *. dy)
495495

496496
let effectiveRange = if playerCrouching {
497497
guard.vision.range *. 0.6
@@ -700,9 +700,9 @@ let updateAntiHacker = (guard: t, ~dt: float, ~playerX: float, ~alertLevel: int)
700700
} else {
701701
0.0
702702
}
703-
psych.courage = Js.Math.max_float(
703+
psych.courage = Math.max(
704704
0.0,
705-
Js.Math.min_float(1.0, baseCourage +. backupBonus +. alertPenalty +. proximityPenalty),
705+
Math.min(1.0, baseCourage +. backupBonus +. alertPenalty +. proximityPenalty),
706706
)
707707

708708
switch guard.state {
@@ -899,9 +899,9 @@ let updateRival = (guard: t, ~dt: float, ~playerX: float): unit => {
899899
// Track player awareness
900900
let playerDist = distanceTo(guard, ~x=playerX)
901901
if playerDist < 200.0 {
902-
rival.awareness = Js.Math.min_float(1.0, rival.awareness +. dt *. 0.3)
902+
rival.awareness = Math.min(1.0, rival.awareness +. dt *. 0.3)
903903
} else {
904-
rival.awareness = Js.Math.max_float(0.0, rival.awareness -. dt *. 0.1)
904+
rival.awareness = Math.max(0.0, rival.awareness -. dt *. 0.1)
905905
}
906906

907907
switch guard.state {
@@ -1089,7 +1089,7 @@ let updateAssassin = (guard: t, ~dt: float, ~playerX: float): unit => {
10891089
}
10901090
| None => {
10911091
// No waypoints just fade and reposition randomly
1092-
ai.visibility = Js.Math.max_float(0.0, ai.visibility -. dt *. 0.3)
1092+
ai.visibility = Math.max(0.0, ai.visibility -. dt *. 0.3)
10931093
if ai.visibility <= 0.05 {
10941094
guard.state = Hiding
10951095
}
@@ -1330,7 +1330,7 @@ let renderGuard = (guard: t): unit => {
13301330
let baseAngle = if guard.facing == Right {
13311331
0.0
13321332
} else {
1333-
Js.Math._PI
1333+
Math.Constants.pi
13341334
}
13351335
let startAngle = baseAngle -. guard.vision.halfAngle
13361336
let endAngle = baseAngle +. guard.vision.halfAngle
@@ -1339,12 +1339,12 @@ let renderGuard = (guard: t): unit => {
13391339
guard.coneGraphic
13401340
->Graphics.moveTo(0.0, -.h /. 2.0 -. 14.0)
13411341
->Graphics.lineTo(
1342-
Js.Math.cos(startAngle) *. guard.vision.range,
1343-
-.h /. 2.0 -. 14.0 +. Js.Math.sin(startAngle) *. guard.vision.range,
1342+
Math.cos(startAngle) *. guard.vision.range,
1343+
-.h /. 2.0 -. 14.0 +. Math.sin(startAngle) *. guard.vision.range,
13441344
)
13451345
->Graphics.lineTo(
1346-
Js.Math.cos(endAngle) *. guard.vision.range,
1347-
-.h /. 2.0 -. 14.0 +. Js.Math.sin(endAngle) *. guard.vision.range,
1346+
Math.cos(endAngle) *. guard.vision.range,
1347+
-.h /. 2.0 -. 14.0 +. Math.sin(endAngle) *. guard.vision.range,
13481348
)
13491349
->Graphics.lineTo(0.0, -.h /. 2.0 -. 14.0)
13501350
->Graphics.fill({"color": coneColor, "alpha": coneAlpha})
@@ -1520,7 +1520,7 @@ let update = (
15201520
}
15211521
}
15221522
| Peripheral(amount) => {
1523-
guard.suspicion = Js.Math.min_float(1.0, guard.suspicion +. amount *. dt *. 0.5)
1523+
guard.suspicion = Math.min(1.0, guard.suspicion +. amount *. dt *. 0.5)
15241524
let threshold = switch guard.rank {
15251525
| BasicGuard => 0.85 // Very slow to notice
15261526
| SecurityGuard => 0.65
@@ -1540,7 +1540,7 @@ let update = (
15401540
| EliteGuard => 0.1 // Slow to forget
15411541
| _ => 0.2
15421542
}
1543-
guard.suspicion = Js.Math.max_float(0.0, guard.suspicion -. dt *. decayRate)
1543+
guard.suspicion = Math.max(0.0, guard.suspicion -. dt *. decayRate)
15441544
}
15451545
}
15461546

src/app/enemies/SecurityDog.res

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ let detectPlayer = (
189189
} else {
190190
let dx = playerX -. dog.x
191191
let dy = playerY -. dog.y
192-
let distance = Js.Math.sqrt(dx *. dx +. dy *. dy)
192+
let distance = Math.sqrt(dx *. dx +. dy *. dy)
193193

194194
switch dog.variant {
195195
| GuardDog => // Scent detection omnidirectional, ignores crouching/walls
@@ -207,15 +207,15 @@ let detectPlayer = (
207207
let baseAngle = if facingRight {
208208
0.0
209209
} else {
210-
Js.Math._PI
210+
Math.Constants.pi
211211
}
212212
// SafeAngle.fromAtan2 guards against non-finite dy/dx inputs
213213
// (NaN/Infinity from degenerate positions would poison the entire
214214
// detection cone calculation).
215215
let targetAngle = SafeAngle.fromAtan2(~y=dy, ~x=dx)
216216
let angleDiff = absFloat(targetAngle -. baseAngle)
217-
let normalised = if angleDiff > Js.Math._PI {
218-
2.0 *. Js.Math._PI -. angleDiff
217+
let normalised = if angleDiff > Math.Constants.pi {
218+
2.0 *. Math.Constants.pi -. angleDiff
219219
} else {
220220
angleDiff
221221
}
@@ -320,7 +320,7 @@ let updateState = (
320320
None
321321
} else if (
322322
dog.variant == RoboDog && {
323-
dog.batteryLevel = Js.Math.max_float(0.0, dog.batteryLevel -. dt *. 0.002)
323+
dog.batteryLevel = Math.max(0.0, dog.batteryLevel -. dt *. 0.002)
324324
dog.batteryLevel <= 0.0
325325
}
326326
) {
@@ -352,7 +352,7 @@ let updateState = (
352352
Some(detection)
353353
}
354354
| _ => {
355-
dog.suspicion = Js.Math.max_float(0.0, dog.suspicion -. dt *. 0.15)
355+
dog.suspicion = Math.max(0.0, dog.suspicion -. dt *. 0.15)
356356
Some(NotDetected)
357357
}
358358
}
@@ -742,7 +742,7 @@ let renderDog = (dog: t): unit => {
742742
let baseAngle = if dog.facing == Right {
743743
0.0
744744
} else {
745-
Js.Math._PI
745+
Math.Constants.pi
746746
}
747747
let startAngle = baseAngle -. dog.detection.cameraHalfAngle
748748
let endAngle = baseAngle +. dog.detection.cameraHalfAngle
@@ -754,12 +754,12 @@ let renderDog = (dog: t): unit => {
754754
dog.detectionGraphic
755755
->Graphics.moveTo(0.0, -.bodyH /. 2.0)
756756
->Graphics.lineTo(
757-
Js.Math.cos(startAngle) *. dog.detection.cameraRange,
758-
-.bodyH /. 2.0 +. Js.Math.sin(startAngle) *. dog.detection.cameraRange,
757+
Math.cos(startAngle) *. dog.detection.cameraRange,
758+
-.bodyH /. 2.0 +. Math.sin(startAngle) *. dog.detection.cameraRange,
759759
)
760760
->Graphics.lineTo(
761-
Js.Math.cos(endAngle) *. dog.detection.cameraRange,
762-
-.bodyH /. 2.0 +. Js.Math.sin(endAngle) *. dog.detection.cameraRange,
761+
Math.cos(endAngle) *. dog.detection.cameraRange,
762+
-.bodyH /. 2.0 +. Math.sin(endAngle) *. dog.detection.cameraRange,
763763
)
764764
->Graphics.lineTo(0.0, -.bodyH /. 2.0)
765765
->Graphics.fill({"color": coneColor, "alpha": 0.08})

src/app/pickups/WorldPickup.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ let makeCollectible = (~item: Inventory.item, ~x: float, ~groundY: float): t =>
281281
// Pulse alpha 0.61.0 based on game time
282282
let updateAnimation = (pickup: t, ~gameTime: float): unit => {
283283
if !pickup.collected {
284-
let pulse = 0.8 +. 0.2 *. Js.Math.sin(gameTime *. 2.0 +. pickup.glowPhase)
284+
let pulse = 0.8 +. 0.2 *. Math.sin(gameTime *. 2.0 +. pickup.glowPhase)
285285
Container.setAlpha(pickup.container, pulse)
286286
}
287287
}
@@ -295,7 +295,7 @@ let isInRange = (pickup: t, ~playerX: float, ~playerY: float): bool => {
295295
} else {
296296
let dx = playerX -. pickup.x
297297
let dy = playerY -. pickup.y
298-
let dist = Js.Math.sqrt(dx *. dx +. dy *. dy)
298+
let dist = Math.sqrt(dx *. dx +. dy *. dy)
299299
dist <= pickup.pickupRadius
300300
}
301301
}

0 commit comments

Comments
 (0)