Skip to content

Commit

Permalink
[config] Add key set name
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometheus3375 committed Jul 19, 2024
1 parent 43d94e9 commit 6c5af08
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions solve/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import tomllib
from dataclasses import dataclass
from enum import Enum

from .key_sets import *
from .players import *
Expand All @@ -24,8 +25,14 @@
}


class KeySetName(Enum):
MIXED = 'mixed'
DOUBLE = 'double'


@dataclass(frozen=True, kw_only=True, slots=True)
class Config:
key_set_name: KeySetName
inner_shapes: tuple[Shape2D, Shape2D, Shape2D]
held_shapes: tuple[Shape3D, Shape3D, Shape3D]
players: tuple[Player, Player, Player]
Expand Down Expand Up @@ -65,6 +72,10 @@ def read_config(filepath: str, /) -> Config:
with open(filepath, 'rb') as f:
data = tomllib.load(f)

key_set_name = data.get('key_set', 'mixed')
assert key_set_name in KeySetName, \
f'key_set must be either {KeySetName.MIXED.value!r} or {KeySetName.DOUBLE.value!r}'

is_doing_triumph = data.get('is_doing_triumph', False)
assert isinstance(is_doing_triumph, bool), 'is_doing_triumph must be a boolean'

Expand Down Expand Up @@ -101,6 +112,7 @@ def read_config(filepath: str, /) -> Config:
players.append(Player(**p))

return Config(
key_set_name=KeySetName(key_set_name),
inner_shapes=(inner[0], inner[1], inner[2]),
held_shapes=(held[0], held[1], held[2]),
players=(players[0], players[1], players[2]),
Expand Down

0 comments on commit 6c5af08

Please sign in to comment.