honeylisp/editor/init.fnl

65 lines
2.4 KiB
Fennel

(require :vendor.lite.main)
(local util (require :lib.util))
(local TileView (require :editor.tileedit))
(local MapEditView (require :editor.mapedit))
(local PortraitView (require :editor.portraitedit))
(local {: cmd-predicate} (util.require :editor.imstate))
(local core (require :core))
(local command (require :core.command))
(local keymap (require :core.keymap))
(local common (require :core.common))
(let [commands {}]
(each [_ name (ipairs [:tile :portrait :font])]
(local cls (require (.. "editor." name "edit")))
(tset commands (.. "honeylisp:" name "-editor") (fn []
(local node (core.root_view:get_active_node))
(node:add_view (cls)))))
(command.add nil commands))
(command.add nil {
"honeylisp:map-editor" (fn []
(core.command_view:enter "Open Map"
(fn [text item]
(local node (core.root_view:get_active_node))
(node:add_view (MapEditView (or (and item item.text) text))))
(fn [text]
(local files [])
(each [_ item (pairs core.project_files)]
(when (and (= item.type :file) (item.filename:find "^game/map%d+%.json"))
(table.insert files item.filename)))
(common.fuzzy_match files text))))
})
(command.add (cmd-predicate :editor.gfxedit) {
"graphics-editor:save" (fn [] (core.active_view:save) (core.log "Saved"))
"graphics-editor:reload" (fn [] (core.active_view:reload) (core.log "Reloaded"))
"graphics-editor:next-tile" #(core.active_view:select-rel 1)
"graphics-editor:previous-tile" #(core.active_view:select-rel -1)
})
(command.add (cmd-predicate :editor.tileedit) {
"tileedit:copy"
#(system.set_clipboard (: (core.active_view:tile) :tohex))
"tileedit:paste"
#(when (= (length (system.get_clipboard)) 64)
(core.active_view:update-tile (: (system.get_clipboard) :fromhex)))
})
(keymap.add {
"ctrl+s" "graphics-editor:save"
"alt+r" "graphics-editor:reload"
"left" "graphics-editor:previous-tile"
"right" "graphics-editor:next-tile"
"ctrl+c" "tileedit:copy"
"ctrl+v" "tileedit:paste"
})
(fn inline-eval [eval]
(let [ldoc core.active_view.doc
(aline acol bline bcol) (ldoc:get_selection)
inject #(ldoc:insert bline bcol (eval $1))]
(if (and (= aline bline) (= acol bcol))
(inject (ldoc:get_text aline 1 aline 10000000))
(inject (ldoc:get_text aline acol bline bcol)))))
{: inline-eval}