add custom hotbar

This commit is contained in:
Reid 2023-08-11 17:38:07 -07:00
parent 72029047a5
commit 8232eacff2
12 changed files with 304 additions and 8 deletions

View file

@ -0,0 +1,34 @@
import { World } from "@rbxts/matter"
import Roact, { createContext } from "@rbxts/roact"
import Hooks, { CoreHooks } from "@rbxts/roact-hooks"
import { clientState } from "ReplicatedStorage/ecs/state"
interface WorldContextValue {
world: World
clientState: clientState
}
interface Props {
world: World
clientState: clientState
}
const WorldProviderWithoutHooks: Hooks.FC<Props> = (props) => {
const { world, clientState } = props
return <WorldContext.Provider value={{ world, clientState }}>{props[Roact.Children]}</WorldContext.Provider>
}
const WorldProvider = new Hooks(Roact)(WorldProviderWithoutHooks)
export default WorldProvider
const WorldContext = createContext<WorldContextValue | undefined>(undefined)
export const useWorldContext = ({ useContext }: CoreHooks): WorldContextValue => {
const context = useContext(WorldContext)
if (!context) {
error("useContext must be called within a Provider")
}
return context
}