chiark / gitweb /
changelog: document further make-release changes
[otter.git] / apitest / at-hidden.rs
1 // Copyright 2020-2021 Ian Jackson and contributors to Otter
2 // SPDX-License-Identifier: AGPL-3.0-or-later
3 // There is NO WARRANTY.
4
5 use crate::*;
6
7 type Ctx = UsualCtx;
8
9 impl Ctx {
10   #[throws(Explode)]
11   fn dice(&mut self) {
12     self.su().mgmt_conn().cmd(&MC::SetFakeTime(FakeTimeSpec(Some(0))))?;
13     self.otter_resetting(&G("reset demo"))?;
14     
15     let mut alice = self.connect_player(&self.alice)?;
16     let mut bob = self.connect_player(&self.bob)?;
17
18     let mut a_pieces = alice.pieces::<PIA>()?;
19     let hand = a_pieces.find_by_desc_glob(otter::hand::UNCLAIMED_HAND_DESC);
20     let hand_pos = a_pieces[hand].pos;
21     let die_a = a_pieces.find_by_desc_glob("a d2 *");
22     let die_red = a_pieces.find_by_desc_glob("a red die *");
23
24     let move_into_hand = |alice: &mut Session, a_pieces: &'_ mut _, p, x_off| {
25       let pos = (hand_pos + PosC::new(x_off,0))?;
26       alice.api_piece(GH::With, PuSynch(&mut (a_pieces, p)), pos)?;
27       Ok::<_,Explode>(())
28     };
29     move_into_hand(&mut alice, &mut a_pieces, die_a, -10)?;
30
31     alice.api_piece(GH::With, PuSynch(&mut (&mut a_pieces, hand)),
32                     ("k", json!({ "opname": "claim",
33                                    "wrc": WRC::Unpredictable })))?;
34     move_into_hand(&mut alice, &mut a_pieces, die_red, 10)?;
35
36     self.su().mgmt_conn().cmd(&MC::SetFakeTime(FakeTimeSpec(Some(6000))))?;
37     alice.synch()?;
38     bob.synch()?;
39     alice.api_piece(GH::With, PuSynch(&mut (&mut a_pieces, die_red)),
40                     ("k", json!({ "opname": "roll",
41                                    "wrc": WRC::UpdateSvg })))?;
42
43     alice.api_piece(GH::With, PuSynch(&mut (&mut a_pieces, hand)),
44                     ("k", json!({ "opname": "deactivate",
45                                    "wrc": WRC::Unpredictable })))?;
46     alice.synch()?;
47     bob.synch()?;
48   }
49 }
50
51 #[throws(Explode)]
52 fn tests(mut c: Ctx) {
53   test!(c, "dice",                          c.dice()                   ?);
54 }
55
56 #[throws(Explode)]
57 pub fn main() {
58   tests(Ctx::setup()?)?;
59 }