Skip to content

Commit

Permalink
chore: add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
buxx committed May 6, 2024
1 parent 07ad2f4 commit 09e812c
Show file tree
Hide file tree
Showing 26 changed files with 817 additions and 247 deletions.
25 changes: 23 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@
"name": "launcher",
"cargo": {
"args": [
"build",
"run",
"--bin=oc_launcher",
"--package=oc_launcher",
"--release"
Expand All @@ -876,6 +876,27 @@
"env": {
"RUST_BACKTRACE": "1"
}
}
},
{
"type": "lldb",
"request": "launch",
"name": "face_to_face_close_up",
"cargo": {
"args": [
"build",
"--bin=face_to_face_close_up",
"--package=examples"
],
"filter": {
"name": "face_to_face_close_up",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
]
}
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
"libfontconfig",
"libudev",
"libzmq",
"mosin",
"Mosin",
"msys",
"msystem",
"nagant",
"Nagant",
"nanos",
"ocbs",
Expand Down
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ members = [
"battle_server",
"battle_gui",
"battle_tools",
"examples",
]
22 changes: 21 additions & 1 deletion battle_core/src/deployment/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs, io, path::PathBuf};
use std::{collections::HashMap, fs, io, path::PathBuf};

use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -26,6 +26,26 @@ pub struct Deployment {
}

impl Deployment {
pub fn new(
soldiers: Vec<SoldierDeployment>,
vehicles: Vec<VehicleDeployment>,
boards: SoldiersOnBoard,
) -> Self {
Self {
soldiers,
vehicles,
boards,
}
}

pub fn empty() -> Self {
Self {
soldiers: vec![],
vehicles: vec![],
boards: HashMap::new(),
}
}

pub fn from_battle_state(battle_state: &BattleState) -> Self {
let soldiers: Vec<SoldierDeployment> = battle_state
.soldiers()
Expand Down
31 changes: 28 additions & 3 deletions battle_core/src/map/terrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,31 @@ pub struct TerrainTile {
}

impl TerrainTile {
#[allow(clippy::too_many_arguments)]
pub fn new(
type_: TileType,
tile_width: u32,
tile_height: u32,
relative_tile_width: f32,
relative_tile_height: f32,
x: u32,
y: u32,
tile_x: u32,
tile_y: u32,
) -> Self {
Self {
type_,
tile_width,
tile_height,
relative_tile_width,
relative_tile_height,
x,
y,
tile_x,
tile_y,
}
}

#[allow(clippy::too_many_arguments)]
pub fn from_str_id(
id: &str,
Expand All @@ -164,8 +189,8 @@ impl TerrainTile {
tile_x: u32,
tile_y: u32,
) -> Result<Self, TerrainTileError> {
Ok(Self {
type_: TileType::from_str(id)?,
Ok(Self::new(
TileType::from_str(id)?,
tile_width,
tile_height,
relative_tile_width,
Expand All @@ -174,7 +199,7 @@ impl TerrainTile {
y,
tile_x,
tile_y,
})
))
}

pub fn type_(&self) -> &TileType {
Expand Down
17 changes: 6 additions & 11 deletions battle_core/src/state/battle/builder.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use std::{collections::HashMap, fmt::Display, path::PathBuf};
use std::{collections::HashMap, fmt::Display};

use crate::{
game::flag::FlagsOwnership,
map::reader::{MapReader, MapReaderError},
map::{reader::MapReaderError, Map},
};

use super::{phase::Phase, BattleState};

pub struct BattleStateBuilder {
map_name: String,
resources: PathBuf,
map: Map,
}

#[derive(Debug)]
Expand All @@ -34,18 +33,14 @@ impl Display for BattleStateBuilderError {
}

impl BattleStateBuilder {
pub fn new(map_name: &str, resources: PathBuf) -> Self {
Self {
map_name: map_name.to_string(),
resources,
}
pub fn new(map: Map) -> Self {
Self { map }
}

pub fn build(&self) -> Result<BattleState, BattleStateBuilderError> {
let map = MapReader::new(&self.map_name, &self.resources)?.build()?;
let mut state = BattleState::new(
0,
map,
self.map.clone(),
vec![],
vec![],
HashMap::new(),
Expand Down
12 changes: 6 additions & 6 deletions battle_gui/src/engine/physics/canon_blast.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use battle_core::physics::event::cannon_blast::CannonBlast;
use ggez::graphics::MeshBuilder;
use ggez::GameResult;



use crate::engine::message::EngineMessage;
use crate::engine::Engine;
Expand Down Expand Up @@ -56,8 +56,8 @@ impl Engine {
messages
}

pub fn draw_cannon_blasts(&self, _mesh_builder: &mut MeshBuilder) -> GameResult {
// Nothing here because drawn by graphics sequences
Ok(())
}
// pub fn draw_cannon_blasts(&self, _mesh_builder: &mut MeshBuilder) -> GameResult {
// // Nothing here because drawn by graphics sequences
// Ok(())
// }
}
1 change: 1 addition & 0 deletions battle_gui/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 0 additions & 1 deletion battle_gui/src/graphics/decors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use ggez::{
graphics::{DrawParam, Image, InstanceArray, Rect},
Context, GameError, GameResult,
};
use glam::Vec2;

use crate::utils::qualified::ToQualified;

Expand Down
91 changes: 91 additions & 0 deletions battle_gui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
pub mod audio;
pub mod debug;
pub mod engine;
pub mod error;
pub mod graphics;
pub mod physics;
pub mod run;
pub mod saves;
pub mod server;
pub mod ui;
pub mod utils;

use battle_core::deployment::DeploymentReaderError;
use battle_core::map::reader::MapReaderError;
use battle_core::message::InputMessage;
use battle_core::network::error::NetworkError;
use battle_core::state::battle::builder::BattleStateBuilderError;

use crossbeam_channel::SendError;
use ggez::GameError;
use oc_core::resources::ResourcesError;
use server::EmbeddedServerError;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum GuiError {
#[error("Resource load error : {0}")]
Resources(ResourcesError),
#[error("Deployment load error : {0}")]
Deployment(DeploymentReaderError),
#[error("Error during map load : {0}")]
MapReader(MapReaderError),
#[error("Running error : {0}")]
RunGame(GameError),
#[error("Error during input send : {0}")]
SendInput(SendError<Vec<InputMessage>>),
#[error("Network error : {0}")]
Network(NetworkError),
#[error("Embedded server error : {0}")]
EmbeddedServer(EmbeddedServerError),
#[error("Battle state builder error : {0}")]
BattleStateBuilderError(BattleStateBuilderError),
}

impl From<MapReaderError> for GuiError {
fn from(error: MapReaderError) -> Self {
Self::MapReader(error)
}
}

impl From<GameError> for GuiError {
fn from(error: GameError) -> Self {
Self::RunGame(error)
}
}

impl From<SendError<Vec<InputMessage>>> for GuiError {
fn from(error: SendError<Vec<InputMessage>>) -> Self {
Self::SendInput(error)
}
}

impl From<NetworkError> for GuiError {
fn from(error: NetworkError) -> Self {
Self::Network(error)
}
}

impl From<EmbeddedServerError> for GuiError {
fn from(error: EmbeddedServerError) -> Self {
Self::EmbeddedServer(error)
}
}

impl From<ResourcesError> for GuiError {
fn from(error: ResourcesError) -> Self {
Self::Resources(error)
}
}

impl From<DeploymentReaderError> for GuiError {
fn from(error: DeploymentReaderError) -> Self {
Self::Deployment(error)
}
}

impl From<BattleStateBuilderError> for GuiError {
fn from(error: BattleStateBuilderError) -> Self {
Self::BattleStateBuilderError(error)
}
}
Loading

0 comments on commit 09e812c

Please sign in to comment.