From 0c8a8cf8d861bc4ef3162e45e8b58d2f0173d2f7 Mon Sep 17 00:00:00 2001 From: equa Date: Sun, 18 Apr 2021 09:57:30 -0500 Subject: nanpa wan commit of the last two days: working cellular automata and rendering, prototype system, etc --- lib/main.fnl | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 lib/main.fnl (limited to 'lib/main.fnl') diff --git a/lib/main.fnl b/lib/main.fnl new file mode 100644 index 0000000..4a9d26e --- /dev/null +++ b/lib/main.fnl @@ -0,0 +1,69 @@ +(local lume (require :vendor.lume)) +(local proto (require :lib.proto)) +(local state (require :lib.state)) +(local game (require :lib.game)) + +;; i am thinking we could actually do a really hacky thing (modules add themselves +;; to this list) with this later but +;; i'm not sure if it'd be worth it (it'd require those dependency loops maybe) +;; TODO: ^ +(local hotswap-modules + [:lib.cells + :lib.game + :lib.main]) + +;; the +;; oh thats why it doesnt work lmao + +(fn love.load [] + (global the-state (state.init game)) + (global messages {}) + (print "a")) + +(fn love.draw [] + (match (pcall #(state.draw the-state)) + (true x) nil + (false x) (do + (love.graphics.reset) + (print (.. "draw \n" x)) + (love.graphics.print (.. "draw: \n" x)))) + (love.graphics.reset) + (love.graphics.print (love.timer.getFPS)) + (when true ;; debug stuff + (love.graphics.print (table.concat + (lume.map messages #$.msg) + "\n") + 0 + 40) + (each [i v (lume.ripairs messages)] + (if (= v.ticks 0) + (table.remove messages i) + (set v.ticks (- v.ticks 1)))))) + +;; TODO: we need a better way to display errors at runtime for updates too +(fn love.update [] + ;; TODO: make state changes actually possible + (match (pcall #(state.update the-state)) + (true x) nil + (false x) (do + (print (.. "update: \n" x)) + (table.insert messages + {:ticks 1 + :msg (.. "update: \n" x)})))) + +(fn love.keypressed [key scancode repeat] + ;; (print key scancode repeat) + (when (= key "r") + (each [k v (lume.ripairs messages)] + (when (= v.type :reload-error) + (table.remove messages k))) + (print (.. (if (love.keyboard.isDown :lshift) :hard :soft) + " reloading...")) + (each [_ v (ipairs hotswap-modules)] + (match (lume.hotswap v) + (nil x) (table.insert messages + {:ticks -1 + :type :reload-error + :msg (.. "can't reload module " v "\n" x)}))) + (when (love.keyboard.isDown :lshift) + (love.load)))) -- cgit 1.3.0-6-gf8a5