Skip to content

Commit

Permalink
Remove tokio, futures, and reqwest
Browse files Browse the repository at this point in the history
  • Loading branch information
aldahick committed Jun 20, 2023
1 parent cab8256 commit f8a3473
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 1,189 deletions.
1,180 changes: 39 additions & 1,141 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ license = "MIT"
publish = false

[dependencies]
futures = "0.3.28"
geojson = "0.24.1"
link-cplusplus = "1.0.8"
reqwest = "0.11.18"
serde = "1.0.164"
serde_json = "1.0.97"
sfml = "0.20.0"
tokio = { version = "1.28.1", features = ["full"] }
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Play strategy, on a map.
## Playing

1. Install [Rust](https://www.rust-lang.org/tools/install)
2. Install [SFML](https://docs.rs/sfml/latest/sfml/). On Ubuntu, do `apt install libsfml-dev build-essential pkg-config libssl-dev`
2. Install dependencies: `apt install libsfml-dev build-essential pkg-config`
3. Execute `cargo run .`

## Todo
Expand Down
4 changes: 2 additions & 2 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pub struct Game {
}

impl Game {
pub async fn new(config: &MapConfig) -> Result<Game, Box<dyn Error>> {
let world_map = WorldMap::new(config).await?;
pub fn new(config: &MapConfig) -> Result<Game, Box<dyn Error>> {
let world_map = WorldMap::new(config)?;
let mut window = RenderWindow::new((1920, 1080), "mapgame", Style::CLOSE, &Default::default());
window.set_framerate_limit(60);
let player = Player::new();
Expand Down
7 changes: 2 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![deny(elided_lifetimes_in_paths)]
extern crate link_cplusplus;

pub mod config;
pub mod errors;
Expand All @@ -9,21 +8,19 @@ pub mod math;
pub mod nation;
pub mod player;
pub mod province;
pub mod util;
pub mod world_map;

use std::error::Error;

use config::get_available_maps;
use game::Game;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
fn main() -> Result<(), Box<dyn Error>> {
let maps = get_available_maps()?;
if maps.len() != 1 {
panic!("Only one map is currently supported. lol");
}
let mut game = Game::new(maps.get(maps.keys().next().unwrap()).unwrap()).await?;
let mut game = Game::new(maps.get(maps.keys().next().unwrap()).unwrap())?;
game.start();
Ok(())
}
4 changes: 2 additions & 2 deletions src/nation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct Nation {
pub type Nations = HashMap<String, Box<Nation>>;

impl Nation {
pub async fn new(
pub fn new(
feature: Feature,
bounds: &Bounds,
config: &MapConfig,
Expand All @@ -31,7 +31,7 @@ impl Nation {
let geo_drawable = GeoDrawable::new(feature, bounds, "ADMIN", Some("ISO_A3"))?;
let nation_id = geo_drawable.id.clone();
let province_mapping = province_mappings.get(&nation_id);
let provinces = Province::load_nation(config, nation_id, province_mapping).await?;
let provinces = Province::load_nation(config, nation_id, province_mapping)?;
let mut nation = Box::new(Nation {
geo_drawable,
highlighted: false,
Expand Down
11 changes: 5 additions & 6 deletions src/province.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::{collections::HashMap, error::Error};
use std::{collections::HashMap, error::Error, fs::read_to_string};

use geojson::{Feature, FeatureCollection, GeoJson};
use serde::Deserialize;
use sfml::graphics::{Color, Rect};
use tokio::fs::read_to_string;

use crate::{
config::MapConfig,
Expand All @@ -26,14 +25,14 @@ pub type ProvinceMappings = HashMap<String, ProvinceMapping>;
const DEFAULT_NAME_PROPERTY: &str = "name";

impl Province {
pub async fn load_mappings(
pub fn load_mappings(
config: &MapConfig,
) -> Result<HashMap<String, ProvinceMapping>, Box<dyn Error>> {
let json_str = read_to_string(&config.province_mappings_path).await?;
let json_str = read_to_string(&config.province_mappings_path)?;
Ok(serde_json::from_str(&json_str)?)
}

pub async fn load_nation(
pub fn load_nation(
config: &MapConfig,
nation_id: String,
mapping: Option<&ProvinceMapping>,
Expand All @@ -45,7 +44,7 @@ impl Province {
if !path.exists() {
return Ok(None);
}
let geojson_str = read_to_string(path).await?;
let geojson_str = read_to_string(path)?;
let geojson = geojson_str.parse::<GeoJson>()?;
let features = FeatureCollection::try_from(geojson)?;
let bounds = Rect::new(0.0, 0.0, 100.0, 100.0);
Expand Down
20 changes: 0 additions & 20 deletions src/util.rs

This file was deleted.

15 changes: 7 additions & 8 deletions src/world_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use sfml::{
graphics::{RenderTarget, RenderWindow},
system::Vector2f,
};
use tokio::fs::read_to_string;

use std::{collections::HashMap, error::Error, ops::Deref};
use std::{collections::HashMap, error::Error, fs::read_to_string, ops::Deref};

use geojson::FeatureCollection;
use sfml::graphics::Rect;
Expand All @@ -27,8 +26,8 @@ pub struct WorldMap {
}

impl WorldMap {
pub async fn new<'a>(config: &MapConfig) -> Result<WorldMap, Box<dyn Error>> {
let nations = WorldMap::load_nations(config).await?;
pub fn new<'a>(config: &MapConfig) -> Result<WorldMap, Box<dyn Error>> {
let nations = WorldMap::load_nations(config)?;
Ok(WorldMap {
name: config.name.clone(),
nations,
Expand Down Expand Up @@ -62,7 +61,7 @@ impl WorldMap {
geojson::FeatureCollection::try_from(geojson)
}

async fn load_nations(config: &MapConfig) -> Result<Nations, Box<dyn Error>> {
fn load_nations(config: &MapConfig) -> Result<Nations, Box<dyn Error>> {
if !config.nations_path.exists() {
return Err(Box::new(MapLoadError {
reason: format!(
Expand All @@ -71,13 +70,13 @@ impl WorldMap {
),
}));
}
let geojson_str = read_to_string(&config.nations_path).await?;
let geojson_str = read_to_string(&config.nations_path)?;
let features = WorldMap::parse_features(geojson_str)?;
let province_mappings = Province::load_mappings(config).await?;
let province_mappings = Province::load_mappings(config)?;
let bounds = Rect::new(0.0, 0.0, 100.0, 100.0);
let mut nations = HashMap::new();
for feature in features {
let nation = Nation::new(feature, &bounds, config, &province_mappings).await?;
let nation = Nation::new(feature, &bounds, config, &province_mappings)?;
let nation_id = nation.id().clone();
if nation.area() > MIN_NATION_AREA {
nations.insert(nation_id, nation);
Expand Down

0 comments on commit f8a3473

Please sign in to comment.