Skip to content

Commit 4a58316

Browse files
hyperpolymathclaude
andcommitted
refactor: migrate Js.Dict to Dict in remaining src/ dirs (14 files)
Replace deprecated Js.Dict in enemies/, screens/, multiplayer/, popups/, player/, proven/, ui/, and utils/. Part of #28. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 59fe755 commit 4a58316

File tree

14 files changed

+162
-162
lines changed

14 files changed

+162
-162
lines changed

src/app/enemies/Distraction.res

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ let makeActive = (~id: string, ~spec: distractionSpec): activeDistraction => {
165165

166166
type pbxState = {
167167
mutable hacked: bool, // Must hack the physical PBX first
168-
mutable usesRemaining: Js.Dict.t<int>,
168+
mutable usesRemaining: dict<int>,
169169
mutable cooldownSec: float, // Time until next call allowed
170170
mutable activeDistractions: array<activeDistraction>,
171171
mutable totalCalls: int,
@@ -181,12 +181,12 @@ type pbxState = {
181181
let cooldownBetweenCalls = 60.0 // Seconds between PBX calls
182182

183183
let make = (~ipAddress: string): pbxState => {
184-
let uses = Js.Dict.empty()
185-
Js.Dict.set(uses, "pizza", 2)
186-
Js.Dict.set(uses, "maintenance", 1)
187-
Js.Dict.set(uses, "fire", 1)
188-
Js.Dict.set(uses, "prank", 2)
189-
Js.Dict.set(uses, "police", 1)
184+
let uses = Dict.make()
185+
Dict.set(uses, "pizza", 2)
186+
Dict.set(uses, "maintenance", 1)
187+
Dict.set(uses, "fire", 1)
188+
Dict.set(uses, "prank", 2)
189+
Dict.set(uses, "police", 1)
190190

191191
{
192192
hacked: false,
@@ -220,7 +220,7 @@ let call = (pbx: pbxState, ~kind: distractionKind): callResult => {
220220
OnCooldown(pbx.cooldownSec)
221221
} else {
222222
let key = kindToString(kind)
223-
let remaining = Js.Dict.get(pbx.usesRemaining, key)->Belt.Option.getWithDefault(0)
223+
let remaining = Dict.get(pbx.usesRemaining, key)->Belt.Option.getWithDefault(0)
224224
if remaining <= 0 {
225225
NoUsesLeft
226226
} else {
@@ -236,7 +236,7 @@ let call = (pbx: pbxState, ~kind: distractionKind): callResult => {
236236
pbx.nextId = pbx.nextId + 1
237237
pbx.totalCalls = pbx.totalCalls + 1
238238
pbx.cooldownSec = cooldownBetweenCalls
239-
Js.Dict.set(pbx.usesRemaining, key, remaining - 1)
239+
Dict.set(pbx.usesRemaining, key, remaining - 1)
240240
let _ = Js.Array2.push(pbx.activeDistractions, distraction)
241241
Success(distraction)
242242
}
@@ -382,12 +382,12 @@ let applyDifficultyScaling = (pbx: pbxState, ~difficulty: int): unit => {
382382
// difficulty: 0=Tutorial, 1=Easy, 2=Normal, 3=Hard, 4=Expert
383383
// Reduce uses on harder difficulties
384384
if difficulty >= 3 {
385-
Js.Dict.set(pbx.usesRemaining, "pizza", 1)
386-
Js.Dict.set(pbx.usesRemaining, "prank", 1)
385+
Dict.set(pbx.usesRemaining, "pizza", 1)
386+
Dict.set(pbx.usesRemaining, "prank", 1)
387387
}
388388
if difficulty >= 4 {
389-
Js.Dict.set(pbx.usesRemaining, "maintenance", 0)
390-
Js.Dict.set(pbx.usesRemaining, "police", 0)
389+
Dict.set(pbx.usesRemaining, "maintenance", 0)
390+
Dict.set(pbx.usesRemaining, "police", 0)
391391
}
392392
}
393393

@@ -428,7 +428,7 @@ let formatStatus = (pbx: pbxState): string => {
428428
("police", "Fake Police"),
429429
]
430430
->Belt.Array.map(((key, label)) => {
431-
let remaining = Js.Dict.get(pbx.usesRemaining, key)->Belt.Option.getWithDefault(0)
431+
let remaining = Dict.get(pbx.usesRemaining, key)->Belt.Option.getWithDefault(0)
432432
` ${label}: ${Belt.Int.toString(remaining)} remaining`
433433
})
434434
->Array.join("\n")

src/app/multiplayer/MultiplayerClient.res

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type t = {
5959
mutable playerId: string,
6060
mutable role: playerRole,
6161
mutable sessionId: option<string>,
62-
coopPlayers: Js.Dict.t<coopPlayer>,
62+
coopPlayers: dict<coopPlayer>,
6363
chatHistory: array<chatMessage>,
6464
handlers: eventHandlers,
6565
serverUrl: string,
@@ -84,29 +84,29 @@ let roleFromString = (s: string): playerRole => {
8484
let jsonString = (s: string): JSON.t => JSON.Encode.string(s)
8585

8686
let makePayload = (pairs: array<(string, JSON.t)>): JSON.t => {
87-
let obj = Js.Dict.empty()
88-
Belt.Array.forEach(pairs, ((k, v)) => Js.Dict.set(obj, k, v))
87+
let obj = Dict.make()
88+
Belt.Array.forEach(pairs, ((k, v)) => Dict.set(obj, k, v))
8989
JSON.Encode.object(obj)
9090
}
9191

9292
let getJsonString = (json: JSON.t, key: string): string => {
9393
switch JSON.Decode.object(json) {
94-
| Some(obj) => Js.Dict.get(obj, key)->Option.flatMap(x => JSON.Decode.string(x))->Belt.Option.getWithDefault("")
94+
| Some(obj) => Dict.get(obj, key)->Option.flatMap(x => JSON.Decode.string(x))->Belt.Option.getWithDefault("")
9595
| None => ""
9696
}
9797
}
9898

9999
let getJsonFloat = (json: JSON.t, key: string): float => {
100100
switch JSON.Decode.object(json) {
101-
| Some(obj) => Js.Dict.get(obj, key)->Option.flatMap(x => JSON.Decode.float(x))->Belt.Option.getWithDefault(0.0)
101+
| Some(obj) => Dict.get(obj, key)->Option.flatMap(x => JSON.Decode.float(x))->Belt.Option.getWithDefault(0.0)
102102
| None => 0.0
103103
}
104104
}
105105

106106
let getJsonArray = (json: JSON.t, key: string): array<JSON.t> => {
107107
switch JSON.Decode.object(json) {
108108
| Some(obj) =>
109-
Js.Dict.get(obj, key)
109+
Dict.get(obj, key)
110110
->Option.flatMap(x =>
111111
switch JSON.Classify.classify(x) {
112112
| JSON.Classify.Array(arr) => Some(arr)
@@ -135,7 +135,7 @@ let make = (
135135
playerId,
136136
role,
137137
sessionId: None,
138-
coopPlayers: Js.Dict.empty(),
138+
coopPlayers: Dict.make(),
139139
chatHistory: [],
140140
handlers: {
141141
onPlayerJoined: None,
@@ -210,7 +210,7 @@ let setupChannelHandlers = (client: t, ch: PhoenixSocket.channel) => {
210210
y: 0.0,
211211
lastSeen: Date.now(),
212212
}
213-
Js.Dict.set(client.coopPlayers, pid, player)
213+
Dict.set(client.coopPlayers, pid, player)
214214
switch client.handlers.onPlayerJoined {
215215
| Some(cb) => cb(player)
216216
| None => ()
@@ -232,7 +232,7 @@ let setupChannelHandlers = (client: t, ch: PhoenixSocket.channel) => {
232232
let pid = getJsonString(payload, "player_id")
233233
let x = getJsonFloat(payload, "x")
234234
let y = getJsonFloat(payload, "y")
235-
switch Js.Dict.get(client.coopPlayers, pid) {
235+
switch Dict.get(client.coopPlayers, pid) {
236236
| Some(player) => {
237237
player.x = x
238238
player.y = y
@@ -274,7 +274,7 @@ let setupChannelHandlers = (client: t, ch: PhoenixSocket.channel) => {
274274
let pid = getJsonString(payload, "player_id")
275275
let deviceId = getJsonString(payload, "device_id")
276276
let state = switch JSON.Decode.object(payload) {
277-
| Some(obj) => Js.Dict.get(obj, "state")->Belt.Option.getWithDefault(JSON.Encode.null)
277+
| Some(obj) => Dict.get(obj, "state")->Belt.Option.getWithDefault(JSON.Encode.null)
278278
| None => JSON.Encode.null
279279
}
280280
switch client.handlers.onVMState {
@@ -369,7 +369,7 @@ let joinSession = (client: t, ~sessionId: string) => {
369369
if status == "ok" {
370370
switch JSON.Decode.object(payload) {
371371
| Some(obj) =>
372-
switch Js.Dict.get(obj, "response") {
372+
switch Dict.get(obj, "response") {
373373
| Some(resp) =>
374374
switch JSON.Decode.object(resp) {
375375
| Some(session) => {
@@ -408,7 +408,7 @@ let leaveSession = (client: t) => {
408408
client.sessionId = None
409409
client.state = InLobby
410410
// Clear co-op state
411-
let keys = Js.Dict.keys(client.coopPlayers)
411+
let keys = Dict.keysToArray(client.coopPlayers)
412412
Belt.Array.forEach(keys, k => Dict.delete(client.coopPlayers, k))
413413
notifyState(client)
414414
}
@@ -586,11 +586,11 @@ let sendAlertChanged = (client: t, ~level: string) => {
586586
// --- Query state ---
587587

588588
let getCoopPlayers = (client: t): array<coopPlayer> => {
589-
Js.Dict.values(client.coopPlayers)
589+
Dict.valuesToArray(client.coopPlayers)
590590
}
591591

592592
let getCoopPartner = (client: t): option<coopPlayer> => {
593-
Js.Dict.values(client.coopPlayers)-> Belt.Array.getBy(p => p.id != client.playerId)
593+
Dict.valuesToArray(client.coopPlayers)-> Belt.Array.getBy(p => p.id != client.playerId)
594594
}
595595

596596
let stateToString = (state: multiplayerState): string => {

src/app/multiplayer/PhoenixSocket.res

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type messageHandler = JSON.t => unit
5656
type channel = {
5757
topic: string,
5858
mutable state: channelState,
59-
handlers: Js.Dict.t<array<messageHandler>>,
59+
handlers: dict<array<messageHandler>>,
6060
mutable joinRef: option<string>,
6161
}
6262

@@ -70,7 +70,7 @@ type t = {
7070
mutable socket: option<webSocket>,
7171
mutable state: connectionState,
7272
mutable refCounter: int,
73-
channels: Js.Dict.t<channel>,
73+
channels: dict<channel>,
7474
mutable heartbeatTimer: option<int>,
7575
mutable reconnectAttempts: int,
7676
mutable onStateChange: option<connectionState => unit>,
@@ -132,7 +132,7 @@ let make = (~url: string, ~onStateChange: option<connectionState => unit>=?): t
132132
socket: None,
133133
state: Disconnected,
134134
refCounter: 0,
135-
channels: Js.Dict.empty(),
135+
channels: Dict.make(),
136136
heartbeatTimer: None,
137137
reconnectAttempts: 0,
138138
onStateChange,
@@ -165,7 +165,7 @@ let startHeartbeat = (socket: t) => {
165165
{
166166
topic: "phoenix",
167167
event: "heartbeat",
168-
payload: JSON.Encode.object(Js.Dict.empty()),
168+
payload: JSON.Encode.object(Dict.make()),
169169
ref: Some(nextRef(socket)),
170170
joinRef: None,
171171
},
@@ -186,13 +186,13 @@ let stopHeartbeat = (socket: t) => {
186186

187187
// Dispatch an incoming V2 message to the appropriate channel handler.
188188
let dispatchMessage = (socket: t, msg: phoenixMessage) => {
189-
switch Js.Dict.get(socket.channels, msg.topic) {
189+
switch Dict.get(socket.channels, msg.topic) {
190190
| Some(channel) => {
191191
// Handle join reply — update channel state on successful join ack
192192
if msg.event == "phx_reply" && channel.state == Joining {
193193
let statusOk = switch JSON.Decode.object(msg.payload) {
194194
| Some(obj) =>
195-
switch Js.Dict.get(obj, "status") {
195+
switch Dict.get(obj, "status") {
196196
| Some(s) => JSON.Decode.string(s) == Some("ok")
197197
| None => false
198198
}
@@ -209,7 +209,7 @@ let dispatchMessage = (socket: t, msg: phoenixMessage) => {
209209
}
210210

211211
// Dispatch to all registered handlers for this event
212-
switch Js.Dict.get(channel.handlers, msg.event) {
212+
switch Dict.get(channel.handlers, msg.event) {
213213
| Some(handlers) => Belt.Array.forEach(handlers, h => h(msg.payload))
214214
| None => ()
215215
}
@@ -233,7 +233,7 @@ let rec connect = (socket: t) => {
233233

234234
// Rejoin all channels that were previously joined after reconnect.
235235
// join_ref == message_ref for join messages (Phoenix convention).
236-
Js.Dict.entries(socket.channels)->Belt.Array.forEach(((_topic, channel)) => {
236+
Dict.toArray(socket.channels)->Belt.Array.forEach(((_topic, channel)) => {
237237
if channel.state == Joined || channel.state == Joining {
238238
channel.state = Joining
239239
let ref = nextRef(socket)
@@ -243,7 +243,7 @@ let rec connect = (socket: t) => {
243243
{
244244
topic: channel.topic,
245245
event: "phx_join",
246-
payload: JSON.Encode.object(Js.Dict.empty()),
246+
payload: JSON.Encode.object(Dict.make()),
247247
ref: Some(ref),
248248
joinRef: Some(ref),
249249
},
@@ -300,15 +300,15 @@ let channel = (socket: t, ~topic: string): channel => {
300300
let ch: channel = {
301301
topic,
302302
state: Closed,
303-
handlers: Js.Dict.empty(),
303+
handlers: Dict.make(),
304304
joinRef: None,
305305
}
306-
Js.Dict.set(socket.channels, topic, ch)
306+
Dict.set(socket.channels, topic, ch)
307307
ch
308308
}
309309

310310
// Join a channel. For join messages, join_ref == message_ref (Phoenix V2 spec).
311-
let joinChannel = (socket: t, ch: channel, ~payload: JSON.t=JSON.Encode.object(Js.Dict.empty())) => {
311+
let joinChannel = (socket: t, ch: channel, ~payload: JSON.t=JSON.Encode.object(Dict.make())) => {
312312
ch.state = Joining
313313
let ref = nextRef(socket)
314314
ch.joinRef = Some(ref)
@@ -331,7 +331,7 @@ let leaveChannel = (socket: t, ch: channel) => {
331331
{
332332
topic: ch.topic,
333333
event: "phx_leave",
334-
payload: JSON.Encode.object(Js.Dict.empty()),
334+
payload: JSON.Encode.object(Dict.make()),
335335
ref: Some(nextRef(socket)),
336336
joinRef: ch.joinRef,
337337
},
@@ -341,8 +341,8 @@ let leaveChannel = (socket: t, ch: channel) => {
341341
}
342342

343343
let on = (ch: channel, ~event: string, ~handler: messageHandler) => {
344-
let existing = Js.Dict.get(ch.handlers, event)->Belt.Option.getWithDefault([])
345-
Js.Dict.set(ch.handlers, event, Belt.Array.concat(existing, [handler]))
344+
let existing = Dict.get(ch.handlers, event)->Belt.Option.getWithDefault([])
345+
Dict.set(ch.handlers, event, Belt.Array.concat(existing, [handler]))
346346
}
347347

348348
// Push an event to the server. join_ref carries the channel's original join ref

src/app/multiplayer/VMMessageBus.res

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ type portMessage = {
5050

5151
// Module-level singleton port output buffer.
5252
// Keyed by port name (e.g. "console", "coop:sync", "covert:conn-1").
53-
let portOutputBuffer: dict<array<int>> = Js.Dict.empty()
53+
let portOutputBuffer: dict<array<int>> = Dict.make()
5454

5555
// Append values to a port's output buffer.
5656
// Called by game code (terminal handlers, network events, covert-link
5757
// activation) when it wants the message bus to route data on the next
5858
// call to readPortOutput / flushPortMessages.
5959
let writePortOutput = (port: string, values: array<int>): unit => {
60-
let existing = Js.Dict.get(portOutputBuffer, port)->Belt.Option.getWithDefault([])
61-
Js.Dict.set(portOutputBuffer, port, Belt.Array.concat(existing, values))
60+
let existing = Dict.get(portOutputBuffer, port)->Belt.Option.getWithDefault([])
61+
Dict.set(portOutputBuffer, port, Belt.Array.concat(existing, values))
6262
}
6363

6464
// Read and drain all pending output from the named port.
@@ -71,12 +71,12 @@ let writePortOutput = (port: string, values: array<int>): unit => {
7171
// to [] so each value is delivered exactly once.
7272
let readPortOutput = (vmState: VMBridge.vmState, port: string): array<int> => {
7373
let _ = vmState // Reserved for Tier 4 SEND/RECV integration
74-
switch Js.Dict.get(portOutputBuffer, port) {
74+
switch Dict.get(portOutputBuffer, port) {
7575
| None => []
7676
| Some(values) =>
7777
// Drain: replace the port's slice with an empty array before returning
7878
// so concurrent callers (if any) get distinct snapshots.
79-
Js.Dict.set(portOutputBuffer, port, [])
79+
Dict.set(portOutputBuffer, port, [])
8080
values
8181
}
8282
}
@@ -141,8 +141,8 @@ let flushCoopOutbox = (): unit => {
141141
MultiplayerClient.sendVMExecute(client, ~instruction, ~deviceId, ~args)
142142
| VMUndone({deviceId}) => MultiplayerClient.sendVMUndo(client, ~deviceId)
143143
| StateSync({deviceId, registers}) => {
144-
let obj = Js.Dict.empty()
145-
Belt.Array.forEach(registers, ((k, v)) => Js.Dict.set(obj, k, JSON.Encode.float(Int.toFloat(v))))
144+
let obj = Dict.make()
145+
Belt.Array.forEach(registers, ((k, v)) => Dict.set(obj, k, JSON.Encode.float(Int.toFloat(v))))
146146
MultiplayerClient.sendVMState(client, ~deviceId, ~state=JSON.Encode.object(obj))
147147
}
148148
| PortData(_) => () // Port data goes through VM state sync

0 commit comments

Comments
 (0)