struct Prep {
spec: ItemSpec,
- pc: Box<dyn Piece>,
+ pc: Box<dyn PieceTrait>,
uos: Vec<String>,
bbox: Vec<Vec<f64>>,
size: Vec<f64>,
impl_downcast!(PieceXData);
#[enum_dispatch]
-pub trait Outline: Send + Debug {
+pub trait OutlineTrait: Send + Debug {
fn outline_path(&self, pri: &PieceRenderInstructions, scale: f64)
-> Result<Html, IE>;
fn surround_path(&self, pri: &PieceRenderInstructions) -> Result<Html, IE> {
}
#[typetag::serde]
-pub trait Piece: Outline + Send + Debug {
+pub trait PieceTrait: OutlineTrait + Send + Debug {
/// by convention, occult face is nfaces-1
// xxx this is no good, we need a central definition of the occult
// face to avoid weird behaviour with buggy gamespecs
pub ipieces: &'a IPieces,
pub player: PlayerId,
pub piece: PieceId,
- pub p: &'a dyn Piece,
+ pub p: &'a dyn PieceTrait,
}
#[derive(Debug,Clone)]
#[typetag::serde(tag="type")]
pub trait PieceSpec: Debug {
fn count(&self) -> usize { 1 }
- fn load(&self, i: usize) -> Result<Box<dyn Piece>, SpecError>;
+ fn load(&self, i: usize) -> Result<Box<dyn PieceTrait>, SpecError>;
}
// ========== implementations ==========
impl GPiece {
#[throws(IE)]
- pub fn prep_piecestate(&self, p: &dyn Piece, pri: &PieceRenderInstructions)
+ pub fn prep_piecestate(&self, p: &dyn PieceTrait, pri: &PieceRenderInstructions)
-> PreparedPieceState {
PreparedPieceState {
pos : self.pos,
fn ui_operations(&self, gpc: &GPiece) -> Result<Vec<UoDescription>, IE>;
}
-impl<T> PieceExt for T where T: Piece + ?Sized {
+impl<T> PieceExt for T where T: PieceTrait + ?Sized {
#[throws(IE)]
fn make_defs(&self, gpc: &GPiece, pri: &PieceRenderInstructions)
-> Html {
#[derive(Debug,Serialize,Deserialize)]
#[serde(transparent)]
pub struct IPieces(ActualIPieces);
-pub type ActualIPieces = SecondarySlotMap<PieceId, Box<dyn Piece>>;
+pub type ActualIPieces = SecondarySlotMap<PieceId, Box<dyn PieceTrait>>;
#[derive(Copy,Clone,Debug)]
pub struct ModifyingPieces(());
// ========== instance pieces data access ==========
impl IPieces {
- pub fn get(&self, piece: PieceId) -> Option<&Box<dyn Piece>> {
+ pub fn get(&self, piece: PieceId) -> Option<&Box<dyn PieceTrait>> {
self.0.get(piece)
}
#[typetag::serde(name="Hand")]
impl PieceXData for HandState { }
-impl Outline for Hand {
+impl OutlineTrait for Hand {
delegate!{
to self.shape {
fn outline_path(&self, _pri: &PieceRenderInstructions, scale: f64)
#[typetag::serde]
impl PieceSpec for piece_specs::Hand {
#[throws(SpecError)]
- fn load(&self, _: usize) -> Box<dyn Piece> {
+ fn load(&self, _: usize) -> Box<dyn PieceTrait> {
let common = SimpleCommon {
itemname: None,
faces: index_vec![ColourSpec(self.colour.clone())],
&common)?;
Box::new(Hand {
shape,
- }) as Box<dyn Piece>
+ }) as Box<dyn PieceTrait>
}
}
}
#[typetag::serde]
-impl Piece for Hand {
+impl PieceTrait for Hand {
fn nfaces(&self) -> RawFaceId { 1 }
#[throws(IE)]
fn svg_piece(&self, f: &mut Html, gpc: &GPiece,
-x*0.5, -y*0.5, x, y, -x))
}
-impl<Desc, Outl> Outline for GenericSimpleShape<Desc, Outl>
+impl<Desc, Outl> OutlineTrait for GenericSimpleShape<Desc, Outl>
where Desc: Debug + Send + Sync + 'static,
- Outl: Outline,
+ Outl: OutlineTrait,
{
delegate! {
to self.outline {
// let edge_attrs = format!(r##"stroke-width="" stroke"##
#[typetag::serde]
-impl Piece for SimpleShape {
+impl PieceTrait for SimpleShape {
#[throws(IE)]
fn svg_piece(&self, f: &mut Html, _gpc: &GPiece,
pri: &PieceRenderInstructions) {
impl<Desc, Outl> GenericSimpleShape<Desc, Outl>
where Desc: Debug + Send + Sync + 'static,
- Outl: Outline,
+ Outl: OutlineTrait,
{
pub fn count_faces(&self) -> usize {
max(self.colours.len(), self.edges.len())
#[typetag::serde(tag="type")]
pub trait SimplePieceSpec: Debug {
fn load_raw(&self) -> Result<(SimpleShape, &SimpleCommon), SpecError>;
- fn load(&self) -> Result<Box<dyn Piece>, SpecError> {
+ fn load(&self) -> Result<Box<dyn PieceTrait>, SpecError> {
Ok(Box::new(self.load_raw()?.0))
}
}
#[typetag::serde]
impl PieceSpec for piece_specs::Disc {
#[throws(SpecError)]
- fn load(&self, _: usize) -> Box<dyn Piece> { SimplePieceSpec::load(self)? }
+ fn load(&self, _: usize) -> Box<dyn PieceTrait> { SimplePieceSpec::load(self)? }
}
impl piece_specs::Square {
#[typetag::serde]
impl PieceSpec for piece_specs::Square {
#[throws(SpecError)]
- fn load(&self, _: usize) -> Box<dyn Piece> { SimplePieceSpec::load(self)? }
+ fn load(&self, _: usize) -> Box<dyn PieceTrait> { SimplePieceSpec::load(self)? }
}
}
}
-impl Outline for Item { delegate! { to self.outline {
+impl OutlineTrait for Item { delegate! { to self.outline {
fn outline_path(&self, pri: &PieceRenderInstructions, scale: f64)
-> Result<Html, IE>;
fn thresh_dragraise(&self, pri: &PieceRenderInstructions)
}}}
#[typetag::serde(name="Lib")]
-impl Piece for Item {
+impl PieceTrait for Item {
fn nfaces(&self) -> RawFaceId { self.faces.len().try_into().unwrap() }
#[throws(IE)]
impl ItemSpec {
#[throws(SpecError)]
- pub fn load(&self) -> Box<dyn Piece> {
+ pub fn load(&self) -> Box<dyn PieceTrait> {
let lib = libs_lookup(&self.lib)?;
let idata = lib.items.get(&self.item)
.ok_or(SpE::LibraryItemNotFound(self.item.clone()))?;
impl Contents {
fn load1(&self, idata: &ItemData, name: &str)
- -> Result<Box<dyn Piece>,SpecError> {
+ -> Result<Box<dyn PieceTrait>,SpecError> {
let svg_path = format!("{}/{}.usvg", self.dirname, &name);
let svg_data = fs::read_to_string(&svg_path)
.map_err(|e| if e.kind() == ErrorKind::NotFound {
#[typetag::serde(name="Lib")]
impl PieceSpec for ItemSpec {
- fn load(&self, _: usize) -> Result<Box<dyn Piece>, SpecError> {
+ fn load(&self, _: usize) -> Result<Box<dyn PieceTrait>, SpecError> {
self.load()
}
}
#[typetag::serde(name="LibList")]
impl PieceSpec for MultiSpec {
fn count(&self) -> usize { self.items.len() }
- fn load(&self, i: usize) -> Result<Box<dyn Piece>,SpecError> {
+ fn load(&self, i: usize) -> Result<Box<dyn PieceTrait>,SpecError> {
let item = self.items.get(i).ok_or_else(
|| SpE::InternalError(format!("item {:?} from {:?}", i, &self))
)?;
#[derive(Clone,Copy,Debug,Serialize,Deserialize)]
pub struct Circle { pub diam: f64 }
-impl Outline for Circle {
+impl OutlineTrait for Circle {
#[throws(IE)]
fn outline_path(&self, _pri: &PieceRenderInstructions, scale: f64) -> Html {
svg_circle_path(self.diam * scale)?
#[derive(Clone,Copy,Debug,Serialize,Deserialize)]
pub struct Rectangle { pub xy: PosC<f64> }
-impl Outline for Rectangle {
+impl OutlineTrait for Rectangle {
#[throws(IE)]
fn outline_path(&self, _pri: &PieceRenderInstructions, scale: f64) -> Html {
let xy = (self.xy * scale)?;
use super::*;
use crate::prelude::*;
use crate::shapelib::{Circle, Rectangle};
- #[enum_dispatch(Outline)]
+ #[enum_dispatch(OutlineTrait)]
#[derive(Clone,Debug,Serialize,Deserialize)]
#[serde(tag="type")]
pub enum OutlineRepr {
occults: &GameOccults,
player: PlayerId,
gpl: &mut GPlayer,
- piece: PieceId, pc: &GPiece, p: &dyn Piece,
+ piece: PieceId, pc: &GPiece, p: &dyn PieceTrait,
did: &str,
) -> (Vec<LogEntry>, Html) {
let who_by = Html(htmlescape::encode_minimal(&gpl.nick));
occults: &GameOccults,
player: PlayerId,
gpl: &mut GPlayer,
- piece: PieceId, pc: &GPiece, p: &dyn Piece,
+ piece: PieceId, pc: &GPiece, p: &dyn PieceTrait,
did: &str,
) -> Vec<LogEntry> {
log_did_to_piece_whoby(occults,player,gpl,piece,pc,p,did).0
#[throws(InternalError)]
fn piece_update_player(max_z: &mut ZCoord,
pc: &mut GPiece,
- p: &Box<dyn Piece>,
+ p: &Box<dyn PieceTrait>,
op: PieceUpdateOp<(),()>,
pri: &PieceRenderInstructions)
-> PreparedPieceUpdate