Files
2026-11-16 23:50:40 +03:00

428 lines
23 KiB
Luau
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- WorkshopWindow: the "Мастерская" window in the New Year shop style (frame, tabs, buttons: ShopKit).
-- Tabs: Улучшения / Слияние / Бустеры / Как это работает. A tab shows a badge with the number of actions you
-- can do there right now. Button states: see ShopKit.pill. Results: the card flashes and a "+1" floats up.
local K = require(script.Parent:WaitForChild("ShopKit"))
local W = {}
local WHITE, GOLD, SOFT, OK, WARN, NAVY, BODY = K.WHITE, K.GOLD, K.SOFT, K.OK, K.WARN, K.NAVY, K.BODY
local CARD_SLICE = K.CARD_SLICE
local tween, new, corner, art, label, maxText = K.tween, K.new, K.corner, K.art, K.label, K.maxText
local floatText, flash, pill, pricePlate = K.floatText, K.flash, K.pill, K.pricePlate
function W.install(ctx)
local Config, player, remote = ctx.Config, ctx.player, ctx.remote
local fmt = ctx.fmtNum
local function attr(n, d) local v = player:GetAttribute(n); if v == nil then return d end return v end
local win = ctx.win
local refresh
local TABS = {
{ id = "Upgrades", text = "Upgrades", icon = "🛠", tip = "Tip: “Generator Luck” pays off fastest — it works on every generation." },
{ id = "Fusion", text = "Fusion", icon = "✨", tip = "Fusion: " .. Config.FUSION_COUNT .. " identical ornaments + shards = 1 “Fused” ornament one rarity higher — worth more than you put in." },
{ id = "Boosters", text = "Boosters", icon = "🍀", tip = "A booster goes in the generator slot and is used up when you make an ornament. Best with 16 shards." },
{ id = "Help", text = "How It Works", icon = "📖", tip = "The Workshop is always open — the “Workshop” button on the left of the screen." },
}
local ch = K.chrome({ win = win, title = "WORKSHOP", subtitle = "Upgrade the generator,\nfuse and craft", tabs = TABS,
closeWindow = ctx.closeWindow, fmtNum = fmt, onTab = function() refresh() end })
local panel, tabs = ch.panel, ch.tabs
local function makePage(id) local _, s = ch.makePage(id, true); return s end
---------------------------------------------------------------- upgrades page: 2 x 2 ray cards
local UPG = {
Luck = { icon = "🍀", card = "cardGreen" }, Regen = { icon = "⏳", card = "cardCyan" },
Shredder = { icon = "♻️", card = "cardViolet" }, Storage = { icon = "📦", card = "cardOrange" },
}
local function effectText(u, level)
if u.Id == "Luck" then return string.format("luck x%.2f", Config.LuckMult(level)) end
if u.Id == "Regen" then return string.format("cap %d · +1 per %.1fs", Config.RegenCap(level), Config.RegenSeconds(level)) end
if u.Id == "Shredder" then return string.format("recycling x%.2f", Config.ShredderMult(level)) end
if u.Id == "Storage" then return Config.StorageCap(level) .. " slots" end
return ""
end
local upScroll = makePage("Upgrades")
new("UIGridLayout", { CellSize = UDim2.fromOffset(615, 272), CellPadding = UDim2.fromOffset(18, 18), SortOrder = Enum.SortOrder.LayoutOrder, Parent = upScroll })
new("UIPadding", { PaddingLeft = UDim.new(0, 2), PaddingTop = UDim.new(0, 2), Parent = upScroll })
local pending = {} -- key -> os.clock() of the request (busy state)
local upCards = {}
for _, u in Config.UPGRADES do
local d = UPG[u.Id] or { icon = "⭐", card = "cardGreen" }
local card = art(d.card, { LayoutOrder = u.Order, ScaleType = Enum.ScaleType.Slice, SliceCenter = CARD_SLICE, ZIndex = 4, Parent = upScroll })
local disc = new("Frame", { Position = UDim2.fromOffset(30, 50), Size = UDim2.fromOffset(128, 128), BackgroundColor3 = Color3.new(0, 0, 0), BackgroundTransparency = 0.6, ZIndex = 5, Parent = card }, {
corner(UDim.new(0.5, 0)), new("UIStroke", { Color = GOLD, Thickness = 4 }),
})
label({ Size = UDim2.fromScale(1, 1), Text = d.icon, TextSize = 68, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = disc }, 0)
local lvl = label({ AnchorPoint = Vector2.new(0.5, 0.5), Position = UDim2.fromOffset(94, 204), Size = UDim2.fromOffset(140, 40), Text = "", TextSize = 28,
TextColor3 = GOLD, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = card }, 2.5)
maxText(label({ Position = UDim2.fromOffset(180, 40), Size = UDim2.fromOffset(410, 46), Text = u.Name, TextScaled = true, ZIndex = 5, Parent = card }, 3), 38)
maxText(label({ Position = UDim2.fromOffset(182, 86), Size = UDim2.fromOffset(410, 30), Text = u.Desc, TextScaled = true, FontFace = BODY, ZIndex = 5, Parent = card }, 1.5), 21)
local pipRow = new("Frame", { Position = UDim2.fromOffset(182, 124), Size = UDim2.fromOffset(410, 24), BackgroundTransparency = 1, ZIndex = 5, Parent = card }, {
new("UIListLayout", { FillDirection = Enum.FillDirection.Horizontal, Padding = UDim.new(0, 7), SortOrder = Enum.SortOrder.LayoutOrder, VerticalAlignment = Enum.VerticalAlignment.Center }),
})
local pips = {}
for k = 1, u.Max do
pips[k] = new("Frame", { Size = UDim2.fromOffset(28, 22), BackgroundColor3 = Color3.new(0, 0, 0), BackgroundTransparency = 0.55, LayoutOrder = k, ZIndex = 5, Parent = pipRow }, {
corner(UDim.new(0.5, 0)), new("UIStroke", { Color = WHITE, Thickness = 1.5, Transparency = 0.5 }),
})
end
local eff = maxText(label({ Position = UDim2.fromOffset(182, 156), Size = UDim2.fromOffset(410, 30), Text = "", TextScaled = true, FontFace = BODY,
TextColor3 = OK, ZIndex = 5, Parent = card }, 1.5), 22)
local _, price = pricePlate(card, UDim2.fromOffset(196, 198), UDim2.fromOffset(150, 48))
local btn
btn = pill(card, { Position = UDim2.fromOffset(362, 190), Size = UDim2.fromOffset(232, 64), ZIndex = 5, TextMax = 30 }, function()
pending["Upg_" .. u.Id] = os.clock()
btn.set("busy")
remote:FireServer("Upgrade", u.Id)
end)
upCards[u.Id] = { card = card, lvl = lvl, pips = pips, eff = eff, price = price, btn = btn, u = u }
end
---------------------------------------------------------------- boosters page: 2 big cards
local boScroll = makePage("Boosters")
new("UIGridLayout", { CellSize = UDim2.fromOffset(615, 470), CellPadding = UDim2.fromOffset(18, 18), SortOrder = Enum.SortOrder.LayoutOrder, Parent = boScroll })
new("UIPadding", { PaddingLeft = UDim.new(0, 2), PaddingTop = UDim.new(0, 2), Parent = boScroll })
local bOrder = {}
for id, b in Config.BOOSTERS do table.insert(bOrder, { id = id, b = b }) end
table.sort(bOrder, function(x, y) return x.b.Order < y.b.Order end)
local boCards = {}
for i, e in bOrder do
local card = art(i == 1 and "cardGreen" or "cardOrange", { LayoutOrder = i, ScaleType = Enum.ScaleType.Slice, SliceCenter = CARD_SLICE, ZIndex = 4, Parent = boScroll })
local orb = new("Frame", { AnchorPoint = Vector2.new(0.5, 0), Position = UDim2.new(0.5, 0, 0, 52), Size = UDim2.fromOffset(170, 170), BackgroundColor3 = e.b.Color, ZIndex = 5, Parent = card }, {
corner(UDim.new(0.5, 0)), new("UIStroke", { Color = WHITE, Thickness = 6 }),
new("UIGradient", { Rotation = 90, Color = ColorSequence.new(WHITE, Color3.fromRGB(170, 170, 170)) }),
})
label({ Size = UDim2.fromScale(1, 1), Text = "x" .. e.b.Luck, TextSize = 76, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = orb }, 4)
local orbScale = new("UIScale", { Parent = orb })
task.spawn(function()
while orb.Parent do
tween(orbScale, 1.6, { Scale = 1.05 }, Enum.EasingStyle.Sine).Completed:Wait()
tween(orbScale, 1.6, { Scale = 1 }, Enum.EasingStyle.Sine).Completed:Wait()
end
end)
maxText(label({ Position = UDim2.fromOffset(30, 236), Size = UDim2.new(1, -60, 0, 50), Text = e.b.Name, TextScaled = true, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 5, Parent = card }, 3), 44)
maxText(label({ Position = UDim2.fromOffset(40, 288), Size = UDim2.new(1, -80, 0, 30), Text = "one generation luck x" .. e.b.Luck, TextScaled = true, FontFace = BODY,
TextColor3 = SOFT, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 5, Parent = card }, 1.5), 22)
local owned = new("Frame", { AnchorPoint = Vector2.new(1, 0), Position = UDim2.new(1, -30, 0, 44), Size = UDim2.fromOffset(140, 50), BackgroundColor3 = NAVY,
BackgroundTransparency = 0.15, ZIndex = 6, Parent = card }, { corner(UDim.new(0.5, 0)), new("UIStroke", { Color = GOLD, Thickness = 2 }) })
local ownedText = maxText(label({ Position = UDim2.fromOffset(8, 6), Size = UDim2.new(1, -16, 1, -12), Text = "", TextScaled = true, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 7, Parent = owned }, 2), 26)
local _, price = pricePlate(card, UDim2.fromOffset(60, 344), UDim2.fromOffset(180, 56))
local btn
btn = pill(card, { Position = UDim2.fromOffset(262, 334), Size = UDim2.fromOffset(300, 76), ZIndex = 5, TextMax = 34 }, function()
pending["Booster_" .. e.id] = os.clock()
btn.set("busy")
remote:FireServer("CraftBooster", e.id)
end)
boCards[e.id] = { card = card, owned = ownedText, price = price, btn = btn, b = e.b }
end
---------------------------------------------------------------- fusion page: one row per toy group
local fuScroll = makePage("Fusion")
new("UIListLayout", { Padding = UDim.new(0, 14), SortOrder = Enum.SortOrder.LayoutOrder, Parent = fuScroll })
new("UIPadding", { PaddingLeft = UDim.new(0, 4), PaddingRight = UDim.new(0, 18), PaddingTop = UDim.new(0, 4), PaddingBottom = UDim.new(0, 4), Parent = fuScroll })
local fuRows = {}
local function fusionGroups()
local groups = {}
for _, c in ctx.getCards() do
local it = c.item
if not it.Variant and Config.RARITIES[c.rarity.Index + 1] then
local key = it.Toy .. "|" .. it.Rarity
groups[key] = groups[key] or { key = key, toy = Config.ToyById[it.Toy], rarity = c.rarity, n = 0 }
groups[key].n += 1
end
end
local list = {}
for _, g in groups do table.insert(list, g) end
table.sort(list, function(x, y)
local rx, ry = x.n >= Config.FUSION_COUNT, y.n >= Config.FUSION_COUNT
if rx ~= ry then return rx end
if x.rarity.Index ~= y.rarity.Index then return x.rarity.Index > y.rarity.Index end
return x.n > y.n
end)
return list
end
local function rebuildFusion()
for _, r in fuRows do r:Destroy() end
fuRows = {}
local shards = attr("Shards", 0)
local list = fusionGroups()
if #list == 0 then
table.insert(fuRows, K.emptyState({ Size = UDim2.new(1, 0, 0, 520), Parent = fuScroll }, "Nothing to fuse yet",
"Collect " .. Config.FUSION_COUNT .. " identical ornaments of one rarity in the generator — then fuse them into a rarer one."))
return 0
end
local ready = 0
for i, g in list do
local nextR = Config.RARITIES[g.rarity.Index + 1]
local cost = Config.FUSION_COST[g.rarity.Id] or 0
local enough, rich = g.n >= Config.FUSION_COUNT, shards >= cost
if enough and rich then ready += 1 end
local row = new("Frame", { Size = UDim2.new(1, 0, 0, 128), BackgroundColor3 = Color3.new(0, 0, 0), BackgroundTransparency = 0.45, LayoutOrder = i, ZIndex = 5, Parent = fuScroll }, {
corner(UDim.new(0, 26)), new("UIStroke", { Color = enough and GOLD or Color3.fromRGB(120, 150, 140), Thickness = enough and 3 or 2, Transparency = enough and 0 or 0.4 }),
})
local tile = new("Frame", { Position = UDim2.fromOffset(18, 14), Size = UDim2.fromOffset(100, 100), BackgroundColor3 = Color3.fromRGB(12, 30, 40), ZIndex = 6, Parent = row }, {
corner(UDim.new(0, 18)), new("UIStroke", { Color = g.rarity.Color, Thickness = 3 }),
})
local mini = ctx.miniPattern(g.toy.Mask, g.rarity.Color, 76, tile)
mini.AnchorPoint = Vector2.new(0.5, 0.5)
mini.Position = UDim2.fromScale(0.5, 0.5)
mini.ZIndex = 7
maxText(label({ Position = UDim2.fromOffset(140, 14), Size = UDim2.fromOffset(560, 42), Text = g.toy.Name .. " · " .. g.rarity.Name .. " → " .. nextR.Name .. " · Fused",
TextScaled = true, ZIndex = 6, Parent = row }, 2.5), 34)
new("Frame", { Position = UDim2.fromOffset(142, 62), Size = UDim2.fromOffset(14, 14), BackgroundColor3 = g.rarity.Color, ZIndex = 6, Parent = row }, { corner(UDim.new(0.5, 0)) })
new("Frame", { Position = UDim2.fromOffset(162, 62), Size = UDim2.fromOffset(14, 14), BackgroundColor3 = nextR.Color, ZIndex = 6, Parent = row }, { corner(UDim.new(0.5, 0)) })
local bar = new("Frame", { Position = UDim2.fromOffset(190, 60), Size = UDim2.fromOffset(330, 20), BackgroundColor3 = Color3.fromRGB(10, 20, 26), ZIndex = 6, Parent = row }, {
corner(UDim.new(0.5, 0)), new("UIStroke", { Color = WHITE, Thickness = 1.5, Transparency = 0.6 }),
})
new("Frame", { Size = UDim2.fromScale(math.clamp(g.n / Config.FUSION_COUNT, 0.04, 1), 1), BackgroundColor3 = enough and OK or g.rarity.Color, ZIndex = 7, Parent = bar }, { corner(UDim.new(0.5, 0)) })
maxText(label({ Position = UDim2.fromOffset(142, 86), Size = UDim2.fromOffset(560, 30), TextScaled = true, FontFace = BODY, ZIndex = 6, Parent = row,
Text = "have " .. g.n .. " / " .. Config.FUSION_COUNT .. (enough and " · ready to fuse!" or (" · need " .. (Config.FUSION_COUNT - g.n)))
.. " · costs " .. fmt(Config.Value({ Toy = g.toy.Id, Rarity = nextR.Id, Variant = "Fused" }))
.. " (put in " .. fmt(Config.FUSION_COUNT * Config.Value({ Toy = g.toy.Id, Rarity = g.rarity.Id }) + cost) .. ")",
TextColor3 = enough and OK or SOFT }, 1.5), 22)
local _, price = pricePlate(row, UDim2.fromOffset(726, 38), UDim2.fromOffset(170, 52))
price.Text = fmt(cost)
price.TextColor3 = rich and WHITE or WARN
local btn
btn = pill(row, { Position = UDim2.fromOffset(916, 28), Size = UDim2.fromOffset(300, 72), ZIndex = 6, TextMax = 32 }, function()
pending["Fuse"] = os.clock()
btn.set("busy")
remote:FireServer("Fuse", g.toy.Id, g.rarity.Id)
end)
if pending["Fuse"] and os.clock() - pending["Fuse"] < 2.5 then
btn.set("busy")
elseif not enough then
btn.set("off", "Need " .. (Config.FUSION_COUNT - g.n) .. " pcs")
elseif not rich then
btn.set("off", "Need " .. fmt(cost - shards))
else
btn.set("ready", "Fuse")
end
table.insert(fuRows, row)
end
return ready
end
---------------------------------------------------------------- help page: three explainer cards
local heScroll = makePage("Help")
new("UIGridLayout", { CellSize = UDim2.fromOffset(404, 540), CellPadding = UDim2.fromOffset(20, 18), SortOrder = Enum.SortOrder.LayoutOrder, Parent = heScroll })
new("UIPadding", { PaddingLeft = UDim.new(0, 4), PaddingTop = UDim.new(0, 4), Parent = heScroll })
local HELP = {
{ card = "cardCyan", icon = "🛠", title = "Upgrades", tab = "Upgrades",
text = "Always active, even away from the machine. Luck — rarer ornaments, regen — more free shards, shredder — more shards from recycling, storage — more slots." },
{ card = "cardViolet", icon = "✨", title = "Fusion", tab = "Fusion",
text = Config.FUSION_COUNT .. " identical ornaments of one rarity + some shards = 1 “Fused” ornament one rarity higher. It's worth more than you put in, but it can't be fused again." },
{ card = "cardOrange", icon = "🍀", title = "Boosters", tab = "Boosters",
text = "Craft a booster with shards and put it in the generator slot. It multiplies the luck of one generation and is used up when you make an ornament." },
}
for i, h in HELP do
local card = art(h.card, { LayoutOrder = i, ScaleType = Enum.ScaleType.Slice, SliceCenter = CARD_SLICE, ZIndex = 4, Parent = heScroll })
label({ AnchorPoint = Vector2.new(0.5, 0), Position = UDim2.new(0.5, 0, 0, 44), Size = UDim2.fromOffset(120, 110), Text = h.icon, TextSize = 84, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 5, Parent = card }, 0)
maxText(label({ Position = UDim2.fromOffset(24, 160), Size = UDim2.new(1, -48, 0, 50), Text = h.title, TextScaled = true, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 5, Parent = card }, 3), 42)
maxText(label({ Position = UDim2.fromOffset(30, 218), Size = UDim2.new(1, -60, 0, 190), Text = h.text, TextScaled = true, TextWrapped = true, FontFace = BODY,
TextColor3 = WHITE, TextXAlignment = Enum.TextXAlignment.Center, TextYAlignment = Enum.TextYAlignment.Top, ZIndex = 5, Parent = card }, 1.5), 24)
local go = pill(card, { Position = UDim2.fromOffset(62, 420), Size = UDim2.fromOffset(280, 70), ZIndex = 5, TextMax = 30 }, function() ch.showTab(h.tab) end)
go.set("alt", "Open")
end
---------------------------------------------------------------- refresh
local function busy(key) return pending[key] and os.clock() - pending[key] < 2.5 end
refresh = function()
local shards = attr("Shards", 0)
ch.setBalance(shards)
local canUp = 0
for id, c in upCards do
local level = attr("Upg_" .. id, 0)
local cost = Config.UpgradeCost(id, level)
c.lvl.Text = "Lvl " .. level .. " / " .. c.u.Max
for k, pip in c.pips do
local filled = k <= level
pip.BackgroundColor3 = filled and GOLD or Color3.new(0, 0, 0)
pip.BackgroundTransparency = filled and 0 or 0.55
pip.UIStroke.Color = filled and Color3.fromRGB(150, 90, 10) or WHITE
end
if cost then
c.eff.Text = effectText(c.u, level) .. " → " .. effectText(c.u, level + 1)
c.eff.TextColor3 = OK
c.price.Text = fmt(cost)
c.price.TextColor3 = shards >= cost and WHITE or WARN
c.price.Parent.Visible = true
if busy("Upg_" .. id) then c.btn.set("busy")
elseif shards >= cost then c.btn.set("ready", "Upgrade"); canUp += 1
else c.btn.set("off", "Need " .. fmt(cost - shards)) end
else
c.eff.Text = effectText(c.u, level) .. " · max"
c.eff.TextColor3 = GOLD
c.price.Parent.Visible = false
c.btn.set("done", "Maxed")
end
end
tabs.Upgrades.setBadge(canUp)
local canBo = 0
for id, c in boCards do
local cost = Config.BOOSTER_COST[id]
c.owned.Text = "you have: " .. attr("Booster_" .. id, 0)
c.price.Text = fmt(cost)
c.price.TextColor3 = shards >= cost and WHITE or WARN
if busy("Booster_" .. id) then c.btn.set("busy")
elseif shards >= cost then c.btn.set("ready", "Create"); canBo += 1
else c.btn.set("off", "Need " .. fmt(cost - shards)) end
end
tabs.Boosters.setBadge(canBo)
if ch.current() == "Fusion" then
tabs.Fusion.setBadge(rebuildFusion())
else
local n = 0
for _, g in fusionGroups() do
if g.n >= Config.FUSION_COUNT and shards >= (Config.FUSION_COST[g.rarity.Id] or 0) then n += 1 end
end
tabs.Fusion.setBadge(n)
end
end
-- total "things you can do" for the HUD button (sum of the three tab badges), kept live even while the window
-- is closed: ctx.setHudBadge(n) (the HUD badge animates "+N" when it grows)
local function hudCount()
if not ctx.setHudBadge then return end
local shards, n = attr("Shards", 0), 0
for _, u in Config.UPGRADES do
local cost = Config.UpgradeCost(u.Id, attr("Upg_" .. u.Id, 0))
if cost and shards >= cost then n += 1 end
end
for id in Config.BOOSTERS do
if shards >= Config.BOOSTER_COST[id] then n += 1 end
end
for _, g in fusionGroups() do
if g.n >= Config.FUSION_COUNT and shards >= (Config.FUSION_COST[g.rarity.Id] or 0) then n += 1 end
end
ctx.setHudBadge(n)
end
local hudQueued = false
local function hudLater()
if hudQueued then return end
hudQueued = true
task.delay(0.25, function() hudQueued = false; hudCount() end)
end
-- server results: clear the busy state, flash the card, float "+1"
local function watch(name, fn)
player:GetAttributeChangedSignal(name):Connect(function()
if fn then fn() end
hudLater()
if win.overlay.Visible then refresh() end
end)
end
watch("Shards")
for _, u in Config.UPGRADES do
local key, prev = "Upg_" .. u.Id, attr("Upg_" .. u.Id, 0)
watch(key, function()
local v = attr(key, 0)
if pending[key] then
pending[key] = nil
if v > prev and win.overlay.Visible then flash(upCards[u.Id].card); floatText(upCards[u.Id].card, "+1 level!") end
end
prev = v
end)
end
for id in Config.BOOSTERS do
local key, prev = "Booster_" .. id, attr("Booster_" .. id, 0)
watch(key, function()
local v = attr(key, 0)
if pending[key] then
pending[key] = nil
if v > prev and win.overlay.Visible then flash(boCards[id].card); floatText(boCards[id].card, "+1 booster!") end
end
prev = v
end)
end
task.spawn(function()
local inv = player:WaitForChild("OrnamentInventory")
local queued = false
local function changed()
if queued then return end
queued = true
task.delay(0.2, function()
queued = false
pending["Fuse"] = nil
hudCount()
if win.overlay.Visible then refresh() end
end)
end
inv.ChildAdded:Connect(changed)
inv.ChildRemoved:Connect(changed)
for _, item in inv:GetChildren() do item:GetAttributeChangedSignal("OnTree"):Connect(changed) end
inv.ChildAdded:Connect(function(item) item:GetAttributeChangedSignal("OnTree"):Connect(changed) end)
changed()
end)
-- a request the server refused (it sends a toast) must not stay busy forever
task.spawn(function()
while panel.Parent do
task.wait(0.5)
local stale = false
for k, t in pending do
if os.clock() - t >= 2.5 then pending[k] = nil; stale = true end
end
if stale and win.overlay.Visible then refresh() end
end
end)
ch.showTab("Upgrades")
---------------------------------------------------------------- "set collected" notification
-- When a group (same toy + rarity, no variant, not on the tree — exactly what the server's FindFusable counts)
-- reaches FUSION_COUNT, a big toast says so; clicking it opens the Fusion tab. Items that are already there when
-- the player joins do not trigger it (armed after the inventory has been quiet for a moment).
if ctx.toast then
task.spawn(function()
local inv = player:WaitForChild("OrnamentInventory")
local counts, armed, queued = {}, false, false
local quietAt = os.clock()
local function recount()
queued = false
local now = {}
for _, item in inv:GetChildren() do
local toyId, rId = item:GetAttribute("Toy"), item:GetAttribute("Rarity")
local r = rId and Config.RarityById[rId]
if toyId and r and not item:GetAttribute("Variant") and not item:GetAttribute("OnTree")
and Config.RARITIES[r.Index + 1] and Config.FUSION_COST[r.Id] then
local key = toyId .. "|" .. rId
now[key] = (now[key] or 0) + 1
end
end
if armed then
for key, n in now do
if n >= Config.FUSION_COUNT and (counts[key] or 0) < Config.FUSION_COUNT then
local toyId, rId = string.match(key, "^(.-)|(.*)$")
local toy, r = Config.ToyById[toyId], Config.RarityById[rId]
local nextR = Config.RARITIES[r.Index + 1]
ctx.toast(string.format("✨ Set complete: %d × %s · %s!\nClick to fuse into “%s · Fused”",
Config.FUSION_COUNT, toy and toy.Name or toyId, r.Name, nextR.Name), GOLD, true,
function() if K.nav.Workshop then K.nav.Workshop("Fusion") end end)
end
end
end
counts = now
end
local function changed()
quietAt = os.clock()
if queued then return end
queued = true
task.delay(0.2, recount) -- several toys arrive at once: count once
end
local function watch(item) item:GetAttributeChangedSignal("OnTree"):Connect(changed) end
for _, item in inv:GetChildren() do watch(item) end
inv.ChildAdded:Connect(function(item) watch(item); changed() end)
inv.ChildRemoved:Connect(changed)
recount()
while os.clock() - quietAt < 2.5 do task.wait(0.5) end
recount()
armed = true
end)
end
return {
open = function() ch.setBalance(attr("Shards", 0), true); refresh() end,
showTab = ch.showTab,
}
end
return W