})() {
Err(err) => {
let err : GameError = err;
+ if let GameError::InternalErrorSVG(svg) = err { Err(svg)? }
eprintln!("API {:?} => {:?}", &form, &err);
},
Ok((update, logents)) => {
let logent = LogEntry {
html : format!("{} grasped {}",
&htmlescape::encode_minimal(&pl.nick),
- pc.describe_html(&lens.log_pri(piece, pc))),
+ pc.describe_html(&lens.log_pri(piece, pc))?),
};
(update, vec![logent])
let logent = LogEntry {
html : format!("{} released {}",
&htmlescape::encode_minimal(&pl.nick),
- pc.describe_html(&lens.log_pri(piece, pc))),
+ pc.describe_html(&lens.log_pri(piece, pc))?),
};
(update, vec![logent])
Conflict,
PieceGone,
PieceHeld,
+ InternalErrorSVG(#[from] SVGProcessingError),
}
#[derive(Error,Debug)]
pub trait Piece : Send + Debug {
fn svg_piece(&self, f: &mut String, pri: &PieceRenderInstructions) -> SR;
+ #[throws(SE)]
fn outline_path(&self, pri : &PieceRenderInstructions) -> String;
+ #[throws(SE)]
fn surround_path(&self, pri : &PieceRenderInstructions) -> String;
fn svg_x_defs(&self, pri : &PieceRenderInstructions) -> String;
+ #[throws(SE)]
fn thresh_dragraise(&self, pri : &PieceRenderInstructions)
-> Option<Coord>;
- fn describe_html(&self, face : Option<FaceId>) -> String;
+
+ fn describe_html(&self, face : Option<FaceId>) -> Result<String,SE>;
}
#[derive(Debug,Copy,Clone)]
pub fn make_defs(&self, pri : &PieceRenderInstructions) -> String {
let pr = self;
let mut defs = String::new();
- let dragraise = match pr.p.thresh_dragraise(pri) {
- Some(n) if n < 0 => panic!(),
+ let dragraise = match pr.p.thresh_dragraise(pri)? {
+ Some(n) if n < 0 => Err(SE::NegativeDragraise)?,
Some(n) => n,
None => -1,
};
write!(defs, r##"</g>"##)?;
write!(defs,
r##"<path id="select{}" stroke="black" fill="none" d="{}"/>"##,
- pri.id, pr.p.surround_path(&pri))?;
+ pri.id, pr.p.surround_path(&pri)?)?;
write!(defs, "{}", pr.p.svg_x_defs(&pri))?;
defs
}
}
}
- pub fn describe_html(&self, pri : &PieceRenderInstructions) -> String {
+ pub fn describe_html(&self, pri : &PieceRenderInstructions) -> Result<String,SE> {
self.p.describe_html(Some(pri.face))
}
}
UnknownOperator,
BadNumber,
WriteFail,
+ NegativeDragraise,
}
display_as_debug!{SVGProcessingError}
write!(f, r##"<path fill="{}" d="{}"/>"##,
self.colours[pri.face], self.path)?;
}
+ #[throws(SE)]
fn outline_path(&self, _pri : &PieceRenderInstructions) -> String {
self.path.clone()
}
+ #[throws(SE)]
fn surround_path(&self, _pri : &PieceRenderInstructions) -> String {
self.scaled_path.clone()
}
+ #[throws(SE)]
fn thresh_dragraise(&self, _pri : &PieceRenderInstructions)
-> Option<Coord> {
Some(self.approx_dia / 2)
fn svg_x_defs(&self, _pri : &PieceRenderInstructions) -> String {
"".to_owned()
}
+ #[throws(SE)]
fn describe_html(&self, face : Option<FaceId>) -> String {
if let Some(face) = face {
format!("a {} {}", self.colours[face], self.desc)