From: Ian Jackson Date: Sat, 13 Feb 2021 22:02:54 +0000 (+0000) Subject: pass PieceState to [add_]ui_operations X-Git-Tag: otter-0.4.0~504 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=0b3cb32b2ffdd4722722a2cdd0814e7842ea4b5d;p=otter.git pass PieceState to [add_]ui_operations NFC Signed-off-by: Ian Jackson --- diff --git a/daemon/session.rs b/daemon/session.rs index e49dbd37..bd9381d4 100644 --- a/daemon/session.rs +++ b/daemon/session.rs @@ -124,7 +124,7 @@ fn session_inner(form: Json, zg: pr.zlevel.zg, pinned: pr.pinned, angle: vangle, - uos: &p.ui_operations()?, + uos: &p.ui_operations(pr)?, }; let for_piece = SessionPieceContext { diff --git a/src/bin/otterlib.rs b/src/bin/otterlib.rs index f727c189..88e0bde3 100644 --- a/src/bin/otterlib.rs +++ b/src/bin/otterlib.rs @@ -93,7 +93,21 @@ fn preview(items: Vec) { (||{ let pc = spec.clone().load().context("load")?; let mut uos = vec![]; - pc.add_ui_operations(&mut uos).context("add uos")?; + let gen_dummy = Generation(1); + let gpc_dummy = PieceState { + pos: PosC([0,0]), + face: default(), + held: None, + zlevel: ZLevel { z: default(), zg: gen_dummy }, + pinned: false, + occult: default(), + angle: default(), + gen: gen_dummy, + lastclient: ClientId(default()), + gen_before_lastclient: gen_dummy, + xdata: None, + }; + pc.add_ui_operations(&mut uos, &gpc_dummy).context("add uos")?; let uos = uos.into_iter().map(|uo| uo.opname).collect::>(); let spec = spec.clone(); diff --git a/src/gamestate.rs b/src/gamestate.rs index 8316bcc3..a82b18a8 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -135,7 +135,8 @@ pub trait Piece: Outline + Send + Debug { fn nfaces(&self) -> RawFaceId; #[throws(InternalError)] - fn add_ui_operations(&self, _upd: &mut Vec) { } + fn add_ui_operations(&self, _upd: &mut Vec, + _gpc: &PieceState) { } fn ui_operation(&self, _gs: &mut GameState, _player: PlayerId, _piece: PieceId, @@ -269,7 +270,7 @@ impl PieceState { z : self.zlevel.z.clone(), zg : self.zlevel.zg, pinned : self.pinned, - uos : p.ui_operations()?, + uos : p.ui_operations(self)?, } } @@ -294,7 +295,7 @@ impl PieceXDataExt for PieceXDataState { pub trait PieceExt { fn make_defs(&self, pri: &PieceRenderInstructions) -> Result; fn describe_pri(&self, pri: &PieceRenderInstructions) -> Html; - fn ui_operations(&self) -> Result, IE>; + fn ui_operations(&self, gpc: &PieceState) -> Result, IE>; } impl PieceExt for T where T: Piece + ?Sized { @@ -323,7 +324,7 @@ impl PieceExt for T where T: Piece + ?Sized { } #[throws(InternalError)] - fn ui_operations(&self) -> Vec { + fn ui_operations(&self, gpc: &PieceState) -> Vec { type WRC = WhatResponseToClientOp; let mut out = vec![]; @@ -336,7 +337,7 @@ impl PieceExt for T where T: Piece + ?Sized { desc: Html::lit("flip"), }) } - self.add_ui_operations(&mut out)?; + self.add_ui_operations(&mut out, gpc)?; out } }