swap to roact-hooked, init roact-reflex

This commit is contained in:
Reid 2023-08-15 17:58:36 -07:00
parent 3530d84142
commit cfccbe4883
14 changed files with 109 additions and 141 deletions

View file

@ -1,5 +1,4 @@
import Roact from "@rbxts/roact"
import Hooks from "@rbxts/roact-hooks"
import Slot from "./slot"
import { useWorldContext } from "../contexts/worldContext"
import Padding from "ReplicatedStorage/ui/padding"
@ -10,13 +9,12 @@ interface hotbarProps extends Roact.JsxInstanceProperties<Frame> {
Change?: Roact.JsxInstanceChangeEvents<Frame>
}
// no fuck off
StarterGui.SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
const hotbar: Hooks.FC<hotbarProps> = (props, hooks) => {
function hotbar(props: hotbarProps): Roact.Element {
const spreadableProps = { ...props } as Partial<hotbarProps>
const { clientState } = useWorldContext(hooks)
const { clientState } = useWorldContext()
const keycodes: Enum.KeyCode[] = [
Enum.KeyCode.One,
@ -30,6 +28,18 @@ const hotbar: Hooks.FC<hotbarProps> = (props, hooks) => {
Enum.KeyCode.Nine
]
const items: Roact.Element[] = []
clientState.backpack.GetChildren().forEach((tool, i) => {
items.push(
<Slot
Key={`Item${i}`}
index={i + 1}
keycode={keycodes[i]}
tool={tool as Tool}
/>
)
})
return (
<frame
{...spreadableProps}
@ -44,19 +54,11 @@ const hotbar: Hooks.FC<hotbarProps> = (props, hooks) => {
VerticalAlignment={Enum.VerticalAlignment.Bottom}
/>
<Padding
Padding={new UDim(0, 10)}
padding={new UDim(0, 10)}
/>
{
clientState.backpack.GetChildren().map((tool, i) => (
<Slot
index={i + 1}
keycode={keycodes[i]}
tool={tool as Tool}
/>
))
}
{...items}
</frame>
)
}
export default new Hooks(Roact)(hotbar)
export default hotbar