summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2018-06-03 17:22:22 +0200
committerJustin Worthe <justin@worthe-it.co.za>2018-06-03 17:22:22 +0200
commit34c87bf04a9b70809eda125ca180de1d993d410e (patch)
tree805bf7556868f4958a73dd50b0a7996f98c54177 /src
parent9d7d406107998c87525852032495f33f37155294 (diff)
Moved json parsing to be part of a module, with textmap equivalence
Diffstat (limited to 'src')
-rw-r--r--src/bin/perf-test.rs4
-rw-r--r--src/input/json.rs (renamed from src/json.rs)0
-rw-r--r--src/input/mod.rs2
-rw-r--r--src/input/textmap.rs67
-rw-r--r--src/lib.rs2
-rw-r--r--src/main.rs2
6 files changed, 73 insertions, 4 deletions
diff --git a/src/bin/perf-test.rs b/src/bin/perf-test.rs
index 03da160..71044ad 100644
--- a/src/bin/perf-test.rs
+++ b/src/bin/perf-test.rs
@@ -17,7 +17,7 @@ fn main() {
fn normal_state() {
println!("Normal size state file");
let start_time = PreciseTime::now();
- let (settings, state) = match json::read_state_from_file(STATE_PATH) {
+ let (settings, state) = match input::json::read_state_from_file(STATE_PATH) {
Ok(ok) => ok,
Err(error) => {
println!("Error while parsing JSON file: {}", error);
@@ -31,7 +31,7 @@ fn normal_state() {
fn big_state() {
println!("Big state file");
let start_time = PreciseTime::now();
- let (settings, state) = match json::read_state_from_file(STATE_BIG_PATH) {
+ let (settings, state) = match input::json::read_state_from_file(STATE_BIG_PATH) {
Ok(ok) => ok,
Err(error) => {
println!("Error while parsing JSON file: {}", error);
diff --git a/src/json.rs b/src/input/json.rs
index 3a3fbf2..3a3fbf2 100644
--- a/src/json.rs
+++ b/src/input/json.rs
diff --git a/src/input/mod.rs b/src/input/mod.rs
new file mode 100644
index 0000000..47f359a
--- /dev/null
+++ b/src/input/mod.rs
@@ -0,0 +1,2 @@
+pub mod json;
+pub mod textmap;
diff --git a/src/input/textmap.rs b/src/input/textmap.rs
new file mode 100644
index 0000000..dbee60a
--- /dev/null
+++ b/src/input/textmap.rs
@@ -0,0 +1,67 @@
+use std::fs::File;
+use std::io::prelude::*;
+use std::error::Error;
+
+use ::engine::*;
+use ::engine::settings::*;
+use ::engine::geometry::*;
+
+
+pub fn read_state_from_file(filename: &str) -> Result<(GameSettings, GameState), Box<Error>> {
+ let mut file = File::open(filename)?;
+ let mut content = String::new();
+ file.read_to_string(&mut content)?;
+
+ let engine_settings = GameSettings {
+ size: Point::new(8,4),
+ energy_income: 5,
+ energy: BuildingSettings {
+ price: 20,
+ health: 5,
+ construction_time: 2-2,
+ weapon_damage: 0,
+ weapon_speed: 0,
+ weapon_cooldown_period: 0,
+ energy_generated_per_turn: 3
+ },
+ defence: BuildingSettings {
+ price: 30,
+ health: 20,
+ construction_time: 4-2,
+ weapon_damage: 0,
+ weapon_speed: 0,
+ weapon_cooldown_period: 0,
+ energy_generated_per_turn: 0
+ },
+ attack: BuildingSettings {
+ price: 30,
+ health: 5,
+ construction_time: 2-2,
+ weapon_damage: 5,
+ weapon_speed: 2,
+ weapon_cooldown_period: 3,
+ energy_generated_per_turn: 0
+ }
+ };
+ let engine_state = GameState::new(
+ Player {
+ energy: 20,
+ health: 5,
+ energy_generated: 5
+ },
+ Player {
+ energy: 20,
+ health: 5,
+ energy_generated: 5
+ },
+ Vec::new(),
+ Vec::new(),
+ Vec::new(),
+ Vec::new(),
+ Vec::new(),
+ Vec::new(),
+ &engine_settings
+ );
+
+ Ok((engine_settings, engine_state))
+}
diff --git a/src/lib.rs b/src/lib.rs
index 6bcfc00..7b15502 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -9,6 +9,6 @@ extern crate time;
extern crate rayon;
-pub mod json;
+pub mod input;
pub mod engine;
pub mod strategy;
diff --git a/src/main.rs b/src/main.rs
index 651df35..e84e207 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -32,7 +32,7 @@ fn main() {
let start_time = PreciseTime::now();
println!("Reading in state.json file");
- let (settings, state) = match json::read_state_from_file(STATE_PATH) {
+ let (settings, state) = match input::json::read_state_from_file(STATE_PATH) {
Ok(ok) => ok,
Err(error) => {
println!("Error while parsing JSON file: {}", error);