Skip to content
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

UI Components #976

Merged
merged 18 commits into from
Jun 20, 2024
Merged
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
4 changes: 2 additions & 2 deletions fission/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ npm i
| `lint` | Runs eslint on the project. |
| `lint:fix` | Attempts to fix issues found with eslint. |
| `prettier` | Runs prettier on the project as a check. |
| `prettier:fix` | Runs prettier on the project to fix any issues with formating. **DO NOT USE**, I don't like the current format it uses. |
| `format` | Runs `prettier:fix` and `lint:fix`. **Do not use** for the same reasons as `prettier:fix`. |
| `prettier:fix` | Runs prettier on the project to fix any issues with formating. |
| `format` | Runs `prettier:fix` and `lint:fix`. |
| `assetpack` | Downloads the assetpack and unzips/installs it in the correct location. |

### Autodesk Platform Services
Expand Down
Binary file modified fission/bun.lockb
Binary file not shown.
185 changes: 97 additions & 88 deletions fission/package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions fission/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
},
"dependencies": {
"@barclah/jolt-physics": "^0.19.3",
"@mui/base": "^5.0.0-beta.40",
"@mui/icons-material": "^5.15.20",
"@mui/system": "^5.15.20",
"@react-three/drei": "^9.96.5",
"@react-three/fiber": "^8.15.15",
"@vitest/coverage-v8": "^1.6.0",
Expand Down
1 change: 1 addition & 0 deletions fission/prettier.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const config = {
bracketSpacing: true,
bracketSameLine: false,
arrowParens: "avoid",
printWidth: 120
}

export default config;
173 changes: 46 additions & 127 deletions fission/src/Synthesis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { LoadMirabufRemote } from './mirabuf/MirabufLoader.ts';
import { mirabuf } from './proto/mirabuf';
import MirabufParser, { ParseErrorSeverity } from './mirabuf/MirabufParser.ts';
import MirabufInstance from './mirabuf/MirabufInstance.ts';
import { AnimatePresence, motion } from "framer-motion"
import { AnimatePresence } from "framer-motion"
import { ReactElement, useEffect } from "react"
import { ModalControlProvider, useModalManager } from "@/ui/ModalContext"
import { PanelControlProvider, usePanelManager } from "@/ui/PanelContext"
Expand Down Expand Up @@ -54,21 +54,18 @@ import World from '@/systems/World.ts';
import { AddRobotsModal, AddFieldsModal, SpawningModal } from '@/modals/spawning/SpawningModals.tsx';
import ImportMirabufModal from '@/modals/mirabuf/ImportMirabufModal.tsx';

const DEFAULT_MIRA_PATH = '/api/mira/Robots/Team 2471 (2018)_v7.mira';
const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira"

function Synthesis() {

const urlParams = new URLSearchParams(document.location.search);
if (urlParams.has('code')) {
const code = urlParams.get('code')
const urlParams = new URLSearchParams(document.location.search)
if (urlParams.has("code")) {
const code = urlParams.get("code")
window.opener?.setAuthCode(code)
window.close()
}

const { openModal, closeModal, getActiveModalElement } =
useModalManager(initialModals)
const { openPanel, closePanel, closeAllPanels, getActivePanelElements } =
usePanelManager(initialPanels)

const { openModal, closeModal, getActiveModalElement } = useModalManager(initialModals)
const { openPanel, closePanel, closeAllPanels, getActivePanelElements } = usePanelManager(initialPanels)
const { showTooltip } = useTooltipManager()

const { currentTheme, applyTheme } = useTheme()
Expand All @@ -77,141 +74,64 @@ function Synthesis() {
applyTheme(currentTheme)
}, [currentTheme, applyTheme])


const panelElements = getActivePanelElements()

const motionPanelElements = panelElements.map((el, i) => (
<motion.div
initial={{
scale: 0,
opacity: 0,
width: "min-content",
height: "min-content",
}}
animate={{
scale: 1,
opacity: 1,
width: "min-content",
height: "min-content",
}}
exit={{
scale: 0,
opacity: 0,
width: "min-content",
height: "min-content",
}}
transition={{
type: "spring",
stiffness: 300,
damping: 20,
}}
style={{ translateX: "-50%", translateY: "-50%" }}
className="absolute left-1/2 top-1/2"
key={"panel-" + i}
>
{el}
</motion.div>
))

const modalElement = getActiveModalElement()
const motionModalElement =
modalElement == null ? null : (
<motion.div
initial={{
scale: 0,
opacity: 0,
width: "min-content",
height: "min-content",
}}
animate={{
scale: 1,
opacity: 1,
width: "min-content",
height: "min-content",
}}
exit={{
scale: 0,
opacity: 0,
width: "min-content",
height: "min-content",
}}
transition={{
type: "spring",
stiffness: 300,
damping: 25,
}}
style={{ translateX: "-50%", translateY: "-50%" }}
className="absolute left-1/2 top-1/2"
key={"modal"}
>
{getActiveModalElement()}
</motion.div>
)



useEffect(() => {

World.InitWorld();
useEffect(() => {
World.InitWorld()

let mira_path = DEFAULT_MIRA_PATH;
let mira_path = DEFAULT_MIRA_PATH

const urlParams = new URLSearchParams(document.location.search);
const urlParams = new URLSearchParams(document.location.search)

if (urlParams.has("mira")) {
mira_path = `test_mira/${urlParams.get("mira")!}`;
console.debug(`Selected Mirabuf File: ${mira_path}`);
mira_path = `test_mira/${urlParams.get("mira")!}`
console.debug(`Selected Mirabuf File: ${mira_path}`)
}
console.log(urlParams)

const setup = async () => {

const miraAssembly = await LoadMirabufRemote(mira_path)
.catch(
_ => LoadMirabufRemote(DEFAULT_MIRA_PATH)
).catch(console.error);
const setup = async () => {
const miraAssembly = await LoadMirabufRemote(mira_path)
.catch(_ => LoadMirabufRemote(DEFAULT_MIRA_PATH))
.catch(console.error)

await (async () => {
if (!miraAssembly || !(miraAssembly instanceof mirabuf.Assembly)) {
return;
return
}
const parser = new MirabufParser(miraAssembly);

const parser = new MirabufParser(miraAssembly)
if (parser.maxErrorSeverity >= ParseErrorSeverity.Unimportable) {
console.error(`Assembly Parser produced significant errors for '${miraAssembly.info!.name!}'`);
return;
console.error(`Assembly Parser produced significant errors for '${miraAssembly.info!.name!}'`)
return
}

const mirabufSceneObject = new MirabufSceneObject(new MirabufInstance(parser));
World.SceneRenderer.RegisterSceneObject(mirabufSceneObject);
})();
};
setup();

let mainLoopHandle = 0;
const mainLoop = () => {
mainLoopHandle = requestAnimationFrame(mainLoop);

World.UpdateWorld();
};
mainLoop();
const mirabufSceneObject = new MirabufSceneObject(new MirabufInstance(parser))
World.SceneRenderer.RegisterSceneObject(mirabufSceneObject)
})()
}
setup()

let mainLoopHandle = 0
const mainLoop = () => {
mainLoopHandle = requestAnimationFrame(mainLoop)

World.UpdateWorld()
}
mainLoop()
// Cleanup
return () => {
// TODO: Teardown literally everything
cancelAnimationFrame(mainLoopHandle);
World.DestroyWorld();
cancelAnimationFrame(mainLoopHandle)
World.DestroyWorld()
// World.SceneRenderer.RemoveAllSceneObjects();
};
}, []);
}
}, [])

return (
<AnimatePresence>
<TooltipControlProvider
showTooltip={(
type: TooltipType,
controls?: TooltipControl[],
duration: number = TOOLTIP_DURATION
) => {
showTooltip={(type: TooltipType, controls?: TooltipControl[], duration: number = TOOLTIP_DURATION) => {
showTooltip(type, controls, duration)
}}
>
Expand All @@ -229,11 +149,10 @@ function Synthesis() {
}}
>
<ToastProvider>
<Scene useStats={true} />
<Scene useStats={true} />
<MainHUD />
{motionPanelElements.length > 0 &&
motionPanelElements}
{motionModalElement && motionModalElement}
{panelElements.length > 0 && panelElements}
{modalElement && <div className="absolute w-full h-full left-0 top-0">{modalElement}</div>}
<ToastContainer />
</ToastProvider>
</PanelControlProvider>
Expand Down Expand Up @@ -276,7 +195,7 @@ const initialModals = [
]

const initialPanels: ReactElement[] = [
<RobotSwitchPanel panelId="multibot" />,
<RobotSwitchPanel panelId="multibot" openLocation="right" sidePadding={8} />,
<DriverStationPanel panelId="driver-station" />,
<SpawnLocationsPanel panelId="spawn-locations" />,
<ScoreboardPanel panelId="scoreboard" />,
Expand All @@ -286,4 +205,4 @@ const initialPanels: ReactElement[] = [
<ZoneConfigPanel panelId="zone-config" />,
]

export default Synthesis;
export default Synthesis
4 changes: 2 additions & 2 deletions fission/src/Window.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
declare interface Window {
setAuthCode(code: string): void;
}
setAuthCode(code: string): void
}
Loading
Loading