This commit is contained in:
Auric Vente 2024-07-27 21:02:10 -06:00
parent b803feedc6
commit 4b88a71d04
3 changed files with 21 additions and 14 deletions

View File

@ -150,22 +150,14 @@ class Game:
def add_item(item: QWidget) -> None: def add_item(item: QWidget) -> None:
from .filter import Filter from .filter import Filter
fade = Game.started and Args.fade animation: QPropertyAnimation | None = None
if fade: if Game.started and Args.fade:
opacity_effect = QGraphicsOpacityEffect(item) animation = Game.add_fade(item)
item.setGraphicsEffect(opacity_effect)
animation = QPropertyAnimation(opacity_effect, b"opacity")
animation.setDuration(Config.fade_duration)
animation.setStartValue(0)
animation.setEndValue(1)
animation.setEasingCurve(QEasingCurve.InOutQuad)
animation.finished.connect(lambda: Game.animations.remove(animation))
Game.animations.append(animation)
Window.view.insertWidget(0, item) Window.view.insertWidget(0, item)
if fade: if animation:
animation.start() animation.start()
while Window.view.count() > Config.max_updates: while Window.view.count() > Config.max_updates:
@ -367,7 +359,6 @@ class Game:
@staticmethod @staticmethod
def start_loop() -> None: def start_loop() -> None:
Game.started = True
Game.timer.stop() Game.timer.stop()
speed = Settings.speed speed = Settings.speed
@ -456,11 +447,13 @@ class Game:
size = int(data["size"].split(" ")[0]) size = int(data["size"].split(" ")[0])
Game.started = False Game.started = False
Game.timer.stop()
Window.clear_view() Window.clear_view()
Ants.populate(size) Ants.populate(size)
Window.to_top() Window.to_top()
Game.intro() Game.intro()
Game.start_loop() Game.start_loop()
Game.started = True
@staticmethod @staticmethod
def update_size() -> None: def update_size() -> None:
@ -611,3 +604,16 @@ class Game:
Filter.clear() Filter.clear()
else: else:
Filter.set_value(ant.name) Filter.set_value(ant.name)
@staticmethod
def add_fade(item: QWidget) -> QPropertyAnimation:
opacity = QGraphicsOpacityEffect(item)
item.setGraphicsEffect(opacity)
animation = QPropertyAnimation(opacity, b"opacity")
animation.setDuration(Config.fade_duration)
animation.setStartValue(0)
animation.setEndValue(1)
animation.setEasingCurve(QEasingCurve.InOutQuad)
animation.finished.connect(lambda: Game.animations.remove(animation))
Game.animations.append(animation)
return animation

View File

@ -48,6 +48,7 @@ def main() -> None:
Filter.prepare() Filter.prepare()
Game.prepare() Game.prepare()
Game.start_loop() Game.start_loop()
Game.started = True
Window.start() Window.start()

View File

@ -1,5 +1,5 @@
{ {
"version": "3.4.0", "version": "3.5.0",
"title": "Cromulant", "title": "Cromulant",
"program": "cromulant", "program": "cromulant",
"author": "madprops", "author": "madprops",