diff options
Diffstat (limited to 'life.lua')
-rw-r--r-- | life.lua | 57 |
1 files changed, 56 insertions, 1 deletions
@@ -178,13 +178,68 @@ gol.formats[".gol"] = function (fname) end end +gol.formats[".cell"] = function (fname) + return false -- stub +end + +gol.formats[".rle"] = function (fname) + local parser = require "parsers/rle" + return parser(fname) +end + +function gol.extend_area(rows) + local tmp = {} + local c = mplife.setup.current + + context.writestatus("simpleslides","Extending area horizontally by "..c.extendx.."cells.") + context.writestatus("simpleslides","Extending area vertically by "..c.extendy.."cells.") + + if c.extendy > 0 then + local row = "" + for i=1, rows[1]:len(), 1 do -- buildling an empty row + row = row.."0" + end + + for i=1, c.extendy, 1 do + table.insert(tmp, row) + end + + for _, r in ipairs(rows) do + table.insert(tmp, r) + end + + for i=1, c.extendy, 1 do + table.insert(tmp, row) + end + end + + if c.extendx > 0 then + local add = "" + for i=1, c.extendx, 1 do -- building an empty pre- and suffix + add = add .. "0" + end + + for n, r in ipairs(tmp) do + tmp[n] = add .. r .. add + end + end + + --for i,j in ipairs(tmp) do print(i,j) end + return tmp +end function gol.parse_file (fname) local p_suf = P"." * (1-P".")^3 * -P(1) local p_fn = (1-p_suf)^1 * C(p_suf) local suffix = p_fn:match(fname) or ".gol" -- assume .gol format as default - return gol.formats[suffix] ( fname ) + local tmp = gol.formats[suffix] ( fname ) + if mplife and mplife.setup.current and ( + mplife.setup.current.extendx > 0 or + mplife.setup.current.extendy > 0) then + tmp = gol.extend_area(tmp) + end + return tmp end |