Mods
This commit is contained in:
parent
91040eb390
commit
9e2c382e07
Binary file not shown.
|
@ -36,6 +36,7 @@ class Config:
|
|||
hit_icon: str = "🎃"
|
||||
triumph_message: str = "Scored a triumph"
|
||||
hit_message: str = "Took a hit"
|
||||
song_path: Path
|
||||
|
||||
@staticmethod
|
||||
def prepare() -> None:
|
||||
|
@ -53,3 +54,4 @@ class Config:
|
|||
Config.names_json = Config.here / "data" / "names.json"
|
||||
Config.font_path = Config.here / "fonts" / "NotoSans-Regular.ttf"
|
||||
Config.emoji_font_path = Config.here / "fonts" / "NotoEmoji-Regular.ttf"
|
||||
Config.song_path = Config.here / "audio" / "March of the Cyber Ants.mp3"
|
||||
|
|
|
@ -22,6 +22,7 @@ from .window import Window
|
|||
|
||||
class Game:
|
||||
timer: QTimer
|
||||
playing_song: bool = False
|
||||
|
||||
@staticmethod
|
||||
def prepare() -> None:
|
||||
|
@ -122,6 +123,7 @@ class Game:
|
|||
rgb = Utils.get_rgb(color)
|
||||
image_label.setStyleSheet(f"border: 2px solid {rgb};")
|
||||
|
||||
image_label.mousePressEvent = lambda event: Game.toggle_song()
|
||||
return image_label
|
||||
|
||||
@staticmethod
|
||||
|
@ -210,3 +212,13 @@ class Game:
|
|||
|
||||
Window.info.setText(Config.info_separator.join(text))
|
||||
Window.info.adjustSize()
|
||||
|
||||
@staticmethod
|
||||
def toggle_song() -> None:
|
||||
if Game.playing_song:
|
||||
Window.stop_audio()
|
||||
else:
|
||||
path = str(Config.song_path)
|
||||
Window.play_audio(path)
|
||||
|
||||
Game.playing_song = not Game.playing_song
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
from __future__ import annotations
|
||||
|
||||
|
||||
import random
|
||||
import colorsys
|
||||
import time
|
||||
from typing import ClassVar
|
||||
|
||||
from fontTools.ttLib import TTFont # type: ignore
|
||||
|
||||
from .config import Config
|
||||
|
|
|
@ -21,6 +21,9 @@ from PySide6.QtGui import QMouseEvent
|
|||
from PySide6.QtGui import QIcon
|
||||
from PySide6.QtCore import Qt # type: ignore
|
||||
from PySide6.QtCore import Signal
|
||||
from PySide6.QtCore import QUrl
|
||||
from PySide6.QtMultimedia import QMediaPlayer # type: ignore
|
||||
from PySide6.QtMultimedia import QAudioOutput
|
||||
|
||||
from .config import Config
|
||||
|
||||
|
@ -46,6 +49,8 @@ class Window:
|
|||
info: SpecialButton
|
||||
font: str
|
||||
emoji_font: str
|
||||
player: QMediaPlayer
|
||||
audio: QAudioOutput
|
||||
|
||||
@staticmethod
|
||||
def prepare() -> None:
|
||||
|
@ -102,9 +107,11 @@ class Window:
|
|||
btn_hatch.middleClicked.connect(lambda: Ants.hatch_burst())
|
||||
|
||||
btn_terminate = SpecialButton("Terminate")
|
||||
|
||||
btn_terminate.setToolTip(
|
||||
"Terminate a random ant\nMiddle Click to terminate all"
|
||||
)
|
||||
|
||||
btn_terminate.clicked.connect(lambda e: Ants.terminate())
|
||||
btn_terminate.middleClicked.connect(lambda: Ants.terminate_all())
|
||||
|
||||
|
@ -215,3 +222,16 @@ class Window:
|
|||
container.addWidget(Window.info)
|
||||
root.setLayout(container)
|
||||
Window.root.addWidget(root)
|
||||
|
||||
@staticmethod
|
||||
def play_audio(path: str) -> None:
|
||||
Window.player = QMediaPlayer()
|
||||
Window.audio = QAudioOutput()
|
||||
Window.player.setAudioOutput(Window.audio)
|
||||
Window.player.setSource(QUrl.fromLocalFile(path))
|
||||
Window.audio.setVolume(100)
|
||||
Window.player.play()
|
||||
|
||||
@staticmethod
|
||||
def stop_audio() -> None:
|
||||
Window.player.stop()
|
||||
|
|
Loading…
Reference in New Issue