Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
a-crowell committed Aug 6, 2024
1 parent 1ed0fd2 commit 6deab17
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
40 changes: 18 additions & 22 deletions fission/src/mirabuf/MirabufLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,14 @@ const fieldFolderHandle = await root.getDirectoryHandle(fieldsDirName, { create:
export const backUpRobots: Map<MirabufCacheID, ArrayBuffer> = new Map<MirabufCacheID, ArrayBuffer>()
export const backUpFields: Map<MirabufCacheID, ArrayBuffer> = new Map<MirabufCacheID, ArrayBuffer>()

const canOPFS = await (async() => {
const canOPFS = await (async () => {
try {
if (robotFolderHandle.name == robotsDirName) {
robotFolderHandle.entries
robotFolderHandle.keys

const fileHandle = await robotFolderHandle.getFileHandle(
"0",
{ create: true }
)
const writable = await fileHandle.createWritable()
const fileHandle = await robotFolderHandle.getFileHandle("0", { create: true })
const writable = await fileHandle.createWritable()
await writable.close()
await fileHandle.getFile()

Expand Down Expand Up @@ -97,7 +94,6 @@ class MirabufCachingService {
}
}


/**
* Cache remote Mirabuf file
*
Expand Down Expand Up @@ -246,17 +242,18 @@ class MirabufCachingService {
try {
// Get buffer from hashMap. If not in hashMap, check OPFS. Otherwise, buff is undefined
const cache = miraType == MiraType.ROBOT ? backUpRobots : backUpFields
const buff = cache.get(id) ?? await (async() => {
const fileHandle = canOPFS ? await (miraType == MiraType.ROBOT ? robotFolderHandle : fieldFolderHandle).getFileHandle(
id,
{
create: false,
}
) : undefined
return fileHandle ? await fileHandle.getFile().then(x => x.arrayBuffer()) : undefined
})()

// If we have buffer, get assembly
const buff =
cache.get(id) ??
(await (async () => {
const fileHandle = canOPFS
? await (miraType == MiraType.ROBOT ? robotFolderHandle : fieldFolderHandle).getFileHandle(id, {
create: false,
})
: undefined
return fileHandle ? await fileHandle.getFile().then(x => x.arrayBuffer()) : undefined
})())

// If we have buffer, get assembly
if (buff) {
const assembly = this.AssemblyFromBuffer(buff)
World.AnalyticsSystem?.Event("Cache Get", {
Expand Down Expand Up @@ -370,10 +367,9 @@ class MirabufCachingService {
// Store buffer
if (canOPFS) {
// Store in OPFS
const fileHandle = await (miraType == MiraType.ROBOT ? robotFolderHandle : fieldFolderHandle).getFileHandle(
backupID,
{ create: true }
)
const fileHandle = await (
miraType == MiraType.ROBOT ? robotFolderHandle : fieldFolderHandle
).getFileHandle(backupID, { create: true })
const writable = await fileHandle.createWritable()
await writable.write(miraBuff)
await writable.close()
Expand Down
6 changes: 5 additions & 1 deletion fission/src/ui/panels/DebugPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import WPILibBrain from "@/systems/simulation/wpilib_brain/WPILibBrain"
import { MainHUD_AddToast } from "../components/MainHUD"
import { ToastType } from "../ToastContext"
import { Random } from "@/util/Random"
import MirabufCachingService, { backUpFields as hashedMiraFields, backUpRobots as hashedMiraRobots, MiraType } from "@/mirabuf/MirabufLoader"
import MirabufCachingService, {
backUpFields as hashedMiraFields,
backUpRobots as hashedMiraRobots,
MiraType,
} from "@/mirabuf/MirabufLoader"
import { Box, styled } from "@mui/material"
import { usePanelControlContext } from "../PanelContext"
import APS from "@/aps/APS"
Expand Down

0 comments on commit 6deab17

Please sign in to comment.