shapes migration

This commit is contained in:
ntr 2019-09-14 19:46:14 +10:00
parent fcd7a66880
commit 443d39725f
7 changed files with 35 additions and 22 deletions

View File

@ -1,11 +1,9 @@
// Update with your config settings.
const local = {
module.exports = {
client: 'postgresql',
connection: {
database: 'mnml',
user: 'mnml',
password: process.env.MNML_PG_PASSWORD,
password: 'gggggggggg',
},
pool: {
min: 2,
@ -15,9 +13,3 @@ const local = {
tableName: 'knex_migrations'
}
};
module.exports = {
development: local,
production: local,
};

View File

@ -0,0 +1,11 @@
const uuidv4 = require('uuid/v4');
// give everybody the shapes mtx
exports.up = async knex => {
await knex.raw(`
INSERT INTO mtx (id, account, variant)
SELECT uuid_generate_v4() as id, id as account, 'Shapes'
FROM accounts;
`);
};
exports.down = async () => {};

View File

@ -17,6 +17,6 @@
"pg": "^7.4.3",
"request": "^2.88.0",
"sdftosvg": "0.0.4",
"uuid": "^3.3.2"
"uuid": "^3.3.3"
}
}

View File

@ -891,7 +891,7 @@ pub fn construct_spawn(tx: &mut Transaction, account: Uuid, name: String, team:
let _returned = result.iter().next().ok_or(err_msg("no row returned"))?;
img::molecular_write(construct.img)?;
img::shapes_write(construct.img)?;
info!("spawned construct account={:} name={:?}", account, construct.name);
return Ok(construct);

View File

@ -102,8 +102,8 @@ pub fn shapes_write(id: Uuid) -> Result<Uuid, Error> {
// distribution for lightness
// bellcurve around 75%
let l_dist = Normal::new(70.0, 10.0);
let s_dist = Normal::new(25.0, 10.0);
let l_dist = Normal::new(50.0, 10.0);
let s_dist = Normal::new(75.0, 10.0);
// 8 6 or 4 points in shape
// 1 head point
@ -123,17 +123,27 @@ pub fn shapes_write(id: Uuid) -> Result<Uuid, Error> {
];
let shape_dist = WeightedIndex::new(shapes.iter().map(|v| v.1))?;
let n_shapes = rng.gen_range(4, 5);
let n_shapes = 4;
let n_shapes_items = [
(2, 1),
(3, 5),
(4, 10),
(5, 10),
];
let num_dist = WeightedIndex::new(n_shapes_items.iter().map(|v| v.1))?;
let n_shapes = num_dist.sample(&mut rng) as usize;
write!(&mut svg, "<svg xmlns='http://www.w3.org/2000/svg' version='1.1' viewBox='-500 -500 1000 1000' width='1000' height='1000'><g>")?;
for i in 0..n_shapes {
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 scalar = rng.gen_range(50.0, 200.0);
let scalar = match i == n_shapes {
true => 0.0,
false => rng.gen_range(50.0, 200.0),
};
let rotation = rng.gen_range(0, 180);
let angle: f64 = i as f64 * (1.0 / n_shapes as f64) * f64::consts::PI;
let x_translate = angle.cos() * scalar;
@ -193,7 +203,6 @@ pub fn shapes_write(id: Uuid) -> Result<Uuid, Error> {
write!(&mut svg, "</g></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)?;

View File

@ -712,7 +712,7 @@ pub fn instance_practice(tx: &mut Transaction, account: &Account) -> Result<Inst
// generate bot imgs for the client to see
for c in bot.constructs.iter() {
img::molecular_write(c.img)?;
img::shapes_write(c.img)?;
}
let mut instance = Instance::new()
@ -830,14 +830,14 @@ pub fn demo() -> Result<Vec<Player>, Error> {
// generate bot imgs for the client to see
for c in bot.constructs.iter() {
img::molecular_write(c.img)?;
img::shapes_write(c.img)?;
};
let bot2 = bot_player();
// generate bot imgs for the client to see
for c in bot2.constructs.iter() {
img::molecular_write(c.img)?;
img::shapes_write(c.img)?;
};

View File

@ -63,6 +63,7 @@ impl TryFrom<String> for MtxVariant {
"Rename" => Ok(MtxVariant::Rename),
"Molecular" => Ok(MtxVariant::Molecular),
"Invader" => Ok(MtxVariant::Invader),
"Shapes" => Ok(MtxVariant::Shapes),
_ => Err(format_err!("mtx variant not found variant={:?}", v)),
}
}