From 14d458842597ea7d061c8fb12ae1f3a238aa9a41 Mon Sep 17 00:00:00 2001 From: Auric Vente Date: Sat, 27 Jul 2024 13:33:03 -0600 Subject: [PATCH] Mods --- arguments.md | 8 ++++++++ cromulant/args.py | 2 ++ cromulant/argspec.py | 6 ++++++ cromulant/game.py | 44 ++++++++++++++++++++++++++++++++++---------- cromulant/main.py | 1 + 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/arguments.md b/arguments.md index 14e5008..2500a1b 100644 --- a/arguments.md +++ b/arguments.md @@ -179,3 +179,11 @@ Use a monospace font Default: False Action: store_true + +--- + +### no-fade + +Don't apply a fade-in effect on new updates + +Action: store_false diff --git a/cromulant/args.py b/cromulant/args.py index 470d54b..5b39559 100644 --- a/cromulant/args.py +++ b/cromulant/args.py @@ -28,6 +28,7 @@ class Args: argdoc: bool = False score: bool = False mono: bool = False + fade: bool = True @staticmethod def prepare() -> None: @@ -42,6 +43,7 @@ class Args: ("no_header", "header"), ("no_footer", "footer"), ("no_intro", "intro"), + ("no_fade", "fade"), ] for r_item in other_name: diff --git a/cromulant/argspec.py b/cromulant/argspec.py index 48f9a9f..9059824 100644 --- a/cromulant/argspec.py +++ b/cromulant/argspec.py @@ -178,3 +178,9 @@ class ArgSpec: action="store_true", info="Use a monospace font", ) + + ArgSpec.add_argument( + "no_fade", + action="store_false", + info="Don't apply a fade-in effect on new updates", + ) diff --git a/cromulant/game.py b/cromulant/game.py index 9c8c944..8f22259 100644 --- a/cromulant/game.py +++ b/cromulant/game.py @@ -1,7 +1,7 @@ from __future__ import annotations import random -from typing import Any +from typing import Any, ClassVar from PySide6.QtWidgets import QHBoxLayout # type: ignore from PySide6.QtWidgets import QVBoxLayout @@ -10,11 +10,14 @@ from PySide6.QtWidgets import QWidget from PySide6.QtWidgets import QFrame from PySide6.QtWidgets import QMenu from PySide6.QtWidgets import QDialog +from PySide6.QtWidgets import QGraphicsOpacityEffect from PySide6.QtGui import QCursor # type: ignore from PySide6.QtGui import QMouseEvent from PySide6.QtGui import QPixmap from PySide6.QtGui import QAction -from PySide6.QtCore import QSize # type: ignore +from PySide6.QtCore import QPropertyAnimation # type: ignore +from PySide6.QtCore import QEasingCurve +from PySide6.QtCore import QSize from PySide6.QtCore import QTimer from PySide6.QtCore import Qt @@ -74,13 +77,18 @@ class Opts: class Game: - timer: QTimer | None = None + timer: QTimer playing_song: bool = False merge_charge: int = 0 speed: str = "paused" + animations: ClassVar[list[QPropertyAnimation]] = [] + started: bool = False @staticmethod def prepare() -> None: + Game.timer = QTimer() + Game.timer.timeout.connect(Game.get_status) + Game.fill() Game.info() @@ -142,8 +150,24 @@ class Game: def add_item(item: QWidget) -> None: from .filter import Filter + fade = Game.started and Args.fade + + if fade: + opacity_effect = QGraphicsOpacityEffect(item) + item.setGraphicsEffect(opacity_effect) + fade_in = QPropertyAnimation(opacity_effect, b"opacity") + fade_in.setDuration(500) + fade_in.setStartValue(0) + fade_in.setEndValue(1) + fade_in.setEasingCurve(QEasingCurve.InOutQuad) + fade_in.finished.connect(lambda: Game.animations.remove(fade_in)) + Game.animations.append(fade_in) + Window.view.insertWidget(0, item) + if fade: + fade_in.start() + while Window.view.count() > Config.max_updates: item = Window.view.takeAt(Window.view.count() - 1) @@ -343,9 +367,7 @@ class Game: @staticmethod def start_loop() -> None: - if Game.timer: - Game.timer.stop() - + Game.timer.stop() speed = Settings.speed if speed == "fast": @@ -359,11 +381,13 @@ class Game: return Game.speed = speed - Game.timer = QTimer() - Game.timer.timeout.connect(Game.get_status) - msecs = minutes * 60 * 1000 - Game.timer.start(msecs) + + if msecs < 1000: + msecs = 1000 + + Game.timer.setInterval(msecs) + Game.timer.start() @staticmethod def update_speed() -> None: diff --git a/cromulant/main.py b/cromulant/main.py index 0fd3391..1b439a1 100644 --- a/cromulant/main.py +++ b/cromulant/main.py @@ -48,6 +48,7 @@ def main() -> None: Filter.prepare() Game.prepare() Game.start_loop() + Game.started = True Window.start()