Skip to content

Commit 555e294

Browse files
committed
allow default input data of all graph input pin types
1 parent 22cd057 commit 555e294

10 files changed

Lines changed: 43 additions & 38 deletions

File tree

crates/bevy_animation_graph_builtin_nodes/src/graph_node.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ impl NodeLike for GraphNode {
9999
.ok_or(GraphError::GraphAssetMissing)?;
100100
for input in graph.io_spec.sorted_inputs() {
101101
match input {
102-
NodeInput::Time(GraphInputPin::Default(pin_id)) => {
102+
NodeInput::Time(GraphInputPin::Passthrough(pin_id)) => {
103103
ctx.add_input_time(pin_id);
104104
}
105-
NodeInput::Data(GraphInputPin::Default(pin_id), data_spec) => {
105+
NodeInput::Data(GraphInputPin::Passthrough(pin_id), data_spec) => {
106106
ctx.add_input_data(pin_id, data_spec);
107107
}
108108
_ => {}
@@ -139,7 +139,7 @@ impl<'a> GraphIoEnv for NestedGraphIoEnv<'a> {
139139
ctx: GraphContext,
140140
) -> Result<DataValue, GraphError> {
141141
match pin_id {
142-
GraphInputPin::Default(pin_id) => self
142+
GraphInputPin::Passthrough(pin_id) => self
143143
.parent_ctx
144144
.clone()
145145
.with_state_key(ctx.state_key)
@@ -154,7 +154,7 @@ impl<'a> GraphIoEnv for NestedGraphIoEnv<'a> {
154154
ctx: GraphContext,
155155
) -> Result<DurationData, GraphError> {
156156
match pin_id {
157-
GraphInputPin::Default(pin_id) => self
157+
GraphInputPin::Passthrough(pin_id) => self
158158
.parent_ctx
159159
.clone()
160160
.with_state_key(ctx.state_key)

crates/bevy_animation_graph_core/src/animation_graph/loader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ impl AssetLoader for AnimationGraphLoader {
5858
graph.io_spec = serial.io_spec;
5959

6060
// Set default data values
61-
for (param_name, param_value) in serial.default_data {
62-
graph.set_default_data(param_name, param_value.clone());
61+
for (param_key, param_value) in serial.default_data {
62+
graph.set_default_data(param_key, param_value.clone());
6363
}
6464

6565
// Set up edges

crates/bevy_animation_graph_core/src/animation_graph/mod.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ pub struct NodeId(#[uuid] pub(crate) Uuid);
3535

3636
pub type PinId = String;
3737

38-
#[derive(Reflect, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
38+
#[derive(Reflect, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
3939
pub enum GraphInputPin {
40-
Default(PinId),
40+
Passthrough(PinId),
4141
/// Specifies that input with provided [`PinId`] should be retrieved from a source state's
4242
/// animation graph, e.g. if in an FSM transition.
4343
FromFsmSource(PinId),
@@ -49,7 +49,7 @@ pub enum GraphInputPin {
4949

5050
impl Default for GraphInputPin {
5151
fn default() -> Self {
52-
Self::Default("".into())
52+
Self::Passthrough("".into())
5353
}
5454
}
5555

@@ -237,7 +237,7 @@ pub struct AnimationGraph {
237237
/// Defines inputs and outputs for this graph.
238238
pub io_spec: GraphSpec,
239239

240-
pub default_data: HashMap<PinId, DataValue>,
240+
pub default_data: HashMap<GraphInputPin, DataValue>,
241241

242242
#[reflect(ignore)]
243243
pub editor_metadata: EditorMetadata,
@@ -304,13 +304,12 @@ impl AnimationGraph {
304304
// --- Setting graph inputs and outputs
305305
// ----------------------------------------------------------------------------------------
306306
/// Sets the value for a default parameter, registering it if it wasn't yet done
307-
pub fn set_default_data(&mut self, input: PinId, value: DataValue) {
308-
let input = input.into();
307+
pub fn set_default_data(&mut self, input: GraphInputPin, value: DataValue) {
309308
self.default_data.insert(input, value);
310309
}
311310

312311
/// Get the default value of an input parameter, if it exists
313-
pub fn get_default_data(&mut self, input: &PinId) -> Option<DataValue> {
312+
pub fn get_default_data(&mut self, input: &GraphInputPin) -> Option<DataValue> {
314313
self.default_data.get(input).cloned()
315314
}
316315

@@ -723,14 +722,13 @@ impl AnimationGraph {
723722
SourcePin::InputData(graph_input_pin) => ctx
724723
.io
725724
.get_data_back(graph_input_pin.clone(), ctx.clone())
726-
.or_else(|e| {
727-
if let GraphInputPin::Default(pin_id) = graph_input_pin {
728-
self.default_data.get(pin_id).cloned().ok_or_else(|| {
725+
.or_else(|_| {
726+
self.default_data
727+
.get(graph_input_pin)
728+
.cloned()
729+
.ok_or_else(|| {
729730
GraphError::OutputMissing(SourcePin::InputData(graph_input_pin.clone()))
730731
})
731-
} else {
732-
Err(e)
733-
}
734732
})?,
735733
SourcePin::NodeTime(_) => {
736734
// TODO: Make a graph error

crates/bevy_animation_graph_core/src/animation_graph/serial.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use bevy::{platform::collections::HashMap, reflect::TypeRegistry};
1414
use serde::{Deserialize, Serialize};
1515

1616
use crate::{
17-
animation_graph::{AnimationGraph, EditorMetadata, PinId, SourcePin, TargetPin},
17+
animation_graph::{AnimationGraph, EditorMetadata, GraphInputPin, SourcePin, TargetPin},
1818
animation_node::serial::{AnimationNodeDeserializer, AnimationNodeSerializer},
1919
context::spec_context::GraphSpec,
2020
edge_data::DataValue,
@@ -27,7 +27,7 @@ pub struct AnimationGraphDeserializer {
2727

2828
pub io_spec: GraphSpec,
2929

30-
pub default_data: HashMap<PinId, DataValue>,
30+
pub default_data: HashMap<GraphInputPin, DataValue>,
3131

3232
pub editor_metadata: EditorMetadata,
3333
}
@@ -39,7 +39,7 @@ pub struct AnimationGraphSerializer<'a> {
3939

4040
pub io_spec: GraphSpec,
4141

42-
pub default_data: HashMap<PinId, DataValue>,
42+
pub default_data: HashMap<GraphInputPin, DataValue>,
4343

4444
pub editor_metadata: EditorMetadata,
4545
}

crates/bevy_animation_graph_core/src/animation_graph_player.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ impl AnimationGraphPlayer {
133133
pub fn set_input_data(&mut self, input_pin: impl Into<PinId>, value: DataValue) {
134134
self.io_overrides
135135
.data
136-
.insert(GraphInputPin::Default(input_pin.into()), value);
136+
.insert(GraphInputPin::Passthrough(input_pin.into()), value);
137137
}
138138

139139
/// Return an input parameter for the animation graph
140140
pub fn get_input_data(&self, input_pin: PinId) -> Option<DataValue> {
141141
self.io_overrides
142142
.data
143-
.get(&GraphInputPin::Default(input_pin))
143+
.get(&GraphInputPin::Passthrough(input_pin))
144144
.cloned()
145145
}
146146

@@ -173,7 +173,7 @@ impl AnimationGraphPlayer {
173173
pub(crate) fn update(&mut self, system_resources: &SystemResources, root_entity: Entity) {
174174
self.outputs.clear();
175175
self.io_overrides.data.insert(
176-
GraphInputPin::Default(Self::USER_EVENTS.into()),
176+
GraphInputPin::Passthrough(Self::USER_EVENTS.into()),
177177
std::mem::take(&mut self.queued_events).into(),
178178
);
179179

crates/bevy_animation_graph_core/src/state_machine/low_level/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ impl Ord for LowLevelTransitionType {
6767
}
6868
}
6969

70-
#[derive(Reflect, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
70+
#[derive(
71+
Reflect, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Default,
72+
)]
7173
pub enum FsmBuiltinPin {
7274
#[default]
7375
PercentThroughDuration,
@@ -497,7 +499,7 @@ impl<'a> GraphIoEnv for FsmIoEnv<'a> {
497499
ctx: GraphContext,
498500
) -> Result<DataValue, GraphError> {
499501
match graph_input_pin {
500-
GraphInputPin::Default(pin_id) => self.parent_graph_data_back(&pin_id, &ctx),
502+
GraphInputPin::Passthrough(pin_id) => self.parent_graph_data_back(&pin_id, &ctx),
501503
GraphInputPin::FromFsmSource(pin_id) => self
502504
.state_machine
503505
.get_source(&self.current_state)
@@ -517,7 +519,7 @@ impl<'a> GraphIoEnv for FsmIoEnv<'a> {
517519
ctx: GraphContext,
518520
) -> Result<DurationData, GraphError> {
519521
match graph_input_pin {
520-
GraphInputPin::Default(pin_id) => self.parent_graph_duration_back(&pin_id, &ctx),
522+
GraphInputPin::Passthrough(pin_id) => self.parent_graph_duration_back(&pin_id, &ctx),
521523
GraphInputPin::FromFsmSource(_) => self
522524
.state_machine
523525
.get_source(&self.current_state)

crates/bevy_animation_graph_editor/src/graph_show.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ impl GraphReprSpec {
720720

721721
fn graph_input_pin_string(input: &GraphInputPin) -> String {
722722
match input {
723-
GraphInputPin::Default(pin_id) => pin_id.clone(),
723+
GraphInputPin::Passthrough(pin_id) => pin_id.clone(),
724724
GraphInputPin::FromFsmSource(pin_id) => format!("src: {}", pin_id),
725725
GraphInputPin::FromFsmTarget(pin_id) => format!("tgt: {}", pin_id),
726726
GraphInputPin::FsmBuiltin(fsm_builtin_pin) => format!("fsm: {:?}", fsm_builtin_pin),

crates/bevy_animation_graph_editor/src/ui/actions/graph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use bevy::{
1111
platform::collections::HashMap,
1212
};
1313
use bevy_animation_graph::core::{
14-
animation_graph::{AnimationGraph, Edge, NodeId, PinId, SourcePin, TargetPin},
14+
animation_graph::{AnimationGraph, Edge, GraphInputPin, NodeId, SourcePin, TargetPin},
1515
animation_node::{AnimationNode, dyn_node_like::DynNodeLike},
1616
context::spec_context::{GraphSpec, SpecResources},
1717
edge_data::DataValue,
@@ -91,7 +91,7 @@ pub struct RemoveNode {
9191

9292
pub struct UpdateDefaultData {
9393
pub graph: Handle<AnimationGraph>,
94-
pub input_data: HashMap<PinId, DataValue>,
94+
pub input_data: HashMap<GraphInputPin, DataValue>,
9595
}
9696

9797
pub struct UpdateGraphSpec {

crates/bevy_animation_graph_editor/src/ui/generic_widgets/graph_input_pin.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<'a> egui::Widget for GraphInputPinWidget<'a> {
2626
let mut response = PickerWidget::new_salted("pin type picker")
2727
.ui(ui, format!("{:?}", selected), |ui| {
2828
for val in [
29-
GraphInputPinType::Default,
29+
GraphInputPinType::Passthrough,
3030
GraphInputPinType::FsmSource,
3131
GraphInputPinType::FsmTarget,
3232
GraphInputPinType::FsmBuiltin,
@@ -45,7 +45,7 @@ impl<'a> egui::Widget for GraphInputPinWidget<'a> {
4545
}
4646

4747
match self.graph_input_pin {
48-
GraphInputPin::Default(pin_id)
48+
GraphInputPin::Passthrough(pin_id)
4949
| GraphInputPin::FromFsmSource(pin_id)
5050
| GraphInputPin::FromFsmTarget(pin_id) => {
5151
response |= ui.text_edit_singleline(pin_id);
@@ -77,7 +77,7 @@ impl<'a> egui::Widget for GraphInputPinWidget<'a> {
7777

7878
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7979
enum GraphInputPinType {
80-
Default,
80+
Passthrough,
8181
FsmSource,
8282
FsmTarget,
8383
FsmBuiltin,
@@ -86,7 +86,7 @@ enum GraphInputPinType {
8686
impl From<&GraphInputPin> for GraphInputPinType {
8787
fn from(value: &GraphInputPin) -> Self {
8888
match value {
89-
GraphInputPin::Default(_) => Self::Default,
89+
GraphInputPin::Passthrough(_) => Self::Passthrough,
9090
GraphInputPin::FromFsmSource(_) => Self::FsmSource,
9191
GraphInputPin::FromFsmTarget(_) => Self::FsmTarget,
9292
GraphInputPin::FsmBuiltin(_) => Self::FsmBuiltin,
@@ -103,7 +103,7 @@ impl ToString for GraphInputPinType {
103103
impl GraphInputPinType {
104104
pub fn initialize(&self) -> GraphInputPin {
105105
match self {
106-
GraphInputPinType::Default => GraphInputPin::Default(PinId::default()),
106+
GraphInputPinType::Passthrough => GraphInputPin::Passthrough(PinId::default()),
107107
GraphInputPinType::FsmSource => GraphInputPin::FromFsmSource(PinId::default()),
108108
GraphInputPinType::FsmTarget => GraphInputPin::FromFsmTarget(PinId::default()),
109109
GraphInputPinType::FsmBuiltin => GraphInputPin::FsmBuiltin(FsmBuiltinPin::default()),

crates/bevy_animation_graph_editor/src/ui/native_windows/inspector.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,13 @@ fn graph_inspector(
262262
let default_values_response =
263263
HashMapWidget::new_salted(default_values_buffer, "graph_default_values").ui(
264264
ui,
265-
|ui, key| ui.text_edit_singleline(key),
266-
|ui, key| ui.label(key),
265+
|ui, key| {
266+
ui.add(GraphInputPinWidget::new_salted(
267+
key,
268+
"default value graph input pin",
269+
))
270+
},
271+
|ui, key| ui.label(format!("{:?}", key)),
267272
|ui, value| ui.add(DataValueWidget::new_salted(value, "default value widget")),
268273
);
269274

0 commit comments

Comments
 (0)