Strategická: Rozšíření API na moc brzy
This commit is contained in:
parent
c76f21fc3b
commit
281567422e
2 changed files with 9 additions and 2 deletions
|
@ -11,9 +11,10 @@ Parametry:
|
||||||
- `main` - Hlavní hra
|
- `main` - Hlavní hra
|
||||||
- `test_{0,1,..}` Testovací hra daného uživatele (číslo je jako který tým hrají)
|
- `test_{0,1,..}` Testovací hra daného uživatele (číslo je jako který tým hrají)
|
||||||
- round_id: To zjistí z otazu na stav
|
- round_id: To zjistí z otazu na stav
|
||||||
|
- min_round: Validní odpovědi pouze pokud je tento nebo pozdější tah, jinak "too-early"
|
||||||
|
|
||||||
Stav:
|
Stav:
|
||||||
GET na `/api/state?game=<jmeno_hry>&token=<token>`
|
GET na `/api/state?game=<jmeno_hry>&token=<token>&min_round=<min_round>`
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
status: "ok"
|
status: "ok"
|
||||||
|
@ -39,7 +40,7 @@ GET na `/api/state?game=<jmeno_hry>&token=<token>`
|
||||||
nebo
|
nebo
|
||||||
|
|
||||||
{
|
{
|
||||||
status: "working" # Server počítá následující stav, klient má počkat
|
status: "working" nebo "too-early" # Server počítá následující stav nebo je některý z předchozích tahů, klient má počkat
|
||||||
wait: <float> # Jak dlouho má klient čekat, než se zeptá znovu
|
wait: <float> # Jak dlouho má klient čekat, než se zeptá znovu
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -35,6 +35,12 @@ def api_state():
|
||||||
team = get_context()
|
team = get_context()
|
||||||
game = team.game
|
game = team.game
|
||||||
team_id = team.team_id
|
team_id = team.team_id
|
||||||
|
min_round = args_get("min_round", int, True)
|
||||||
|
if min_round is not None and min_round > game.current_round:
|
||||||
|
return json.dumps({
|
||||||
|
"status": "too-early",
|
||||||
|
"wait": 5.0,
|
||||||
|
})
|
||||||
state = game.current_state()
|
state = game.current_state()
|
||||||
if state is None:
|
if state is None:
|
||||||
return json.dumps({
|
return json.dumps({
|
||||||
|
|
Loading…
Reference in a new issue