progress on /apps/demos/crawl
This commit is contained in:
parent
bd3b090f6f
commit
80a4ae3d0e
@ -1,24 +1,27 @@
|
|||||||
@map
|
@map
|
||||||
-- Grid of entities defined by @classes.
|
-- Grid of symbols defined by @classes section.
|
||||||
#####
|
#####
|
||||||
#.@.#
|
#.@.#
|
||||||
#...#
|
#...#
|
||||||
##.##
|
##.######
|
||||||
#...#
|
#...X...#
|
||||||
#...#
|
#./.#####
|
||||||
#####
|
#####
|
||||||
|
|
||||||
|
|
||||||
@classes
|
@classes
|
||||||
-- Defines classes under symbols, which could have properties.
|
-- Defines classes under symbols, which could have properties attached.
|
||||||
# wall
|
# wall
|
||||||
. void
|
. floor
|
||||||
test : this
|
|
||||||
@ player_spawn
|
@ player_spawn
|
||||||
unique :
|
unique :
|
||||||
face : south
|
face : south
|
||||||
hold : torch
|
hold : torch
|
||||||
|
X door
|
||||||
|
open_on : sg_torch0
|
||||||
|
/ torch
|
||||||
|
emit : sg_torch0
|
||||||
|
|
||||||
@meta
|
@meta
|
||||||
-- Arbitrary sections could be defined with values pairs.
|
-- Arbitrary sections could be defined with value pairs.
|
||||||
description : Test Level! Just two square rooms.
|
description : Test Level! Just two square rooms and a tunnel opened by lever.
|
||||||
|
@ -4,10 +4,15 @@ function load_level(file)
|
|||||||
local f = file_read { file = file }
|
local f = file_read { file = file }
|
||||||
|
|
||||||
local result = {
|
local result = {
|
||||||
classes = {},
|
classes = {
|
||||||
glossary = {},
|
void = { },
|
||||||
|
},
|
||||||
|
glossary = {
|
||||||
|
[" "] = "void",
|
||||||
|
},
|
||||||
grid = {},
|
grid = {},
|
||||||
map = {},
|
map = {},
|
||||||
|
size = { x = 0, y = 0 },
|
||||||
}
|
}
|
||||||
|
|
||||||
-- iterate over lines
|
-- iterate over lines
|
||||||
@ -20,21 +25,23 @@ function load_level(file)
|
|||||||
if #line == 0 or line:find("^%-%-%s*") then
|
if #line == 0 or line:find("^%-%-%s*") then
|
||||||
goto skip
|
goto skip
|
||||||
-- start new section
|
-- start new section
|
||||||
elseif line:find("^@%a+") then
|
elseif line:find("^@%g+") then
|
||||||
section = line:sub(2); subsection = "none"
|
section = line:sub(2); subsection = "none"
|
||||||
-- decode map one line at a time
|
-- decode map one line at a time
|
||||||
elseif section == "map" then
|
elseif section == "map" then
|
||||||
local l = #result.map + 1
|
local l = #result.map + 1
|
||||||
|
if result.size.x < #line then
|
||||||
|
result.size.x = #line
|
||||||
|
end
|
||||||
result.map[l] = {}
|
result.map[l] = {}
|
||||||
for i = 1, #line do
|
for i = 1, #line do
|
||||||
result.map[l][i] = line:sub(i,i)
|
result.map[l][i] = line:sub(i,i)
|
||||||
end
|
end
|
||||||
assert(#result.map[1] == #result.map[l])
|
|
||||||
-- templates to expand
|
-- templates to expand
|
||||||
elseif section == "classes" then
|
elseif section == "classes" then
|
||||||
-- properties
|
-- properties
|
||||||
if line:find("^ %a+") then
|
if line:find("^ %g+") then
|
||||||
local _, _, property, value = line:find("^ (%a+)%s?:%s?(.*)")
|
local _, _, property, value = line:find("^ (%g+)%s?:%s?(.*)")
|
||||||
result.classes[subsection][property] = value
|
result.classes[subsection][property] = value
|
||||||
goto skip
|
goto skip
|
||||||
end
|
end
|
||||||
@ -45,7 +52,7 @@ function load_level(file)
|
|||||||
result.glossary[symbol] = classname
|
result.glossary[symbol] = classname
|
||||||
subsection = classname
|
subsection = classname
|
||||||
elseif section ~= "none" then
|
elseif section ~= "none" then
|
||||||
local _, _, property, value = line:find("^(%a+)%s?:%s?(.*)")
|
local _, _, property, value = line:find("^(%g+)%s?:%s?(.*)")
|
||||||
if result[section] == nil then
|
if result[section] == nil then
|
||||||
result[section] = {}
|
result[section] = {}
|
||||||
end
|
end
|
||||||
@ -58,15 +65,23 @@ function load_level(file)
|
|||||||
-- post process
|
-- post process
|
||||||
for y = 1, #result.map do
|
for y = 1, #result.map do
|
||||||
result.grid[y] = {}
|
result.grid[y] = {}
|
||||||
for x = 1, #result.map[y] do
|
for x = 1, result.size.x do
|
||||||
local class = result.classes[result.glossary[result.map[y][x]]]
|
-- past defined for line
|
||||||
|
local symbol
|
||||||
|
if x > #result.map[y] then symbol = " "
|
||||||
|
else symbol = result.map[y][x]
|
||||||
|
end
|
||||||
|
local class = result.classes[result.glossary[symbol]]
|
||||||
if class["unique"] ~= nil then
|
if class["unique"] ~= nil then
|
||||||
class.position = { x = x, y = y }
|
class.position = { x = x, y = y }
|
||||||
end
|
end
|
||||||
result.grid[y][x] = class
|
result.grid[y][x] = class
|
||||||
|
::continue::
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
result.size.y = #result.map
|
||||||
|
|
||||||
print(result.meta.description)
|
print(result.meta.description)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
Loading…
Reference in New Issue
Block a user