finished object json writes
This commit is contained in:
parent
759ac868dd
commit
c853299c46
@ -1,3 +1,5 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@ -864,7 +866,12 @@ pub fn game_update(tx: &mut Transaction, game: &Game) -> Result<(), Error> {
|
|||||||
result.iter().next().ok_or(format_err!("game {:?} could not be written", game))?;
|
result.iter().next().ok_or(format_err!("game {:?} could not be written", game))?;
|
||||||
|
|
||||||
if game.finished() {
|
if game.finished() {
|
||||||
info!("game finished state={:?}", game);
|
info!("finished id={:?}", game.id);
|
||||||
|
|
||||||
|
match game_json_file_write(&game) {
|
||||||
|
Ok(dest) => info!("wrote dest={:?}", dest),
|
||||||
|
Err(e) => error!("json write error={:?}", e),
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(i) = game.instance {
|
if let Some(i) = game.instance {
|
||||||
instance_game_finished(tx, &game, i)?;
|
instance_game_finished(tx, &game, i)?;
|
||||||
@ -874,6 +881,12 @@ pub fn game_update(tx: &mut Transaction, game: &Game) -> Result<(), Error> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn game_json_file_write(g: &Game) -> Result<String, Error> {
|
||||||
|
let dest = format!("/var/lib/mnml/data/games/{}.mnml.game.json", g.id);
|
||||||
|
serde_json::to_writer(File::create(&dest)?, g)?;
|
||||||
|
Ok(dest)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn game_skill(tx: &mut Transaction, account: &Account, game_id: Uuid, construct_id: Uuid, target_construct_id: Option<Uuid>, skill: Skill) -> Result<Game, Error> {
|
pub fn game_skill(tx: &mut Transaction, account: &Account, game_id: Uuid, construct_id: Uuid, target_construct_id: Option<Uuid>, skill: Skill) -> Result<Game, Error> {
|
||||||
let mut game = game_get(tx, game_id)?;
|
let mut game = game_get(tx, game_id)?;
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use serde_cbor::{from_slice, to_vec};
|
use serde_cbor::{from_slice, to_vec};
|
||||||
@ -547,15 +549,26 @@ pub fn instance_update(tx: &mut Transaction, instance: Instance) -> Result<Insta
|
|||||||
|
|
||||||
result.iter().next().ok_or(err_msg("no instance row returned"))?;
|
result.iter().next().ok_or(err_msg("no instance row returned"))?;
|
||||||
|
|
||||||
// info!("{:?} wrote instance", instance.id);
|
trace!("{:?} wrote instance", instance.id);
|
||||||
|
|
||||||
if instance.finished() {
|
if instance.finished() {
|
||||||
info!("instance finished state={:?}", instance);
|
info!("finished id={:?}", instance.id);
|
||||||
|
|
||||||
|
match instance_json_file_write(&instance) {
|
||||||
|
Ok(dest) => info!("wrote dest={:?}", dest),
|
||||||
|
Err(e) => error!("json write error={:?}", e),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(instance);
|
return Ok(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn instance_json_file_write(g: &Instance) -> Result<String, Error> {
|
||||||
|
let dest = format!("/var/lib/mnml/data/instances/{}.mnml.instance.json", g.id);
|
||||||
|
serde_json::to_writer(File::create(&dest)?, g)?;
|
||||||
|
Ok(dest)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn instance_get(tx: &mut Transaction, instance_id: Uuid) -> Result<Instance, Error> {
|
pub fn instance_get(tx: &mut Transaction, instance_id: Uuid) -> Result<Instance, Error> {
|
||||||
let query = "
|
let query = "
|
||||||
SELECT *
|
SELECT *
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user