diff --git a/font-list.txt b/font-list.txt index 9d21265..cd1ca30 100644 --- a/font-list.txt +++ b/font-list.txt @@ -8,7 +8,7 @@ Franklin Gothic Frutiger Helvetica Gill Sans -#Gotham +Gotham #Myriad Pro #News Gothic #Roboto diff --git a/font_game/game.py b/font_game/game.py index bad5cb8..3cb9137 100644 --- a/font_game/game.py +++ b/font_game/game.py @@ -20,7 +20,7 @@ def pick_fonts(game_length: int): return [(i, FONTS[i]) for i in font_list] -def start_game(game_length: int = 10) -> str: +def start_game(game_length: int = 10, hard_mode: bool = False) -> str: picked_fonts = pick_fonts(game_length) images = [] for font in picked_fonts: @@ -33,7 +33,8 @@ def start_game(game_length: int = 10) -> str: "i": "0", "game_length": str(game_length), "images": ','.join(images), - "fonts": ','.join(i[0] for i in picked_fonts) + "fonts": ','.join(i[0] for i in picked_fonts), + "hard_mode": str(hard_mode) } game = "\n".join([f"{key}:{value}" for key, value in game_dict.items()]) @@ -48,7 +49,8 @@ def test_game(game_id: str): def guess_font(game_id: str, font_guess: str): game_dict = read_file(f"current_games/{game_id}") i = int(game_dict['i']) - font = game_dict['fonts'].split(',')[i] + font_guess = font_guess.lower().replace(" ","-") + font = game_dict['fonts'].split(',')[i].lower().replace(" ","-") if font_guess == font: game_dict['points'] = str(int(game_dict['points']) + 1) diff --git a/font_game/images.py b/font_game/images.py index c878eb1..0189b92 100644 --- a/font_game/images.py +++ b/font_game/images.py @@ -15,7 +15,7 @@ def gen_image(font: ImageFont.ImageFont) -> str: text_list = [] line = "" for word in text.split(" "): - if drawer.textsize(line + word, font)[0] > text_width: + if drawer.textlength(line + word, font) > text_width: text_list.append(line) line = "" else: @@ -36,7 +36,7 @@ def gen_image(font: ImageFont.ImageFont) -> str: path = f"static/images/{filename}.png" new_size = (IMAGE_SIZE[0] // 2, IMAGE_SIZE[1] // 2) - img = img.resize(new_size, resample=Image.ANTIALIAS) + img = img.resize(new_size) img.save(path) return filename diff --git a/font_game/util.py b/font_game/util.py index 3ad0009..a2c22fd 100644 --- a/font_game/util.py +++ b/font_game/util.py @@ -57,7 +57,7 @@ def make_test_pages(fonts: dict[str, ImageFont.FreeTypeFont]): final_text = [] current_text = "" for char in TEST_TEXT: - if font.getsize(current_text + char)[0] > (writable_area): + if font.getbbox(current_text + char)[2] > (writable_area): final_text.append(current_text) current_text = char else: @@ -94,7 +94,7 @@ def make_fonts(): font_path = f"./fonts/{font_name}.{file_type}" tmp_font = ImageFont.truetype(font_path, FONT_SIZE) letter_height = int(average([ - tmp_font.getsize(i)[1] for i in TEST_TEXT + tmp_font.getbbox(i)[3] for i in TEST_TEXT ])) new_size = (FONT_SIZE**2)//letter_height new_font = ImageFont.truetype(font_path, new_size) diff --git a/font_game/web.py b/font_game/web.py index 905bc9d..ea76fe2 100644 --- a/font_game/web.py +++ b/font_game/web.py @@ -32,7 +32,17 @@ def font_game(): game = read_file(f"current_games/{game_id}") - if int(game['i']) == int(game['game_length']): + end_game = ( + ( + int(game['game_length']) != 0 and + int(game['i']) == int(game['game_length']) + ) or + ( + int(game['game_length']) == 0 and + int(game['i']) > int(game['points']) + ) + ) + if end_game: os.remove(f"current_games/{game_id}") return flask.render_template("final.html", points=game['points'], game_length=game['game_length']) @@ -45,7 +55,8 @@ def font_game(): "url": url, "i": str(int(game['i']) + 1), "round_n": game['i'], - "game_length": game['game_length'], + "game_length": int(game['game_length']), + "hard_mode": game['hard_mode'] == 'True', "points":game['points'], "fonts":FONTS, "id":args['id'] @@ -63,7 +74,9 @@ def start(): else: game_length = 10 - game_id = start_game(game_length) + hard_mode = 'hard_mode' in flask.request.form + + game_id = start_game(game_length, hard_mode) return flask.redirect(f"/fontgame?id={game_id}") @app.route("/all") diff --git a/static/css/stylesheet.css b/static/css/stylesheet.css index 46eebf0..a0c4626 100644 --- a/static/css/stylesheet.css +++ b/static/css/stylesheet.css @@ -28,6 +28,23 @@ font-size: 20pt; } +.menupage form { + display: flex; + flex-direction: column; + justify-content: center; + align-content: center; + align-items: center; + justify-items: center; +} + +.menupage form p { + margin-top: -10pt; + margin-bottom: 10pt; +} +.menupage form div { + margin-bottom: 10pt; +} + .menupage form .number { width: 50pt; text-align: right; diff --git a/templates/fontgame.html b/templates/fontgame.html index 3ecf75b..b54c2b6 100644 --- a/templates/fontgame.html +++ b/templates/fontgame.html @@ -7,19 +7,25 @@
-
- Round {{ i }} of {{ game_length }} -
+ {% if game_length > 0 %} +
+ Round {{ i }} of {{ game_length }} +
+ {% endif %}
{{ points }}/{{ round_n }} points.
-
- + + {% if not hard_mode %} + + {% else %} + + {% endif %}
diff --git a/templates/menu.html b/templates/menu.html index e3270f8..cb9e6dc 100644 --- a/templates/menu.html +++ b/templates/menu.html @@ -1,13 +1,20 @@ - +

Font Game

- - +
+ + +
+

(0 for endless mode)

+
+ + +