Skip to content

Commit

Permalink
Merge pull request #82 from dmarx/more_flexible_pgroup
Browse files Browse the repository at this point in the history
improved pgroup deserialization
  • Loading branch information
dmarx committed Mar 3, 2023
2 parents 4e23548 + dfb1962 commit cb0ec0b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

setup(
name='keyframed',
version='0.3.8',
version='0.3.9',
author='David Marx',
long_description=README,
long_description_content_type='text/markdown',
Expand Down
10 changes: 9 additions & 1 deletion src/keyframed/serialization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .curve import Keyframe, Curve, CurveBase, ParameterGroup, Composition

from numbers import Number

# can probably use a simpler yaml library
from omegaconf import OmegaConf

Expand Down Expand Up @@ -81,7 +83,13 @@ def from_dict(d:dict):

curves = {}
for k,v in d['parameters'].items():
curves[k] = from_dict(v)
if isinstance(v, Number):
param = v
elif isinstance(v, dict):
param = from_dict(v)
else:
raise NotImplementedError(f"expected number of dict, got {v} of type {type(v)}")
curves[k] = param
d_['parameters'] = curves

if not _is_comp(d):
Expand Down
20 changes: 20 additions & 0 deletions tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,24 @@ def test_sinusoidal():

###########################

def test_pgroup_from_ultra_simple_yaml():
txt1 = """
parameters:
a: 0
b: 1
bar:
curve:
- - 0
- 0.3
- eased_lerp
- - 49
- 0.0001
- - 99
- 0.3
loop: true
""".strip()
pg = from_yaml(txt1)
assert pg[1] == {'a':0,'b':1, 'bar':0.2996919116429129}
###########################

# to do: test loop and bounce serialization

0 comments on commit cb0ec0b

Please sign in to comment.