aboutsummaryrefslogtreecommitdiff
path: root/web/planetwars-rs/src/types.rs
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2021-12-29 21:24:57 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2021-12-29 21:25:29 +0100
commit0c6d978442b244ca3f29c1ffdd44b5007ae7ad93 (patch)
treebaae5fa459a49ecd362e548e0649e2f58c669a70 /web/planetwars-rs/src/types.rs
parent3eeaab6cec70e7a06a99a1ac2662974f71064bee (diff)
downloadplanetwars.dev-0c6d978442b244ca3f29c1ffdd44b5007ae7ad93.tar.xz
planetwars.dev-0c6d978442b244ca3f29c1ffdd44b5007ae7ad93.zip
separate out visualizer library
Diffstat (limited to 'web/planetwars-rs/src/types.rs')
-rw-r--r--web/planetwars-rs/src/types.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/web/planetwars-rs/src/types.rs b/web/planetwars-rs/src/types.rs
new file mode 100644
index 0000000..2d7d8c0
--- /dev/null
+++ b/web/planetwars-rs/src/types.rs
@@ -0,0 +1,45 @@
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct Expedition {
+ pub id: u64,
+ pub ship_count: u64,
+ pub origin: String,
+ pub destination: String,
+ pub owner: u64,
+ pub turns_remaining: u64,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct Planet {
+ pub ship_count: u64,
+ pub x: f32,
+ pub y: f32,
+ pub owner: Option<u32>,
+ pub name: String,
+}
+
+use std::hash::{Hash, Hasher};
+use std::mem;
+
+impl Hash for Planet {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ unsafe {
+ let x: u32 = mem::transmute_copy(&self.x);
+ let y: u32 = mem::transmute_copy(&self.y);
+ state.write_u32(x);
+ state.write_u32(y);
+ }
+ }
+}
+
+impl PartialEq for Planet {
+ fn eq(&self, other: &Self) -> bool {
+ (self.x - other.x).abs() < 0.0001 && (self.y - other.y).abs() < 0.0001
+ }
+}
+impl Eq for Planet {}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct State {
+ pub planets: Vec<Planet>,
+ pub expeditions: Vec<Expedition>,
+}