From 3e333c3d2dd48fab58aad115c9fe587bb189bc02 Mon Sep 17 00:00:00 2001 From: dscarpac Date: Thu, 11 Jan 2024 15:55:32 -0600 Subject: [PATCH 1/3] added button to reshuffle encounter discard pile into deck --- objects/MythosArea.9f334f.json | 2 +- src/core/MythosArea.ttslua | 21 +++++++++++++++++++++ xml/MythosArea.xml | 10 ++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 xml/MythosArea.xml diff --git a/objects/MythosArea.9f334f.json b/objects/MythosArea.9f334f.json index 1eeead24..6565bb79 100644 --- a/objects/MythosArea.9f334f.json +++ b/objects/MythosArea.9f334f.json @@ -82,5 +82,5 @@ "scaleZ": 6.5 }, "Value": 0, - "XmlUI": "" + "XmlUI": "\u003cInclude src=\"MythosArea.xml\"/\u003e" } diff --git a/src/core/MythosArea.ttslua b/src/core/MythosArea.ttslua index a4f0f719..3b0cd774 100644 --- a/src/core/MythosArea.ttslua +++ b/src/core/MythosArea.ttslua @@ -201,6 +201,27 @@ function reshuffleEncounterDeck(params) Wait.time(function() isReshuffling = false end, 1) end +function discardIntoDeck() + --flag to avoid multiple calls + if isReshuffling then return end + isReshuffling = true + + -- flip deck and then shuffle + local discardPile = searchLib.atPosition(ENCOUNTER_DISCARD_POSITION, "isCardOrDeck") + if #discardPile > 0 then + local deck = discardPile[1] + if not deck.is_face_down then deck.flip() end + deck.setPositionSmooth(Vector(ENCOUNTER_DECK_POS) + Vector(0, 2, 0), false, true) + --wait until deck is in place .75 seconds, then shuffle + broadcastToAll("Shuffled encounter discard into deck.", "White") + Wait.time(function() searchLib.atPosition(ENCOUNTER_DECK_POS, "isCardOrDeck")[1].shuffle() end, .75) + else + broadcastToAll("Encounter discard pile is already empty.", "Red") + end + + -- disable flag + Wait.time(function() isReshuffling = false end, 1) +end --------------------------------------------------------- -- helper functions --------------------------------------------------------- diff --git a/xml/MythosArea.xml b/xml/MythosArea.xml new file mode 100644 index 00000000..80631181 --- /dev/null +++ b/xml/MythosArea.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file From 86f2329f5a150483780e8b181abee873dd43f222 Mon Sep 17 00:00:00 2001 From: dscarpac Date: Fri, 12 Jan 2024 14:33:32 -0600 Subject: [PATCH 2/3] made adjustments to merge with current encounter reshuffle function --- src/core/MythosArea.ttslua | 60 ++++++++++++++------------------------ xml/MythosArea.xml | 2 +- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/src/core/MythosArea.ttslua b/src/core/MythosArea.ttslua index 3b0cd774..7814d3f7 100644 --- a/src/core/MythosArea.ttslua +++ b/src/core/MythosArea.ttslua @@ -134,13 +134,6 @@ end function getEncounterDeck() local searchResult = searchLib.atPosition(ENCOUNTER_DECK_POS, "isCardOrDeck") - for _, obj in ipairs(searchResult) do - if obj.type == 'Deck' then - return obj - end - end - - -- if no deck was found, return the first hit (a card) if #searchResult > 0 then return searchResult[1] end @@ -151,6 +144,7 @@ function drawEncounterCard(params) local encounterDeck = getEncounterDeck() if encounterDeck then + reshuffledAlready = false local card if encounterDeck.type == "Deck" then card = encounterDeck.takeObject() @@ -160,7 +154,14 @@ function drawEncounterCard(params) actualEncounterCardDraw(card, params) else -- nothing here, time to reshuffle - reshuffleEncounterDeck(params) + if reshuffledAlready == true then + reshuffledAlready = false + -- print something? + return + end + reshuffleEncounterDeck() -- if there is no discard pile either, reshuffleEncounterDeck will give an error message already + reshuffledAlready = true + drawEncounterCard(params) end end @@ -180,41 +181,24 @@ function actualEncounterCardDraw(card, params) deckLib.placeOrMergeIntoDeck(card, pos, { 0, rotY, faceUpRotation }) end -function reshuffleEncounterDeck(params) - -- flag to avoid multiple calls - if isReshuffling then return end - isReshuffling = true - - -- shuffle and flip deck, draw card after completion - local searchResult = searchLib.atPosition(ENCOUNTER_DISCARD_POSITION, "isCardOrDeck") - if #searchResult > 0 then - local deck = searchResult[1] - if not deck.is_face_down then deck.flip() end - deck.shuffle() - deck.setPositionSmooth(Vector(ENCOUNTER_DECK_POS) + Vector(0, 2, 0), false, true) - Wait.time(function() actualEncounterCardDraw(deck.takeObject({ index = 0 }), params) end, 0.5) - else - printToAll("Couldn't find encounter discard pile to reshuffle.", { 1, 0, 0 }) - end - - -- disable flag - Wait.time(function() isReshuffling = false end, 1) -end - -function discardIntoDeck() +function reshuffleEncounterDeck() --flag to avoid multiple calls if isReshuffling then return end isReshuffling = true - - -- flip deck and then shuffle + local encounterDeck = getEncounterDeck() local discardPile = searchLib.atPosition(ENCOUNTER_DISCARD_POSITION, "isCardOrDeck") + if #discardPile > 0 then - local deck = discardPile[1] - if not deck.is_face_down then deck.flip() end - deck.setPositionSmooth(Vector(ENCOUNTER_DECK_POS) + Vector(0, 2, 0), false, true) - --wait until deck is in place .75 seconds, then shuffle - broadcastToAll("Shuffled encounter discard into deck.", "White") - Wait.time(function() searchLib.atPosition(ENCOUNTER_DECK_POS, "isCardOrDeck")[1].shuffle() end, .75) + local discardDeck = discardPile[1] + if not discardDeck.is_face_down then discardDeck.setRotation({0, -90, 180}) end --flips discard pile + if encounterDeck == nil then + discardDeck.setPosition(Vector(ENCOUNTER_DECK_POS) + Vector({0, 1, 0})) + discardDeck.shuffle() + else + encounterDeck.putObject(discardDeck) + encounterDeck.shuffle() + end + broadcastToAll("Shuffled encounter discard into deck.", "White") else broadcastToAll("Encounter discard pile is already empty.", "Red") end diff --git a/xml/MythosArea.xml b/xml/MythosArea.xml index 80631181..07de2c8e 100644 --- a/xml/MythosArea.xml +++ b/xml/MythosArea.xml @@ -4,7 +4,7 @@ height="74" width="74"> - + \ No newline at end of file From e8269ed69c0b5fdea45b21f412d9b99b2ebbdac8 Mon Sep 17 00:00:00 2001 From: dscarpac Date: Sun, 14 Jan 2024 16:34:05 -0600 Subject: [PATCH 3/3] coding and button appearance updates --- src/core/MythosArea.ttslua | 9 +++++---- xml/MythosArea.xml | 13 +++---------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/core/MythosArea.ttslua b/src/core/MythosArea.ttslua index 7814d3f7..b9b94001 100644 --- a/src/core/MythosArea.ttslua +++ b/src/core/MythosArea.ttslua @@ -156,7 +156,6 @@ function drawEncounterCard(params) -- nothing here, time to reshuffle if reshuffledAlready == true then reshuffledAlready = false - -- print something? return end reshuffleEncounterDeck() -- if there is no discard pile either, reshuffleEncounterDeck will give an error message already @@ -182,7 +181,7 @@ function actualEncounterCardDraw(card, params) end function reshuffleEncounterDeck() - --flag to avoid multiple calls + -- flag to avoid multiple calls if isReshuffling then return end isReshuffling = true local encounterDeck = getEncounterDeck() @@ -190,7 +189,9 @@ function reshuffleEncounterDeck() if #discardPile > 0 then local discardDeck = discardPile[1] - if not discardDeck.is_face_down then discardDeck.setRotation({0, -90, 180}) end --flips discard pile + if not discardDeck.is_face_down then --flips discard pile + discardDeck.setRotation({0, -90, 180}) + end if encounterDeck == nil then discardDeck.setPosition(Vector(ENCOUNTER_DECK_POS) + Vector({0, 1, 0})) discardDeck.shuffle() @@ -198,7 +199,7 @@ function reshuffleEncounterDeck() encounterDeck.putObject(discardDeck) encounterDeck.shuffle() end - broadcastToAll("Shuffled encounter discard into deck.", "White") + broadcastToAll("Shuffled encounter discard into deck.", "White") else broadcastToAll("Encounter discard pile is already empty.", "Red") end diff --git a/xml/MythosArea.xml b/xml/MythosArea.xml index 07de2c8e..bbe1cde1 100644 --- a/xml/MythosArea.xml +++ b/xml/MythosArea.xml @@ -1,10 +1,3 @@ - - - - - - - \ No newline at end of file + + +