}
#[throws(OnlineError)]
- fn check_held(&self, pc: &PieceState, player: PlayerId) {
+ fn check_held(&self, pc: &GPiece, player: PlayerId) {
if pc.held != None && pc.held != Some(player) {
throw!(OnlineError::PieceHeld)
}
struct ApiPieceWrest {
}
#[throws(OnlineError)]
- fn check_held(&self, _pc: &PieceState, _player: PlayerId) { }
+ fn check_held(&self, _pc: &GPiece, _player: PlayerId) { }
#[throws(ApiPieceOpError)]
fn op(&self, a: ApiPieceOpArgs) -> PieceUpdate {
struct ApiPieceMove(Pos);
#[throws(OnlineError)]
- fn check_held(&self, pc: &PieceState, player: PlayerId) {
+ fn check_held(&self, pc: &GPiece, player: PlayerId) {
// This will ensure that occultations are (in general) properly
// updated, because the player will (have to) release the thing
// again
};
let timezone = &arecord.timezone;
let tz = tz_from_str(&timezone);
- let gpl = GPlayerState {
+ let gpl = GPlayer {
nick: nick.to_string(),
layout: arecord.layout,
idmap: default(),
MGI::ListPieces => readonly(cs,ag,ig, &[TP::ViewNotSecret], |ig|{
let pieces = ig.gs.pieces.iter().filter_map(
|(piece,p)| (|| Ok::<_,MgmtError>(if_chain!{
- let &PieceState { pos, face, .. } = p;
+ let &GPiece { pos, face, .. } = p;
if let Some(pinfo) = ig.ipieces.get(piece);
let desc_html = pinfo.describe_html_infallible(None, p);
let itemname = pinfo.itemname().to_string();
if p.nfaces() <= face.into() {
throw!(SpecError::FaceNotFound);
}
- let pc = PieceState {
+ let pc = GPiece {
held: None,
zlevel: ZLevel { z: z.increment()?, zg: gs.gen },
lastclient: default(),
(||{
let pc = spec.clone().load().context("load")?;
let mut uos = vec![];
- let gpc_dummy = PieceState::dummy();
+ let gpc_dummy = GPiece::dummy();
pc.add_ui_operations(&mut uos, &gpc_dummy).context("add uos")?;
let uos = uos.into_iter().map(|uo| uo.opname).collect::<Vec<_>>();
let spec = spec.clone();
let max_facecols = pieces.iter().map(|s| s.face_cols()).max().unwrap_or(1);
let max_uos = pieces.iter().map(|s| s.uos.len()).max().unwrap_or(0);
- let gpc_dummy = PieceState::dummy();
+ let gpc_dummy = GPiece::dummy();
println!("{}", &HTML_PRELUDE);
println!(r#"<table rules="all">"#);
pub occults: GameOccults,
}
-pub type GPlayers = DenseSlotMap<PlayerId, GPlayerState>;
+pub type GPlayers = DenseSlotMap<PlayerId, GPlayer>;
#[derive(Debug,Serialize,Deserialize,Clone)]
-pub struct GPlayerState {
+pub struct GPlayer {
pub nick: String,
pub layout: PresentationLayout,
pub idmap: PerPlayerIdMap,
}
#[derive(Debug,Serialize,Deserialize)]
-pub struct PieceState {
+pub struct GPiece {
pub pos: Pos,
pub face: FaceId,
pub held: Option<PlayerId>,
#[throws(InternalError)]
fn add_ui_operations(&self, _upd: &mut Vec<UoDescription>,
- _gpc: &PieceState) { }
+ _gpc: &GPiece) { }
fn ui_operation(&self, _a: ApiPieceOpArgs<'_>,
_opname: &str, _wrc: WhatResponseToClientOp)
}
// #[throws] doesn't work here - fehler #todo
- fn svg_piece(&self, f: &mut Html, gpc: &PieceState,
+ fn svg_piece(&self, f: &mut Html, gpc: &GPiece,
pri: &PieceRenderInstructions) -> Result<(),IE>;
- fn describe_html(&self, face: Option<FaceId>, gpc: &PieceState)
+ fn describe_html(&self, face: Option<FaceId>, gpc: &GPiece)
-> Result<Html,IE>;
- fn delete_hook(&self, _p: &PieceState, _gs: &mut GameState)
+ fn delete_hook(&self, _p: &GPiece, _gs: &mut GameState)
-> ExecuteGameChangeUpdates {
ExecuteGameChangeUpdates{ pcs: vec![], log: vec![], raw: None }
}
// ---------- game state - rendering etc. ----------
-impl PieceState {
+impl GPiece {
#[throws(IE)]
pub fn prep_piecestate(&self, p: &dyn Piece, pri: &PieceRenderInstructions)
-> PreparedPieceState {
pub fn dummy() -> Self {
let gen_dummy = Generation(1);
- PieceState {
+ GPiece {
pos: PosC([0,0]),
face: default(),
held: None,
}
pub trait PieceExt {
- fn make_defs(&self, gpc: &PieceState, pri: &PieceRenderInstructions)
+ fn make_defs(&self, gpc: &GPiece, pri: &PieceRenderInstructions)
-> Result<Html, IE>;
- fn describe_html_infallible(&self, face: Option<FaceId>, gpc: &PieceState)
+ fn describe_html_infallible(&self, face: Option<FaceId>, gpc: &GPiece)
-> Html;
- fn describe_pri(&self, gpc: &PieceState, pri: &PieceRenderInstructions)
+ fn describe_pri(&self, gpc: &GPiece, pri: &PieceRenderInstructions)
-> Html;
- fn ui_operations(&self, gpc: &PieceState) -> Result<Vec<UoDescription>, IE>;
+ fn ui_operations(&self, gpc: &GPiece) -> Result<Vec<UoDescription>, IE>;
}
impl<T> PieceExt for T where T: Piece + ?Sized {
#[throws(IE)]
- fn make_defs(&self, gpc: &PieceState, pri: &PieceRenderInstructions)
+ fn make_defs(&self, gpc: &GPiece, pri: &PieceRenderInstructions)
-> Html {
let mut defs = Html(String::new());
let dragraise = match self.thresh_dragraise(pri)? {
defs
}
- fn describe_html_infallible(&self, face: Option<FaceId>, gpc: &PieceState)
+ fn describe_html_infallible(&self, face: Option<FaceId>, gpc: &GPiece)
-> Html {
self.describe_html(face, gpc)
.unwrap_or_else(|e| {
})
}
- fn describe_pri(&self, gpc: &PieceState, pri: &PieceRenderInstructions)
+ fn describe_pri(&self, gpc: &GPiece, pri: &PieceRenderInstructions)
-> Html {
self.describe_html_infallible(Some(pri.face), gpc)
}
#[throws(InternalError)]
- fn ui_operations(&self, gpc: &PieceState) -> Vec<UoDescription> {
+ fn ui_operations(&self, gpc: &GPiece) -> Vec<UoDescription> {
type WRC = WhatResponseToClientOp;
let mut out = vec![];
#[derive(Debug,Serialize,Deserialize,Default)]
#[serde(transparent)]
pub struct GPieces(pub(in crate::global) ActualGPieces);
-type ActualGPieces = DenseSlotMap<PieceId, PieceState>;
+type ActualGPieces = DenseSlotMap<PieceId, GPiece>;
#[derive(Debug)]
pub struct Client {
/// caller is responsible for logging; threading it through
/// proves the caller has a log entry.
#[throws(MgmtError)]
- pub fn player_new(&mut self, gnew: GPlayerState, inew: IPlayerState,
+ pub fn player_new(&mut self, gnew: GPlayer, inew: IPlayerState,
account: Arc<AccountName>, logentry: LogEntry)
-> (PlayerId, PreparedUpdateEntry, LogEntry) {
// saving is fallible, but we can't attempt to save unless
pub fn players_remove(&mut self, old_players_set: &HashSet<PlayerId>)
->
Result<Vec<
- (Option<GPlayerState>, Option<IPlayerState>, PreparedUpdateEntry)
+ (Option<GPlayer>, Option<IPlayerState>, PreparedUpdateEntry)
>, InternalError>
{
// We have to filter this player out of everything
occults: default(),
};
- let held_by_old = |p: &PieceState| if_chain! {
+ let held_by_old = |p: &GPiece| if_chain! {
if let Some(held) = p.held;
if old_players_set.contains(&held);
then { true }
deref_to_field!{GPieces, ActualGPieces, 0}
impl GPieces {
- pub fn get_mut(&mut self, piece: PieceId) -> Option<&mut PieceState> {
+ pub fn get_mut(&mut self, piece: PieceId) -> Option<&mut GPiece> {
self.0.get_mut(piece)
}
- pub fn values_mut(&mut self) -> sm::ValuesMut<PieceId, PieceState> {
+ pub fn values_mut(&mut self) -> sm::ValuesMut<PieceId, GPiece> {
self.0.values_mut()
}
pub fn as_mut(&mut self, _: ModifyingPieces) -> &mut ActualGPieces {
impl ById for GPieces {
type Id = PieceId;
- type Entry = PieceState;
+ type Entry = GPiece;
type Error = OnlineError;
#[throws(OE)]
- fn byid(&self, piece: PieceId) -> &PieceState {
+ fn byid(&self, piece: PieceId) -> &GPiece {
self.get(piece).ok_or(OE::PieceGone)?
}
#[throws(OE)]
- fn byid_mut(&mut self, piece: PieceId) -> &mut PieceState {
+ fn byid_mut(&mut self, piece: PieceId) -> &mut GPiece {
self.get_mut(piece).ok_or(OE::PieceGone)?
}
}
fn into_iter(self) -> Self::IntoIter { (&self.0).into_iter() }
}*/
impl<'p> IntoIterator for &'p mut GPieces {
- type Item = (PieceId, &'p mut PieceState);
- type IntoIter = sm::IterMut<'p, PieceId, PieceState>;
+ type Item = (PieceId, &'p mut GPiece);
+ type IntoIter = sm::IterMut<'p, PieceId, GPiece>;
fn into_iter(self) -> Self::IntoIter { (&mut self.0).into_iter() }
}
impl Piece for Hand {
fn nfaces(&self) -> RawFaceId { 1 }
#[throws(IE)]
- fn svg_piece(&self, f: &mut Html, gpc: &PieceState,
+ fn svg_piece(&self, f: &mut Html, gpc: &GPiece,
pri: &PieceRenderInstructions) {
self.shape.svg_piece_raw(f, pri, &mut |f: &mut String| {
if_chain!{
}
#[throws(IE)]
- fn describe_html(&self, _face: Option<FaceId>, gpc: &PieceState) -> Html {
+ fn describe_html(&self, _face: Option<FaceId>, gpc: &GPiece) -> Html {
let xdata = gpc.xdata.get()?;
self.describe_html_inner(xdata)
}
#[throws(InternalError)]
fn add_ui_operations(&self, upd: &mut Vec<UoDescription>,
- gpc: &PieceState) {
+ gpc: &GPiece) {
upd.push(if_chain! {
if let Some(xdata) = gpc.xdata.get::<HandState>()?;
if let Some(_owner) = &xdata.owner;
pub fn piece_pri(
_occults: &GameOccults, // xxx
player: PlayerId,
- gpl: &mut GPlayerState,
+ gpl: &mut GPlayer,
piece: PieceId,
- pc: &PieceState,
+ pc: &GPiece,
) -> PieceRenderInstructions {
let vpiece = gpl.idmap.fwd_or_insert(piece);
let angle = VisiblePieceAngle(pc.angle);
pub fn vpiece_decode(
_gs: &GameState, // xxx
player: PlayerId,
- gpl: &GPlayerState,
+ gpl: &GPlayer,
vis: VisiblePieceId
) -> Option<PieceId> {
let piece = gpl.idmap.rev(vis);
#[typetag::serde]
impl Piece for SimpleShape {
#[throws(IE)]
- fn svg_piece(&self, f: &mut Html, _gpc: &PieceState,
+ fn svg_piece(&self, f: &mut Html, _gpc: &GPiece,
pri: &PieceRenderInstructions) {
self.svg_piece_raw(f, pri, &mut |_|Ok(()))?;
}
#[throws(IE)]
- fn describe_html(&self, face: Option<FaceId>, _gpc: &PieceState) -> Html {
+ fn describe_html(&self, face: Option<FaceId>, _gpc: &GPiece) -> Html {
Html(if_chain! {
if let Some(face) = face;
if let Some(colour) = self.colours.get(face);
fn nfaces(&self) -> RawFaceId { self.faces.len().try_into().unwrap() }
#[throws(IE)]
- fn svg_piece(&self, f: &mut Html, _gpc: &PieceState,
+ fn svg_piece(&self, f: &mut Html, _gpc: &GPiece,
pri: &PieceRenderInstructions) {
let face = &self.faces[pri.face];
let svgd = &self.svgs[face.svg];
svgd.0)?;
}
#[throws(IE)]
- fn describe_html(&self, face: Option<FaceId>, _gpc: &PieceState) -> Html {
+ fn describe_html(&self, face: Option<FaceId>, _gpc: &GPiece) -> Html {
self.descs[ match face {
Some(face) => self.faces[face].desc,
None => self.desc_hidden,
let ier = ItemEnquiryData {
itemname: k.clone(),
f0bbox,
- f0desc: loaded.describe_html(Some(default()), &PieceState::dummy())?,
+ f0desc: loaded.describe_html(Some(default()), &GPiece::dummy())?,
};
out.push(ier);
}
fn deliver(&self,
ag: &AccountsGuard,
g: &Instance,
- gpl: &GPlayerState,
+ gpl: &GPlayer,
ipl: &IPlayerState,
token: AccessTokenInfo)
-> Result<AccessTokenReport, TDE>;
fn deliver(&self,
_ag: &AccountsGuard,
_g: &Instance,
- _gpl: &GPlayerState,
+ _gpl: &GPlayer,
_ipl: &IPlayerState,
_token: AccessTokenInfo) -> AccessTokenReport {
AccessTokenReport { lines: vec![
fn deliver(&self,
_ag: &AccountsGuard,
_g: &Instance,
- _gpl: &GPlayerState,
+ _gpl: &GPlayer,
_ipl: &IPlayerState,
_token: AccessTokenInfo) -> AccessTokenReport {
AccessTokenReport { lines: vec![ "Fixed access token".to_string() ] }
fn deliver<'t>(&self,
_ag: &AccountsGuard,
_g: &Instance,
- _gpl: &GPlayerState,
+ _gpl: &GPlayer,
_ipl: &IPlayerState,
token: AccessTokenInfo)
-> AccessTokenReport {
fn deliver<'t>(&self,
ag: &AccountsGuard,
g: &Instance,
- gpl: &GPlayerState,
+ gpl: &GPlayer,
ipl: &IPlayerState,
token: AccessTokenInfo)
-> AccessTokenReport {
pub fn log_did_to_piece_whoby(
occults: &GameOccults,
player: PlayerId,
- gpl: &mut GPlayerState,
- piece: PieceId, pc: &PieceState, p: &dyn Piece,
+ gpl: &mut GPlayer,
+ piece: PieceId, pc: &GPiece, p: &dyn Piece,
did: &str,
) -> (Vec<LogEntry>, Html) {
let who_by = Html(htmlescape::encode_minimal(&gpl.nick));
pub fn log_did_to_piece(
occults: &GameOccults,
player: PlayerId,
- gpl: &mut GPlayerState,
- piece: PieceId, pc: &PieceState, p: &dyn Piece,
+ gpl: &mut GPlayer,
+ piece: PieceId, pc: &GPiece, p: &dyn Piece,
did: &str,
) -> Vec<LogEntry> {
log_did_to_piece_whoby(occults,player,gpl,piece,pc,p,did).0
#[throws(InternalError)]
fn piece_update_player(max_z: &mut ZCoord,
- pc: &mut PieceState,
+ pc: &mut GPiece,
p: &Box<dyn Piece>,
op: PieceUpdateOp<(),()>,
pri: &PieceRenderInstructions)
ops: PieceUpdateOps,
gen_update: GUF)
-> PreparedUpdateEntry_Piece
- where GUF: FnOnce(&mut PieceState, Generation, &IsResponseToClientOp)
+ where GUF: FnOnce(&mut GPiece, Generation, &IsResponseToClientOp)
{
let gen = self.gen();
let gs = &mut self.g.gs;