-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.lua
63 lines (57 loc) · 1.11 KB
/
test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
args = {...}
function split(str, pat)
local t = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
return t
end
file = args[1]..".txt"
path = dfhack.getDFPath().."/hack/scripts/spells/"..file
iofile = io.open(path,"r")
read = iofile:read("*all")
iofile:close()
reada = split(read,',')
x = {}
y = {}
t = {}
xi = 0
yi = 1
for i,v in ipairs(reada) do
if split(v,'\n')[1] ~= v then
xi = 1
yi = yi + 1
else
xi = xi + 1
end
if v == 'X' or v == '\nX' then
x0 = xi
y0 = yi
end
if v == 'X' or v == '\nX' or v == '1' or v == '\n1' then
t[i] = true
else
t[i] = false
end
x[i] = xi
y[i] = yi
end
rx = math.max(table.unpack(x))
ry = math.max(table.unpack(y))
for i,_ in ipairs(x) do
x[i] = x[i] - x0 + 121
y[i] = y[i] - y0 + 146
t[tostring(x[i])..'_'..tostring(y[i])] = t[i]
end
printall(t)