169 lines
4.7 KiB
Lua
169 lines
4.7 KiB
Lua
local json = require("json")
|
|
function tprint (tbl, indent)
|
|
if not indent then indent = 0 end
|
|
for k, v in pairs(tbl) do
|
|
formatting = string.rep(" ", indent) .. k .. ": "
|
|
if type(v) == "table" then
|
|
print(formatting)
|
|
tprint(v, indent+1)
|
|
else
|
|
print(formatting .. tostring(v))
|
|
end
|
|
end
|
|
end
|
|
|
|
function ListItems(dir)
|
|
if Dir_Exist(dir) then
|
|
temp=List_Files(dir) -- current directory if blank
|
|
if GetDirectory(dir)=="C:\\\n" then
|
|
a,b=string.find(temp,"C:\\",1,true)
|
|
a=a+2
|
|
else
|
|
a,b=string.find(temp,"..",1,true)
|
|
end
|
|
temp=string.sub(temp,a+2)
|
|
list=StringLineToTable(temp)
|
|
temp=string.sub(temp,1,list[#list-2])
|
|
slist=lines(temp)
|
|
table.remove(slist,1)
|
|
table.remove(slist,#slist)
|
|
temp={}
|
|
temp2={}
|
|
for i=1,#slist do
|
|
table.insert(temp,string.sub(slist[i],40,-1))
|
|
end
|
|
return temp
|
|
else
|
|
print("Directory does not exist")
|
|
return nil
|
|
end
|
|
end
|
|
|
|
function lines(str)
|
|
local t = {}
|
|
local function helper(line) table.insert(t, line) return "" end
|
|
helper((str:gsub("(.-)\r?\n", helper)))
|
|
return t
|
|
end
|
|
|
|
function StringLineToTable(s)
|
|
local t = {} -- table to store the indices
|
|
local i = 0
|
|
while true do
|
|
i = string.find(s, "\n", i+1) -- find 'next' newline
|
|
if i == nil then return t end
|
|
table.insert(t, i)
|
|
end
|
|
end
|
|
|
|
function GetDirectory(dir,flop)
|
|
s=List_Files(dir)
|
|
drive=string.sub(string.match(s,"drive.."),-1)
|
|
local t = {} -- table to store the indices
|
|
local i = 0
|
|
while true do
|
|
i = string.find(s, "\n", i+1) -- find 'next' newline
|
|
if i == nil then
|
|
a,b=string.find(s,drive..":\\",1,true)
|
|
main = string.gsub(string.sub(s,a,t[4]), "\n", "")
|
|
if flop then
|
|
main=main:gsub("%\\", "/")
|
|
end
|
|
return main
|
|
end
|
|
table.insert(t, i)
|
|
end
|
|
end
|
|
|
|
function List_Files(dir)
|
|
if not(dir) then dir="" end
|
|
local f = io.popen("dir \""..dir.."\"")
|
|
if f then
|
|
return f:read("*a")
|
|
else
|
|
print("failed to read")
|
|
end
|
|
end
|
|
|
|
function GetFiles(dir)
|
|
local temp2={}
|
|
local dirs=ListItems(dir)
|
|
for i=1,#dirs do
|
|
if Dir_Exist(string.gsub(GetDirectory(dir).."\\"..dirs[i], "\n", "")) then
|
|
else
|
|
table.insert(temp2,dirs[i])
|
|
end
|
|
end
|
|
return temp2
|
|
end
|
|
|
|
function Dir_Exist(strFolderName)
|
|
local fileHandle, strError = io.open(strFolderName.."\\*.*","r")
|
|
if fileHandle ~= nil then
|
|
io.close(fileHandle)
|
|
return true
|
|
else
|
|
if string.match(strError,"No such file or directory") then
|
|
return false
|
|
else
|
|
return true
|
|
end
|
|
end
|
|
end
|
|
|
|
function GetDirectories(dir)
|
|
temp2={}
|
|
dirs=ListItems(dir)
|
|
for i=1,#dirs do
|
|
if Dir_Exist(string.gsub(GetDirectory(dir).."\\"..dirs[i], "\n", "")) then
|
|
table.insert(temp2,dirs[i])
|
|
end
|
|
end
|
|
return temp2
|
|
end
|
|
|
|
local id = 0
|
|
|
|
local cards = {}
|
|
for _, dir in pairs(GetDirectories("cards")) do
|
|
for _, card in pairs(GetFiles("cards/"..dir)) do
|
|
id = id + 1
|
|
print("Processing card: cards/"..dir.."/"..card)
|
|
table.insert(cards,{
|
|
ID = id,
|
|
UUID = "", -- Generated during game
|
|
Name = (card:gsub("_"," "):gsub(".png","")),
|
|
Source = "assets/cards/" .. dir .. "/" .. card,
|
|
Count = 0,
|
|
Default_Pack = dir,
|
|
Rune_Cost = 0,
|
|
Attack_Cost = 0,
|
|
Insight_Cost = 0,
|
|
Night = false,
|
|
Day = false,
|
|
Honor = 0,
|
|
Type = {
|
|
Base = "Hero/Construct/Monster/Dreamscape/Temple",
|
|
Faction = "Mechana,Void,Enlightened,Lifebound",
|
|
Token = false,
|
|
Ongoing = false,
|
|
Transformation_Source = "",
|
|
},
|
|
Unbanishable = false,
|
|
Effects = {
|
|
"Gain(#,'Rune,Attack,Insight,Honor',target)",
|
|
"Draw(#)",
|
|
"Shuffle(#)",
|
|
"Discard(#, target)",
|
|
"AdjustCost(#,'Rune,Attack,Insight',target)",
|
|
"Aquire(#,'Rune,Attack,Insight')",
|
|
"XasX('Rune,Attack,Insight', 'Rune,Attack,Insight')",
|
|
"Temple(type)",
|
|
"Banish(#, target)",
|
|
"TopDeck(#,target)"
|
|
}
|
|
})
|
|
end
|
|
end
|
|
|
|
json.encode_file("card_data/cards.json", cards) |