Make lanes explicit symbol views
This commit is contained in:
parent
fb38990090
commit
e459307a4a
22 changed files with 2183 additions and 2330 deletions
|
|
@ -1,28 +1,53 @@
|
|||
(ns arthur.events.lane-test
|
||||
(:require [cljs.test :refer [deftest is]]
|
||||
[arthur.domain.lane-test :as fixture]
|
||||
[arthur.domain.clip :as clip]
|
||||
[arthur.domain.correction :as correction]
|
||||
[arthur.domain.lane :as lane]
|
||||
[arthur.events.ui :as ui]
|
||||
[arthur.domain.history :as history]
|
||||
[arthur.domain.leaf :as leaf]
|
||||
[arthur.domain.symbol :as symbol]
|
||||
[arthur.domain.sequence-test :as fixture]
|
||||
[arthur.domain.span :as span]
|
||||
[arthur.events.ui :as ui]
|
||||
[arthur.footage.store :as store]
|
||||
[arthur.ui.timeline :as timeline]))
|
||||
[arthur.ui.timeline :as timeline]
|
||||
[re-frame.core :as rf]
|
||||
[re-frame.db :as rf-db]))
|
||||
|
||||
(deftest one-row-projects-all-cels-and-keeps-selection-addresses
|
||||
(deftest symbol-and-lane-creation-are-distinct-explicit-commands
|
||||
(letfn [(run [event key]
|
||||
(let [doc (clip/blank)
|
||||
id (store/install! {:clip doc :store {}} key)]
|
||||
(reset! rf-db/app-db {:clip/current id :paint/revision 0
|
||||
:ui {:open :main} :playback {:frame 0}})
|
||||
(rf/dispatch-sync event)
|
||||
(let [db @rf-db/app-db
|
||||
saved (:clip (store/entry id))
|
||||
[_ _ instance-id] (get-in db [:ui :selection])
|
||||
sid (get-in saved [:symbols :main :nodes instance-id :source :symbol])]
|
||||
{:db db :symbol (clip/symbol saved sid)})))]
|
||||
(let [{ordinary :symbol} (run [::ui/new-symbol :inside] "explicit-symbol")
|
||||
{lane :symbol lane-db :db} (run [::ui/new-lane] "explicit-lane")]
|
||||
(is (nil? (:display ordinary)) "new symbol means ordinary symbol")
|
||||
(is (= :lane (:display lane)) "only the lane command creates a lane")
|
||||
(is (some? (get-in lane-db [:ui :target]))
|
||||
"the new lane is aimed so drawing and pool drops can go into it"))))
|
||||
|
||||
(deftest an-explicit-lane-is-one-row-of-clips
|
||||
(let [doc (fixture/document)
|
||||
rows (timeline/rows doc :main #{})
|
||||
lane (first (filter :cels rows))]
|
||||
(is (= 2 (count rows)))
|
||||
lane (first (filter :lane? rows))]
|
||||
(is (= 2 (count rows)) "the lane row plus the span-less plate")
|
||||
(is (= [[0 4] [4 8] [8 12]] (mapv :span (:cels lane))))
|
||||
(is (= [[:node :main :a [:a]] [:node :main :b [:b]] [:node :main :insert [:insert]]]
|
||||
(mapv :select (:cels lane))))
|
||||
(is (= [0 6 12] (:keys lane)))
|
||||
(is (= 1 (count (filter :cels (timeline/rows doc :main #{[:girl]})))))))
|
||||
(is (= [[:node :main :a [:a]]
|
||||
[:node :main :b [:b]]
|
||||
[:node :main :insert [:insert]]]
|
||||
(mapv :select (:cels lane))))))
|
||||
|
||||
(deftest a-nested-selection-converts-the-open-playhead-to-its-owning-symbol
|
||||
(deftest an-ordinary-symbol-keeps-a-row-per-node
|
||||
(let [doc (update-in (fixture/document) [:symbols :main] dissoc :display)
|
||||
rows (timeline/rows doc :main #{})]
|
||||
(is (empty? (filter :lane? rows)))
|
||||
(is (= #{[:a] [:b] [:insert] [:plate]} (set (map :path rows))))))
|
||||
|
||||
(deftest a-nested-selection-converts-the-open-playhead-to-its-owner
|
||||
(let [doc (assoc-in (fixture/document) [:symbols :outer]
|
||||
{:id :outer :frames 30
|
||||
:nodes {:take {:id :take :kind :instance :z "a"
|
||||
|
|
@ -34,189 +59,59 @@
|
|||
(is (= 12 (ui/selection-frame doc nil :main
|
||||
[:node :main :a [:a]] 12)))))
|
||||
|
||||
(deftest polygon-landing-follows-the-target-not-the-selection
|
||||
(let [doc (fixture/document)
|
||||
db {:ui {:open :main
|
||||
:selection [:node :main :plate [:plate]]
|
||||
:target {:sid :main :id :insert :path [:insert]}}
|
||||
:playback {:frame 5}}
|
||||
landing (ui/polygon-landing doc {} db)]
|
||||
(is (= doc (:clip landing)))
|
||||
(is (= [:insert] (:path landing))
|
||||
"looking at another shape does not silently move the creation target")
|
||||
(is (false? (:lane? landing)))))
|
||||
(deftest polygon-landing-obeys-the-destination-symbol-mode
|
||||
(let [lane (fixture/document)
|
||||
ordinary (update-in lane [:symbols :main] dissoc :display)
|
||||
db {:ui {:open :main :target {:sid :main :id :plate :path [:plate]}}
|
||||
:playback {:frame 5}}]
|
||||
(is (true? (:lane? (ui/polygon-landing lane {} db))))
|
||||
(is (false? (:lane? (ui/polygon-landing ordinary {} db))))))
|
||||
|
||||
(deftest timeline-polygon-landing-is-decided-by-the-aimed-lane
|
||||
(let [doc (fixture/document)
|
||||
base {:ui {:open :main
|
||||
:selection [:node :main :plate [:plate]]
|
||||
:target {:sid :main :id :girl :path [:girl]}}
|
||||
:playback {:frame 5}}
|
||||
occupied (ui/polygon-landing doc {} base)
|
||||
with-gap (:clip (lane/blank doc :main :girl [5 7] {:id :rest}))
|
||||
gap (ui/polygon-landing with-gap {} (assoc-in base [:playback :frame] 6))]
|
||||
(is (= [:b] (:path occupied))
|
||||
"the cel on screen wins even while an unrelated stage node is selected")
|
||||
(is (= doc (:clip occupied)) "an existing cel needs no document edit")
|
||||
(is (true? (:lane? occupied)))
|
||||
(is (= 1 (count (:path gap))))
|
||||
(is (not (contains? (get-in with-gap [:symbols :main :nodes])
|
||||
(first (:path gap))))
|
||||
"a gap receives a fresh drawing")
|
||||
(is (contains? (get-in (:clip gap) [:symbols :main :nodes])
|
||||
(first (:path gap))))
|
||||
(is (empty? (clip/problems (:clip gap))))))
|
||||
|
||||
(deftest polygon-landing-without-an-aimed-lane-uses-the-ordinary-target
|
||||
(let [doc (fixture/document)
|
||||
db {:ui {:open :main
|
||||
:target {:sid :main :id :plate :path [:plate]}}
|
||||
:playback {:frame 5}}
|
||||
landing (ui/polygon-landing doc {} db)]
|
||||
(is (= doc (:clip landing)))
|
||||
(is (= [] (:path landing)))
|
||||
(is (false? (:lane? landing)))))
|
||||
|
||||
(deftest beginning-a-polygon-materializes-a-missing-timeline-drawing
|
||||
(let [doc (fixture/document)
|
||||
with-gap (:clip (lane/blank doc :main :girl [5 7] {:id :rest}))
|
||||
id (store/install! {:clip with-gap :store {}} "polygon-start-test")
|
||||
db {:clip/current id :paint/revision 0
|
||||
:ui {:open :main
|
||||
:target {:sid :main :id :girl :path [:girl]}}
|
||||
:playback {:frame 6}}
|
||||
after (ui/beginning-polygon db)
|
||||
saved (:clip (store/entry (:clip/current after)))
|
||||
[_ sid cel-id path] (get-in after [:ui :selection])]
|
||||
(is (= :polygon (get-in after [:ui :tool])))
|
||||
(is (= [] (get-in after [:ui :draft])))
|
||||
(is (= :main sid))
|
||||
(is (= [cel-id] path))
|
||||
(is (contains? (get-in saved [:symbols :main :nodes]) cel-id)
|
||||
"the drawing exists before the first draft point is added")
|
||||
(is (= 6 (get-in saved [:symbols :main :nodes cel-id :time :at])))
|
||||
(is (empty? (clip/problems saved)))))
|
||||
|
||||
(deftest beginning-a-polygon-does-not-invent-an-unselected-lane
|
||||
(deftest beginning-a-polygon-does-not-invent-a-lane
|
||||
(let [doc (clip/blank)
|
||||
id (store/install! {:clip doc :store {}} "polygon-lane-start-test")
|
||||
id (store/install! {:clip doc :store {}} "polygon-no-implicit-lane")
|
||||
db {:clip/current id :paint/revision 0
|
||||
:ui {:open :main}
|
||||
:playback {:frame 6}}
|
||||
after (ui/beginning-polygon db)
|
||||
saved (:clip (store/entry (:clip/current after)))
|
||||
lanes (symbol/lanes (get-in saved [:symbols :main :nodes]))]
|
||||
saved (:clip (store/entry (:clip/current after)))]
|
||||
(is (= :polygon (get-in after [:ui :tool])))
|
||||
(is (= [:lane] (mapv :id lanes))
|
||||
"the lane the symbol was born with, and no second one invented here")
|
||||
(is (empty? (symbol/lane-clips (get-in saved [:symbols :main :nodes]) :lane))
|
||||
"and nothing put in it")
|
||||
(is (nil? (get-in after [:ui :target])))
|
||||
(is (nil? (get-in (store/entry (:clip/current after)) [:history :done])))
|
||||
(is (empty? (clip/problems saved)))))
|
||||
(is (= {} (get-in saved [:symbols :main :nodes])))
|
||||
(is (nil? (get-in saved [:symbols :main :display])))
|
||||
(is (nil? (get-in (store/entry (:clip/current after)) [:history :done])))))
|
||||
|
||||
(deftest sequence-commands-use-isolated-history-transactions
|
||||
(let [doc (fixture/document)
|
||||
id (store/install! {:clip doc :store {}} "sequence-test")
|
||||
id (store/install! {:clip doc :store {}} "sequence-command-test")
|
||||
db {:clip/current id :paint/revision 0
|
||||
:ui {:open :main :selection [:node :main :a [:a]]}}
|
||||
refused (ui/apply-lane-command db :main
|
||||
(lane/extend-hold doc :main :a 1 {}) [:retry])]
|
||||
refused (ui/apply-command db :main
|
||||
(span/extend-hold doc :main :a 1 {}) [:retry])]
|
||||
(is (= doc (:clip (store/entry id))))
|
||||
(is (nil? (:history (store/entry id))))
|
||||
(is (= [:retry] (get-in refused [:ui :lane-retry])))
|
||||
(let [r1 (lane/extend-hold doc :main :a 1 {:extent :grow-symbol})
|
||||
db1 (ui/apply-lane-command db :main r1 nil)
|
||||
r2 (lane/extend-hold (:clip r1) :main :a 1 {:extent :grow-symbol})
|
||||
db2 (ui/apply-lane-command db1 :main r2 nil)
|
||||
(is (= [:retry] (get-in refused [:ui :retry])))
|
||||
(let [r1 (span/extend-hold doc :main :a 1 {:extent :grow-symbol})
|
||||
db1 (ui/apply-command db :main r1 nil)
|
||||
r2 (span/extend-hold (:clip r1) :main :a 1 {:extent :grow-symbol})
|
||||
db2 (ui/apply-command db1 :main r2 nil)
|
||||
h (:history (store/entry id))
|
||||
undo (history/undo h (leaf/leaves "u" (:clip r2)))
|
||||
undo2 (history/undo (:history undo) (:leaves undo))]
|
||||
(is (= 2 (count (:done h))) "rapid button presses remain separate commands")
|
||||
(is (= 2 (count (:done h))))
|
||||
(is (= (:clip r1) (leaf/clip "u" (:leaves undo))))
|
||||
(is (= doc (leaf/clip "u" (:leaves undo2))))
|
||||
(is (= [:node :main :a [:a]] (get-in db2 [:ui :selection]))))))
|
||||
|
||||
(deftest a-correction-is-one-step-and-keeps-the-full-selection-address
|
||||
(deftest an-expanded-lane-opens-the-selected-clip
|
||||
(let [doc (fixture/document)
|
||||
id (store/install! {:clip doc :store {}} "correction-event-test")
|
||||
selection [:node :main :a [:outer :a]]
|
||||
db {:clip/current id :paint/revision 0
|
||||
:ui {:open :outer :selection selection}}
|
||||
result (correction/add doc :main :a [:xform :rot]
|
||||
{:id :nudge :support [0 3] :motion :return
|
||||
:start 0 :peak 0.5 :peak-frame 1})
|
||||
after (ui/apply-correction-command db result)
|
||||
entry (store/entry id)]
|
||||
(is (= selection (get-in after [:ui :selection])))
|
||||
(is (= 1 (count (get-in entry [:history :done]))))
|
||||
(is (= 0.5 (get-in (:clip entry)
|
||||
[:symbols :main :nodes :a :channels [:xform :rot]
|
||||
:over 0 :values :keys 1])))
|
||||
(let [refused (ui/apply-correction-command after {:refused "nope"})]
|
||||
(is (= "nope" (get-in refused [:project :status])))
|
||||
(is (= 1 (count (get-in (store/entry id) [:history :done])))))))
|
||||
rows (timeline/rows doc :main #{[:arthur.ui.timeline/lane] [:insert]} [:insert])
|
||||
portal (first (filter :portal? rows))]
|
||||
(is (= [:insert] (:path portal)))
|
||||
(is (= [:node :main :insert [:insert]] (:select portal)))
|
||||
(is (some #{"mark"} (map :label rows)))))
|
||||
|
||||
(deftest an-expanded-lane-opens-the-selected-clip-and-everything-under-it
|
||||
;; The whole document is editable from the root timeline: a lane opens one
|
||||
;; portal — the clip selected in it — and that portal opens the lanes and
|
||||
;; nodes of the symbol it places, mapped into this ruler.
|
||||
(let [doc (fixture/document)
|
||||
open #{[:girl] [:insert]}
|
||||
shut (timeline/rows doc :main open [:insert])
|
||||
of (fn [rows] (mapv (juxt :label :depth) rows))
|
||||
lane-row (first (filter :cels (timeline/rows doc :main open [:insert])))]
|
||||
(is (= 1 (count (filter :portal? shut)))
|
||||
"exactly one clip is opened, not one branch per clip in the lane")
|
||||
(is (= [:insert] (:path (first (filter :portal? shut))))
|
||||
"and it is the selected one")
|
||||
(is (some #{["mark" 2]} (of shut))
|
||||
"the clip's own symbol appears under it, at its depth")
|
||||
(is (= [:node :main :insert [:insert]]
|
||||
(:select (first (filter :portal? shut))))
|
||||
"the portal addresses the same clip its block in the lane does")
|
||||
(is (= (:keys (second (:cels lane-row)))
|
||||
(:keys (first (filter #(= [:b] (:path %)) (timeline/rows doc :main open [:b])))))
|
||||
"a clip's keys are on its block whether or not its portal is open")))
|
||||
|
||||
(deftest a-nested-selection-keeps-the-portal-that-revealed-it-open
|
||||
;; Clicking a shape inside the clip — or the end of its span — is still
|
||||
;; working inside that clip. Matching the selected id alone would close the
|
||||
;; portal the moment anything under it was touched.
|
||||
(let [doc (fixture/document)
|
||||
open #{[:girl] [:insert]}
|
||||
deep (timeline/rows doc :main open [:insert :mark])
|
||||
none (timeline/rows doc :main open [:plate])]
|
||||
(is (= [:insert] (:path (first (filter :portal? deep))))
|
||||
"a selection under the clip keeps that clip's portal")
|
||||
(is (empty? (filter :portal? none)))
|
||||
(is (some #{"select a clip to inspect"} (map :label none))
|
||||
"with nothing selected in it, an open lane says what it is waiting for")))
|
||||
|
||||
(deftest a-held-clip-shows-its-contents-without-inventing-frames-for-them
|
||||
;; `clip/source-time` is nil for a hold, so nested keys have no place on this
|
||||
;; ruler — but the drawing's own nodes must still be reachable from here.
|
||||
(let [doc (fixture/document)
|
||||
rows (timeline/rows doc :main #{[:girl] [:a]} [:a])
|
||||
inside (filter :unmapped? rows)]
|
||||
(is (seq inside) "a held drawing opens")
|
||||
(is (some #{"mark"} (map :label inside)))
|
||||
(is (every? (comp empty? :keys) inside)
|
||||
"no key is placed where the hold cannot say it belongs")
|
||||
(is (= [[0 4]] (distinct (keep :span (filter #(= :node (:kind %)) inside))))
|
||||
"its rows span the hold, which is when it is on screen")))
|
||||
|
||||
(deftest a-lane-of-sounds-is-drawn-as-a-lane-and-not-flattened-twice
|
||||
(let [made (lane/add-lane (fixture/document) :main :track)
|
||||
seeded (clip/place-sound (:clip made) :main {:sound "s1"} "voice" 6 1 2 :vo)
|
||||
doc (:clip (lane/adopt seeded :main :track :vo 2 {:extent :grow-symbol}))
|
||||
picture (remove :sound? (timeline/rows doc :main #{} nil))
|
||||
sound-lanes (filter :sound? (timeline/rows doc :main #{} nil))
|
||||
flattened (timeline/sound-rows doc :main #{})]
|
||||
(is (= 1 (count sound-lanes)) "the sound's lane is one row, like any lane")
|
||||
(is (= [:vo] (mapv :id (:cels (first sound-lanes))))
|
||||
"with the sound on it as a block that can be moved and trimmed")
|
||||
(is (empty? (filter #(= [:track] (:path %)) picture))
|
||||
"and it is not also listed among the picture rows")
|
||||
(is (empty? flattened)
|
||||
"nor flattened into a second, parallel audio row")))
|
||||
(deftest a-lane-of-sounds-is-not-flattened-twice
|
||||
(let [base (:clip (span/draw-as-lane (clip/blank) :main true {}))
|
||||
doc (clip/place-sound base :main {:sound "s1"} "voice" 6 1 2 :vo)
|
||||
lane (first (filter :lane? (timeline/rows doc :main #{} nil)))]
|
||||
(is (= [:vo] (mapv :id (:cels lane))))
|
||||
(is (empty? (timeline/sound-rows doc :main #{})))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue