Skip to content

Commit 3cdf18d

Browse files
committed
feat: use lowercase singular names for everything
1 parent bba96f1 commit 3cdf18d

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

fission/src/mirabuf/MirabufLoader.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Pako from "pako"
2-
import { clean } from "@/util/Utility"
32
import { Data, downloadData } from "@/aps/APSDataManagement"
43
import { globalAddToast } from "@/components/GlobalUIControls"
54
import { mirabuf } from "@/proto/mirabuf"
@@ -32,9 +31,9 @@ export interface MirabufRemoteInfo {
3231

3332
type MapCache = { [id: MirabufCacheID]: MirabufCacheInfo }
3433

35-
const robotsDirName = "Robots"
36-
const fieldsDirName = "Fields"
37-
const piecesDirName = "Pieces"
34+
const robotsDirName = "robot"
35+
const fieldsDirName = "field"
36+
const piecesDirName = "piece"
3837
const root = await navigator.storage.getDirectory()
3938
const getDirectoryHandle = (dirName: string) => root.getDirectoryHandle(dirName, { create: true })
4039

@@ -90,11 +89,18 @@ export const canOPFS = await (async () => {
9089
fieldFolderHandle.removeEntry(key)
9190
}
9291

92+
const pieceFolderHandle = dirHandleMap[MiraType.PIECE]
93+
for await (const key of pieceFolderHandle.keys()) {
94+
pieceFolderHandle.removeEntry(key)
95+
}
96+
9397
window.localStorage.setItem(robotsDirName, "{}")
9498
window.localStorage.setItem(fieldsDirName, "{}")
9599
window.localStorage.setItem(piecesDirName, "{}")
96100

97-
;[...Object.values(backUpMap)].forEach(clean)
101+
backUpMap[MiraType.FIELD] = {}
102+
backUpMap[MiraType.PIECE] = {}
103+
backUpMap[MiraType.ROBOT] = {}
98104

99105
return false
100106
}
@@ -162,9 +168,10 @@ class MirabufCachingService {
162168
if (!resp.ok) throw new Error(`${resp.status} ${resp.statusText}`)
163169

164170
const miraBuff = await resp.arrayBuffer()
171+
miraType ??= this.assemblyFromBuffer(miraBuff).dynamic ? MiraType.ROBOT : MiraType.FIELD
165172

166173
World.analyticsSystem?.event("Remote Download", {
167-
type: miraType === MiraType.ROBOT ? "robot" : miraType === MiraType.FIELD ? "field" : "piece",
174+
type: dirNameMap[miraType],
168175
fileSize: miraBuff.byteLength,
169176
})
170177

@@ -180,7 +187,7 @@ class MirabufCachingService {
180187
return {
181188
id: Date.now().toString(),
182189
// There isn't a way to know set this to game piece correctly, since you must parse the assembly to know
183-
miraType: miraType ?? (this.assemblyFromBuffer(miraBuff).dynamic ? MiraType.ROBOT : MiraType.FIELD),
190+
miraType,
184191
cacheKey: fetchLocation,
185192
buffer: miraBuff,
186193
name: name,
@@ -211,7 +218,7 @@ class MirabufCachingService {
211218
}
212219

213220
World.analyticsSystem?.event("APS Download", {
214-
type: dirNameMap[miraType].toLowerCase(),
221+
type: dirNameMap[miraType],
215222
fileSize: miraBuff.byteLength,
216223
})
217224

@@ -389,7 +396,7 @@ class MirabufCachingService {
389396
const assembly = this.assemblyFromBuffer(buff)
390397
World.analyticsSystem?.event("Cache Get", {
391398
key: id,
392-
type: miraType == MiraType.ROBOT ? "robot" : miraType == MiraType.FIELD ? "field" : "piece",
399+
type: dirNameMap[miraType],
393400
assemblyName: assembly.info!.name!,
394401
fileSize: buff.byteLength,
395402
})
@@ -429,7 +436,7 @@ class MirabufCachingService {
429436

430437
World.analyticsSystem?.event("Cache Remove", {
431438
key: key,
432-
type: miraType == MiraType.ROBOT ? "robot" : miraType == MiraType.FIELD ? "field" : "piece",
439+
type: dirNameMap[miraType],
433440
})
434441
return true
435442
} catch (e) {
@@ -444,21 +451,20 @@ class MirabufCachingService {
444451
*/
445452
public static async removeAll() {
446453
if (canOPFS) {
447-
const robotFolderHandle = dirHandleMap[MiraType.ROBOT]
448-
for await (const key of robotFolderHandle.keys()) {
449-
robotFolderHandle.removeEntry(key)
450-
}
451-
452-
const fieldFolderHandle = dirHandleMap[MiraType.FIELD]
453-
for await (const key of fieldFolderHandle.keys()) {
454-
fieldFolderHandle.removeEntry(key)
455-
}
454+
Object.values(dirHandleMap).forEach(async dirHandle => {
455+
for await (const key of dirHandle.keys()) {
456+
dirHandle.removeEntry(key)
457+
}
458+
})
456459
}
457460

458461
window.localStorage.setItem(robotsDirName, "{}")
459462
window.localStorage.setItem(fieldsDirName, "{}")
463+
window.localStorage.setItem(piecesDirName, "{}")
460464

461-
;[...Object.values(backUpMap)].forEach(clean)
465+
backUpMap[MiraType.FIELD] = {}
466+
backUpMap[MiraType.PIECE] = {}
467+
backUpMap[MiraType.ROBOT] = {}
462468
}
463469

464470
/**
@@ -497,7 +503,7 @@ class MirabufCachingService {
497503

498504
World.analyticsSystem?.event("Devtool Cache Persist", {
499505
key: id,
500-
type: miraType == MiraType.ROBOT ? "robot" : "field",
506+
type: dirNameMap[miraType],
501507
assemblyName: assembly.info?.name ?? "unknown",
502508
fileSize: updatedBuffer.byteLength,
503509
})
@@ -540,7 +546,7 @@ class MirabufCachingService {
540546
World.analyticsSystem?.event("Cache Store", {
541547
name: name ?? "-",
542548
key: key,
543-
type: miraType == MiraType.ROBOT ? "robot" : miraType == MiraType.FIELD ? "field" : "piece",
549+
type: dirNameMap[miraType],
544550
fileSize: miraBuff.byteLength,
545551
})
546552

fission/src/util/Utility.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,3 @@ export function findListDifference<T>(previousList: T[], currentList: T[]): { ad
1717

1818
return { added, removed }
1919
}
20-
21-
export function clean<V>(cache: { [k: string]: V }) {
22-
Object.keys(cache).forEach(key => delete cache[key])
23-
}

0 commit comments

Comments
 (0)