From: Ian Jackson Date: Sat, 14 May 2022 22:11:56 +0000 (+0100) Subject: Move outline into its own file X-Git-Tag: otter-1.1.0~159 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=7d0187a426a3d2be5d90f3f59e7a2e0de860a9b6;p=otter.git Move outline into its own file Signed-off-by: Ian Jackson --- diff --git a/src/imports.rs b/src/imports.rs index f1aa955b..cf03b444 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -96,6 +96,7 @@ pub use crate::materials_format; pub use crate::mgmtchannel::*; pub use crate::occultilks::*; pub use crate::organise; +pub use crate::outline::*; pub use crate::pcaliases::*; pub use crate::pcrender::*; pub use crate::pieces::*; diff --git a/src/lib.rs b/src/lib.rs index f601e92d..ad74d08c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,6 +41,7 @@ pub mod mgmtchannel; pub mod nwtemplates; pub mod occultilks; pub mod organise; +pub mod outline; pub mod pcaliases; pub mod pcrender; pub mod pieces; diff --git a/src/outline.rs b/src/outline.rs new file mode 100644 index 00000000..ebe25122 --- /dev/null +++ b/src/outline.rs @@ -0,0 +1,56 @@ +// Copyright 2020-2021 Ian Jackson and contributors to Otter +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +// Copyright 2020-2021 Ian Jackson and contributors to Otter +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +use crate::prelude::*; + +//================ principal definitions of both shapes ================ + +macro_rules! shape_defns { { + $( $Shape:ident $serde:literal ;)* +} => { paste!{ + + + $( use crate::shapelib::[< $Shape Outline >]; )* + + #[dyn_upcast(OutlineTrait)] + #[enum_dispatch(OutlineTrait)] + #[derive(Clone,Debug,Serialize,Deserialize)] + #[serde(tag="type")] + pub enum Outline { $( + #[serde(rename=$serde)] [< $Shape Outline >], + )* } + + + #[derive(Deserialize,Debug,Copy,Clone,Eq,PartialEq)] + pub enum Shape { $( + #[serde(rename=$serde)] [< $Shape >], + )* } + + + $( + #[derive(Deserialize,Debug)] + pub struct [< $Shape ShapeIndicator >]; + )* + + + impl Shape { + pub fn shapelib_loadable(self) + -> &'static dyn shapelib::ShapeLoadableTrait + { + match self { $( + Self::$Shape => &[< $Shape ShapeIndicator >] as _, + )* } + } + } + +} } } + +shape_defns! { + Circle "Circle"; + Rect "Rect" ; +} diff --git a/src/spec.rs b/src/spec.rs index ab0c5c82..07929b0d 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -5,6 +5,7 @@ // game specs use crate::crates::*; +use crate::outline::*; use otter_support::crates::*; use otter_base::crates::*; @@ -256,51 +257,6 @@ pub struct ItemSpec { pub item: String, } -mod outline { - use crate::prelude::*; - - macro_rules! shape_defns { { - $( $Shape:ident $serde:literal ;)* - } => { paste!{ - $( use crate::shapelib::[< $Shape Outline >]; )* - - #[dyn_upcast(OutlineTrait)] - #[enum_dispatch(OutlineTrait)] - #[derive(Clone,Debug,Serialize,Deserialize)] - #[serde(tag="type")] - pub enum Outline { $( - #[serde(rename=$serde)] [< $Shape Outline >], - )* } - - #[derive(Deserialize,Debug,Copy,Clone,Eq,PartialEq)] - pub enum Shape { $( - #[serde(rename=$serde)] [< $Shape >], - )* } - - $( - #[derive(Deserialize,Debug)] - pub struct [< $Shape ShapeIndicator >]; - )* - - impl Shape { - pub fn shapelib_loadable(self) - -> &'static dyn shapelib::ShapeLoadableTrait - { - match self { $( - Self::$Shape => &[< $Shape ShapeIndicator >] as _, - )* } - } - } - - } } } - - shape_defns! { - Circle "Circle"; - Rect "Rect" ; - } -} -pub use outline::*; - pub mod piece_specs { use super::*;