Skip to content

Commit

Permalink
feat: added user commands
Browse files Browse the repository at this point in the history
  • Loading branch information
roboteng committed Dec 14, 2023
1 parent 426bae1 commit a38958d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fn spawn_units(mut creations: EventReader<SpawnUnit>, mut commands: Commands) {
#[derive(Bundle)]
struct MyBundle {
transform: Transform,
commands: UserCommandComponent,
}

#[derive(Component)]
Expand All @@ -26,13 +27,24 @@ enum UnitComponents {
Villager,
}

#[derive(Component, Debug, Default, PartialEq, Eq)]
struct UserCommandComponent {
command: Option<UserCommand>,
}

#[derive(Debug, PartialEq, Eq)]
enum UserCommand {}

fn create_unit_bundles(spawn: &SpawnUnitData) -> MyBundle {
let transform = Transform {
translation: Vec3::new(spawn.pos.x, spawn.pos.y, 0.0),
..Default::default()
};

MyBundle { transform }
MyBundle {
transform,
commands: UserCommandComponent::default(),
}
}

#[derive(Debug, Event)]
Expand Down Expand Up @@ -82,6 +94,16 @@ mod test {

assert_eq!(Vec3::new(3.0, 4.0, 0.0), actual.transform.translation);
}

#[test]
fn user_commands_get_created() {
let actual = create_unit_bundles(&SpawnUnitData {
pos: Vec2::default(),
unit: Unit::Villager,
});

assert_eq!(UserCommandComponent::default(), actual.commands);
}
}

mod acceptance {
Expand Down

0 comments on commit a38958d

Please sign in to comment.