Skip to content

Commit 07dbbe9

Browse files
committed
added foil effect via decals
1 parent d8ba6fd commit 07dbbe9

2 files changed

Lines changed: 34 additions & 74 deletions

File tree

loader.lua

Lines changed: 32 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ BOOSTER_INDEX_URL =
1313
BASE_BOOSTER_FILE_URL =
1414
"https://raw.githubusercontent.com/Morgenmvffel/tts-mtg-booster-creator/refs/heads/master/booster"
1515

16-
BOOSTER_IMAGE_URL = "https://raw.githubusercontent.com/Morgenmvffel/tts-mtg-booster-creator/refs/heads/master/Booster.png"
16+
BOOSTER_IMAGE_URL = "https://steamusercontent-a.akamaihd.net/ugc/12048320118311789698/728EE5247F5FE466F92DAAC0E9997225CD3E8865/"
17+
FOIL_EFFECT_URL = "https://steamusercontent-a.akamaihd.net/ugc/18215652933654632959/A843EB4C96D1CE5E339D66F48A414D671B2CB4CC/"
1718

1819
MAINDECK_POSITION_OFFSET = {2, 0.2, -0.2}
1920
TOKENS_POSITION_OFFSET = {1.9, 0.2, 0.9}
@@ -73,7 +74,7 @@ advanced = false
7374
cardBackInput = ""
7475
languageInput = ""
7576
forceLanguage = false
76-
enableTokenButtons = false
77+
enableFoil = true
7778
blowCache = false
7879
pngGraphics = true
7980
spawnEverythingFaceDown = false
@@ -127,7 +128,7 @@ local function stringToBool(s)
127128
end
128129

129130
------ CARD SPAWNING
130-
local function jsonForCardFace(face, position, rotationY, flipped)
131+
local function jsonForCardFace(face, position, rotationY, flipped, foil)
131132
local rotation = self.getRotation()
132133

133134
local rotZ = rotation.z
@@ -179,68 +180,25 @@ local function jsonForCardFace(face, position, rotationY, flipped)
179180
Type = 0
180181
}
181182

182-
if enableTokenButtons and face.tokenData and face.tokenData[1] and face.tokenData[1].name and
183-
string.len(face.tokenData[1].name) > 0 then
184-
json.LuaScript = [[function onLoad(saved_data)
185-
if saved_data ~= "" then
186-
tokens = JSON.decode(saved_data)
187-
else
188-
tokens = {}
189-
end
190-
191-
local pZ = -1.04
192-
for i, token in ipairs(tokens) do
193-
self.createButton({label = token.name,
194-
tooltip = "Create " .. token.name .. "\n" .. token.oracleText,
195-
click_function = "gt" .. i,
196-
function_owner = self,
197-
width = math.max(400, 40 * string.len(token.name) + 40),
198-
height = 100,
199-
color = {1, 1, 1, 0.5},
200-
hover_color = {1, 1, 1, .7},
201-
font_color = {0, 0, 0, 2},
202-
position = {.5, 0.5, pZ},
203-
font_size = 75})
204-
pZ = pZ + 0.28
205-
end
206-
end
207-
208-
function onSave()
209-
return JSON.encode(tokens)
210-
end
183+
if enableFoil and foil then
184+
json.LuaScript = [[
211185
212-
function gt1() getToken(1) end
213-
function gt2() getToken(2) end
214-
function gt3() getToken(3) end
215-
function gt4() getToken(4) end
216-
217-
function getToken(i)
218-
token = tokens[i]
219-
spawnObject({
220-
type = "Card",
221-
sound = false,
222-
rotation = self.getRotation(),
223-
position = self.positionToWorld({-2.2,0.1,0}),
224-
scale = self.getScale(),
225-
callback_function = (function(obj)
226-
obj.memo = ""
227-
obj.setName(token.name)
228-
obj.setDescription(token.oracleText)
229-
obj.setCustomObject({
230-
face = token.front,
231-
back = token.back
232-
})
233-
if (parent) then
234-
parent.call("CAddButtons",{obj, self})
235-
end
236-
end)
237-
})
238-
end
239-
]]
186+
decal = {
187+
name = "Foil",
188+
url = "https://steamusercontent-a.akamaihd.net/ugc/18215652933654632959/A843EB4C96D1CE5E339D66F48A414D671B2CB4CC/",
189+
position = Vector(0, 0.25, 0),
190+
rotation = Vector(90, 0, 0),
191+
scale = Vector(-2.14, -3.06, 1)
192+
}
240193
241-
json.LuaScriptState = JSON.encode(face.tokenData)
194+
function onLoad(saved_data)
195+
if self.getDecals() == nil then
196+
self.addDecal(decal)
197+
log("added Decal")
198+
end
199+
end
200+
]]
242201
end
243-
244202
return json
245203
end
246204

@@ -261,12 +219,12 @@ local function spawnCard(faces, position, rotation, flipped, onFullySpawned)
261219
flipped = true
262220
end
263221

264-
local jsonFace1 = jsonForCardFace(faces[1], position, rotation, flipped)
222+
local jsonFace1 = jsonForCardFace(faces[1], position, rotation, flipped, false)
265223

266224
if #faces > 1 then
267225
jsonFace1.States = {}
268226
for i = 2, (#(faces)) do
269-
local jsonFaceI = jsonForCardFace(faces[i], position, rotation, flipped)
227+
local jsonFaceI = jsonForCardFace(faces[i], position, rotation, flipped, false)
270228

271229
jsonFace1.States[tostring(i)] = jsonFaceI
272230
end
@@ -397,12 +355,12 @@ local function spawnBagWithCards(cards, bagName, position, flipped, onFullySpawn
397355
}}
398356

399357
-- Build the card JSON with States for multiple faces
400-
local jsonFace1 = jsonForCardFace(faces[1], position, 0, flipped)
358+
local jsonFace1 = jsonForCardFace(faces[1], position, 0, flipped, card.foil)
401359

402360
if #faces > 1 then
403361
jsonFace1.States = {}
404362
for j = 2, #faces do
405-
local jsonFaceJ = jsonForCardFace(faces[j], position, 0, flipped)
363+
local jsonFaceJ = jsonForCardFace(faces[j], position, 0, flipped, card.foil)
406364
jsonFace1.States[tostring(j)] = jsonFaceJ
407365
end
408366
end
@@ -880,7 +838,7 @@ local function loadDeck(cardIDs, deckName, onComplete, onError)
880838

881839
-- Spawn each pack pile side by side
882840
for packIndex, cardGroup in pairs(packs) do
883-
print("Spawning pack" .. packIndex)
841+
-- print("Spawning pack " .. packIndex)
884842
local relativeOffset = {
885843
MAINDECK_POSITION_OFFSET[1] + (packIndex - 1) * POSITION_SPACING,
886844
MAINDECK_POSITION_OFFSET[2],
@@ -1005,8 +963,9 @@ local function parseCardId(cardId)
1005963

1006964
local setCode = parts[1] or ""
1007965
local collectorNum = parts[2] or ""
966+
local isFoil = (parts[3] == "foil")
1008967

1009-
return setCode, collectorNum
968+
return setCode, collectorNum, isFoil
1010969
end
1011970

1012971
local function queryGeneratePacks(numPacks, onSuccess, onError)
@@ -1022,13 +981,14 @@ local function queryGeneratePacks(numPacks, onSuccess, onError)
1022981
local drawn = drawCardsFromSheet(packInfo.sheets[sheetName], count)
1023982

1024983
for _, rawId in ipairs(drawn) do
1025-
local setCode, collectorNum = parseCardId(rawId)
984+
local setCode, collectorNum, isFoil = parseCardId(rawId)
1026985

1027986
table.insert(allCards, {
1028987
count = 1,
1029988
name = "",
1030989
setCode = setCode,
1031990
collectorNum = collectorNum,
991+
foil = isFoil,
1032992
packIndex = packIndex,
1033993
sheetName = sheetName,
1034994
packName = packInfo.name
@@ -1096,7 +1056,7 @@ function generatePacks()
10961056

10971057
queryGeneratePacks(numberOfPacks, function(cardIDs, deckName)
10981058
loadDeck(cardIDs, deckName, function()
1099-
printToAll("Pack import complete!")
1059+
printToAll("Pack generation complete!")
11001060
lock = false
11011061
end, function(e)
11021062
printToAll("Pack load error: " .. tostring(e))
@@ -1330,8 +1290,8 @@ function mtgdl__onForceLanguageInput(_, value, _)
13301290
forceLanguage = stringToBool(value)
13311291
end
13321292

1333-
function mtgdl__onTokenButtonsInput(_, value, _)
1334-
enableTokenButtons = stringToBool(value)
1293+
function mtgdl__onFoilInput(_, value, _)
1294+
enableFoil = stringToBool(value)
13351295
end
13361296

13371297
function mtgdl__onBlowCacheInput(_, value, _)

ui.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Panel position="0 0 0">
1010
<Text>Card Back</Text>
1111
<InputField position = "18 0 0" onEndEdit="mtgdl__onCardBackInput" placeholder="Enter card back URL"></InputField>
12-
<Toggle position="185 0 0" onValueChanged="mtgdl__onTokenButtonsInput" isOn="false">Token Buttons</Toggle>
12+
<Toggle position="185 0 0" onValueChanged="mtgdl__onFoilInput" isOn="true">Add Foil Cards</Toggle>
1313
</Panel>
1414

1515
<Panel position="0 -40 0">
@@ -27,4 +27,4 @@
2727
<Panel position="300 -80 0">
2828
<Toggle position="-70 0 0" onValueChanged="mtgdl__onFaceDownInput" fontSize="10">Spaw everything face-down</Toggle>
2929
</Panel>
30-
</Panel>
30+
</Panel>

0 commit comments

Comments
 (0)