Skip to content

Commit

Permalink
Revert "enable import/export in native client"
Browse files Browse the repository at this point in the history
This reverts commit 5396c38.
  • Loading branch information
zeitlinger committed Sep 16, 2024
1 parent 5396c38 commit e1089e5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.
4 changes: 0 additions & 4 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ name = "client"
version = "0.1.0"
edition = "2021"

[features]
# disable file import and export
wasm = []

# may be needed for remote client
#[lib]
#name = "client"
Expand Down
35 changes: 20 additions & 15 deletions client/src/local_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

use crate::client;
use macroquad::prelude::next_frame;
use std::fs::File;
use std::io::BufReader;

use crate::client::{Features, GameSyncRequest, GameSyncResult};
use server::city::City;
use server::game::{Game, GameData};
use server::game::Game;
use server::map::Terrain;
use server::position::Position;
use server::resource_pile::ResourcePile;
use server::unit::UnitType;

pub async fn run(mut game: Game, features: &Features) {
pub async fn run(mut game: Game) {
let mut state = client::init().await;
let features = Features {
import_export: true,
};

let mut sync_result = GameSyncResult::None;
loop {
Expand Down Expand Up @@ -109,19 +110,23 @@ fn add_terrain(game: &mut Game, pos: &str, terrain: Terrain) {
game.map.tiles.insert(Position::from_offset(pos), terrain);
}

const EXPORT_FILE: &str = "game.json";
// const EXPORT_FILE: &str = "game.json";

fn import() -> Game {
let file = File::open(EXPORT_FILE).expect("Failed to open export file");
let reader = BufReader::new(file);
let data: GameData = serde_json::from_reader(reader).expect("Failed to read export file");
Game::from_data(data)
// todo only works with native client
// let file = File::open(EXPORT_FILE).expect("Failed to open export file");
// let reader = BufReader::new(file);
// let data: GameData = serde_json::from_reader(reader).expect("Failed to read export file");
// Game::from_data(data)
panic!()
}

fn export(game: &Game) {
serde_json::to_writer_pretty(
File::create(EXPORT_FILE).expect("Failed to create export file"),
&game.cloned_data(),
)
.expect("Failed to write export file");
fn export(_game: &Game) {
// todo only works with native client
// serde_json::to_writer_pretty(
// File::create(EXPORT_FILE).expect("Failed to create export file"),
// &game.cloned_data(),
// )
// .expect("Failed to write export file");
panic!()
}
9 changes: 1 addition & 8 deletions client/src/local_client/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
use client::client::Features;
use client::local_client;
use server::game::Game;

#[macroquad::main("Clash")]
async fn main() {
let wasm = cfg!(feature = "wasm");

let features = Features {
import_export: !wasm,
};

//todo add button to decide random or fixed game
let game = if false {
Game::new(2, "a".repeat(32), true)
} else {
local_client::setup_local_game()
};

local_client::run(game, &features).await;
local_client::run(game).await;
}
4 changes: 2 additions & 2 deletions client/wasm-bindgen-macroquad.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ TARGET_DIR="target/wasm32-unknown-unknown"
# Build
echo "Building $PROJECT_NAME..."
if [ -n "$RELEASE" ]; then
cargo build --release --target wasm32-unknown-unknown --features "wasm"
cargo build --release --target wasm32-unknown-unknown
TARGET_DIR="$TARGET_DIR/release"
else
cargo build --target wasm32-unknown-unknown --features "wasm"
cargo build --target wasm32-unknown-unknown
TARGET_DIR="$TARGET_DIR/debug"
fi

Expand Down

0 comments on commit e1089e5

Please sign in to comment.