timeline inspector, various cleanup
This commit is contained in:
parent
c1a849f593
commit
aa03b4515f
9 changed files with 44 additions and 21 deletions
|
|
@ -111,8 +111,8 @@
|
|||
(fn with-style [form ...]
|
||||
(form-defaults form :font style.font :color style.text :xpad style.padding.x :ypad style.padding.y ...))
|
||||
|
||||
(local form-preserved-keys (collect [_ key (ipairs [:view :x :y :font :color :xpad :ypad])] key true))
|
||||
(local style-preserved-keys (collect [_ key (ipairs [:view :x :y])] key true))
|
||||
(local form-preserved-keys (collect [_ key (ipairs [:view :x :y :font :color :xpad :ypad :actions])] key true))
|
||||
(local style-preserved-keys (collect [_ key (ipairs [:view :x :y :actions])] key true))
|
||||
(fn rebuild-form [form preserved-keys overrides]
|
||||
(if (and overrides overrides.into (not= overrides.into form))
|
||||
(rebuild-form (lume.extend (lume.clear overrides.into) form) preserved-keys overrides)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
(local style (require :core.style))
|
||||
(local lume (require :lib.lume))
|
||||
(local {: textbutton : under : group-wrapper} (util.require :editor.imgui))
|
||||
(local {: inspect} (util.require :inspector))
|
||||
(local repl (util.hot-table ...))
|
||||
|
||||
(fn repl.notify [listeners vals]
|
||||
|
|
|
|||
|
|
@ -27,8 +27,7 @@
|
|||
(table.insert self.log line))
|
||||
|
||||
(fn ReplView.append [self vals]
|
||||
(let [actions [#(when (textbutton $1 :R.V) (set self.conn.env.R.V $3) true)]]
|
||||
(self:append-line {:draw ReplView.draw-val : vals :states (icollect [_ (ipairs vals)] {: actions})})))
|
||||
(self:append-line {:draw #(self:draw-val $...) : vals :states (icollect [_ (ipairs vals)] {})}))
|
||||
|
||||
(fn ReplView.draw-cmd [{: x : y : w : view &as form} {: cmd} iline]
|
||||
(label form cmd)
|
||||
|
|
@ -39,10 +38,13 @@
|
|||
(when (textbutton (reform form {:x (+ x w (* -60 SCALE)) :into {}}) :!)
|
||||
(view:submit cmd))))
|
||||
|
||||
(fn ReplView.draw-val [{: w &as form} {: vals : states} iline]
|
||||
(fn ReplView.actions [self]
|
||||
[(fn [form state value] (when (textbutton form :R.V) (set self.conn.env.R.V value) true))])
|
||||
|
||||
(fn ReplView.draw-val [self {: w &as form} {: vals : states} iline]
|
||||
(let [g (group-wrapper form)]
|
||||
(each [i v (ipairs vals)]
|
||||
(g inspector.draw (under (g) {: w :tag [:repl-line iline]}) (. states i) v))
|
||||
(g inspector.draw (under (g) {: w :tag [:repl-line iline] :actions (self:actions)}) (. states i) v))
|
||||
(g)))
|
||||
|
||||
(fn ReplView.submit [self ?cmd]
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
(local repl (require :editor.repl))
|
||||
(local core (require :core))
|
||||
(local command (require :core.command))
|
||||
(local keymap (require :core.keymap))
|
||||
(local {: inspect} (require :inspector.debug))
|
||||
|
||||
(local gamemode (require :game.meta.mode))
|
||||
|
|
@ -16,13 +17,18 @@
|
|||
(node:add_view view)))
|
||||
|
||||
(command.add nil {
|
||||
"love:game" #(open-view (ModeView gamemode))
|
||||
"love:restart" #(vats.restart)
|
||||
"game:new-tab" #(open-view (ModeView gamemode))
|
||||
"game:reload" #(vats.reload)
|
||||
"game:restart" #(vats.restart)
|
||||
"timeline:last-5-seconds" #(inspect "Timeline" (vats.make-timeline (* 30 5)))
|
||||
"vat:snapshot-repl" #(let [vat (: (vats.get-game-vat) :new)]
|
||||
(open-view (ReplView (repl.new vat.env) (.. "Step " (tostring (vat:stepcount))))))
|
||||
"vat:live-repl" #(open-view (ReplView (repl.new (. (vats.get-game-vat) :env)) "Live"))
|
||||
})
|
||||
|
||||
(keymap.add {
|
||||
"alt+g" "game:reload"
|
||||
})
|
||||
|
||||
{}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
(local vats (require :game.meta.vats))
|
||||
(local dim (require :game.dim))
|
||||
(local lume (require :lib.lume))
|
||||
(local {: textbutton} (require :editor.imgui))
|
||||
|
||||
(fn is-tilemap? [o]
|
||||
(and (= (type o) :table) (= (getmetatable o) nil)
|
||||
|
|
@ -51,7 +52,9 @@
|
|||
(inspector.register :gamestate 50 is-gamestate?
|
||||
(fn [form state value]
|
||||
(when (= state.scale nil) (set state.scale 0.25))
|
||||
(draw-game-window form value {:scale state.scale})))
|
||||
(draw-game-window form value {:scale state.scale}))
|
||||
[(fn [form state value] (when (textbutton form :-) (set state.scale (/ state.scale 1.5))))
|
||||
(fn [form state value] (when (textbutton form :+) (set state.scale (* state.scale 1.5))))])
|
||||
|
||||
(fn draw-game-near-entity [form state entity]
|
||||
(draw-game-window form state {:x (- (. entity.pos 1) (* dim.halftile 4))
|
||||
|
|
|
|||
|
|
@ -7,19 +7,24 @@
|
|||
(local {: on-love-key-event : love-input : make-love-draw-env} (require :vat.lib.love))
|
||||
(local {: deepmerge} (require :lib.util))
|
||||
(local lume (require :lib.lume))
|
||||
(local {: textbutton} (require :editor.imgui))
|
||||
|
||||
(local game-vat
|
||||
(let [vat (Vat.new :tracked)
|
||||
module-vat (vat:extend-module-vat)]
|
||||
(vat:install-components
|
||||
{:game {:overrides {:inspectors
|
||||
{:game {:hooks {:reload (fn [self] (self:set-tick :game :tick))}
|
||||
:overrides {:inspectors
|
||||
(fn [f] (fn [self inspector]
|
||||
(let [{: state-inspectors} (require :game.meta.mapinspector)
|
||||
(let [actions [(fn [form state value] (when (textbutton form "reload") (self:reload) true))]
|
||||
{: state-inspectors} (require :game.meta.mapinspector)
|
||||
inspectors (icollect [_ inspect (ipairs state-inspectors)]
|
||||
{:label inspect
|
||||
: actions
|
||||
:inspect (fn [form state val] (inspector.proxy form state val.env.state {:inspector inspect}))})]
|
||||
(table.insert inspectors
|
||||
{:label :state
|
||||
: actions
|
||||
:inspect (fn [form state val] (inspector.proxy form state val.env.state))})
|
||||
(icollect [_ inspect (ipairs (f self inspector)) &into inspectors] inspect))))}}})
|
||||
(module-vat:inject (deepmerge {} multimethod basic-sandbox))
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
(let [get-kstate (fn [tbl k state]
|
||||
(when (= nil state.keys) (set state.keys {}))
|
||||
(when (= nil (?. state.keys k))
|
||||
(util.nested-tset state [:keys k] {:collapsed (= (type (. tbl k)) :table) :children {:actions state.actions}}))
|
||||
(util.nested-tset state [:keys k] {:collapsed (= (type (. tbl k)) :table) :children {}}))
|
||||
(. state.keys k))
|
||||
g (group-wrapper form)]
|
||||
(var empty true)
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
(set kstate.collapsed (not kstate.collapsed)))
|
||||
(if kstate.collapsed
|
||||
(g label (right-of form {:color style.syntax.comment :into {}}) "...")
|
||||
(g inspector.draw (right-of form {:w (when w (- w form.w)) :into {}}) kstate.children v))
|
||||
(g inspector.draw (right-of form {:w (when w (- w form.w)) :tag [form.tag k] :into {}}) kstate.children v))
|
||||
(g)))
|
||||
(when empty
|
||||
(g label (right-of form) "{}"))
|
||||
|
|
@ -47,7 +47,7 @@
|
|||
(when (= nil state.keys) (set state.keys {}))
|
||||
(g label (h form) "[")
|
||||
(each [i item (ipairs value)]
|
||||
(when (= nil (. state.keys i)) (tset state.keys i {:children {:actions state.actions}}))
|
||||
(when (= nil (. state.keys i)) (tset state.keys i {:children {}}))
|
||||
(g inspector.draw (h form) (. state.keys i :children) item))
|
||||
(g label (h form) "]")
|
||||
(g)))
|
||||
|
|
@ -72,7 +72,6 @@
|
|||
(when (= state.item-inspectors nil) (set state.item-inspectors (rebuild-list value)))
|
||||
(let [done (case (dropdown (reform form {: tag}) "[ITEMS]" state.item-inspectors)
|
||||
(selection true) (do (each [_ child-state (ipairs state.keys)] (tset child-state.children :inspector selection))
|
||||
(print (length value) (fv selection))
|
||||
true))]
|
||||
(when (and (active? form.view tag) (not was-active))
|
||||
(set state.item-inspectors (rebuild-list value))))))])
|
||||
|
|
|
|||
|
|
@ -76,16 +76,19 @@
|
|||
|
||||
(draw-action inspector.select-inspector)
|
||||
(draw-actions (inspector.actions state.inspector))
|
||||
(draw-actions state.actions)
|
||||
(draw-actions form.actions)
|
||||
|
||||
(under (ag) {:into form})))
|
||||
|
||||
(g #(tbcall inspector.inspect :inspect-error $...) (under form {: w : tag}) state value)
|
||||
(g #(tbcall inspector.inspect :inspect-error $...) (under form {: w : tag :actions form.actions}) state value)
|
||||
(g) (values)))
|
||||
|
||||
(fn inspector.proxy [form state value ?opts]
|
||||
(let [new-state (util.ensure state (or (?. ?opts :key) :proxy))]
|
||||
(case (?. ?opts :inspector) inspector (set new-state.inspector inspector))
|
||||
(inspector.draw form new-state value)))
|
||||
(let [inspect (?. ?opts :inspector)
|
||||
new-state (util.ensure state (or (?. ?opts :key) (inspector.name inspect) :proxy))]
|
||||
(if inspect
|
||||
(do (set new-state.inspector inspect)
|
||||
(inspector.inspect form new-state value))
|
||||
(inspector.draw form new-state value))))
|
||||
|
||||
inspector.hot
|
||||
|
|
|
|||
|
|
@ -87,4 +87,10 @@
|
|||
(self:insert-snapshot isnap vat (+ prev-snap.src-steplim stepcount) (+ prev-snap.tick 1))
|
||||
(self:build-snapshots isnap (when count (- count 1))))))))
|
||||
|
||||
(fn Timeline.__inspectors [self]
|
||||
(let [inspector (require :inspector)
|
||||
snapshots (setmetatable {} {:__index (fn [_ index] (?. self.snapshots index :vat))})]
|
||||
[{:label :snapshots
|
||||
:inspect (fn [form state value] (inspector.proxy form state snapshots))}]))
|
||||
|
||||
Timeline
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue