From 014c12efa8cb34b6bfd1713d06b4e1860d4dc7e4 Mon Sep 17 00:00:00 2001 From: Didictateur Date: Wed, 18 Feb 2026 15:20:52 +0100 Subject: [PATCH] minimal menu --- .gitignore | 3 +- backend/src/api.py | 29 +++++++++++--- backend/src/game/tile.py | 29 +++++++++----- backend/src/game/value.py | 14 +++---- components/menu.html | 82 +++++++++++++++++++++++++++++++++++++++ index.html | 18 +++++++++ 6 files changed, 153 insertions(+), 22 deletions(-) create mode 100644 components/menu.html diff --git a/.gitignore b/.gitignore index 7d245c9..2fa3ae9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ package-lock.json -build/ \ No newline at end of file +build/ +__pycache__ \ No newline at end of file diff --git a/backend/src/api.py b/backend/src/api.py index 0dc0c38..90cc34c 100644 --- a/backend/src/api.py +++ b/backend/src/api.py @@ -2,23 +2,42 @@ from flask import Flask, jsonify, request from flask_cors import CORS from game.tile import * +from game.error import * app = Flask(__name__) CORS(app) -tiles = tiles = Tile.generateAll() +tiles = Tile.generateAll() # ============= GET ================ -@app.route('api/tiles', methods=['GET']) +@app.route('/api/tiles', methods=['GET']) def get_all_tiles(): """Récupère toutes les tuiles""" - return jsonify(tiles) + tiles_data = [ + { + 'id': tile.id, + 'family': str(tile.family), + 'value': str(tile.value), + 'svg': tile.get_img() + } + for tile in tiles + ] + return jsonify({'tiles': tiles_data}) -@app.route('api/tiles/', method=['GET']) +@app.route('/api/tiles/', methods=['GET']) def get_tile(tile_id): if tile_id < 0 or tile_id >= len(tiles): return jsonify({'error': 'Tuile non trouvée'}), 404 - return jsonify({'tile': tiles[tile_id]}) + tile = tiles[tile_id] + return jsonify({ + 'id': tile.id, + 'family': str(tile.family), + 'value': str(tile.value), + 'svg': tile.get_img() + }) # ============== POST ================ + +if __name__ == '__main__': + app.run(debug=True, port=5000) diff --git a/backend/src/game/tile.py b/backend/src/game/tile.py index 02412b1..83230b0 100644 --- a/backend/src/game/tile.py +++ b/backend/src/game/tile.py @@ -1,5 +1,5 @@ -from error import * -from value import * +from game.error import * +from game.value import * class Tile: def __init__(self, family, value, id): @@ -52,14 +52,25 @@ class Tile: def get_img(self): if self.img == None: - self.img = f""" - - - - - - """ + shadow = self._load_svg(self.img_shadow, x=4, y=4) + front = self._load_svg(self.img_front, x=0, y=0) + symbol = self._load_svg(self.img_symbol, x=12, y=20, scale=0.9) + + self.img = f""" + {shadow} + {front} + {symbol} + """ return self.img + + @staticmethod + def _load_svg(filename, x=0, y=0, scale=1): + try: + with open(f'img/Regular/{filename}', 'r', encoding='utf-8') as f: + svg_content = f.read() + return f'{svg_content}' + except FileNotFoundError: + raise InvalidValueError(f"SVG non trouvé: {filename}") def __eq__(self, other: Tile): return self.value == other.value and self.family == other.family diff --git a/backend/src/game/value.py b/backend/src/game/value.py index a4f1c74..b5a607b 100644 --- a/backend/src/game/value.py +++ b/backend/src/game/value.py @@ -8,12 +8,12 @@ class Family(Enum): DRAGON = 4 class Wind(Enum): - EAST : 0 - SOUTH : 1 - WEST : 2 - NORTH : 3 + EAST = 0 + SOUTH = 1 + WEST = 2 + NORTH = 3 class Dragon(Enum): - RED : 0 - GREEN : 1 - WHITE : 2 \ No newline at end of file + RED = 0 + GREEN = 1 + WHITE = 2 \ No newline at end of file diff --git a/components/menu.html b/components/menu.html new file mode 100644 index 0000000..52a5887 --- /dev/null +++ b/components/menu.html @@ -0,0 +1,82 @@ + + + diff --git a/index.html b/index.html index e69de29..93ea8bb 100644 --- a/index.html +++ b/index.html @@ -0,0 +1,18 @@ + + + + + Tuto Riichi + + + + + + + \ No newline at end of file