From: Ian Jackson Date: Sat, 27 Feb 2021 13:37:31 +0000 (+0000) Subject: rename PieceTrait and OutlineTrait X-Git-Tag: otter-0.4.0~317 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=25e9f41bbd4801e1447b37108192d46646652db4;p=otter.git rename PieceTrait and OutlineTrait Signed-off-by: Ian Jackson --- diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index 9364de06..9ac611c4 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -70,7 +70,7 @@ fn preview(items: Vec) { struct Prep { spec: ItemSpec, - pc: Box, + pc: Box, uos: Vec, bbox: Vec>, size: Vec, diff --git a/src/gamestate.rs b/src/gamestate.rs index 8c6e651c..cefb563a 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -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; fn surround_path(&self, pri: &PieceRenderInstructions) -> Result { @@ -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, SpecError>; + fn load(&self, i: usize) -> Result, 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, IE>; } -impl PieceExt for T where T: Piece + ?Sized { +impl PieceExt for T where T: PieceTrait + ?Sized { #[throws(IE)] fn make_defs(&self, gpc: &GPiece, pri: &PieceRenderInstructions) -> Html { diff --git a/src/global.rs b/src/global.rs index 1c37d0c4..1ce19e1b 100644 --- a/src/global.rs +++ b/src/global.rs @@ -70,7 +70,7 @@ pub struct IPlayer { #[derive(Debug,Serialize,Deserialize)] #[serde(transparent)] pub struct IPieces(ActualIPieces); -pub type ActualIPieces = SecondarySlotMap>; +pub type ActualIPieces = SecondarySlotMap>; #[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> { + pub fn get(&self, piece: PieceId) -> Option<&Box> { self.0.get(piece) } diff --git a/src/hand.rs b/src/hand.rs index 56082d02..a9a8fd34 100644 --- a/src/hand.rs +++ b/src/hand.rs @@ -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 { + fn load(&self, _: usize) -> Box { 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 + }) as Box } } @@ -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, diff --git a/src/pieces.rs b/src/pieces.rs index b3803cc5..5a2383f8 100644 --- a/src/pieces.rs +++ b/src/pieces.rs @@ -111,9 +111,9 @@ pub fn svg_rectangle_path(PosC([x,y]): PosC) -> Html { -x*0.5, -y*0.5, x, y, -x)) } -impl Outline for GenericSimpleShape +impl OutlineTrait for GenericSimpleShape where Desc: Debug + Send + Sync + 'static, - Outl: Outline, + Outl: OutlineTrait, { delegate! { to self.outline { @@ -128,7 +128,7 @@ impl Outline for GenericSimpleShape // 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 GenericSimpleShape 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 GenericSimpleShape #[typetag::serde(tag="type")] pub trait SimplePieceSpec: Debug { fn load_raw(&self) -> Result<(SimpleShape, &SimpleCommon), SpecError>; - fn load(&self) -> Result, SpecError> { + fn load(&self) -> Result, 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 { SimplePieceSpec::load(self)? } + fn load(&self, _: usize) -> Box { 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 { SimplePieceSpec::load(self)? } + fn load(&self, _: usize) -> Box { SimplePieceSpec::load(self)? } } diff --git a/src/shapelib.rs b/src/shapelib.rs index 98146f69..e3145a75 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -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; 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 { + pub fn load(&self) -> Box { 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,SpecError> { + -> Result,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, SpecError> { + fn load(&self, _: usize) -> Result, 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,SpecError> { + fn load(&self, i: usize) -> Result,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) { #[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 } -impl Outline for Rectangle { +impl OutlineTrait for Rectangle { #[throws(IE)] fn outline_path(&self, _pri: &PieceRenderInstructions, scale: f64) -> Html { let xy = (self.xy * scale)?; diff --git a/src/spec.rs b/src/spec.rs index 07682832..5f333cd9 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -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 { diff --git a/src/updates.rs b/src/updates.rs index 946c69ba..5b246822 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -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, 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 { 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, + p: &Box, op: PieceUpdateOp<(),()>, pri: &PieceRenderInstructions) -> PreparedPieceUpdate