2020-10-29 02:59:47 +00:00
|
|
|
(local util (require :lib.util))
|
2020-10-12 15:48:14 +00:00
|
|
|
(local TileView (require :editor.tileedit))
|
2020-10-19 00:13:26 +00:00
|
|
|
(local MapEditView (require :editor.mapedit))
|
2021-01-17 02:40:04 +00:00
|
|
|
(local ScreenEditView (require :editor.screenedit))
|
2020-11-22 03:50:11 +00:00
|
|
|
(local PortraitView (require :editor.portraitedit))
|
2020-10-29 02:59:47 +00:00
|
|
|
(local {: cmd-predicate} (util.require :editor.imstate))
|
2020-10-12 15:48:14 +00:00
|
|
|
(local core (require :core))
|
|
|
|
(local command (require :core.command))
|
|
|
|
(local keymap (require :core.keymap))
|
2020-12-02 13:33:27 +00:00
|
|
|
(local common (require :core.common))
|
2020-10-12 15:48:14 +00:00
|
|
|
|
2021-04-25 03:39:50 +00:00
|
|
|
(require :editor.8bitsy)
|
2021-06-19 01:31:21 +00:00
|
|
|
(require :presentation.commands)
|
2021-04-25 03:39:50 +00:00
|
|
|
|
2020-11-23 00:44:56 +00:00
|
|
|
(let [commands {}]
|
2021-04-24 02:54:28 +00:00
|
|
|
(each [_ name (ipairs [:tile :portrait :font :brush :map])]
|
2020-11-23 00:44:56 +00:00
|
|
|
(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))
|
2020-10-12 15:48:14 +00:00
|
|
|
|
2021-01-17 02:40:04 +00:00
|
|
|
(local fileeditors
|
2021-04-24 02:54:28 +00:00
|
|
|
{:screen {:view ScreenEditView :filefilter "^game/.*%.screen"}})
|
2021-01-17 02:40:04 +00:00
|
|
|
|
|
|
|
(each [type {: view : filefilter} (pairs fileeditors)]
|
|
|
|
(command.add nil
|
|
|
|
{(.. "honeylisp:" type "-editor") (fn []
|
|
|
|
(core.command_view:enter (.. "Open " type)
|
|
|
|
(fn [text item]
|
|
|
|
(local node (core.root_view:get_active_node))
|
|
|
|
(node:add_view (view (or (and item item.text) text))))
|
|
|
|
(fn [text]
|
|
|
|
(local files [])
|
|
|
|
(each [_ item (pairs core.project_files)]
|
|
|
|
(when (and (= item.type :file) (item.filename:find filefilter))
|
|
|
|
(table.insert files item.filename)))
|
|
|
|
(common.fuzzy_match files text))))}))
|
2020-12-02 13:33:27 +00:00
|
|
|
|
2020-10-29 02:59:47 +00:00
|
|
|
(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))
|
2020-10-18 14:53:43 +00:00
|
|
|
"tileedit:paste"
|
2021-01-17 02:40:04 +00:00
|
|
|
#(when (= (length (system.get_clipboard)) (* (core.active_view:tilebytelen) 2))
|
2020-10-18 14:53:43 +00:00
|
|
|
(core.active_view:update-tile (: (system.get_clipboard) :fromhex)))
|
2020-10-12 15:48:14 +00:00
|
|
|
})
|
|
|
|
(keymap.add {
|
2020-10-29 02:59:47 +00:00
|
|
|
"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"
|
2020-10-19 00:13:26 +00:00
|
|
|
})
|
|
|
|
|
2021-04-18 15:59:04 +00:00
|
|
|
(command.add :editor.replview {
|
|
|
|
"repl:submit" #(core.active_view:submit)
|
|
|
|
})
|
|
|
|
|
|
|
|
(local ReplView (require :editor.replview))
|
|
|
|
(local repl (require :editor.repl))
|
|
|
|
(command.add nil {
|
|
|
|
"repl:create" (fn []
|
|
|
|
(local node (core.root_view:get_active_node))
|
|
|
|
(node:add_view (ReplView (repl.new)))
|
|
|
|
)
|
|
|
|
})
|
|
|
|
(keymap.add {
|
|
|
|
:return "repl:submit"
|
|
|
|
})
|
|
|
|
|
2020-11-08 20:36:38 +00:00
|
|
|
(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}
|