-
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.
integrate the worker messaging layer more
- Loading branch information
Showing
12 changed files
with
219 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -10,7 +10,8 @@ | |
} | ||
|
||
html, | ||
body { | ||
body, | ||
main { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
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,9 @@ | ||
[package] | ||
name = "active_game" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Sean Sullivan <[email protected]>"] | ||
|
||
[dependencies] | ||
game = { workspace = true } | ||
bevy = { workspace = true, default-features = false } |
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,84 @@ | ||
use bevy::prelude::*; | ||
|
||
use game::{Arena, Game, GamePlayers, Word}; | ||
|
||
pub struct ActiveGamePlugin; | ||
|
||
impl Plugin for ActiveGamePlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_event::<ActiveGameUpdate>() | ||
.add_systems( | ||
Update, | ||
Self::set_active_game.run_if(not(resource_exists::<ActiveGame>)), | ||
) | ||
.add_systems( | ||
Update, | ||
Self::trigger_game_update.run_if(resource_exists::<ActiveGame>), | ||
); | ||
} | ||
} | ||
|
||
impl ActiveGamePlugin { | ||
fn set_active_game(mut commands: Commands, spawned_games: Query<Entity, Added<Game>>) { | ||
for game in spawned_games.iter() { | ||
commands.insert_resource(ActiveGame(game)); | ||
} | ||
} | ||
|
||
fn trigger_game_update( | ||
mut commands: Commands, | ||
mut events: EventWriter<ActiveGameUpdate>, | ||
active_game: Res<ActiveGame>, | ||
games: Query<(&GamePlayers, &Arena)>, | ||
words: Query<&Word>, | ||
updated_words: Query<(), Changed<Word>>, | ||
) { | ||
let Some((game, players, arena)) = games | ||
.get(active_game.0) | ||
.ok() | ||
.map(|(players, arena)| (active_game, players, arena)) | ||
.filter(|(game, players, _)| { | ||
game.is_changed() | ||
|| updated_words.contains(players.left) | ||
|| updated_words.contains(players.right) | ||
}) | ||
else { | ||
return; | ||
}; | ||
|
||
let left_word = words | ||
.get(players.left) | ||
.cloned() | ||
.expect("PlayerSide::Left to have a Word"); | ||
let right_word = words | ||
.get(players.right) | ||
.cloned() | ||
.expect("PlayerSide::Right should have a Word"); | ||
let event = ActiveGameUpdate { | ||
game: game.0, | ||
arena_size: arena.size(), | ||
player_left: players.left, | ||
left_word, | ||
player_right: players.right, | ||
right_word, | ||
}; | ||
commands.trigger(event.clone()); | ||
events.send(event); | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
#[derive(Deref, DerefMut, Resource, Reflect)] | ||
pub struct ActiveGame(Entity); | ||
|
||
// Can be read from an EventReader or observed as needed | ||
#[derive(Clone, Debug)] | ||
#[derive(Event)] | ||
pub struct ActiveGameUpdate { | ||
pub game: Entity, | ||
pub arena_size: usize, | ||
pub player_left: Entity, | ||
pub left_word: Word, | ||
pub player_right: Entity, | ||
pub right_word: Word, | ||
} |
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
Oops, something went wrong.