Base structure for engine
This commit is contained in:
parent
da9f8f72ec
commit
a55027e8e3
2 changed files with 70 additions and 7 deletions
|
@ -1,4 +1,40 @@
|
||||||
class Engine:
|
from decimal import Decimal
|
||||||
"""Calculates a sequence."""
|
import logging
|
||||||
|
|
||||||
|
from models import EngineFixture, Flickr
|
||||||
|
|
||||||
|
|
||||||
|
class Engine:
|
||||||
|
"""Render a lightshow."""
|
||||||
|
|
||||||
|
def __init__(self, flickr: Flickr, apis: dict[str, str]) -> None:
|
||||||
|
self.time: Decimal = Decimal.from_float(0)
|
||||||
|
self.fixtures: dict[str, EngineFixture] = {
|
||||||
|
f.id: EngineFixture(f) for s in flickr.spaces for f in s.fixtures
|
||||||
|
}
|
||||||
|
self.flickr = flickr
|
||||||
|
self.apis = apis
|
||||||
|
|
||||||
|
# Validate fixture APIs
|
||||||
|
for id, f in self.fixtures.items():
|
||||||
|
if f.fixture.api not in self.apis.keys():
|
||||||
|
logging.warning(
|
||||||
|
f"Fixture API unknown [{f.fixture.api}]. Fixture will be removed. Fixture ID [{f.fixture.id}]. Known APIs [{', '.join([a for a in self.apis.keys()])}]."
|
||||||
|
)
|
||||||
|
del self.fixtures[id]
|
||||||
|
|
||||||
|
def next(self, step_size: Decimal):
|
||||||
|
"""Calculate light values for next step in time. Step size in seconds."""
|
||||||
|
prev_time = self.time
|
||||||
|
self.time += step_size
|
||||||
|
|
||||||
|
for s in self.flickr.sequences:
|
||||||
|
for t in s.tracks:
|
||||||
|
# TODO: Calculate new state
|
||||||
|
pass
|
||||||
|
|
||||||
|
def propagate(self):
|
||||||
|
"""Forward new fixture states to APIs."""
|
||||||
|
for f in self.fixtures.values():
|
||||||
|
api = self.apis[f.fixture.api]
|
||||||
|
# TODO: Pass update to API
|
||||||
|
|
|
@ -37,6 +37,12 @@ class Fixture:
|
||||||
name: str
|
name: str
|
||||||
"""Human readable name."""
|
"""Human readable name."""
|
||||||
|
|
||||||
|
api: str
|
||||||
|
"""API this fixture has to be used with."""
|
||||||
|
|
||||||
|
api_id: str
|
||||||
|
"""Custom id for specific API."""
|
||||||
|
|
||||||
capabilities: Capabilities
|
capabilities: Capabilities
|
||||||
"""Which dynamic capabilities does the fixture have."""
|
"""Which dynamic capabilities does the fixture have."""
|
||||||
|
|
||||||
|
@ -53,6 +59,29 @@ class Fixture:
|
||||||
"""In range [0,1], how exposed is the light source of the fixture. 0: no exposure. 1: full exposure."""
|
"""In range [0,1], how exposed is the light source of the fixture. 0: no exposure. 1: full exposure."""
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class EngineFixture:
|
||||||
|
"""A fixture for engine use during rendering."""
|
||||||
|
|
||||||
|
fixture: Fixture
|
||||||
|
"""Reference meta data for fixture."""
|
||||||
|
|
||||||
|
on: bool = False
|
||||||
|
"""On state."""
|
||||||
|
|
||||||
|
bri: float = 0
|
||||||
|
"""Brightness state."""
|
||||||
|
|
||||||
|
hue: float = 0
|
||||||
|
"""Hue state."""
|
||||||
|
|
||||||
|
sat: float = 0
|
||||||
|
"""Saturation state."""
|
||||||
|
|
||||||
|
transition: float = 0
|
||||||
|
"""Transition time in seconds."""
|
||||||
|
|
||||||
|
|
||||||
@dataclass_json
|
@dataclass_json
|
||||||
@dataclass
|
@dataclass
|
||||||
class Space:
|
class Space:
|
||||||
|
@ -67,9 +96,6 @@ class Space:
|
||||||
fixtures: list[Fixture]
|
fixtures: list[Fixture]
|
||||||
"""All fixtures present in the space."""
|
"""All fixtures present in the space."""
|
||||||
|
|
||||||
center: SpaceVector
|
|
||||||
"""A reference point in the space from which the audience perspective might be assumed."""
|
|
||||||
|
|
||||||
version: str = "1"
|
version: str = "1"
|
||||||
"""Metatag to track version of datastructure."""
|
"""Metatag to track version of datastructure."""
|
||||||
|
|
||||||
|
@ -164,6 +190,8 @@ if __name__ == "__main__":
|
||||||
Fixture(
|
Fixture(
|
||||||
"98iwd",
|
"98iwd",
|
||||||
"Cool Light",
|
"Cool Light",
|
||||||
|
"hue",
|
||||||
|
"9jsif",
|
||||||
Capabilities.BRIGHTNESS,
|
Capabilities.BRIGHTNESS,
|
||||||
SpaceVector(),
|
SpaceVector(),
|
||||||
SpaceVector(),
|
SpaceVector(),
|
||||||
|
@ -171,7 +199,6 @@ if __name__ == "__main__":
|
||||||
0.5,
|
0.5,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
SpaceVector(),
|
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in a new issue