Skip to content

Create Load Default Option for Field and Robot with Gizmo and Assembl… #1189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions fission/src/ui/modals/MainMenuModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { SynthesisIcons } from "../components/StyledComponents"
import Button from "@/components/Button.tsx"
import { useModalControlContext } from "../helpers/UseModalManager"
import { Global_AddToast } from "@/components/GlobalUIControls.ts"
import { SpawnCachedMira } from "@/ui/panels/mirabuf/ImportMirabufPanel"
import { MiraType } from "@/mirabuf/MirabufLoader"
import MirabufCachingService from "@/mirabuf/MirabufLoader"

const MainMenuModal: React.FC<ModalPropsImpl & { startSingleplayerCallback: () => void }> = ({
modalId,
Expand All @@ -30,6 +33,31 @@ const MainMenuModal: React.FC<ModalPropsImpl & { startSingleplayerCallback: () =
}}
className="w-full my-1"
/>
<Button
value={"Load Default"}
onClick={() => {
closeModal()
startSingleplayerCallback()
Promise.all([
MirabufCachingService.CacheRemote(
"/api/mira/fields/FRC Field 2023_v7.mira",
MiraType.FIELD
).then(cacheInfoField => {
if (cacheInfoField) {
SpawnCachedMira(cacheInfoField, MiraType.FIELD)
}
}),
MirabufCachingService.CacheRemote("/api/mira/robots/Dozer_v9.mira", MiraType.ROBOT).then(
cacheInfoRobot => {
if (cacheInfoRobot) {
SpawnCachedMira(cacheInfoRobot, MiraType.ROBOT)
}
}
),
])
Comment on lines +41 to +57
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still doesn't guarantee order, because you're still spawning the files immediately after their respective promises resolve, rather than spawning synchronously after both cache requests resolve

MDN Promise.all()

Comment on lines +38 to +57
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
onClick={() => {
closeModal()
startSingleplayerCallback()
Promise.all([
MirabufCachingService.CacheRemote(
"/api/mira/fields/FRC Field 2023_v7.mira",
MiraType.FIELD
).then(cacheInfoField => {
if (cacheInfoField) {
SpawnCachedMira(cacheInfoField, MiraType.FIELD)
}
}),
MirabufCachingService.CacheRemote("/api/mira/robots/Dozer_v9.mira", MiraType.ROBOT).then(
cacheInfoRobot => {
if (cacheInfoRobot) {
SpawnCachedMira(cacheInfoRobot, MiraType.ROBOT)
}
}
),
])
onClick={() => {
closeModal()
startSingleplayerCallback()
let cachedField: MirabufCacheInfo | undefined
let cachedRobot: MirabufCacheInfo | undefined
Promise.all([
MirabufCachingService.CacheRemote(
"/api/mira/fields/FRC Field 2023_v7.mira",
MiraType.FIELD
).then(cacheInfoField => {
if (cacheInfoField) { cachedField = cacheInfoField }
}),
MirabufCachingService.CacheRemote("/api/mira/robots/Dozer_v9.mira", MiraType.ROBOT).then(
cacheInfoRobot => { if (cacheInfoRobot) { cachedRobot = cacheInfoRobot } }
),
]).then(() => {
if (cachedField && cachedRobot) {
SpawnCachedMira(cachedField, MiraType.FIELD)
SpawnCachedMira(cachedRobot, MiraType.ROBOT)
}
})
}}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a solution you could look into for resolving zach's comment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the promise.all Promise returns the individual promise results as an array, you don't need to have cachedField and cachedRobot

}}
className="w-full my-1"
/>
<Button
value={"Multiplayer"}
onClick={() => {
Expand Down
4 changes: 2 additions & 2 deletions fission/src/ui/panels/mirabuf/ImportMirabufPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ export type MiraManifest = {
fields: MirabufRemoteInfo[]
}

function GetCacheInfo(miraType: MiraType): MirabufCacheInfo[] {
export function GetCacheInfo(miraType: MiraType): MirabufCacheInfo[] {
return Object.values(
canOPFS ? MirabufCachingService.GetCacheMap(miraType) : miraType == MiraType.ROBOT ? backUpRobots : backUpFields
)
}

function SpawnCachedMira(info: MirabufCacheInfo, type: MiraType, progressHandle?: ProgressHandle) {
export function SpawnCachedMira(info: MirabufCacheInfo, type: MiraType, progressHandle?: ProgressHandle) {
// If spawning a field, then remove all other fields
if (type == MiraType.FIELD) {
World.SceneRenderer.RemoveAllFields()
Expand Down
Loading