Skip to content

Commit 23963bd

Browse files
committed
fix deserialization
1 parent 7722845 commit 23963bd

8 files changed

Lines changed: 80 additions & 48 deletions

File tree

editor/src/messages/layout/utility_types/layout_widget.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -789,25 +789,6 @@ impl DiffUpdate {
789789
}
790790
};
791791

792-
// Recursively fill menu list entries with their realized shortcut keys specific to the current bindings and platform
793-
let apply_action_shortcut_to_menu_lists = |entry_sections: &mut MenuListEntrySections| {
794-
struct RecursiveWrapper<'a>(&'a dyn Fn(&mut MenuListEntrySections, &RecursiveWrapper));
795-
let recursive_wrapper = RecursiveWrapper(&|entry_sections: &mut MenuListEntrySections, recursive_wrapper| {
796-
for entries in entry_sections {
797-
for entry in entries {
798-
// Convert `ActionShortcut::Action` to `ActionShortcut::Shortcut`
799-
if let Some(tooltip_shortcut) = &mut entry.tooltip_shortcut {
800-
tooltip_shortcut.realize_shortcut(action_input_mapping);
801-
}
802-
803-
// Recursively call this inner closure on the menu's children
804-
(recursive_wrapper.0)(&mut entry.children, recursive_wrapper);
805-
}
806-
}
807-
});
808-
(recursive_wrapper.0)(entry_sections, &recursive_wrapper)
809-
};
810-
811792
// Hash the menu list entry sections for caching purposes
812793
let hash_menu_list_entry_sections = |entry_sections: &MenuListEntrySections| {
813794
struct RecursiveHasher<'a> {
@@ -833,11 +814,11 @@ impl DiffUpdate {
833814
// Apply shortcut conversions to all widgets that have menu lists
834815
let convert_menu_lists = |widget_instance: &mut WidgetInstance| match &mut *widget_instance.widget {
835816
Widget::DropdownInput(dropdown_input) => {
836-
apply_action_shortcut_to_menu_lists(&mut dropdown_input.entries);
817+
apply_action_shortcut_to_menu_lists(&mut dropdown_input.entries, action_input_mapping);
837818
dropdown_input.entries_hash = hash_menu_list_entry_sections(&dropdown_input.entries);
838819
}
839820
Widget::TextButton(text_button) => {
840-
apply_action_shortcut_to_menu_lists(&mut text_button.menu_list_children);
821+
apply_action_shortcut_to_menu_lists(&mut text_button.menu_list_children, action_input_mapping);
841822
text_button.menu_list_children_hash = hash_menu_list_entry_sections(&text_button.menu_list_children);
842823
}
843824
_ => {}
@@ -859,3 +840,16 @@ impl DiffUpdate {
859840
}
860841
}
861842
}
843+
844+
// Recursively fill menu list entries with their realized shortcut keys specific to the current bindings and platform
845+
fn apply_action_shortcut_to_menu_lists(entry_sections: &mut MenuListEntrySections, action_input_mapping: &impl Fn(&MessageDiscriminant) -> Option<KeysGroup>) {
846+
for entries in entry_sections {
847+
for entry in entries {
848+
if let Some(tooltip_shortcut) = &mut entry.tooltip_shortcut {
849+
tooltip_shortcut.realize_shortcut(action_input_mapping);
850+
}
851+
852+
apply_action_shortcut_to_menu_lists(&mut entry.children, action_input_mapping);
853+
}
854+
}
855+
}

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2723,7 +2723,7 @@ impl NodeGraphMessageHandler {
27232723
let clippable = layer.can_be_clipped(network_interface.document_metadata());
27242724
let data = LayerPanelEntry {
27252725
id: node_id,
2726-
reference: network_interface.reference(&node_id, &[]).and_then(|x| x.as_ref()).cloned().unwrap_or_default(),
2726+
reference: network_interface.reference(&node_id, &[]).unwrap_or(DefinitionIdentifier::Network("".to_string())),
27272727
alias: network_interface.display_name(&node_id, &[]),
27282728
in_selected_network: selection_network_path.is_empty(),
27292729
children_allowed,

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6227,6 +6227,7 @@ struct InputTransientMetadata {
62276227

62286228
/// Persistent metadata for each node in the network, which must be included when creating, serializing, and deserializing saving a node.
62296229
#[derive(Default, Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
6230+
#[serde(deny_unknown_fields)]
62306231
pub struct DocumentNodePersistentMetadata {
62316232
/// A name chosen by the user for this instance of the node. Empty indicates no given name, in which case the implementation name is displayed to the user in italics.
62326233
/// This is empty for all newly created nodes, except protonodes with #[skip_impl]

editor/src/messages/portfolio/document/utility_types/network_interface/deserialization.rs

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ pub struct DocumentNodePersistentMetadataInputNames {
1919
pub network_metadata: Option<NodeNetworkMetadata>,
2020
}
2121

22-
impl From<DocumentNodePersistentMetadataInputNames> for DocumentNodePersistentMetadata {
22+
impl From<DocumentNodePersistentMetadataInputNames> for DocumentNodePersistentMetadataPropertiesRow {
2323
fn from(old: DocumentNodePersistentMetadataInputNames) -> Self {
24-
DocumentNodePersistentMetadata {
25-
input_metadata: Vec::new(),
24+
DocumentNodePersistentMetadataPropertiesRow {
25+
reference: old.reference,
26+
input_properties: Vec::new(),
2627
display_name: old.display_name,
2728
output_names: old.output_names,
29+
has_primary_output: old.has_primary_output,
2830
locked: old.locked,
2931
pinned: old.pinned,
3032
node_type_metadata: old.node_type_metadata,
@@ -59,7 +61,7 @@ pub struct PropertiesRow {
5961
pub input_description: String,
6062
}
6163

62-
impl From<DocumentNodePersistentMetadataPropertiesRow> for DocumentNodePersistentMetadata {
64+
impl From<DocumentNodePersistentMetadataPropertiesRow> for DocumentNodePersistentMetadataHasPrimaryOutput {
6365
fn from(old: DocumentNodePersistentMetadataPropertiesRow) -> Self {
6466
let mut input_metadata = Vec::new();
6567
for properties_row in old.input_properties {
@@ -73,10 +75,12 @@ impl From<DocumentNodePersistentMetadataPropertiesRow> for DocumentNodePersisten
7375
..Default::default()
7476
})
7577
}
76-
DocumentNodePersistentMetadata {
78+
DocumentNodePersistentMetadataHasPrimaryOutput {
79+
reference: old.reference,
7780
display_name: old.display_name,
7881
input_metadata: Vec::new(),
7982
output_names: old.output_names,
83+
has_primary_output: old.has_primary_output,
8084
locked: old.locked,
8185
pinned: old.pinned,
8286
node_type_metadata: old.node_type_metadata,
@@ -102,9 +106,10 @@ pub struct DocumentNodePersistentMetadataHasPrimaryOutput {
102106
pub network_metadata: Option<NodeNetworkMetadata>,
103107
}
104108

105-
impl From<DocumentNodePersistentMetadataHasPrimaryOutput> for DocumentNodePersistentMetadata {
109+
impl From<DocumentNodePersistentMetadataHasPrimaryOutput> for DocumentNodePersistentMetadataStringReference {
106110
fn from(old: DocumentNodePersistentMetadataHasPrimaryOutput) -> Self {
107-
DocumentNodePersistentMetadata {
111+
DocumentNodePersistentMetadataStringReference {
112+
reference: old.reference,
108113
display_name: old.display_name,
109114
input_metadata: old.input_metadata,
110115
output_names: old.output_names,
@@ -133,6 +138,7 @@ struct DocumentNodePersistentMetadataStringReference {
133138

134139
impl From<DocumentNodePersistentMetadataStringReference> for DocumentNodePersistentMetadata {
135140
fn from(mut old: DocumentNodePersistentMetadataStringReference) -> Self {
141+
log::debug!("Converting from DocumentNodePersistentMetadataStringReference with reference: {:?}", old.reference);
136142
if let Some(metadata) = old.network_metadata.as_mut() {
137143
metadata.persistent_metadata.reference = old.reference;
138144
}
@@ -148,27 +154,57 @@ impl From<DocumentNodePersistentMetadataStringReference> for DocumentNodePersist
148154
}
149155
}
150156

157+
#[derive(serde::Deserialize)]
158+
#[serde(untagged)]
159+
enum DocumentNodePersistentMetadataVersioned {
160+
// Newest first
161+
Current(DocumentNodePersistentMetadata),
162+
163+
StringReference(DocumentNodePersistentMetadataStringReference),
164+
165+
HasPrimaryOutput(DocumentNodePersistentMetadataHasPrimaryOutput),
166+
167+
PropertiesRow(DocumentNodePersistentMetadataPropertiesRow),
168+
169+
InputNames(DocumentNodePersistentMetadataInputNames),
170+
}
171+
151172
pub fn deserialize_node_persistent_metadata<'de, D>(deserializer: D) -> Result<DocumentNodePersistentMetadata, D::Error>
152173
where
153174
D: serde::Deserializer<'de>,
154175
{
155176
use serde::Deserialize;
156177

157178
let value = Value::deserialize(deserializer)?;
158-
if let Ok(document) = serde_json::from_value::<DocumentNodePersistentMetadata>(value.clone()) {
159-
return Ok(document);
160-
};
161-
if let Ok(document) = serde_json::from_value::<DocumentNodePersistentMetadataHasPrimaryOutput>(value.clone()) {
162-
return Ok(document.into());
163-
};
164-
if let Ok(document) = serde_json::from_value::<DocumentNodePersistentMetadataPropertiesRow>(value.clone()) {
165-
return Ok(document.into());
166-
};
167-
if let Ok(document) = serde_json::from_value::<DocumentNodePersistentMetadataStringReference>(value.clone()) {
168-
return Ok(document.into());
179+
180+
let versioned_document = serde_json::from_value::<DocumentNodePersistentMetadataVersioned>(value).map_err(serde::de::Error::custom)?;
181+
182+
let current: DocumentNodePersistentMetadata = match versioned_document {
183+
DocumentNodePersistentMetadataVersioned::Current(v) => v,
184+
185+
DocumentNodePersistentMetadataVersioned::StringReference(v) => {
186+
let v: DocumentNodePersistentMetadataStringReference = v;
187+
v.into()
188+
}
189+
190+
DocumentNodePersistentMetadataVersioned::HasPrimaryOutput(v) => {
191+
let v: DocumentNodePersistentMetadataStringReference = v.into();
192+
v.into()
193+
}
194+
195+
DocumentNodePersistentMetadataVersioned::PropertiesRow(v) => {
196+
let v: DocumentNodePersistentMetadataHasPrimaryOutput = v.into();
197+
let v: DocumentNodePersistentMetadataStringReference = v.into();
198+
v.into()
199+
}
200+
201+
DocumentNodePersistentMetadataVersioned::InputNames(v) => {
202+
let v: DocumentNodePersistentMetadataPropertiesRow = v.into();
203+
let v: DocumentNodePersistentMetadataHasPrimaryOutput = v.into();
204+
let v: DocumentNodePersistentMetadataStringReference = v.into();
205+
v.into()
206+
}
169207
};
170-
match serde_json::from_value::<DocumentNodePersistentMetadataInputNames>(value.clone()) {
171-
Ok(document) => Ok(document.into()),
172-
Err(e) => Err(serde::de::Error::custom(e)),
173-
}
208+
209+
Ok(current)
174210
}

editor/src/messages/portfolio/document/utility_types/nodes.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use super::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
22
use super::network_interface::NodeNetworkInterface;
3+
use crate::messages::portfolio::document::node_graph::document_node_definitions::DefinitionIdentifier;
4+
35
use crate::messages::tool::common_functionality::graph_modification_utils;
46
use glam::DVec2;
57
use graph_craft::document::{NodeId, NodeNetwork};
@@ -34,7 +36,7 @@ impl serde::Serialize for JsRawBuffer {
3436
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, specta::Type)]
3537
pub struct LayerPanelEntry {
3638
pub id: NodeId,
37-
pub reference: String,
39+
pub reference: DefinitionIdentifier,
3840
pub alias: String,
3941
#[serde(rename = "inSelectedNetwork")]
4042
pub in_selected_network: bool,

frontend/package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/components/panels/Layers.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@
644644
{@html $nodeGraph.thumbnails.get(listing.entry.id)}
645645
{/if}
646646
</div>
647-
{#if listing.entry.reference === "Artboard"}
647+
{#if listing.entry.reference.type === "Network" && listing.entry.reference.data === "Artboard"}
648648
<IconLabel icon="Artboard" class="layer-type-icon" tooltipLabel="Artboard" />
649649
{/if}
650650
<LayoutRow class="layer-name" on:dblclick={() => onEditLayerName(listing)}>

frontend/src/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ export class UpdateDocumentLayerDetails extends JsMessage {
833833
export class LayerPanelEntry {
834834
id!: bigint;
835835

836-
reference!: string;
836+
reference!: DefinitionIdentifier;
837837

838838
alias!: string;
839839

0 commit comments

Comments
 (0)