-
Notifications
You must be signed in to change notification settings - Fork 4
/
convert.lua
140 lines (136 loc) · 3.67 KB
/
convert.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/lua
--[[
Convert a graphical dungeon into one for Pico-8 Lua Anteform.
X = wall block = 3
# = pit = 2
~ = under pit = 1
space = open area = 0
Note that pits and under pits are now ignored by Anteform. We're using
them to track location of ladders for ease-of-use, but they don't
really do anything. Likewise periods can be used to map out points
of interest, but they get ignored by this converter.
--]]
dungeons = {
-- Greybeard's Treasure Cave
{
{
"XXXXXXXXXX",
"X X",
"XXXXX XX X",
"X X X#X",
"X X XX XXX",
"X XX X X X",
"X X X",
"X XXXXXX X",
"X~ X",
"XXXXXXXXXX"
}, {
"XXXXXXXXXX",
"X #X",
"XX XX XXXX",
"X XX ~X",
"X X XX X",
"X XXXX X X",
"X X X",
"XXX XX X X",
"X X X",
"XXXXXXXXXX"
}, {
"XXXXXXXXXX",
"X X X~X",
"X X XX X X",
"X X X",
"X XX XXX X",
"X X XX X",
"X X X X",
"XXX XXXX X",
"X .X X",
"XXXXXXXXXX"
}
},
-- Vetusaur Mine
{
{
"XXXXXXXXXX",
"X X X~X",
"X XX X",
"X #X XX X",
"X XXXX X",
"X X XXXX",
"XXX X X",
"X XXXX X",
"X#X X ~X",
"XXXXXXXXXX"
}, {
"XXXXXXXXXX",
"X X X",
"X XXX X",
"X X~XXXX X",
"X X X",
"XXXXX X X",
"X X X X",
"X X X XXXX",
"X~X X",
"XXXXXXXXXX"
}
},
-- Formika Mine
{
{
"XXXXXXXXXX",
"X X X X",
"X X X X",
"X X XXXX X",
"X X X X",
"X XXXX X X",
"X X# X X",
"X XXXXXX X",
"X ~ X",
"XXXXXXXXXX"
}
}
}
-- Work dungeon by dungeon...
for dungeonIdx, dungeon in pairs(dungeons) do
-- Floor by floor...
print("levels={")
for floorIdx, floor in pairs(dungeon) do
if floorIdx == 1 then
print(' {')
end
-- We actually ignore the outer edge. It's required to be wall.
table.remove(floor, 1)
table.remove(floor)
-- We turn each row of each floor into a single hex code.
for rowIdx, row in pairs(floor) do
local rowNum = 0
local row = string.sub(row, 2, -2)
local comma = ''
for colNum = 1, #row do
local col = string.sub(row, colNum, colNum)
rowNum = rowNum * 4
if col == 'X' then
-- it's a wall
rowNum = rowNum + 3
elseif col == '#' then
-- it's a pit
rowNum = rowNum + 2
elseif col == '~' then
-- it's the underside of a pit
rowNum = rowNum + 1
end
-- anything that isn't an X, #, or ~ gets ignored.
if rowIdx < #floor then
comma = ','
end
end
print(string.format(" 0x%04x%s", rowNum, comma))
end
local nextGroupStart = ''
if floorIdx < #dungeon then
nextGroupStart = ',{'
end
print(string.format(' }%s', nextGroupStart))
end
print('}\n')
end