Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions objects/AllPlayerCards.15bb07/BorrowedTime3.0db666.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"IgnoreFoW": false,
"LayoutGroupSortIndex": 0,
"Locked": false,
"LuaScript": "",
"LuaScript": "require(\"playercards/cards/BorrowedTime\")",
"LuaScriptState": "",
"MeasureMovement": false,
"Name": "Card",
Expand All @@ -43,7 +43,9 @@
"Sticky": true,
"Tags": [
"Asset",
"PlayerCard"
"PlayerCard",
"CardWithHelper",
"i18n_XML"
],
"Tooltip": true,
"Transform": {
Expand All @@ -58,5 +60,5 @@
"scaleZ": 1
},
"Value": 0,
"XmlUI": ""
"XmlUI": "\u003cInclude src=\"playercards/BorrowedTime.xml\"/\u003e"
}
8 changes: 8 additions & 0 deletions src/Global/Global.ttslua
Original file line number Diff line number Diff line change
Expand Up @@ -5121,6 +5121,14 @@ function addUseName(obj, params)
end
end

function multiplyScale(obj, mult)
Wait.frames(function()
if obj ~= nil then
obj.setScale(obj.getScale():scale(Vector(mult, 1, mult)))
end
end, 5)
end

---------------------------------------------------------
-- Utility functions
---------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions src/Global/i18nData.ttslua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ I18N_DATA = {
["zh_CN"] = "选项",
["zh_TW"] = "選項",
},
["CARD_BorrowedTime_remove_text"] = {
["de"] = "Remove clicks",
["en"] = "Remove clicks",
["es"] = "Remove clicks",
["fr"] = "Remove clicks",
["it"] = "Remove clicks",
["ko"] = "Remove clicks",
["nl"] = "Remove clicks",
["pt"] = "Remove clicks",
["ru"] = "Remove clicks",
["zh_CN"] = "Remove clicks",
["zh_TW"] = "Remove clicks",
},
["CARD_DarkHorse_text"] = {
["de"] = "☐ Keine Ressource",
["en"] = "☐ Skip resource",
Expand Down
85 changes: 85 additions & 0 deletions src/playercards/cards/BorrowedTime.ttslua
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
require("playercards/CardsWithHelper")
local SearchLib = require("util/SearchLib")
local TokenManagerApi = require("tokens/TokenManagerApi")

-- intentionally global
hasXML = true
isHelperEnabled = false

function updateSave()
self.script_state = JSON.encode({ isHelperEnabled = isHelperEnabled })
end

function onLoad(savedData)
if savedData and savedData ~= "" then
local loadedData = JSON.decode(savedData)
isHelperEnabled = loadedData.isHelperEnabled
if isHelperEnabled then updateDisplay() end
end
end

function searchSelfForTokens()
local clickableResourceCounter
local foundTokens = 0

for _, obj in ipairs(SearchLib.onObject(self, "isTileOrToken", 0.8)) do
local memo = obj.getMemo()
if memo == "click" or memo == "resource" then
foundTokens = foundTokens + math.abs(obj.getQuantity())
elseif memo == "resourceCounter" then
foundTokens = obj.getVar("val")
clickableResourceCounter = obj
break
end
end
return foundTokens, clickableResourceCounter
end

function removeClicks(player)
local foundTokens, clickableResourceCounter = searchSelfForTokens()

if clickableResourceCounter then
clickableResourceCounter.call("updateVal", 0)
else
for _, obj in ipairs(SearchLib.onObject(self, "isTileOrToken", 0.8)) do
local memo = obj.getMemo()
if memo == "click" or memo == "resource" then
obj.destruct()
end
end
end

if foundTokens > 0 then
addAction(player, foundTokens)
else
broadcastToColor("No clicks found!", player.color)
end
end

function addAction(player, foundTokens)
-- only spawn a maximum of 3 action tokens
local numTokens = math.min(foundTokens, 3)
local positions = getSpawnPositions(numTokens)

for i = 1, numTokens do
TokenManagerApi.spawnToken(positions[i], "universalActionAbility", self.getRotation(), "multiplyScale", 0.6, nil, "Temporary")
end

broadcastToColor("Spawning " .. numTokens .. " temporary action token(s).", player.color)
end

-- work out the token spawn positions
local baseOffset = 0.3
local offsetList = { -2, -1, 0, 1, 2 }
local countToIndex = { { 3 }, { 2, 4 }, { 1, 3, 5 } }

function getSpawnPositions(count)
local positions = {}

for _, index in ipairs(countToIndex[count]) do
local pos = Vector(offsetList[index] * baseOffset, 1, 0.75)
table.insert(positions, self.positionToWorld(pos))
end

return positions
end
16 changes: 16 additions & 0 deletions xml/playercards/BorrowedTime.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Button active="false"
id="Helper"
height="300"
width="1200"
rotation="0 0 180"
scale="0.1 0.1 1"
position="0 128 -40"
padding="50"
onClick="removeClicks"
color="#AA1C0080">
<Text id="CARD_BorrowedTime_remove_text"
text="Remove clicks"
color="White"
resizeTextForBestFit="true"
resizeTextMaxSize="500"/>
</Button>
Loading