Skip to content

Commit

Permalink
Add child-seqs to outline nodes for copy+paste handling (#9031)
Browse files Browse the repository at this point in the history
* Add child-seqs to outline nodes for copy+paste handling

* Minor fixups

* Made gen-outline-node-tx-attach-fn public and added to SDK
  • Loading branch information
Jhonnyg authored and AGulev committed Jun 25, 2024
1 parent 303ee7b commit 00e99f9
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions editor/src/clj/editor/gui.clj
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,18 @@
(g/set-property source :child-index next-index)
(attach-gui-node node-tree target source type)))))

;; SDK api
(defn gen-outline-node-tx-attach-fn
([attach-fn]
(gen-outline-node-tx-attach-fn attach-fn :names))
([attach-fn target-name-key]
(fn [target source]
(let [node-tree (node->gui-scene target)
taken-id-names (g/node-value target target-name-key)]
(concat
(g/update-property source :name outline/resolve-id taken-id-names)
(attach-fn node-tree target source))))))

;; Schema validation is disabled because it severely affects project load times.
;; You might want to enable these before making drastic changes to Gui nodes.

Expand Down Expand Up @@ -2035,7 +2047,9 @@
(output name-counts NameCounts :cached (g/fnk [names] (frequencies names)))
(input build-errors g/Any :array)
(output build-errors g/Any (gu/passthrough build-errors))
(output node-outline outline/OutlineData :cached (gen-outline-fnk "Textures" "Textures" 1 false []))
(output node-outline outline/OutlineData :cached
(gen-outline-fnk "Textures" "Textures" 1 false [{:node-type TextureNode
:tx-attach-fn (gen-outline-node-tx-attach-fn attach-texture)}]))
(output add-handler-info g/Any
(g/fnk [_node-id]
[_node-id "Textures..." texture-icon add-textures-handler {}])))
Expand Down Expand Up @@ -2074,7 +2088,9 @@
(output name-counts NameCounts :cached (g/fnk [names] (frequencies names)))
(input build-errors g/Any :array)
(output build-errors g/Any (gu/passthrough build-errors))
(output node-outline outline/OutlineData :cached (gen-outline-fnk "Materials" "Materials" 1 false []))
(output node-outline outline/OutlineData :cached
(gen-outline-fnk "Materials" "Materials" 1 false [{:node-type MaterialNode
:tx-attach-fn (gen-outline-node-tx-attach-fn attach-material)}]))
(output add-handler-info g/Any
(g/fnk [_node-id]
[_node-id "Materials..." material-icon add-materials-handler {}])))
Expand Down Expand Up @@ -2114,17 +2130,20 @@
(output name-counts NameCounts :cached (g/fnk [names] (frequencies names)))
(input build-errors g/Any :array)
(output build-errors g/Any (gu/passthrough build-errors))
(output node-outline outline/OutlineData :cached (gen-outline-fnk "Fonts" "Fonts" 2 false []))
(output node-outline outline/OutlineData :cached
(gen-outline-fnk "Fonts" "Fonts" 2 false [{:node-type FontNode
:tx-attach-fn (gen-outline-node-tx-attach-fn attach-font)}]))
(output add-handler-info g/Any
(g/fnk [_node-id]
[_node-id "Fonts..." font-icon add-fonts-handler {}])))

;; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

(defn- attach-layer
([layers-node layer]
(attach-layer layers-node layer false))
([layers-node layer internal?]
([self layers-node layer]
(attach-layer self layers-node layer false))
;; Self is not used here but added to conform all attach-*** functions
([_self layers-node layer internal?]
(concat
(g/connect layer :_node-id layers-node :nodes)
(when (not internal?)
Expand All @@ -2138,9 +2157,10 @@

(defn add-layer [project scene parent name child-index select-fn]
(g/make-nodes (g/node-id->graph-id scene) [node [LayerNode :name name :child-index child-index]]
(attach-layer parent node)
(when select-fn
(select-fn [node]))))
;; Self is not used when attaching layers
(attach-layer nil parent node)
(when select-fn
(select-fn [node]))))

(defn- add-layer-handler [project {:keys [scene parent]} select-fn]
(let [name (outline/resolve-id "layer" (g/node-value parent :name-counts))
Expand Down Expand Up @@ -2169,7 +2189,9 @@
(output layer->index g/Any :cached (g/fnk [ordered-layer-names]
(zipmap ordered-layer-names (range))))
(input child-indices NodeIndex :array)
(output node-outline outline/OutlineData :cached (gen-outline-fnk "Layers" "Layers" 3 true []))
(output node-outline outline/OutlineData :cached
(gen-outline-fnk "Layers" "Layers" 3 true [{:node-type LayerNode
:tx-attach-fn (gen-outline-node-tx-attach-fn attach-layer :ordered-layer-names)}]))
(output add-handler-info g/Any
(g/fnk [_node-id]
[_node-id "Layer" layer-icon add-layer-handler {}])))
Expand Down Expand Up @@ -2209,7 +2231,11 @@
(output name-counts NameCounts :cached (g/fnk [names] (frequencies names)))
(input build-errors g/Any :array)
(output build-errors g/Any (gu/passthrough build-errors))
(output node-outline outline/OutlineData :cached (gen-outline-fnk "Layouts" "Layouts" 4 false []))
(output node-outline outline/OutlineData :cached
;; Layouts don't have any child-reqs for the outline copy/pasting,
;; since there is essentially only one node that _can_ be supported
;; per "layout type".
(gen-outline-fnk "Layouts" "Layouts" 4 false []))
(output add-handler-info g/Any
(g/fnk [_node-id unused-display-profiles]
(mapv #(vector _node-id % layout-icon add-layout-handler {:display-profile %})
Expand Down Expand Up @@ -2249,7 +2275,9 @@
(output name-counts NameCounts :cached (g/fnk [names] (frequencies names)))
(input build-errors g/Any :array)
(output build-errors g/Any (gu/passthrough build-errors))
(output node-outline outline/OutlineData :cached (gen-outline-fnk "Particle FX" "Particle FX" 5 false []))
(output node-outline outline/OutlineData :cached
(gen-outline-fnk "Particle FX" "Particle FX" 5 false [{:node-type ParticleFXResource
:tx-attach-fn (gen-outline-node-tx-attach-fn attach-particlefx-resource)}]))
(output add-handler-info g/Any
(g/fnk [_node-id]
[_node-id "Particle FX..." particlefx/particle-fx-icon add-particlefx-resources-handler {}])))
Expand Down Expand Up @@ -2916,7 +2944,7 @@
(g/connect layers-node :build-errors self :build-errors)
(g/connect layers-node :node-outline self :child-outlines)
(g/connect layers-node :add-handler-info self :handler-infos)
(attach-layer layers-node no-layer true)
(attach-layer self layers-node no-layer true)
(loop [[layer-desc & more] (:layers scene)
tx-data []
child-index 0]
Expand All @@ -2925,7 +2953,7 @@
[layer [LayerNode
:name (:name layer-desc)
:child-index child-index]]
(attach-layer layers-node layer))]
(attach-layer self layers-node layer))]
(recur more (conj tx-data layer-tx-data) (inc child-index)))
tx-data)))
(g/make-nodes graph-id [node-tree NodeTree]
Expand Down

0 comments on commit 00e99f9

Please sign in to comment.