no_updates(ig, MGR::Fine)
},
+ MGI::ResetFromGameSpec { spec_toml: spec } => {
+ let ig = cs.check_acl(&ag, ig, PCH::Instance, &[TP::ChangePieces])?.0;
+ let spec: toml::Value = spec.parse()
+ .map_err(|e: toml::de::Error| ME::TomlSyntaxError(e.to_string()))?;
+ let GameSpec {
+ pieces, table_size, table_colour, pcaliases,
+ } = toml_de::from_value(&spec)
+ .map_err(|e: toml_de::Error| ME::TomlStructureError(e.to_string()))?;
+ let mut insns = vec![];
+ for piece in ig.gs.pieces.keys() {
+ insns.push(MGI::DeletePiece(piece));
+ }
+ for (alias, target) in pcaliases.into_iter() {
+ insns.push(MGI::DefinePieceAlias{ alias, target });
+ }
+ insns.push(MGI::ClearLog);
+ insns.push(MGI::SetTableSize(table_size));
+ insns.push(MGI::SetTableColour(table_colour));
+ for pspec in pieces.into_iter() {
+ insns.push(MGI::AddPieces(pspec));
+ }
+ let html = hformat!("{} reset the game", &who);
+ (U{ pcs: vec![],
+ log: vec![ LogEntry { html } ],
+ raw: None },
+ MGR::InsnExpanded,
+ None, insns, ig)
+ }
+
MGI::InsnMark(token) => {
let (ig, _) = cs.check_acl(&ag,ig,PCH::Instance, &[TP::TestExistence])?;
no_updates(ig, MGR::InsnMark(token))
}
}
impl<T> SpecParseToml<T> { pub fn new() -> Self { Self(default()) } }
-#[allow(dead_code)]
struct SpecRaw<T>(pub PhantomData<T>);
impl<T:SomeSpec> SpecParse for SpecRaw<T> {
type T = String;
#[throws(AE)]
fn parse(buf: String) -> String { buf }
}
-#[allow(dead_code)]
impl<T> SpecRaw<T> { pub fn new() -> Self { Self(default()) } }
#[throws(AE)]
instance_name.clone(),
MgmtGameUpdateMode::Bulk,
);
- let GameSpec {
- table_size,
- pieces,
- table_colour,
- pcaliases,
- } = read_spec(&ma, &args.game_file, SpecParseToml::new())?;
+ let spec_toml = read_spec(&ma, &args.game_file,
+ SpecRaw::<GameSpec>::new())?;
let mut insns = vec![];
insns.extend(setup_table(&ma, &instance_name, &table_spec)?);
}
- let (pcs, aliases) = chan.list_pieces()?;
- for p in pcs {
- insns.push(MgmtGameInstruction::DeletePiece(p.piece));
- }
- for p in aliases {
- insns.push(MgmtGameInstruction::DeletePieceAlias(p));
- }
-
- for (alias, target) in pcaliases.into_iter() {
- insns.push(MGI::DefinePieceAlias{ alias, target });
- }
-
- insns.push(MGI::ClearLog);
- insns.push(MGI::SetTableSize(table_size));
- insns.push(MGI::SetTableColour(table_colour));
-
- for pspec in pieces.into_iter() {
- insns.push(MGI::AddPieces(pspec));
- }
+ insns.push(MGI::ResetFromGameSpec { spec_toml });
chan.alter_game(insns, None)?;
DeletePieceAlias(String),
DefinePieceAlias { alias: String, target: Box<dyn PieceSpec> },
+ ResetFromGameSpec { spec_toml: String },
+
ResetPlayerAccess(PlayerId),
RedeliverPlayerAccess(PlayerId),
BadSpec(#[from] SpecError),
TokenDeliveryFailed(#[from] TokenDeliveryError),
CoordinateOverflow(#[from] CoordinateOverflow),
+ TomlSyntaxError(String),
+ TomlStructureError(String),
RngIsReal,
}
impl Display for MgmtError {