honeylisp/editor/8bitsy.fnl

60 lines
2.9 KiB
Plaintext
Raw Permalink Normal View History

(local util (require :lib.util))
(local actions (require :editor.actions))
(local {: textbox : dropdown : textfield : label : under : right-of : reform : group-wrapper} (util.require :editor.imgui))
(local files (require :game.files))
(local lume (require :lib.lume))
(local style (require :core.style))
(actions.register :say
(fn [action form i]
(let [characters (lume.map (or files.game.portraits []) #$1.label)
character (or action.character (. characters 1))
lines (or action.lines [])
character (dropdown (under form {:tag [:say :char i] :w form.w}) character characters)
line1 (textbox (under form {:tag [:say :line1 i] :w form.w}) (or (. lines 1) ""))
line2 (textbox (under form {:tag [:say :line2 i] :w form.w}) (or (. lines 2) ""))
line3 (textbox (under form {:tag [:say :line3 i] :w form.w}) (or (. lines 3) ""))
line4 (textbox (under form {:tag [:say :line4 i] :w form.w}) (or (. lines 4) ""))]
(set action.character character)
(util.nested-tset action [:lines 1] (line1:sub 1 33))
(util.nested-tset action [:lines 2] (line2:sub 1 33))
(util.nested-tset action [:lines 3] (line3:sub 1 33))
(util.nested-tset action [:lines 4] (line4:sub 1 33))))
(fn [action vm]
(local {: say} (require :bitsy.defs))
(say action.character (table.unpack (lume.map action.lines #($1:upper))))))
2021-04-25 15:54:12 +00:00
(actions.register :warp
(fn [action form i]
(let [g (group-wrapper form)
maps (icollect [imap _ (ipairs files.game.levels)] (.. :map imap))
2021-04-25 15:54:12 +00:00
map (or action.map (. maps 1))
map (g dropdown (under form {:tag [:warp :map i] :w (- (/ form.w 2) form.xpad)}) map maps)
position-string (g textbox (right-of form {:tag [:warp :loc i] :w form.w}) (string.format "%x" (or action.position 0)))
2021-04-25 15:54:12 +00:00
position (or (tonumber position-string 16) action.position)]
(set action.map map)
(set action.position position)
(g)))
2021-04-25 15:54:12 +00:00
(fn [action vm]
(values :move-to-responder action.position :lit action.map :map-player-yx-ptr :set :lit action.map :next-level :set)))
(actions.register-const :move-here :move-to-responder)
(actions.register-const :disappear :disappear)
2021-04-25 15:54:12 +00:00
2021-05-06 01:09:40 +00:00
(actions.register :set-flag
(fn [action form i]
(let [g (group-wrapper form)
2021-05-06 01:09:40 +00:00
options (lume.concat
[{:label "<Yes>" :value 0xffff} {:label "<No>" :value 0}]
(icollect [_ flag (ipairs files.game.flags)] {:label flag :value (.. :cond- flag)}))
rhs (or action.rhs (. options 1))]
(g label (reform form) "Set ")
(set action.flag (g dropdown (right-of form {:tag [:set-flag :flag i] :w (* 100 SCALE)}) action.flag files.game.flags))
(g label (right-of form) " to ")
(set action.rhs (g dropdown (right-of form {:tag [:set-flag :rhs i] :w (* 100 SCALE)}) rhs options))
(g)))
2021-05-06 01:09:40 +00:00
(fn [action vm]
(values action.rhs.value (.. :cond-var- action.flag) :set)))
{}