Changing the state
The game logic changes the state only through the Table that setup and apply_action receive. Each Table method records the change for the match's history and animations. Read the state at any time with table.state().
If apply_action returns Err, every change the call made is undone, including its log lines and its allow_undo.
Maps
| Method | Does |
|---|---|
set(of, key, value) |
Sets one key of a map, or removes it when value is None. |
write(of, &value) |
Replaces a whole map with your serde type. |
update(of, |value: &mut T| ...) |
Reads a map as T, changes it, and writes it back. |
of is a StateOf (The state). write keeps a field that serializes as null; add #[serde(skip_serializing_if = "Option::is_none")] to remove the key instead.
Pieces
| Method | Does | Returns |
|---|---|---|
add_piece(space_id, piece) |
Puts a piece at the end of a space. | its index |
insert_piece(space_id, index, piece) |
Puts a piece at index. Later pieces move up. |
|
remove_piece(space_id, index) |
Takes a piece out. Later pieces move down. | the Piece |
move_piece(from, index, to) |
Moves a piece to the end of to, which may be from. |
its new index |
move_piece_to(from, index, to, to_index) |
Moves a piece to to_index, counted after the piece has left from. |
|
shuffle(space_id, rng) |
Shuffles a space's pieces. | |
set_public_kind(space_id, index, kind) |
Changes what everyone sees, such as turning a card face up. | |
set_private_kind(space_id, index, kind) |
Changes the hidden part, or removes it with None. |
|
set_piece_owner(space_id, index, owner) |
Gives a piece an owner, or removes it with None. |
Every piece method changes indexes in the spaces it touches. Use the index a method returns, or find the piece again in table.state().
Spaces
| Method | Does | Returns |
|---|---|---|
add_space(space) |
Adds a space and its pieces. Panics if the id is taken. | its position |
remove_space(space_id) |
Removes a space and its pieces. | the Space |
set_space_owner(space_id, owner) |
Gives a space an owner, or removes it with None. |
Turns
set_active_players(ids) sets who may move next. Set it in every step that changes whose turn it is. An empty list means nobody can move; end the game with is_game_over instead.
Movements
Each piece method records a movement for the client to animate: Moved, Added, Removed, Flipped (from set_public_kind) or Shuffled. The game logic does nothing extra. The client reads them with useLastChange (The React client).
Log lines
table.log(line) adds a line to the step's log, which every viewer sees in the match's history. A step may write any number of lines, and so may setup for the opening. A string is a line by the seat that took the step:
table.log(format!("Player {player_id} takes a card"));
table.log(
LogLine::new()
.text(format!("Player {player_id} plays "))
.link(face.clone(), face),
);
Build a line with LogLine::new() and these methods. Import LogLine and LinePlayer from boardweaver_sdk.
| Method | Sets | Default |
|---|---|---|
.player(LinePlayer::Seat(id)) |
whose line it is: LinePlayer::Actor, LinePlayer::Seat(id) or LinePlayer::None |
LinePlayer::Actor, the seat that took the step |
.kind("combat") |
a label the client styles the line by: 1 to 32 characters of a-z, 0-9 and - |
none |
.text("loses ") |
appends plain text. Boardweaver shows it as it is: nothing in it is markup | |
.link(key, text) |
appends text with a key you choose, such as a card id. The client hears a hover or a click on it with useLogLinks |
- Every viewer reads every line, whatever they may see of the state. Name only public facts: "takes a card", never the card. This holds for the text, the link keys, the kind and the player.
- The game logic knows seat ids, not names. Boardweaver shows each line's player by name.
LinePlayer::Seat(id)names a seated player. Any other id panics.LinePlayer::Actoron the opening, which no seat took, shows with no player.- A step's lines have limits (Builds, limits and errors). Going past one panics.
Undo
table.allow_undo() marks the decision this step belongs to as one the seat may take back after it is committed. One call in any step of the decision is enough. The platform's undo takes back one step at a time, and reopens the rest of that decision as the seat's draft.
- Only a decision that ended with a
confirmstep can be undone after commit. A decision that ended by drawing randomness or by a reveal never can. - Draft steps not yet sent can always be taken back, with or without it.
- Undo stops at another seat's committed decision.