-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f48db4
commit 5a87f39
Showing
6 changed files
with
108 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use crate::{ | ||
common::*, | ||
health_bar::{Health, HealthBarBundle}, | ||
teams::Team, | ||
}; | ||
use bevy::{ | ||
prelude::*, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use bevy::{prelude::*, utils::HashMap}; | ||
|
||
#[derive(Resource)] | ||
pub struct Teams { | ||
teams: HashMap<String, Team>, | ||
} | ||
|
||
impl Teams { | ||
pub fn new() -> Self { | ||
let mut teams = Teams { | ||
teams: HashMap::new(), | ||
}; | ||
|
||
teams.add(Team { | ||
id: "a".to_string(), | ||
color: Color::rgb(0.3, 0.3, 0.8), | ||
}); | ||
teams.add(Team { | ||
id: "b".to_string(), | ||
color: Color::rgb(0.8, 0.3, 0.3), | ||
}); | ||
teams.add(Team { | ||
id: "c".to_string(), | ||
color: Color::rgb(0.8, 0.8, 0.3), | ||
}); | ||
teams | ||
} | ||
|
||
pub fn get(&self, id: String) -> Option<&Team> { | ||
self.teams.get(&id) | ||
} | ||
|
||
pub fn get_expect(&self, id: String) -> Team { | ||
self.get(id).expect("no team found").clone() | ||
} | ||
|
||
pub fn add(&mut self, team: Team) -> &mut Self { | ||
self.teams.insert(team.id.clone(), team); | ||
self | ||
} | ||
} | ||
|
||
#[derive(Component, Clone)] | ||
pub struct Team { | ||
pub id: String, | ||
pub color: Color, | ||
} | ||
|
||
pub struct TeamsPlugin; | ||
|
||
impl Plugin for TeamsPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.insert_resource(Teams::new()); | ||
} | ||
} |