Startegická: Zobrazení a editace konfigurace

This commit is contained in:
Jiří Kalvoda 2022-09-14 19:12:16 +02:00
parent 518879428e
commit fbf85454b5
2 changed files with 24 additions and 10 deletions

View file

@ -13,6 +13,7 @@ import sys
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("game_id") parser.add_argument("game_id")
parser.add_argument("--step", action="store_true") parser.add_argument("--step", action="store_true")
parser.add_argument("--born-per-round", nargs="+", type=int)
parser.add_argument("--restore", action="store_true") parser.add_argument("--restore", action="store_true")
parser.add_argument("--set-step-mode", type=str) parser.add_argument("--set-step-mode", type=str)
parser.add_argument("--set-step-s", type=int) parser.add_argument("--set-step-s", type=int)
@ -26,16 +27,6 @@ game_id = args.game_id
game = ses.query(db.Game).filter_by(game_id=game_id).one_or_none() game = ses.query(db.Game).filter_by(game_id=game_id).one_or_none()
if args.set_step_mode:
game.step_mode = db.StepMode(args.set_step_mode)
ses.commit()
if args.set_step_s:
game.step_every_s = db.StepMode(args.set_step_s)
ses.commit()
if args.restore:
lib.game_restore_broken(args.game_id)
if args.step:
lib.game_step(args.game_id)
if args.autosteps: if args.autosteps:
while True: while True:
def sleep(timeout=1): def sleep(timeout=1):
@ -67,3 +58,22 @@ if args.autosteps:
step_in = game.step_every_s - diff step_in = game.step_every_s - diff
print(f"Step in {step_in:.2f} s (every {game.step_every_s})") print(f"Step in {step_in:.2f} s (every {game.step_every_s})")
sleep(step_in) sleep(step_in)
else:
game.lock()
if args.born_per_round:
print(args.born_per_round)
c = game.get_configuration()
c["born_per_round"] = args.born_per_round
game.configuration = db.new_big_data(c)
ses.commit()
print(game.get_configuration())
if args.set_step_mode:
game.step_mode = db.StepMode(args.set_step_mode)
ses.commit()
if args.set_step_s:
game.step_every_s = db.StepMode(args.set_step_s)
ses.commit()
if args.restore:
lib.game_restore_broken(args.game_id)
if args.step:
lib.game_step(args.game_id)

View file

@ -10,6 +10,7 @@ import werkzeug.exceptions
import wtforms import wtforms
from wtforms.fields import EmailField from wtforms.fields import EmailField
from wtforms.widgets import NumberInput from wtforms.widgets import NumberInput
import pprint
import hra.config as config import hra.config as config
import hra.web.html as html import hra.web.html as html
@ -268,6 +269,9 @@ def web_game(game_id):
with b.form(method="POST", _class="btn-group", action=app.url_for(web_game_step.__name__, game_id=game_id)): with b.form(method="POST", _class="btn-group", action=app.url_for(web_game_step.__name__, game_id=game_id)):
b.button(_class="btn btn-primary", type="submit", name="su", value="yes")("Krok") b.button(_class="btn btn-primary", type="submit", name="su", value="yes")("Krok")
if g.org:
b.h3("Aktuální konfigurace")
b.p().pre(pprint.pformat(game.get_configuration()))
return b.print_file() return b.print_file()
@app.route("/game/<int:game_id>/step", methods=['POST']) @app.route("/game/<int:game_id>/step", methods=['POST'])