diff --git a/Cargo.lock b/Cargo.lock index e21bd43..ac8f407 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,6 +7,7 @@ dependencies = [ "rocket 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "rocket_codegen 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "rocket_contrib 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 7ed7264..588c4da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ rocket = "0.3.17" rocket_codegen = "0.3.17" rand = "0.5.5" base64 = "0.9.3" +serde_json = "1.0.32" [dependencies.rocket_contrib] version = "*" diff --git a/Rocket.toml b/Rocket.toml new file mode 100644 index 0000000..aa7833a --- /dev/null +++ b/Rocket.toml @@ -0,0 +1,6 @@ +[development] +address = "0.0.0.0" +port = 8000 +workers = 8 +log = "normal" +limits = { forms = 32768 } \ No newline at end of file diff --git a/main.rs b/main.rs index f6c8d13..53383f9 100644 --- a/main.rs +++ b/main.rs @@ -6,10 +6,13 @@ use std::str::FromStr; extern crate rocket; -extern crate rocket_contrib; +#[macro_use] extern crate rocket_contrib; use rocket::http::RawStr; use rocket_contrib::Json; +//extern crate serde_json; +//use serde_json::{Value, Error}; + extern crate rand; use rand::Rng; @@ -17,7 +20,7 @@ extern crate base64; fn main() { - rocket::ignite().mount("/", routes![index,login]).launch(); + rocket::ignite().mount("/", routes![index,login,]).launch(); } #[get("/")] @@ -27,25 +30,30 @@ fn index() -> &'static str { } #[get("/login//")] -fn login(username: &RawStr, password: &RawStr) -> String +fn login(username: &RawStr, password: &RawStr) -> Json { let mut rng = rand::thread_rng(); let session: u64 = rng.gen(); - format!("{:x}", session) + let session = format!("{:x}", session); + Json(json!(session)) } -/*#[get("///get_stars")] +#[get("/game///get_stars")] fn get_stars(game_id: &RawStr, session_id: &RawStr) -> Json { - let data = r#"{[ - { - id: 0, - "name": "StarGazer", - "resources": 43, - "coordinates { - x: 40, - y: 50 - }, - ]}"#; -*/} \ No newline at end of file + let player = Player { + name: "Daniel", + color: (0,255,255) + }; + + + let star = Star { + id: 80085, + name: "Loli sanctuary", + coordinates: (50, 64), + resources: 50 + }; + + Json(star) +} diff --git a/types.rs b/types.rs new file mode 100644 index 0000000..6bae0c6 --- /dev/null +++ b/types.rs @@ -0,0 +1,117 @@ +#[derive(Serialize)] +struct TechFunc { + on_cycle: Option, + on_tick: Option, + passive: Option +} + +impl Default for TechFunc { + fn default() -> TechFunc { + TechFunc { + on_cycle: None, + on_tick: None, + passive: None + } + } +} + +#[derive(Serialize)] +struct Player { + name: String, + color: (u8, u8, u8), + tech: HashMap, + research_queue: vec, + money: u16 +} + + +fn scanning(player: Player) -> u16 { + let scan_level = player.tech.get("Scanning").0/144; + scan_level + 2 +} + +fn hyperspace(player: Player) -> u16 { + let hyperspace_level = player.tech.get("Hyperspace Range").0/144; + hyperspace_level + 3 +} + +fn terraforming(player: Player) -> u16 { + let terraforming_level = player.tech.get("Terraforming").0/144; + terrafirming*5 +} + +fn experimentation(player: Player) { + let terraforming_level = player.tech.get("Experimentation").0/144; + + let n = player.tech.len(); + let mut rng = rand::thread_rng(); + tech = rng.gen_range(0, n); +} + +impl Default for Player { + fn default() -> Player { + let mut techs = HashMap::new(); + + techs.insert("Scanning", (144, TechFunc{passive: scanning}); + techs.insert("Hyperspace Range", (144, TechFunc{passive: hyperspace})); + techs.insert("Terraforming", (144, TechFunc{passive: terraforming})); + techs.insert("Experimentation", (144, TechFunc)); + techs.insert("Weapons", (144, TechFunc)); + techs.insert("Banking", (144, TechFunc)); + techs.insert("Manufactoring", (144, TechFunc)); + + Player { + tech: techs + } + } +} + +impl process for Weapons { + fn passive() -> (u16, u16) { + (self.amount/144, self.effect2) + } +} + +Player.techs.get("Weapons").passive() + +impl Player { + fn payday() { + let banking_level = self.techs.get("Banking")/144; + self.money = banking_level*75; + + let experimentation_level = self.techs.get("Experimentation") + } +} + +#[derive(Serialize)] +struct Infrastructure { + name: String, + amount: u16 +} + +#[derive(Serialize)] +struct Star { + id: u16, + name: String, + coordinates: (u32, u32), + resources: u16, + owner: Option, + buildings: vec +} + +impl Default for Star { + fn default() { + let infrastructures = [ + Infrastructure {name: "Economy", amount: 0}, + Infrastructure {name: "Industry", amount: 0}, + Infrastructure {name: "Science", amount: 0} + ]; + + Star { + owner: None, + buildings: infrastructures + } + } +} + +