Skip to content

Commit 67f079c

Browse files
committed
Add logic for slot amount
Signed-off-by: Ryan Luu <ryan.luu@ryanluu.dev>
1 parent 3d3f779 commit 67f079c

2 files changed

Lines changed: 25 additions & 24 deletions

File tree

‎src/Components/Hotbar.luau‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
local React = require(script.Parent.Parent.Parent.react)
22

33
local HotbarHint = require(script.Parent.HotbarHint)
4+
local Slot = require(script.Parent.Slot)
45

56
export type Props = {
67
forceHintVisible: boolean?,
8+
slots: number?,
9+
unlocked: boolean?,
710
}
811

912
local function Hotbar(props: Props)
10-
return React.createElement("Frame", {
11-
[React.Tag] = "Hotbar",
12-
}, {
13-
-- Create default hints for switching between hotbar slots
13+
local slotCount = props.slots or 10
14+
15+
local children = {
16+
-- Create default hints for equipping between hotbar slots
1417
SlotLeftHint = React.createElement(HotbarHint, {
1518
key = Enum.KeyCode.ButtonL1,
1619
forceVisible = props.forceHintVisible,
@@ -21,7 +24,19 @@ local function Hotbar(props: Props)
2124
forceVisible = props.forceHintVisible,
2225
order = 100,
2326
}),
24-
})
27+
}
28+
29+
for slotNumber = 1, slotCount do
30+
children[slotNumber] = React.createElement(Slot, {
31+
order = slotNumber,
32+
forceNumberVisible = props.forceHintVisible,
33+
unlocked = props.unlocked,
34+
})
35+
end
36+
37+
return React.createElement("Frame", {
38+
[React.Tag] = "Hotbar",
39+
}, children)
2540
end
2641

2742
return Hotbar

‎src/Components/Hotbar.story.luau‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
local React = require(script.Parent.Parent.Parent.react)
22

33
local Hotbar = require(script.Parent.Hotbar)
4-
local Slot = require(script.Parent.Slot)
54

65
local controls = {
76
forceHintVisible = true,
8-
toolName = "Sword",
9-
slotNumber = 9,
10-
toolImage = "rbxasset://Textures/Sword128.png",
11-
tooltipText = "A classic sword",
7+
slots = 10,
8+
unlocked = false,
129
}
1310

1411
type Props = {
@@ -19,21 +16,10 @@ return {
1916
summary = "Hotbar component that holds hotbar slots and hints",
2017
controls = controls,
2118
story = function(props: Props)
22-
local Tool = Instance.new("Tool")
23-
Tool.Name = props.controls.toolName
24-
Tool.TextureId = props.controls.toolImage
25-
Tool.ToolTip = props.controls.tooltipText
26-
27-
local component = React.createElement(Hotbar, {
19+
return React.createElement(Hotbar, {
2820
forceHintVisible = props.controls.forceHintVisible,
29-
}, {
30-
Tool = React.createElement(Slot, {
31-
tool = Tool,
32-
slotNumber = 1,
33-
order = 1,
34-
}),
21+
slots = props.controls.slots,
22+
unlocked = props.controls.unlocked,
3523
})
36-
37-
return component
3824
end,
3925
}

0 commit comments

Comments
 (0)