From 7191a778bed57624fd4e74e30dbb45092329e138 Mon Sep 17 00:00:00 2001 From: Stefan Rupp Date: Sun, 29 Nov 2020 22:31:03 +0100 Subject: [PATCH] starting with integration of js-cardgame --- routes.py | 7 +- templates/home/gplayer.html | 186 ++++++++++++++++++++++++++++++++++ templates/shared/_layout.html | 19 +++- views/api_views.py | 39 ------- views/gplayer.py | 29 ++++++ views/js_cardgame.py | 29 ++++++ 6 files changed, 265 insertions(+), 44 deletions(-) create mode 100644 templates/home/gplayer.html delete mode 100644 views/api_views.py create mode 100644 views/gplayer.py create mode 100644 views/js_cardgame.py diff --git a/routes.py b/routes.py index 2b4a766..93adc8d 100644 --- a/routes.py +++ b/routes.py @@ -1,14 +1,17 @@ # noinspection PyUnresolvedReferences from app_instance import api # noinspection PyUnresolvedReferences -from views.api_views import * -# noinspection PyUnresolvedReferences from views.home import * # noinspection PyUnresolvedReferences from views.temp_css import * # noinspection PyUnresolvedReferences from views.player import * # noinspection PyUnresolvedReferences +from views.gplayer import * +# noinspection PyUnresolvedReferences +from views.js_cardgame import * +# noinspection PyUnresolvedReferences from views.control import * api.add_route("/static", static=True) +api.add_route("/js", static=True) diff --git a/templates/home/gplayer.html b/templates/home/gplayer.html new file mode 100644 index 0000000..8be0593 --- /dev/null +++ b/templates/home/gplayer.html @@ -0,0 +1,186 @@ +{% extends "/shared/_layout.html" %} + +{% block content %} + + + +
+
+ + + + + + + + +
+ + + + + + +{% endblock %} \ No newline at end of file diff --git a/templates/shared/_layout.html b/templates/shared/_layout.html index 121b430..b1f2326 100644 --- a/templates/shared/_layout.html +++ b/templates/shared/_layout.html @@ -55,6 +55,19 @@ alert("[error]: "+error.message); }; + + + + @@ -94,7 +107,7 @@ - - + + + - \ No newline at end of file diff --git a/views/api_views.py b/views/api_views.py deleted file mode 100644 index 862e389..0000000 --- a/views/api_views.py +++ /dev/null @@ -1,39 +0,0 @@ -from responder import Response - -from app_instance import api - -response_count_max = 10 - - -@api.route("/api/search/{keyword}") -def search_keyword(req, resp, keyword: str): - resp.media = {'keyword': keyword, 'hits': "movie_dicts", 'truncated_results': "limited"} - - -@api.route("/api/director/{director_name}") -def search_director(_, resp, director_name: str): - resp.media = {'keyword': director_name, 'hits': "movies_dicts", 'truncated_results': "limited"} - - -@api.route("/api/movie/genre/{genre}") -def movies_by_genre(_, resp: Response, genre: str): - resp.media = {'genre': genre, 'hits': "hits_dicts", 'truncated_results': "limited"} - - -@api.route("/api/movie/{imdb_number}") -def search_imdb(_, resp, imdb_number: str): - resp.media = {'foo': "bar"} - - -@api.route("/api/movie/top") -def top_movies(_, resp: Response): - resp.media = {'keyword': "keyword", 'hits': "hits_dicts", 'truncated_results': "limited"} - - -@api.route("/api/movie/genre/all") -def all_genres(_, resp: Response): - resp.media = {"all": "stuff"} - -@api.route("/api/shuffle") -def cards_shuffle(_, resp: Response): - resp.media = {"shuffled": "done"} \ No newline at end of file diff --git a/views/gplayer.py b/views/gplayer.py new file mode 100644 index 0000000..22727f2 --- /dev/null +++ b/views/gplayer.py @@ -0,0 +1,29 @@ +from app_instance import api + +from wiz_game import the_game +from starlette.websockets import WebSocketDisconnect +import asyncio + +# don't define here, it's defined elsewhere! +#playing_lock = asyncio.Lock() + + +@api.route("/gplayer/{player}") +def show(req, resp, player: str): + p = int(player) + tcard = the_game.trump_card + tcolor = the_game.get_trump_color() + try: + isActive = the_game.players_ordered[the_game.active_player].id == p + except IndexError: + isActive = False + + prev_player = the_game.get_prev_player() + if tcard and tcard.value == 'Z' and tcolor == '-': + choose_trump_color = True + else: + choose_trump_color = False + resp.content = api.template('home/gplayer.html', player=p, playerActive=isActive, choose_trump_player=prev_player, + cards=the_game.players[p].cards, choose_trump_color=choose_trump_color, + trump_card=tcard, trump_color=tcolor, played_cards=the_game.played_cards, last_trick=the_game.last_trick) + diff --git a/views/js_cardgame.py b/views/js_cardgame.py new file mode 100644 index 0000000..797458e --- /dev/null +++ b/views/js_cardgame.py @@ -0,0 +1,29 @@ +import os + +from app_instance import api + + +@api.route("/js-cardgame/{file}") +def css(req, resp, file): + resp.headers['Content-Type'] = 'application/javascript' + full_file = os.path.join( + os.path.dirname(__file__), + '..', + 'js-cardgame', + file + ) + with open(full_file, encoding='utf-8') as fin: + resp.content = fin.read() + +@api.route("/js-cardgame/js/{file}") +def css(req, resp, file): + resp.headers['Content-Type'] = 'application/javascript' + full_file = os.path.join( + os.path.dirname(__file__), + '..', + 'js-cardgame', + 'js', + file + ) + with open(full_file, encoding='utf-8') as fin: + resp.content = fin.read()