Browse Source

Update README, fix typos, and update dependecies

new_protocol
ThePerkinrex 5 years ago
parent
commit
e3cfcba58a
No known key found for this signature in database GPG Key ID: 1F45A7C4BFB41607
  1. 111
      README.md
  2. 4
      gen-grpc-unity.sh
  3. 4
      server/Cargo.toml
  4. 2
      server/src/games/run.rs

111
README.md

@ -1,2 +1,113 @@
# cards-simulator
Gaem.
# The server
When run it creates a `properties.json` with some configs, `output.log` with the server output, and the `games` folder. Inside that folder games can be placed. For now only games coded in Rhai are supported, but myabe later support is added for wasm based games, or shared libraries, although the latter is quite unsafe and its support is quite unprobable.
## Making a game
The most important part of the game is the `game.json` file. It contains the metadata and many attributes for the game.
(`$json_schema` is where the file located in `server/schema/game-config.json`, in the future a public link will be offered)
```json
{
"$schema": "$json_schema",
"name": "UNO",
"version": "0.0.0",
"authors": ["ThePerkinrex"],
"script": "game.rhai",
"default_back": "cards/uno_back.png",
"available_cards": {
"B0": {
"image": "cards/blue0.png"
},
"+4": {
"image": "cards/plus4.png"
}
},
"piles": {
"deck": {
"cards": [
"B0", "+4", "+4", "+4", "+4"
]
},
"placed": {}
},
"player_piles": {
"deck": {}
}
}
```
In this file, firstly, the name of the game, the version and the authors are specified. The script (the game logic), is also specified, and the rest is the definition of the structure:
* `available_cards` contains the cards by id, which can have an `image` and `back_image`, this last one is not required when the `default_back` property is set.
* `piles` contains the card piles common to all players, these are named, and can have default cards placed in them.
* `player_piles` are the same as `piles` but specific to each player, so when the game is setup, a clone is created for each of the players.
* lastly, `default_back`, which isn't required as long as all thee cards have a `back_image` property, has the back image which will be used when `back_image` isn't specified.
Then we have the script, in this case `game.rhai`:
```rs
// setup(data) -> data
fn setup(data) { // Required
print("Setting up UNO for " + data.players + " players");
data.piles.deck = shuffle(data.piles.deck);
for i in range(0, 2) {
for player_idx in range(0, data.player_piles.len) {
let drawed_card = data.piles.deck.cards.pop();
data.player_piles[player_idx].deck.cards.push(drawed_card);
}
}
data.fw = true;
// Sets the turn direction used in UNO.
// This is an example of how the data object keeps custom properties, like some kind of global variable
return data;
}
// turn_end(data, player) -> [data, next_player]
fn turn_end(data, player) { // Required
print("Turn for " + player + " ending");
if data.fw {
player.add(1);
}else{
player.sub(1);
}
return [data, player];
}
// turn_start(data, player) -> data
fn turn_start(data, player) { // Not required
print("Turn for " + player + " starting");
return data;
}
// turn_start(data, card_clicked, action_author, current_player) -> [data, turn_has_ended]
fn on_click(data, card, action_author, current_player) { // Required
if action_author == current_player {
if card.pile_kind == "common" {
if card.pile_name == "deck" {
// Get a card from the deck
let c = data.pop_card(card);
data.player_piles[player.val].deck.cards.push(c);
}
}else{
if card.pile_name == "deck" {
let c = data.pop_card(card);
data.piles.placed.cards.push(c);
}
}
return [data, true];
}
return [data, false];
}
```
See for example the `shuffle` function, which is provided by the environment.
Go to the [rhai book](https://schungx.github.io/rhai/language/index.html) for the language reference.
### Common errors:
* When taking more cards than are available from a pile, `()` (null or undefined) is returned

4
gen-grpc-unity.sh

@ -1,4 +0,0 @@
#!/bin/bash
chmod +x unity/Packages/Grpc.Tools.2.33.1/tools/linux_x64/protoc
chmod +x unity/Packages/Grpc.Tools.2.33.1/tools/linux_x64/grpc_csharp_plugin
unity/Packages/Grpc.Tools.2.33.1/tools/linux_x64/protoc -I protobuf --csharp_out=unity/Assets/Scripts/grpc --grpc_out=unity/Assets/Scripts/grpc --plugin=protoc-gen-grpc=unity/Packages/Grpc.Tools.2.33.1/tools/linux_x64/grpc_csharp_plugin $(ls protobuf | grep .proto)

4
server/Cargo.toml

@ -18,7 +18,7 @@ regex = "1.4.2"
lazy_static = "1.4.0"
# Game loading
rhai = {version = "0.19.4", features = ["serde", "sync"]}
rhai = {version = "0.19.7", features = ["serde", "sync"]}
serde_json = "1.0.59"
serde = "1.0.117"
schemars = "0.8.0"
@ -30,7 +30,7 @@ prost = "0.6"
prost-types = "0.6.1"
# Database (SQLite)
rusqlite = {version = "0.24.1", features=["bundled"]}
rusqlite = {version = "0.24.2", features=["bundled"]}
# sqlx = { version = "0.3", default-features = false, features = [ "runtime-tokio", "macros", "sqlite" ] }
# TUI

2
server/src/games/run.rs

@ -73,7 +73,7 @@ impl RunningGame {
for (i, player) in current_players.iter().enumerate() {
players.insert(player.clone(), i as u32);
}
log::info!("PLayers in game {}: {:?}", name, players);
log::info!("Players in game {}: {:?}", name, players);
Self {
name,
piles,

Loading…
Cancel
Save