Skip to content

Commit

Permalink
feat: debug nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchantey committed Dec 23, 2023
1 parent 113b47c commit a21d714
Show file tree
Hide file tree
Showing 13 changed files with 9 additions and 191 deletions.
2 changes: 1 addition & 1 deletion crates/gamai/src/action/action_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ macro_rules! action_list {
use gamai::exports::*;
use strum::IntoEnumIterator;
use strum_macros::EnumIter;
#[derive(EnumIter, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, EnumIter, Serialize, Deserialize)]
pub enum $name {
$($variant($variant),)*
}
Expand Down
22 changes: 0 additions & 22 deletions crates/gamai/src/action/entity_graph.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,7 @@
use crate::prelude::*;
use anyhow::anyhow;
use anyhow::Result;
use bevy_derive::Deref;
use bevy_derive::DerefMut;
use bevy_ecs::prelude::*;
use petgraph::graph::DiGraph;
use petgraph::graph::NodeIndex;

#[derive(Debug, Clone, Deref, DerefMut)]
pub struct EntityGraph(pub DiGraph<Entity, ()>);

impl EntityGraph {
pub fn set_action<T: IntoAction>(
&self,
world: &mut World,
message: &SetActionMessage<T>,
) -> Result<()> {
let mut entity = self
.0
.node_weight(NodeIndex::new(message.node_index))
.map(|entity| world.entity_mut(*entity))
.ok_or_else(|| anyhow!("Node not found: {}", message.node_index))?;

message.value.into_action_ref().spawn(&mut entity);
Ok(())
}
pub fn into_tree(self) -> Tree<Entity> { self.0.into_tree() }
}
2 changes: 1 addition & 1 deletion crates/gamai/src/builtin_nodes/actions/scorers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::Deserialize;
use serde::Serialize;

#[action(system=empty_action)]
#[derive(Default, Clone, Serialize, Deserialize, Component)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Component)]
pub struct SetScore {
#[shared]
pub score: Score,
Expand Down
6 changes: 3 additions & 3 deletions crates/gamai/src/builtin_nodes/actions/simple_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use serde::Serialize;


#[action(system=empty_action)]
#[derive(Default, Clone, Component, Serialize, Deserialize)]
#[derive(Debug, Default, Clone, Component, Serialize, Deserialize)]
pub struct EmptyAction;
pub fn empty_action() {}

// intentionally dont deref to avoid bugs.
#[action(system=set_run_result)]
#[derive(Default, Clone, Serialize, Deserialize, Component)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Component)]
pub struct SetRunResult(pub RunResult);

impl SetRunResult {
Expand All @@ -29,7 +29,7 @@ pub fn set_run_result(
}

#[action(system=succeed_in_duration)]
#[derive(Default, Clone, Serialize, Deserialize, Component)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Component)]
pub struct SucceedInDuration {
pub duration: Duration,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::Serialize;
/// If a child succeeds it will succeed.
///
/// If the last child fails it will fail.
#[derive(Default, Clone, Serialize, Deserialize, Component)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Component)]
#[action(system=fallback)]
pub struct FallbackSelector;
pub fn fallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use serde::Serialize;
/// If there are no more children to run it will succeed.
///
/// If a child fails it will fail.
#[derive(Default, Clone, Serialize, Deserialize, Component)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Component)]
#[action(system=sequence)]
pub struct SequenceSelector;
pub fn sequence(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bevy_ecs::schedule::SystemConfigs;
use serde::Deserialize;
use serde::Serialize;

#[derive(Default, Clone, Serialize, Deserialize, Component)]
#[derive(Debug, Default, Clone, Serialize, Deserialize, Component)]
#[action(system=utility_selector)]
pub struct UtilitySelector;

Expand Down
2 changes: 0 additions & 2 deletions crates/gamai/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pub mod builtin_nodes;
pub mod edge;
pub mod extensions;
pub mod graph_utils;
pub mod message;
pub mod node;
pub mod prop;

Expand All @@ -19,7 +18,6 @@ pub mod prelude {
pub use crate::edge::*;
pub use crate::extensions::*;
pub use crate::graph_utils::*;
pub use crate::message::*;
pub use crate::node::*;
pub use crate::prop::*;
pub use gamai_macros::*;
Expand Down
54 changes: 0 additions & 54 deletions crates/gamai/src/message/builtin_message.rs

This file was deleted.

75 changes: 0 additions & 75 deletions crates/gamai/src/message/message_service.rs

This file was deleted.

4 changes: 0 additions & 4 deletions crates/gamai/src/message/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/gamai/src/node/score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Scoring;

/// Used to indicate to selectors how favorable a child node would be to run.
#[derive(
Default, Serialize, Deserialize, Debug, Clone, Copy, Component, PartialEq,
Debug, Default, Serialize, Deserialize, Clone, Copy, Component, PartialEq,
)]
pub enum Score {
#[default]
Expand Down
25 changes: 0 additions & 25 deletions crates/gamai/test/action/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,6 @@ use bevy_app::App;
use gamai::prelude::*;
use sweet::*;

#[sweet_test]
pub fn set_action_message() -> Result<()> {
let mut app = App::new();
let target = app.world.spawn_empty().id();
let actions = test_action_graph();
let entities = actions.spawn(&mut app.world, target);
let index = entities.0.node_indices().next().unwrap();

let message =
SetActionMessage::new(TestAction::new(Score::Pass), index.index(), 0);

entities.set_action(&mut app.world, &message)?;

let entity = entities.node_weight(index).unwrap();

expect(&app)
.component::<TestAction>(*entity)?
.map(|my_entity| my_entity.score)
.to_be(Score::Pass)?;

Ok(())
}


#[sweet_test]
pub fn default_components() -> Result<()> {
Expand All @@ -44,8 +21,6 @@ pub fn default_components() -> Result<()> {
Ok(())
}



#[sweet_test]
pub fn sync_system() -> Result<()> {
let mut app = App::new();
Expand Down

0 comments on commit a21d714

Please sign in to comment.