From 5199d6d83651d859fe0b6473e3392e82dd16a64c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 16 Mar 2021 18:16:23 +0000 Subject: [PATCH] clock: wip, skeleton Signed-off-by: Ian Jackson --- specs/penultima.game.toml | 14 +++++---- src/clock.rs | 63 +++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + 3 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 src/clock.rs diff --git a/specs/penultima.game.toml b/specs/penultima.game.toml index 81000f44..d55e4f92 100644 --- a/specs/penultima.game.toml +++ b/specs/penultima.game.toml @@ -142,7 +142,7 @@ items = ["K","Q","R","R","B","B","N","N"] posd = [10, 0] [[pieces]] -pos = [210, 85] +pos = [210, 45] type = "LibList" lib = "wikimedia" prefix = "chess-purple-" @@ -150,7 +150,7 @@ items = ["K","Q","R","R","B","B","N","N"] posd = [10, 0] [[pieces]] -pos = [205, 115] +pos = [205, 125] type = "LibList" lib = "wikimedia" prefix = "chess-w-" @@ -159,7 +159,7 @@ items = ["commoner","elephant","knight-king","mann","zebra", posd = [10, 0] [[pieces]] -pos = [205, 125] +pos = [205, 135] type = "LibList" lib = "wikimedia" prefix = "chess-w-" @@ -168,7 +168,7 @@ items = ["commoner","elephant","knight-king","mann","zebra", posd = [10, 0] [[pieces]] -pos = [205, 135] +pos = [205, 145] type = "LibList" lib = "wikimedia" prefix = "chess-b-" @@ -177,7 +177,7 @@ items = ["commoner","elephant","knight-king","mann","zebra", posd = [10, 0] [[pieces]] -pos = [205, 145] +pos = [205, 155] type = "LibList" lib = "wikimedia" prefix = "chess-b-" @@ -192,3 +192,7 @@ edge = "white" colour = "grey" shape.type = "Rectangle" shape.xy = [20,10] + +[[pieces]] +pos = [240, 100] +type = "ChessClock" diff --git a/src/clock.rs b/src/clock.rs new file mode 100644 index 00000000..3598af0c --- /dev/null +++ b/src/clock.rs @@ -0,0 +1,63 @@ +// Copyright 2020-2021 Ian Jackson and contributors to Otter +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +use crate::prelude::*; +use shapelib::Rectangle; + +const W: Coord = 50; +const H: Coord = 20; +const OUTLINE: Rectangle = Rectangle { xy: PosC([W as f64, H as f64]) }; + +#[derive(Debug,Clone,Serialize,Deserialize)] +pub struct ChessClock { // spec +} + +#[derive(Debug,Serialize,Deserialize)] +struct Clock { // state +} + +#[typetag::serde] +impl PieceSpec for ChessClock { + #[throws(SpecError)] + fn load(&self, _: usize) -> PieceSpecLoaded { + let clock = Clock { + + }; + PieceSpecLoaded { + p: Box::new(clock), + occultable: None, + } + } +} + +#[dyn_upcast] +impl OutlineTrait for Clock { + delegate!{ + to OUTLINE { + fn outline_path(&self, scale: f64) -> Result; + fn thresh_dragraise(&self) -> Result, IE>; + fn bbox_approx(&self) -> Result<[Pos;2], IE>; + } + } +} + +#[typetag::serde(name="ChessClock")] +impl PieceTrait for Clock { + fn nfaces(&self) -> RawFaceId { 1 } + + #[throws(IE)] + fn svg_piece(&self, f: &mut Html, _gpc: &GPiece, id: VisiblePieceId) { + dbgc!("rendering", id); + write!( &mut f.0, r##" + + "##)?; + } + + #[throws(IE)] + fn describe_html(&self, _gpc: &GPiece) -> Html { + Html::lit("the chess clock") + } + + fn itemname(&self) -> &str { "chess-clock" } +} diff --git a/src/lib.rs b/src/lib.rs index 1c4072c1..1703862c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,7 @@ pub mod prelude; pub mod accounts; pub mod authproofs; +pub mod clock; pub mod commands; pub mod config; pub mod debugreader; -- 2.30.2