chiark / gitweb /
rename PieceTrait and OutlineTrait
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Feb 2021 13:37:31 +0000 (13:37 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 27 Feb 2021 13:37:31 +0000 (13:37 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otterlib.rs
src/gamestate.rs
src/global.rs
src/hand.rs
src/pieces.rs
src/shapelib.rs
src/spec.rs
src/updates.rs

index 9364de0626771738a2453ac2fad5c236b0d077e5..9ac611c48cfa44fb7052c5bd86bd7d701f073a3e 100644 (file)
@@ -70,7 +70,7 @@ fn preview(items: Vec<ItemForOutput>) {
 
   struct Prep {
     spec: ItemSpec,
-    pc: Box<dyn Piece>,
+    pc: Box<dyn PieceTrait>,
     uos: Vec<String>,
     bbox: Vec<Vec<f64>>,
     size: Vec<f64>,
index 8c6e651c213fc3ceda7d0d736520ae17184a10a5..cefb563a143b58e004d9fd2b6a94d0d56edf7a91 100644 (file)
@@ -111,7 +111,7 @@ pub trait PieceXData: Downcast + Debug + Send + 'static {
 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> {
@@ -137,7 +137,7 @@ pub struct UoDescription {
 }
 
 #[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
@@ -174,7 +174,7 @@ pub struct ApiPieceOpArgs<'a> {
   pub ipieces: &'a IPieces,
   pub player: PlayerId,
   pub piece: PieceId,
-  pub p: &'a dyn Piece,
+  pub p: &'a dyn PieceTrait,
 }
 
 #[derive(Debug,Clone)]
@@ -187,7 +187,7 @@ pub struct PieceRenderInstructions {
 #[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 ==========
@@ -281,7 +281,7 @@ impl VisiblePieceAngle {
 
 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,
@@ -373,7 +373,7 @@ pub trait PieceExt {
   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 {
index 1c37d0c4e183dcd2b618c6a582eb15ada4e9eb36..1ce19e1b6b65a357abd3a0971aadbd6e79bdcae4 100644 (file)
@@ -70,7 +70,7 @@ pub struct IPlayer {
 #[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(());
 
@@ -1247,7 +1247,7 @@ pub fn process_all_players_for_account<
 // ========== 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)
   }
 
index 56082d02b14723ba16f58356a36661268a9a1065..a9a8fd34cc1730f518db249f789548c5436c03ae 100644 (file)
@@ -27,7 +27,7 @@ struct HandState {
 #[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)
@@ -42,7 +42,7 @@ impl Outline for Hand {
 #[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())],
@@ -60,7 +60,7 @@ impl PieceSpec for piece_specs::Hand {
       &common)?;
     Box::new(Hand {
       shape,
-    }) as Box<dyn Piece>
+    }) as Box<dyn PieceTrait>
   }
 }
 
@@ -76,7 +76,7 @@ impl Hand {
 }
 
 #[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,
index b3803cc549931df883ae0bdeeddccf2f2b90a8f9..5a2383f82824b15ac9b8652734d1ea5dd7c2859a 100644 (file)
@@ -111,9 +111,9 @@ pub fn svg_rectangle_path(PosC([x,y]): PosC<f64>) -> Html {
                -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 {
@@ -128,7 +128,7 @@ impl<Desc, Outl> Outline for GenericSimpleShape<Desc, Outl>
 //    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) {
@@ -150,7 +150,7 @@ impl Piece for SimpleShape {
 
 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())
@@ -234,7 +234,7 @@ impl<Desc, Outl> GenericSimpleShape<Desc, Outl>
 #[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))
   }
 }
@@ -256,7 +256,7 @@ impl SimplePieceSpec for piece_specs::Disc {
 #[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 {
@@ -287,5 +287,5 @@ impl SimplePieceSpec for 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)? }
 }
index 98146f69cfceceae81b4423164d8c2aa9adc952b..e3145a75a4f8e10ca2d680fe5f865e687e54861e 100644 (file)
@@ -142,7 +142,7 @@ impl ItemEnquiryData {
   }
 }
 
-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)
@@ -151,7 +151,7 @@ impl Outline for Item { delegate! { to self.outline {
 }}}
 
 #[typetag::serde(name="Lib")]
-impl Piece for Item {
+impl PieceTrait for Item {
   fn nfaces(&self) -> RawFaceId { self.faces.len().try_into().unwrap() }
 
   #[throws(IE)]
@@ -199,7 +199,7 @@ pub fn libs_lookup(libname: &str)
 
 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()))?;
@@ -209,7 +209,7 @@ impl ItemSpec {
 
 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 {
@@ -276,7 +276,7 @@ impl Contents {
 
 #[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()
   }
 }
@@ -284,7 +284,7 @@ impl PieceSpec for ItemSpec {
 #[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))
     )?;
@@ -496,7 +496,7 @@ pub fn load(libs: &Vec<Config1>) {
 #[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)?
@@ -538,7 +538,7 @@ impl CircleDefn {
 #[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)?;
index 076828329e4757c7663c58c30d06c4ca4e2280f6..5f333cd9d4b7018cd19b25dfdfc4c550ff77e737 100644 (file)
@@ -199,7 +199,7 @@ mod outline {
   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 {
index 946c69bad01a6feea074e520be1c762fd29dd2c2..5b246822e7ca23fcc47f5a7da7120135b464062c 100644 (file)
@@ -200,7 +200,7 @@ pub fn log_did_to_piece_whoby(
   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));
@@ -218,7 +218,7 @@ pub fn log_did_to_piece(
   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
@@ -486,7 +486,7 @@ impl<'r> PrepareUpdatesBuffer<'r> {
   #[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