diff options
| author | troido <troido@protonmail.com> | 2020-02-03 20:16:09 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-03 20:16:09 +0100 |
| commit | 53f358f73c37e86f4db9e7bd7af309697dc7237e (patch) | |
| tree | d118cdfb10e1519995a92ac0c58db1051c41325d /src/pos.rs | |
| parent | 30509956d4274b2565052dc045eec3742a159357 (diff) | |
only send changed cells, not the whole field each time
Diffstat (limited to 'src/pos.rs')
| -rw-r--r-- | src/pos.rs | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -1,18 +1,17 @@ - use std::ops::Add; use serde_json::{Value, json}; -use specs::{Component, VecStorage}; +use serde::{Serialize, Serializer, ser::SerializeTuple}; use super::util::{clamp, ToJson}; -#[derive(Component, Debug, Hash, PartialEq, Eq, Clone, Copy)] -#[storage(VecStorage)] +#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] pub struct Pos { pub x: i32, pub y: i32 } + impl Pos { pub fn new(x: i32, y: i32) -> Pos { @@ -27,6 +26,19 @@ impl Pos { } } + +impl Serialize for Pos { + fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> + where + S: Serializer, + { + let mut tup = serializer.serialize_tuple(2)?; + tup.serialize_element(&self.x)?; + tup.serialize_element(&self.y)?; + tup.end() + } +} + impl Add<Pos> for Pos { type Output = Pos; |
