From 13ca11c70e5cee897457a4f72b0485aae5ba7d28 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Fri, 1 Mar 2019 12:44:12 +0100 Subject: [PATCH] Begins refactoring of layout parser to accomodate more layout details --- data/layoutparser.lua | 88 +++++++++++------- data/pitlayouts.dat | 210 +++++++++++++++++++++--------------------- 2 files changed, 158 insertions(+), 140 deletions(-) diff --git a/data/layoutparser.lua b/data/layoutparser.lua index 1215f98..8ca9e43 100644 --- a/data/layoutparser.lua +++ b/data/layoutparser.lua @@ -7,7 +7,7 @@ local function readLayoutFile(file) local cleanData = "" for i=1, #layoutfile do local c = layoutfile:sub(i+1, i+1) - if c == "#" or c == "-" then + if c ~= " " and c ~= "\n" and c ~= "\r" then cleanData = cleanData .. c end end @@ -21,16 +21,59 @@ local function readLayoutFile(file) local row = row % 12 if not matrix[layout] then matrix[layout] = {} end if not matrix[layout][col] then matrix[layout][col] = {} end - if c == "#" then - matrix[layout][col][row] = true - else - matrix[layout][col][row] = false - end + matrix[layout][col][row] = c end return matrix; end +local function getTileStateFor(matrix, i, j, c) + local above = matrix[i][j-1] == c; + local below = matrix[i][j+1] == c; + local left = matrix[i-1][j] == c; + local right = matrix[i+1][j] == c; + + local above_left = matrix[i-1][j-1] == c; + local above_right = matrix[i+1][j-1] == c; + local below_left = matrix[i-1][j+1] == c; + local below_right = matrix[i+1][j+1] == c; + + return above, below, left, right, above_left, above_right, below_left, below_right +end + +local function setPitTile(room, matrix, i, j) + if matrix[i][j] ~= "p" then + return + end + + local above, below, left, right, above_left, above_right, below_left, below_right = getTileStateFor(matrix, i, j, "p"); + + room.decor[i][j] = nil + if not above_left and not above_right and left and right and above then + room.tiles[i][j] = pits.innermid + elseif not above_left and left and above then + room.tiles[i][j] = pits.innerleft + elseif not above_right and right and above then + room.tiles[i][j] = pits.innerright + elseif not left and not above and not right then + room.tiles[i][j] = pits.topcrevice + elseif not left and not right then + room.tiles[i][j] = pits.bottomcrevice + elseif not left and not above then + room.tiles[i][j] = pits.topleft + elseif not right and not above then + room.tiles[i][j] = pits.topright + elseif not left then + room.tiles[i][j] = pits.left + elseif not right then + room.tiles[i][j] = pits.right + elseif not above then + room.tiles[i][j] = pits.top + else + room.tiles[i][j] = pits.center + end +end + local module = {} function module.load_textures(map) local t_pit0 = add_texture(map, "Objects/Pit0.png") @@ -53,9 +96,9 @@ function module.load_textures(map) end function module.add_pits_to_room(room) - if CURRENT_LEVEL < 2 or random(5) ~= 1 then - return false - end + --if CURRENT_LEVEL < 2 or random(5) ~= 1 then + --return false + --end local matrix = readLayoutFile("pitlayouts.dat") @@ -63,32 +106,7 @@ function module.add_pits_to_room(room) matrix = matrix[random(#matrix)] for i=2,13 do for j=2,10 do - if matrix[i][j] then - room.decor[i][j] = nil - if not matrix[i-1][j-1] and not matrix[i+1][j-1] and matrix[i-1][j] and matrix[i+1][j] and matrix[i][j-1] then - room.tiles[i][j] = pits.innermid - elseif not matrix[i-1][j-1] and matrix[i-1][j] and matrix[i][j-1] then - room.tiles[i][j] = pits.innerleft - elseif not matrix[i+1][j-1] and matrix[i+1][j] and matrix[i][j-1] then - room.tiles[i][j] = pits.innerright - elseif not matrix[i-1][j] and not matrix[i][j-1] and not matrix[i+1][j] then - room.tiles[i][j] = pits.topcrevice - elseif not matrix[i-1][j] and not matrix[i+1][j] then - room.tiles[i][j] = pits.bottomcrevice - elseif not matrix[i-1][j] and not matrix[i][j-1] then - room.tiles[i][j] = pits.topleft - elseif not matrix[i+1][j] and not matrix[i][j-1] then - room.tiles[i][j] = pits.topright - elseif not matrix[i-1][j] then - room.tiles[i][j] = pits.left - elseif not matrix[i+1][j] then - room.tiles[i][j] = pits.right - elseif not matrix[i][j-1] then - room.tiles[i][j] = pits.top - else - room.tiles[i][j] = pits.center - end - end + setPitTile(room, matrix, i, j); end end diff --git a/data/pitlayouts.dat b/data/pitlayouts.dat index d545d9c..7ef223f 100644 --- a/data/pitlayouts.dat +++ b/data/pitlayouts.dat @@ -1,13 +1,13 @@ ---------------- ---------------- ---##--------##-- ---##--####--##-- --------##------- --------##------- --------##------- --------##------- ---##--####--##-- ---##--------##-- +--pp--------pp-- +--pp--pppp--pp-- +-------pp------- +-------pp------- +-------pp------- +-------pp------- +--pp--pppp--pp-- +--pp--------pp-- ---------------- ---------------- @@ -15,11 +15,11 @@ ---------------- ---------------- ---------------- ------##-##------ ------##-##------ +-----pp-pp------ +-----pp-pp------ ---------------- ------##-##------ ------##-##------ +-----pp-pp------ +-----pp-pp------ ---------------- ---------------- ---------------- @@ -27,12 +27,12 @@ ---------------- ---------------- ---------------- ---############-- +--pppppppppppp-- ---------------- ---------------- ---------------- ---------------- ---############-- +--pppppppppppp-- ---------------- ---------------- ---------------- @@ -40,194 +40,194 @@ ---------------- ---------------- ---------------- ---############-- +--pppppppppppp-- ---------------- ---############-- ---############-- +--pppppppppppp-- +--pppppppppppp-- ---------------- ---############-- +--pppppppppppp-- ---------------- ---------------- ---------------- ---------------- ---------------- ---############-- ---############-- +--pppppppppppp-- +--pppppppppppp-- ---------------- ---------------- ---------------- ---------------- ---############-- ---############-- +--pppppppppppp-- +--pppppppppppp-- ---------------- ---------------- ---------------- ---------------- --------#-------- -------###------- --------#-------- -------###------- -------###------- --------#-------- -------###------- --------#-------- +-------p-------- +------ppp------- +-------p-------- +------ppp------- +------ppp------- +-------p-------- +------ppp------- +-------p-------- ---------------- ---------------- ---------------- ---------------- ---############-- ---#----------#-- ---#----------#-- +--pppppppppppp-- +--p----------p-- +--p----------p-- ---------------- ---------------- ---#----------#-- ---#----------#-- ---############-- +--p----------p-- +--p----------p-- +--pppppppppppp-- ---------------- ---------------- ---------------- ---------------- ---############-- ---#----------#-- ---#-########-#-- -----#----------- ------------#---- ---#-########-#-- ---#----------#-- ---############-- +--pppppppppppp-- +--p----------p-- +--p-pppppppp-p-- +----p----------- +-----------p---- +--p-pppppppp-p-- +--p----------p-- +--pppppppppppp-- ---------------- ---------------- ---------------- ---------------- ---############-- ---#----------#-- ---#-###-####-#-- -----###---##---- -----#####-##---- ---#-#####-##-#-- ---#----------#-- ---############-- +--pppppppppppp-- +--p----------p-- +--p-ppp-pppp-p-- +----ppp---pp---- +----ppppp-pp---- +--p-ppppp-pp-p-- +--p----------p-- +--pppppppppppp-- ---------------- ---------------- ---------------- ---------------- ---##--------##-- ---##--------##-- +--pp--------pp-- +--pp--------pp-- ---------------- --------##------- --------##------- ---#----------#-- ---#----------#-- ---############-- +-------pp------- +-------pp------- +--p----------p-- +--p----------p-- +--pppppppppppp-- ---------------- ---------------- ---------------- ---------------- ---##--------##-- ---##--------##-- +--pp--------pp-- +--pp--------pp-- ---------------- --------##------- --------##------- +-------pp------- +-------pp------- ---------------- ---##--------##-- ---##--------##-- +--pp--------pp-- +--pp--------pp-- ---------------- ---------------- ---------------- ---------------- ---##--------##-- ---##--------##-- +--pp--------pp-- +--pp--------pp-- ---------------- ---------------- ---------------- ---------------- ---##--------##-- ---##--------##-- +--pp--------pp-- +--pp--------pp-- ---------------- ---------------- ---------------- ---------------- ---##---##---##-- ---##---##---##-- +--pp---pp---pp-- +--pp---pp---pp-- ---------------- ---------------- ---------------- ---------------- ---##---##---##-- ---##---##---##-- +--pp---pp---pp-- +--pp---pp---pp-- ---------------- ---------------- ---------------- ---------------- ---##---##---##-- ---##---##---##-- +--pp---pp---pp-- +--pp---pp---pp-- ---------------- ---##---##---##-- ---##---##---##-- +--pp---pp---pp-- +--pp---pp---pp-- ---------------- ---##---##---##-- ---##---##---##-- +--pp---pp---pp-- +--pp---pp---pp-- ---------------- ---------------- ---------------- ---------------- ----#----#----#-- ---##---##---##-- +---p----p----p-- +--pp---pp---pp-- ---------------- ----#----#----#-- ---##---##---##-- +---p----p----p-- +--pp---pp---pp-- ---------------- ----#----#----#-- ---##---##---##-- +---p----p----p-- +--pp---pp---pp-- ---------------- ---------------- ---------------- ---------------- ---##---##---##-- ---#----------#-- +--pp---pp---pp-- +--p----------p-- ---------------- ---#----##----#-- ---#----##----#-- +--p----pp----p-- +--p----pp----p-- ---------------- ---#----------#-- ---##---##---##-- +--p----------p-- +--pp---pp---pp-- ---------------- ---------------- ---------------- ---------------- ---##---##---##-- ---#----------#-- +--pp---pp---pp-- +--p----------p-- ---------------- ---#----------#-- ---#----------#-- +--p----------p-- +--p----------p-- ---------------- ---#----------#-- ---##---##---##-- +--p----------p-- +--pp---pp---pp-- ---------------- ---------------- ---------------- ---------------- ---##---##---##-- ---#----------#-- ------##--##----- ---#--#----#--#-- ---#--#----#--#-- ------##--##----- ---#----------#-- ---##---##---##-- +--pp---pp---pp-- +--p----------p-- +-----pp--pp----- +--p--p----p--p-- +--p--p----p--p-- +-----pp--pp----- +--p----------p-- +--pp---pp---pp-- ---------------- ----------------