Kistaro Windrider
5fef5bad00
commitb91ebeb775
Author: Kistaro Windrider <kistaro@gmail.com> Date: Wed Dec 20 13:33:00 2023 -0800 fix boss it works now except for a square being drawn in the shield. good enough commitab687f8f6d
Author: Kistaro Windrider <kistaro@gmail.com> Date: Wed Dec 20 13:23:29 2023 -0800 adjust spawning now it runs for a little tiny bit! commitbef95df6a1
Author: Kistaro Windrider <kistaro@gmail.com> Date: Wed Dec 20 13:18:20 2023 -0800 typo commit24435a3c15
Author: Kistaro Windrider <kistaro@gmail.com> Date: Wed Dec 20 13:18:01 2023 -0800 move guns before ships commit0c3a36f1fd
Author: Kistaro Windrider <kistaro@gmail.com> Date: Wed Dec 20 13:15:34 2023 -0800 defer zap_gun creation until it exists commita39c419e5f
Author: Kistaro Windrider <kistaro@gmail.com> Date: Wed Dec 20 13:13:51 2023 -0800 fix mknew commit9ef762268f
Author: Kistaro Windrider <kistaro@gmail.com> Date: Wed Dec 20 13:04:13 2023 -0800 many assorted syntax errors commite50f516b11
Author: Kistaro Windrider <kistaro@gmail.com> Date: Wed Dec 20 12:00:34 2023 -0800 allow strings when spawning guns commitf9e28fa0e2
Author: Kistaro Windrider <kistaro@gmail.com> Date: Wed Dec 20 11:59:20 2023 -0800 fix missing paren commit38a054dec1
Author: Kistaro Windrider <kistaro@gmail.com> Date: Wed Dec 20 11:48:08 2023 -0800 candidate conversion to csv for level format commitfd391ff3bc
Author: Kistaro Windrider <kistaro@gmail.com> Date: Wed Dec 20 11:40:11 2023 -0800 use _ENV to get rid of level_events and spawns commitfbd9f97429
Author: Kistaro Windrider <kistaro@gmail.com> Date: Wed Dec 20 11:33:59 2023 -0800 maybe fix the level parser commit2a61e8b5d6
Author: Kistaro Windrider <kistaro@gmail.com> Date: Sun Oct 15 21:09:12 2023 -0700 partial conversion to CSV-based levels, does not run yet commit4ccbe1dc35
Author: Kistaro Windrider <kistaro@gmail.com> Date: Fri Oct 13 01:02:43 2023 -0700 okay honestly this all can and should just be CSVs commitb536d2c987
Author: Kistaro Windrider <kistaro@gmail.com> Date: Sun Oct 8 00:41:24 2023 -0700 base for representing a level as a string
62 lines
1.3 KiB
Lua
62 lines
1.3 KiB
Lua
pico-8 cartridge // http://www.pico-8.com
|
|
version 41
|
|
__lua__
|
|
-- the parser
|
|
|
|
parser = {}
|
|
mknew(parser)
|
|
|
|
-- calls parse_into with a nop
|
|
-- emit function.
|
|
function parser:parse(str)
|
|
self:parse_into(str, function() end)
|
|
end
|
|
|
|
-- read a file of commands and
|
|
-- execute them, emitting the
|
|
-- results from each call into
|
|
-- `emit` as a table per row.
|
|
--
|
|
-- a "command" is a method on
|
|
-- self. a row alternates
|
|
-- commands with args. when
|
|
-- calling a command, it also
|
|
-- gets a table of previous
|
|
-- results as the first arg.
|
|
-- args are split on ','.
|
|
function parser:parse_into(str, emit)
|
|
for row in all(split(str, "\n")) do
|
|
local prev = {}
|
|
local sectors = split(row, ":")
|
|
for i=1,#sectors,2 do
|
|
local x = self[sectors[i]](self, prev, usplit(sectors[i+1]))
|
|
if (x) add(prev, x)
|
|
end
|
|
emit(prev)
|
|
end
|
|
end
|
|
|
|
-- saves prev[sel] as self.name.
|
|
-- if sel is unspecified, saves
|
|
-- all of prev (as a table).
|
|
function parser:saveas(prev, name, sel)
|
|
self[name] = sel and prev[sel] or prev
|
|
end
|
|
|
|
-- returns its args, ignoring
|
|
-- prev. Used to stuff things
|
|
-- into prev. args are packed
|
|
-- if there's multiple.
|
|
function parser:val(_, ...)
|
|
local ret := pack(...)
|
|
if (#ret == 1) return ret[1]
|
|
return ret
|
|
end
|
|
|
|
function parser:bind(_, fn, ...)
|
|
local f = self[fn]
|
|
return function()
|
|
f(...)
|
|
end
|
|
end
|