generated from tipragot/rust
This commit is contained in:
parent
b0d743f1b6
commit
93d07bdb2d
|
@ -6,6 +6,7 @@ use std::ops::{
|
|||
|
||||
use bevy::prelude::*;
|
||||
use paste::paste;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Represents a number that can be used in calculations for hexagonal grids.
|
||||
pub trait Number:
|
||||
|
@ -99,7 +100,7 @@ number_impl! {
|
|||
/// Represents a position in a hexagonal grid.
|
||||
/// We use the axial coordinate system explained in this
|
||||
/// [documentation](https://www.redblobgames.com/grids/hexagons/#coordinates).
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Component)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Component, Serialize, Deserialize)]
|
||||
pub struct HexPosition<T: Number>(pub T, pub T);
|
||||
|
||||
/// All possible directions in a hexagonal grid.
|
||||
|
|
|
@ -7,6 +7,7 @@ pub mod renderer;
|
|||
pub mod selected_tile;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use self::hex::*;
|
||||
|
||||
|
@ -14,7 +15,7 @@ use self::hex::*;
|
|||
pub type TilePosition = HexPosition<i32>;
|
||||
|
||||
/// The tile of the map.
|
||||
#[derive(Component, Debug)]
|
||||
#[derive(Component, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum Tile {
|
||||
/// The breeding tile.
|
||||
Breeding,
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
//! All code related to the ownership of the tiles.
|
||||
|
||||
use bevy::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::Player;
|
||||
|
||||
/// The owner of a tile.
|
||||
#[derive(Component, Clone)]
|
||||
#[derive(Component, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub struct Owner(pub Player);
|
||||
|
||||
/// The plugin to render the ownership of the tiles.
|
||||
|
|
|
@ -11,6 +11,7 @@ use crate::CurrentScene;
|
|||
|
||||
pub mod check_connection;
|
||||
pub mod connection;
|
||||
pub mod reconnection;
|
||||
|
||||
/// The plugin for the networking.
|
||||
pub struct NetworkingPlugin;
|
||||
|
|
36
crates/border-wars/src/networking/reconnection.rs
Normal file
36
crates/border-wars/src/networking/reconnection.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
//! All program related to reconnection logic.
|
||||
|
||||
use bevnet::NetworkAppExt;
|
||||
use bevy::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::map::ownership::Owner;
|
||||
use crate::map::{Tile, TilePosition};
|
||||
use crate::Player;
|
||||
|
||||
/// The plugin for the reconnection.
|
||||
pub struct ReconnectionPlugin;
|
||||
|
||||
impl Plugin for ReconnectionPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_network_event::<ReconnectionRequest>()
|
||||
.add_network_event::<ReconnectionResponse>();
|
||||
}
|
||||
}
|
||||
|
||||
/// The event to request the reconnection.
|
||||
#[derive(Event, Serialize, Deserialize)]
|
||||
pub struct ReconnectionRequest;
|
||||
|
||||
/// The event to response to the reconnection.
|
||||
#[derive(Event, Serialize, Deserialize)]
|
||||
pub struct ReconnectionResponse {
|
||||
/// All the players in the game.
|
||||
pub players: Vec<Player>,
|
||||
|
||||
/// The map of the game.
|
||||
pub map: Vec<(Option<Owner>, Tile, TilePosition)>,
|
||||
|
||||
/// The current player.
|
||||
pub current_player: Player,
|
||||
}
|
Loading…
Reference in a new issue