diff --git a/VERSION b/VERSION index c9929e36..3c80e4f0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.4.2 \ No newline at end of file +1.4.3 \ No newline at end of file diff --git a/acp/package.json b/acp/package.json index 6ed6d040..f7b4ba07 100644 --- a/acp/package.json +++ b/acp/package.json @@ -1,6 +1,6 @@ { "name": "mnml-client", - "version": "1.4.2", + "version": "1.4.3", "description": "", "main": "index.js", "scripts": { diff --git a/client/package.json b/client/package.json index 8512d4d4..081153f9 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "mnml-client", - "version": "1.4.2", + "version": "1.4.3", "description": "", "main": "index.js", "scripts": { diff --git a/client/src/components/construct.jsx b/client/src/components/construct.jsx index 249a9e22..17e97349 100644 --- a/client/src/components/construct.jsx +++ b/client/src/components/construct.jsx @@ -43,7 +43,7 @@ class ConstructAvatar extends Component { if (!animTarget && !animSource) { if (!this.idle) { this.idle = idleAnimation(this.props.construct.id); - this.animations.push(this.idle); + return this.animations.push(this.idle); } return this.idle.play(); @@ -77,6 +77,10 @@ class ConstructAvatar extends Component { // back to idle if (!animTarget && !animSource) { + if (!this.idle) { + this.idle = idleAnimation(this.props.construct.id); + return this.animations.push(this.idle); + } return this.idle.play(); } diff --git a/client/src/socket.jsx b/client/src/socket.jsx index a6a97162..74140922 100644 --- a/client/src/socket.jsx +++ b/client/src/socket.jsx @@ -213,7 +213,7 @@ function createSocket(events) { let pongTimeout; function onPong() { events.setPing(Date.now() - ping); - pongTimeout = setTimeout(sendPing, 10000); + pongTimeout = setTimeout(sendPing, 1000); } // ------------- diff --git a/ops/package.json b/ops/package.json index 3eb65099..805c3f1a 100755 --- a/ops/package.json +++ b/ops/package.json @@ -1,6 +1,6 @@ { "name": "mnml-ops", - "version": "1.4.2", + "version": "1.4.3", "description": "", "main": "index.js", "scripts": { diff --git a/server/Cargo.toml b/server/Cargo.toml index a92823d2..0a21651d 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mnml" -version = "1.4.2" +version = "1.4.3" authors = ["ntr "] [dependencies] diff --git a/server/src/img.rs b/server/src/img.rs index d9309323..4575924b 100644 --- a/server/src/img.rs +++ b/server/src/img.rs @@ -1,12 +1,13 @@ -use uuid::Uuid; -use rand::prelude::*; -use rand::distributions::{Normal, WeightedIndex}; - +use std::f64; use std::fs::copy; use std::fs::File; use std::io::prelude::*; use std::char::from_u32; +use uuid::Uuid; +use rand::prelude::*; +use rand::distributions::{Normal, WeightedIndex}; + use failure::Error; use failure::err_msg; @@ -36,8 +37,8 @@ pub fn invader_write(id: Uuid) -> Result { // filters ? // distribution for lightness - // bellcurve around 50% - let l_dist = Normal::new(50.0, 10.0); + // bellcurve around 75% + let l_dist = Normal::new(75.0, 10.0); let s_dist = Normal::new(25.0, 10.0); let mut colours = std::iter @@ -83,7 +84,104 @@ pub fn invader_write(id: Uuid) -> Result { Ok(id) } -fn hieroglyph() -> String { +enum ConstructShape { + Square, + Triangle, + Circle, + Line, + V, + Tri, + Plus, + Blank, +} + +// default ? shape +pub fn construct(id: Uuid) -> Result { + let mut rng = thread_rng(); + let mut svg = Vec::new(); + + // distribution for lightness + // bellcurve around 75% + let l_dist = Normal::new(50.0, 10.0); + let s_dist = Normal::new(25.0, 10.0); + + // 8 6 or 4 points in shape + // 1 head point + // n / 2 shapes with a colour each + // random size/radius props for each + + // add up to 100 for % + let shapes = [ + (ConstructShape::Square, 100), + // (ConstructShape::Triangle, 10), + // (ConstructShape::Circle, 10), + // (ConstructShape::Line, 10), + // (ConstructShape::V, 10), + // (ConstructShape::Tri, 3), + // (ConstructShape::Plus, 5), + // (ConstructShape::Blank, 1), + ]; + let shape_dist = WeightedIndex::new(shapes.iter().map(|v| v.1))?; + + let n_shapes = rng.gen_range(2, 10); + + write!(&mut svg, "")?; + for i in 0..n_shapes - 1 { + let h = rng.gen_range(0, 360); + let s = s_dist.sample(&mut rng) as usize; + let l = l_dist.sample(&mut rng) as usize; + let colour = format!("hsl({:}, {:}%, {:}%)", h, s, l); + + let fraction: f64 = (1.0 / n_shapes as f64) * i as f64; + let angle: f64 = (fraction * 180.0) / f64::consts::PI; + + match shapes[shape_dist.sample(&mut rng)].0 { + ConstructShape::Square => { + let size = rng.gen_range(5, 50); + let distance = rng.gen_range(50, 200); + let rotation = rng.gen_range(0, 180); + write!(&mut svg, "", + colour, size / 2, size / 2, size, size, rotation, distance, angle)?; + write!(&mut svg, "", + colour, size / 2, size / 2, size, size, rotation, distance, angle + 180.0)?; + }, + ConstructShape::Triangle => { + + }, + ConstructShape::Circle => { + + }, + ConstructShape::Line => { + + }, + ConstructShape::V => { + + }, + ConstructShape::Tri => { + + }, + ConstructShape::Plus => { + + }, + ConstructShape::Blank => { + + }, + } + } + + write!(&mut svg, "")?; + + let dest = format!("/var/lib/mnml/public/imgs/{}.svg", id); + println!("default dest={:?}", dest); + + let mut file = File::create(dest)?; + file.write_all(&svg)?; + + Ok(id) +} + + +fn _hieroglyph() -> String { let mut rng = thread_rng(); let mut s = String::new(); @@ -99,7 +197,6 @@ fn hieroglyph() -> String { return s; } - #[cfg(test)] mod tests { use super::*; @@ -111,9 +208,16 @@ mod tests { // } // } + // #[test] + // fn hieroglyph_test() { + // hieroglyph(); + // } + #[test] - fn hieroglyph_test() { - hieroglyph(); + fn construct_img_test() { + for i in 0..100 { + construct(Uuid::new_v4()).unwrap(); + } } } @@ -124,7 +228,7 @@ mod tests { // var h = Math.floor(rand() * 360); // //saturation goes from 40 to 100, it avoids greyish colors // var s = ((rand() * 60) + 40) + '%'; -// //lightness can be anything from 0 to 100, but probabilities are a bell curve around 50% +// //lightness can be anything from 0 to 100, but probabilities are a bell curve around 75% // var l = ((rand()+rand()+rand()+rand()) * 25) + '%'; // var color = 'hsl(' + h + ',' + s + ',' + l + ')'; diff --git a/server/src/instance.rs b/server/src/instance.rs index 10f6ede4..4f8d8804 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -271,6 +271,9 @@ impl Instance { let mut game = Game::new(); current_round.game_id = Some(game.id); + // disable upkeep until players finish their game + self.phase_end = None; + game .set_player_num(2) .set_player_constructs(3) @@ -303,7 +306,6 @@ impl Instance { self.phase_start = Utc::now(); self.phase_end = self.time_control.vbox_phase_end(); - self.players.iter_mut().for_each(|p| { p.set_ready(false); p.vbox.fill();