Init
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from led_platform.domain import PhysicalOutput, Tile
|
||||
|
||||
|
||||
class TileStore:
|
||||
def __init__(self, config_path: Path, wall_width: int, wall_height: int) -> None:
|
||||
self.config_path = config_path
|
||||
self.wall_width = wall_width
|
||||
self.wall_height = wall_height
|
||||
self._tiles: dict[str, Tile] = {}
|
||||
self.reload()
|
||||
|
||||
def reload(self) -> None:
|
||||
if self.config_path.exists():
|
||||
data = json.loads(self.config_path.read_text(encoding="utf-8"))
|
||||
tiles = [Tile(**item) for item in data["tiles"]]
|
||||
else:
|
||||
tiles = self._default_tiles()
|
||||
self._tiles = {tile.id: tile for tile in tiles}
|
||||
|
||||
def all(self) -> list[Tile]:
|
||||
return list(self._tiles.values())
|
||||
|
||||
def get(self, tile_id: str) -> Tile:
|
||||
if tile_id not in self._tiles:
|
||||
raise KeyError(tile_id)
|
||||
return self._tiles[tile_id]
|
||||
|
||||
def ids(self) -> list[str]:
|
||||
return list(self._tiles.keys())
|
||||
|
||||
def _default_tiles(self) -> list[Tile]:
|
||||
half_width = self.wall_width // 2
|
||||
return [
|
||||
Tile(
|
||||
id="left",
|
||||
name="Left output server",
|
||||
x=0,
|
||||
y=0,
|
||||
width=half_width,
|
||||
height=self.wall_height,
|
||||
wall_width=self.wall_width,
|
||||
wall_height=self.wall_height,
|
||||
desktop_width=7680,
|
||||
desktop_height=4320,
|
||||
physical_outputs=self._default_outputs("left"),
|
||||
),
|
||||
Tile(
|
||||
id="right",
|
||||
name="Right output server",
|
||||
x=half_width,
|
||||
y=0,
|
||||
width=self.wall_width - half_width,
|
||||
height=self.wall_height,
|
||||
wall_width=self.wall_width,
|
||||
wall_height=self.wall_height,
|
||||
desktop_width=7680,
|
||||
desktop_height=4320,
|
||||
physical_outputs=self._default_outputs("right"),
|
||||
),
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def _default_outputs(prefix: str) -> list[PhysicalOutput]:
|
||||
return [
|
||||
PhysicalOutput(id=f"{prefix}-1", index=1, x=0, y=0),
|
||||
PhysicalOutput(id=f"{prefix}-2", index=2, x=3840, y=0),
|
||||
PhysicalOutput(id=f"{prefix}-3", index=3, x=0, y=2160),
|
||||
PhysicalOutput(id=f"{prefix}-4", index=4, x=3840, y=2160),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user