fix: defaults

This commit is contained in:
cha0s 2021-03-31 16:03:04 -05:00
parent feb5b58e21
commit 700ed92b68
2 changed files with 15 additions and 2 deletions

View File

@ -34,14 +34,14 @@ const Animated = ({json, path}) => {
Offset Offset
<VectorComponent <VectorComponent
onChange={patch.onChange(join(path, 'params/animations', key, 'offset'))} onChange={patch.onChange(join(path, 'params/animations', key, 'offset'))}
value={animation.offset} value={animation.offset || [0, 0]}
/> />
</label> </label>
<label> <label>
Jitter Jitter
<Number <Number
onChange={patch.onChange(join(path, 'params/animations', key, 'jitter'))} onChange={patch.onChange(join(path, 'params/animations', key, 'jitter'))}
value={animation.jitter} value={animation.jitter || 0}
/> />
</label> </label>
</> </>

View File

@ -307,4 +307,17 @@ export default (latus) => class Animated extends decorate(Trait) {
animation.tick(elapsed); animation.tick(elapsed);
} }
static withoutDefaults(json) {
Object.keys(json.params.animations).forEach((key) => {
const animation = json.params.animations[key];
if (Vector.equals([0, 0], animation.offset)) {
delete animation.offset;
}
if (0 === animation.jitter) {
delete animation.jitter;
}
});
return super.withoutDefaults(json);
}
}; };