Skip to content

Commit

Permalink
updated demo
Browse files Browse the repository at this point in the history
  • Loading branch information
HappySunChild committed Feb 16, 2025
1 parent 5c908b2 commit d629166
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 39 deletions.
39 changes: 21 additions & 18 deletions demos/Inventory/Hotbar.luau
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
local ReplicatedStorage = game:GetService 'ReplicatedStorage'

local Fusion = require(ReplicatedStorage.Libraries.ConFusion)
local HotbarSlot = require(script.Parent.HotbarSlot)
local Rusion = require(ReplicatedStorage.Libraries.ReFusion)

local function Hotbar(scope: Rusion.Scope, props)
local function Hotbar(scope: Fusion.Scope, props)
local hotbarScope = scope:innerScope {
HotbarSlot = HotbarSlot,
}

local created = {}
local slots = hotbarScope:ForPairs(props.Items, function(_, index, tool: Tool)
local slot = created[tool]

if not slot then
slot = hotbarScope:HotbarSlot {
Item = tool,
Index = index,
Callback = props.EquipCallback,
Cleanup = function()
created[tool] = nil
end,
}
created[tool] = slot
local slots = hotbarScope:ForPairs(
props.Items,
function(_, index, tool: Tool)
local slot = created[tool]

if not slot then
slot = hotbarScope:HotbarSlot {
Item = tool,
Index = index,
Callback = props.EquipCallback,
Cleanup = function()
created[tool] = nil
end,
}
created[tool] = slot
end

return index, slot
end

return index, slot
end)
)

local height = props.Height
local padding = props.Padding
Expand Down
30 changes: 20 additions & 10 deletions demos/Inventory/HotbarSlot.luau
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ local Players = game:GetService 'Players'
local ReplicatedStorage = game:GetService 'ReplicatedStorage'
local TextService = game:GetService 'TextService'

local Rusion = require(ReplicatedStorage.Libraries.ReFusion)
local OnEvent = Rusion.OnEvent
local Fusion = require(ReplicatedStorage.Libraries.ConFusion)
local OnEvent = Fusion.OnEvent

local Foreground = Color3.fromRGB(245, 247, 234)
local ActiveForeground = Color3.fromRGB(225, 86, 63)
local Background = Color3.fromRGB(45, 48, 50)

local HoverInfo = TweenInfo.new(0.4, Enum.EasingStyle.Circular)
local TooltipInfo = TweenInfo.new(0.2, Enum.EasingStyle.Exponential)

local function HotbarSlot(
scope: Rusion.Scope,
props: { Item: Tool, Index: number, Callback: () -> (), Cleanup: () -> () }
scope: Fusion.Scope,
props: {
Item: Tool,
Index: number,
Callback: () -> (),
Cleanup: () -> (),
}
)
local slotScope = scope:innerScope()

Expand All @@ -38,7 +42,12 @@ local function HotbarSlot(
return 0
end

local bounds = TextService:GetTextSize(use(toolTip), 14, Enum.Font.SourceSans, Vector2.new(math.huge, 16))
local bounds = TextService:GetTextSize(
use(toolTip),
14,
Enum.Font.SourceSans,
Vector2.new(math.huge, 16)
)

return bounds.X + 4
end)
Expand All @@ -48,11 +57,12 @@ local function HotbarSlot(
local currentBackpack = Players.LocalPlayer.Backpack

return slotScope:New('TextButton', {
Size = slotScope:Tween(
Size = slotScope:Spring(
slotSize:map(function(size)
return UDim2.fromScale(size, size)
end),
HoverInfo
50,
2
),
SizeConstraint = Enum.SizeConstraint.RelativeYY,

Expand All @@ -74,11 +84,11 @@ local function HotbarSlot(
TextTruncate = Enum.TextTruncate.AtEnd,
TextColor3 = Foreground,

[Rusion.Cleanup] = {
[Fusion.Cleanup] = {
slotScope,
props.Cleanup,
},
[Rusion.Startup] = function()
[Fusion.Startup] = function()
slotSize:set(1)
end,

Expand Down
30 changes: 19 additions & 11 deletions demos/Inventory/inventoryTest.client.luau
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)

local Hotbar = require(script.Parent.Hotbar)

local Rusion = require(ReplicatedStorage.Libraries.ReFusion)
local peek = Rusion.peek
local Fusion = require(ReplicatedStorage.Libraries.ConFusion)
local peek = Fusion.peek

local keys = {
Enum.KeyCode.One,
Expand All @@ -25,7 +25,7 @@ local keys = {
Enum.KeyCode.Zero,
}

local scope = Rusion:scoped {
local scope = Fusion:scoped {
Hotbar = Hotbar,
}

Expand Down Expand Up @@ -95,7 +95,10 @@ local function addTool(tool: Instance)

local connection
connection = tool.AncestryChanged:Connect(function(_, parent)
if parent == nil or parent ~= player.Backpack and parent ~= player.Character then
if
parent == nil
or parent ~= player.Backpack and parent ~= player.Character
then
connection:Disconnect()

removeTool(tool)
Expand Down Expand Up @@ -143,15 +146,20 @@ scope:New('ScreenGui', {
},
})

ContextActionService:BindAction('Equip', function(_, state: Enum.UserInputState, input: InputObject)
if state ~= Enum.UserInputState.Begin then
return
end
ContextActionService:BindAction(
'Equip',
function(_, state: Enum.UserInputState, input: InputObject)
if state ~= Enum.UserInputState.Begin then
return
end

local index = table.find(keys, input.KeyCode)
local index = table.find(keys, input.KeyCode)

equipTool(index)
end, false, unpack(keys))
equipTool(index)
end,
false,
unpack(keys)
)

characterAdded(player.Character or player.CharacterAdded:Wait())
player.CharacterAdded:Connect(characterAdded)

0 comments on commit d629166

Please sign in to comment.