From 5bc5b3dc5cbf24d6464cbfecb0135d8bac73abd1 Mon Sep 17 00:00:00 2001 From: gahusb Date: Mon, 8 Jun 2026 01:07:46 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8D=B1=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EC=83=9D=EC=84=B1=EA=B8=B0:=20=ED=95=B8=EB=93=A4?= =?UTF-8?q?=EB=9F=AC=20=ED=81=B4=EB=A1=9C=EC=A0=80=ED=99=94=C2=B7=EC=B9=B4?= =?UTF-8?q?=EB=93=9C=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=8B=A8=EC=9D=BC?= =?UTF-8?q?=ED=99=94=C2=B7=EC=B9=B4=EB=93=9C=ED=81=B4=EB=A6=AD=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=C2=B7pcall=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- tools/gen-slaydeck.mjs | 104 ++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 42 deletions(-) diff --git a/tools/gen-slaydeck.mjs b/tools/gen-slaydeck.mjs index 6da250d..690ab3f 100644 --- a/tools/gen-slaydeck.mjs +++ b/tools/gen-slaydeck.mjs @@ -193,6 +193,14 @@ function upsertUi() { sp.ImageRUID = { DataId: '' }; sp.Type = 1; sp.Color = cards[i - 1].tint; + sp.RaycastTarget = true; + const comps = card.jsonString['@components']; + if (!comps.some((c) => c['@type'] === 'MOD.Core.ButtonComponent')) { + comps.push(button()); + } + if (!card.componentNames.includes('MOD.Core.ButtonComponent')) { + card.componentNames += ',MOD.Core.ButtonComponent'; + } card.jsonString.enable = true; card.jsonString.visible = true; @@ -383,12 +391,18 @@ function writeCodeblocks() { prop('number', 'Turn', '0'), prop('number', 'TweenEventId', '0'), prop('any', 'EndTurnHandler'), + prop('any', 'Cards'), ], [ method('OnBeginPlay', `self:StartCombat()`), method('StartCombat', `self.MaxEnergy = 3 self.Turn = 0 self.DiscardPile = {} self.Hand = {} +self.Cards = { + Strike = { name = "타격", cost = 1, desc = "피해 6", kind = "Attack" }, + Defend = { name = "방어", cost = 1, desc = "방어도 5", kind = "Skill" }, + Bash = { name = "강타", cost = 2, desc = "피해 10", kind = "Attack" }, +} self.DrawPile = { "Strike", "Strike", "Strike", "Strike", "Strike", "Defend", "Defend", "Defend", "Defend", "Bash" } self:Shuffle(self.DrawPile) self:BindButtons() @@ -400,15 +414,20 @@ for i = #list, 2, -1 do \tlocal j = math.random(1, i) \tlist[i], list[j] = list[j], list[i] end`, [{ Type: 'any', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'list' }]), - method('BindButtons', `local buttonEntity = _EntityService:GetEntityByPath("/ui/DefaultGroup/DeckHud/EndTurnButton") -if buttonEntity == nil or buttonEntity.ButtonComponent == nil then -\treturn + method('BindButtons', `local endTurn = _EntityService:GetEntityByPath("/ui/DefaultGroup/DeckHud/EndTurnButton") +if endTurn ~= nil and endTurn.ButtonComponent ~= nil then + if self.EndTurnHandler ~= nil then + endTurn:DisconnectEvent(ButtonClickEvent, self.EndTurnHandler) + self.EndTurnHandler = nil + end + self.EndTurnHandler = endTurn:ConnectEvent(ButtonClickEvent, function() self:EndPlayerTurn() end) end -if self.EndTurnHandler ~= nil then -\tbuttonEntity:DisconnectEvent(ButtonClickEvent, self.EndTurnHandler) -\tself.EndTurnHandler = nil -end -self.EndTurnHandler = buttonEntity:ConnectEvent(ButtonClickEvent, self.EndPlayerTurn)`), +for i = 1, 5 do + local cardEntity = _EntityService:GetEntityByPath("/ui/DefaultGroup/CardHand/Card" .. tostring(i)) + if cardEntity ~= nil and cardEntity.ButtonComponent ~= nil then + cardEntity:ConnectEvent(ButtonClickEvent, function() self:PlayCard(i) end) + end +end`), method('StartPlayerTurn', `self.Turn = self.Turn + 1 self.Energy = self.MaxEnergy self:DrawCards(5) @@ -460,43 +479,22 @@ for i = 1, 5 do \tend end self:RenderPiles()`, [{ Type: 'boolean', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'animate' }]), - method('ApplyCardVisual', `local name = cardId -local cost = 0 -local desc = "" -local kind = "Skill" -if cardId == "Strike" then -\tname = "타격" -\tcost = 1 -\tdesc = "피해 6" -\tkind = "Attack" -elseif cardId == "Defend" then -\tname = "방어" -\tcost = 1 -\tdesc = "방어도 5" -\tkind = "Skill" -elseif cardId == "Bash" then -\tname = "강타" -\tcost = 2 -\tdesc = "피해 10" -\tkind = "Attack" + method('ApplyCardVisual', `local c = self.Cards[cardId] +if c == nil then + c = { name = cardId, cost = 0, desc = "", kind = "Skill" } end -self:SetText("/ui/DefaultGroup/CardHand/Card" .. tostring(slot) .. "/Cost", tostring(cost)) -self:SetText("/ui/DefaultGroup/CardHand/Card" .. tostring(slot) .. "/Name", name) -self:SetText("/ui/DefaultGroup/CardHand/Card" .. tostring(slot) .. "/Desc", desc) +self:SetText("/ui/DefaultGroup/CardHand/Card" .. tostring(slot) .. "/Cost", tostring(c.cost)) +self:SetText("/ui/DefaultGroup/CardHand/Card" .. tostring(slot) .. "/Name", c.name) +self:SetText("/ui/DefaultGroup/CardHand/Card" .. tostring(slot) .. "/Desc", c.desc) local cardEntity = _EntityService:GetEntityByPath("/ui/DefaultGroup/CardHand/Card" .. tostring(slot)) if cardEntity ~= nil and cardEntity.SpriteGUIRendererComponent ~= nil then -\tlocal ok = false -\tlocal color = nil -\tif kind == "Attack" then -\t\tok, color = pcall(function() return Color(0.86, 0.42, 0.38, 1) end) -\telseif kind == "Skill" then -\t\tok, color = pcall(function() return Color(0.42, 0.55, 0.85, 1) end) -\telse -\t\tok, color = pcall(function() return Color(0.46, 0.68, 0.52, 1) end) -\tend -\tif ok == true and color ~= nil then -\t\tcardEntity.SpriteGUIRendererComponent.Color = color -\tend + if c.kind == "Attack" then + cardEntity.SpriteGUIRendererComponent.Color = Color(0.86, 0.42, 0.38, 1) + elseif c.kind == "Skill" then + cardEntity.SpriteGUIRendererComponent.Color = Color(0.42, 0.55, 0.85, 1) + else + cardEntity.SpriteGUIRendererComponent.Color = Color(0.46, 0.68, 0.52, 1) + end end`, [ { Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' }, { Type: 'string', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'cardId' }, @@ -530,6 +528,28 @@ end, 1 / 60)`, [ { Type: 'any', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'toPos' }, { Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'duration' }, ]), + method('PlayCard', `if self.Hand == nil then + return +end +local cardId = self.Hand[slot] +if cardId == nil then + return +end +local c = self.Cards[cardId] +if c == nil then + return +end +if self.Energy < c.cost then + self:Toast("에너지가 부족합니다") + return +end +self.Energy = self.Energy - c.cost +self:Toast(c.name .. " — " .. c.desc) +table.remove(self.Hand, slot) +table.insert(self.DiscardPile, cardId) +self:RenderHand(false) +self:RenderPiles()`, [{ Type: 'number', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'slot' }]), + method('Toast', `log(message)`, [{ Type: 'string', DefaultValue: null, SyncDirection: 0, Attributes: [], Name: 'message' }]), ]); for (const m of combat.ContentProto.Json.Methods) { m.ExecSpace = 6;