mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 03:30:13 +01:00
add typing to config file
This commit is contained in:
@@ -18,6 +18,7 @@ Download for OS of choice on releases page
|
||||
|
||||
How to run:
|
||||
Windows:
|
||||
Install VC redistributable package from Microsoft
|
||||
```
|
||||
Run PyTaiko.exe
|
||||
```
|
||||
|
||||
@@ -2,6 +2,8 @@ from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from libs.utils import Config
|
||||
|
||||
@dataclass
|
||||
class Modifiers:
|
||||
"""
|
||||
@@ -66,7 +68,7 @@ class GlobalData:
|
||||
session_data (list[SessionData]): Session data for both players.
|
||||
"""
|
||||
songs_played: int = 0
|
||||
config: dict[str, Any] = field(default_factory=lambda: dict())
|
||||
config: Config = field(default_factory=lambda: dict())
|
||||
song_hashes: dict[str, list[dict]] = field(default_factory=lambda: dict()) #Hash to path
|
||||
song_paths: dict[Path, str] = field(default_factory=lambda: dict()) #path to hash
|
||||
song_progress: float = 0.0
|
||||
|
||||
@@ -8,7 +8,7 @@ import json
|
||||
from libs.global_data import global_data
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import Any, Optional
|
||||
from typing import Any, Optional, TypedDict
|
||||
|
||||
import pyray as ray
|
||||
import tomlkit
|
||||
@@ -22,6 +22,80 @@ from libs.texture import TextureWrapper
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class GeneralConfig(TypedDict):
|
||||
fps_counter: bool
|
||||
audio_offset: int
|
||||
visual_offset: int
|
||||
language: str
|
||||
hard_judge: int
|
||||
touch_enabled: bool
|
||||
timer_frozen: bool
|
||||
judge_counter: bool
|
||||
nijiiro_notes: bool
|
||||
log_level: int
|
||||
|
||||
class NameplateConfig(TypedDict):
|
||||
name: str
|
||||
title: str
|
||||
title_bg: int
|
||||
dan: int
|
||||
gold: bool
|
||||
|
||||
class PathsConfig(TypedDict):
|
||||
tja_path: list[str]
|
||||
video_path: list[str]
|
||||
|
||||
class Keys1PConfig(TypedDict):
|
||||
exit_key: str
|
||||
left_kat: list[str]
|
||||
left_don: list[str]
|
||||
right_don: list[str]
|
||||
right_kat: list[str]
|
||||
|
||||
class Keys2PConfig(TypedDict):
|
||||
left_kat: list[str]
|
||||
left_don: list[str]
|
||||
right_don: list[str]
|
||||
right_kat: list[str]
|
||||
|
||||
class GamepadConfig(TypedDict):
|
||||
left_kat: list[int]
|
||||
left_don: list[int]
|
||||
right_don: list[int]
|
||||
right_kat: list[int]
|
||||
|
||||
class AudioConfig(TypedDict):
|
||||
device_type: int
|
||||
sample_rate: int
|
||||
buffer_size: int
|
||||
exclusive: bool
|
||||
|
||||
class VolumeConfig(TypedDict):
|
||||
sound: float
|
||||
music: float
|
||||
voice: float
|
||||
hitsound: float
|
||||
|
||||
class VideoConfig(TypedDict):
|
||||
screen_width: int
|
||||
screen_height: int
|
||||
fullscreen: bool
|
||||
borderless: bool
|
||||
target_fps: int
|
||||
vsync: bool
|
||||
|
||||
class Config(TypedDict):
|
||||
general: GeneralConfig
|
||||
nameplate_1p: NameplateConfig
|
||||
nameplate_2p: NameplateConfig
|
||||
paths: PathsConfig
|
||||
keys_1p: Keys1PConfig
|
||||
keys_2p: Keys2PConfig
|
||||
gamepad: GamepadConfig
|
||||
audio: AudioConfig
|
||||
volume: VolumeConfig
|
||||
video: VideoConfig
|
||||
|
||||
def force_dedicated_gpu():
|
||||
"""Force Windows to use dedicated GPU for this application"""
|
||||
if sys.platform == "win32":
|
||||
@@ -75,7 +149,7 @@ def get_pixels_per_frame(bpm: float, time_signature: float, distance: float) ->
|
||||
total_frames = 60 * total_time
|
||||
return (distance / total_frames)
|
||||
|
||||
def get_config() -> dict[str, Any]:
|
||||
def get_config() -> Config:
|
||||
"""Get the configuration from the TOML file"""
|
||||
config_path = Path('dev-config.toml') if Path('dev-config.toml').exists() else Path('config.toml')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user