mirror of
https://github.com/kristoferssolo/Tetris.git
synced 2025-10-21 20:00:35 +00:00
feat(utils): add settings.toml
This commit is contained in:
parent
06f962f5c7
commit
f1e854a38c
21
settings.toml
Normal file
21
settings.toml
Normal file
@ -0,0 +1,21 @@
|
||||
[keybinds]
|
||||
rotate_colockwise = "up arrow"
|
||||
hard_drop = "space"
|
||||
hold = "shift+c"
|
||||
rotate_counter_colockwise = "ctrl+z"
|
||||
pause = "esc+F1"
|
||||
move_left = "left arrow"
|
||||
move_right = "right arrow"
|
||||
move_down = "down arrow"
|
||||
|
||||
[numpad]
|
||||
hold = "numpad 0"
|
||||
hard_drop = "numpad 5"
|
||||
move_left = "numpad 4"
|
||||
move_right = "numpad 6"
|
||||
soft_drop = "numpad 2"
|
||||
rotate_colockwise_1 = "numpad 1"
|
||||
rotate_colockwise_2 = "numpad 5"
|
||||
rotate_colockwise_3 = "numpad 9"
|
||||
rotate_counter_colockwise_1 = "numpad 3"
|
||||
rotate_counter_colockwise_2 = "numpad 7"
|
||||
@ -3,6 +3,7 @@ from .enum import Direction, GameMode, Rotation
|
||||
from .figure import Figure, FigureConfig
|
||||
from .log import log
|
||||
from .path import BASE_PATH
|
||||
from .settings import read_settings, save_settings
|
||||
from .tuples import BestMove, Size
|
||||
from .weights import Weights
|
||||
|
||||
@ -18,4 +19,6 @@ __all__ = [
|
||||
"GameMode",
|
||||
"Weights",
|
||||
"BestMove",
|
||||
"read_settings",
|
||||
"save_settings",
|
||||
]
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
from pathlib import Path
|
||||
|
||||
from attr import define, field
|
||||
from attr import define
|
||||
from pygame import Vector2 as Vec2
|
||||
|
||||
from .colors import TokyoNightNight
|
||||
|
||||
33
src/utils/settings.py
Normal file
33
src/utils/settings.py
Normal file
@ -0,0 +1,33 @@
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
import toml
|
||||
|
||||
from .config import CONFIG, Config
|
||||
from .log import log
|
||||
|
||||
|
||||
def save_settings(settings: Config, file_path: Path) -> None:
|
||||
with open(file_path, "w") as file:
|
||||
toml.dump(settings, file)
|
||||
|
||||
|
||||
def read_settings(file_path: Path) -> Optional[dict[str, str]]:
|
||||
"""
|
||||
Read and parse a TOML file and return the content as a dictionary.
|
||||
|
||||
Args:
|
||||
file_path: The path to the TOML file.
|
||||
|
||||
Returns:
|
||||
dict: The parsed content of the TOML file.
|
||||
"""
|
||||
try:
|
||||
with open(file_path, "r") as file:
|
||||
return toml.load(file)
|
||||
except FileNotFoundError:
|
||||
log.error(f"Error: The file '{file_path}' does not exist.")
|
||||
return None
|
||||
except toml.TomlDecodeError as e:
|
||||
log.error(f"rror decoding TOML file: {e}")
|
||||
return None
|
||||
Loading…
Reference in New Issue
Block a user