Skip to content

Commit 8bda518

Browse files
author
Liam Sherwin
committed
Animation and Color updates
1 parent 36d9400 commit 8bda518

File tree

14 files changed

+800
-376
lines changed

14 files changed

+800
-376
lines changed

core/animation/Animator.gd

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ var _animation_data: Dictionary = {}
5353
## Time to stop the animation at
5454
var _stop_at: float = length
5555

56+
## Previous time for the animation step
57+
var _previous_time: float = 0
58+
5659

5760
func _ready() -> void:
5861
set_process(false)
@@ -77,6 +80,7 @@ func _process(delta: float) -> void:
7780

7881
if elapsed_time >= _stop_at:
7982
finish()
83+
is_playing = false
8084

8185

8286
## Plays this animation
@@ -148,17 +152,24 @@ func _seek_to(time: float) -> void:
148152
Tween.EASE_IN_OUT
149153
)
150154

151-
elif play_backwards and time <= animation_track.stop:
155+
elif _previous_time > time and time <= animation_track.stop:
152156
new_data = animation_track.from
153157

154-
elif not play_backwards and time >= animation_track.start:
158+
elif time > _previous_time and time >= animation_track.start:
155159
new_data = animation_track.to
156160

161+
157162
if new_data != - 1 and animation_track.current != new_data:
158163
animation_track.current = new_data
159-
var fixture: Fixture = animation_track.fixture
160-
fixture.set_parameter(animation_track.parameter, animation_track.function, new_data, layer_id, animation_track.zone)
161164

165+
if animation_track.has("fixture"):
166+
var fixture: Fixture = animation_track.fixture
167+
fixture.set_parameter(animation_track.parameter, animation_track.function, new_data, layer_id, animation_track.zone)
168+
169+
elif animation_track.has("method"):
170+
animation_track.method.call(new_data)
171+
172+
_previous_time = time
162173
steped.emit(time)
163174

164175

core/components/FixtureManifest.gd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func remove_parameter(p_mode: String, p_zone: String, p_parameter: String) -> bo
9696

9797

9898
## Adds a funtion to the given parameter
99-
func add_parameter_function(p_mode: String, p_zone: String, p_parameter: String, p_function: String, p_name: String, p_default: int, p_range: Array[int], p_can_fade: bool) -> bool:
99+
func add_parameter_function(p_mode: String, p_zone: String, p_parameter: String, p_function: String, p_name: String, p_default: int, p_range: Array[int], p_can_fade: bool, p_vdim_effected: bool) -> bool:
100100
if not _modes.has(p_mode) or not _modes[p_mode].zones.has(p_zone) or not _modes[p_mode].zones[p_zone].has(p_parameter):
101101
return false
102102

@@ -105,6 +105,7 @@ func add_parameter_function(p_mode: String, p_zone: String, p_parameter: String,
105105
"name": p_name,
106106
"default": p_default,
107107
"can_fade": p_can_fade,
108+
"vdim_effected": p_vdim_effected,
108109
"dmx_range": p_range.duplicate(),
109110
"sets": []
110111
}
@@ -155,6 +156,11 @@ func function_can_fade(p_mode: String, p_zone: String, p_parameter: String, p_fu
155156
return _modes.get(p_mode, {}).get("zones", {}).get(p_zone, {}).get(p_parameter, {}).get("functions", {}).get(p_function, {}).get("can_fade", false)
156157

157158

159+
## Checks if this FixtureManifest has a function that can vdim
160+
func function_can_vdim(p_mode: String, p_zone: String, p_parameter: String, p_function: String) -> bool:
161+
return _modes.get(p_mode, {}).get("zones", {}).get(p_zone, {}).get(p_parameter, {}).get("functions", {}).get(p_function, {}).get("vdim_effected", false)
162+
163+
158164
## Returns the given mode
159165
func get_mode(p_mode: String) -> Dictionary:
160166
return _modes.get(p_mode, {}).duplicate(true)

core/components/containers/DataContainer.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,15 @@ func _load_stored_global_data(p_serialized_stored_global_data: Dictionary) -> vo
199199
)
200200

201201

202-
## Serializes this scene and returnes it in a dictionary
202+
## Serializes this DataContainer and returnes it in a dictionary
203203
func _serialize() -> Dictionary:
204204
return {
205205
"fixture_data": _serialize_stored_data(),
206206
"global_data": _serialize_stored_global_data(),
207207
}
208208

209209

210-
## Called when this scene is to be loaded from serialized data
210+
## Called when this DataContainer is to be loaded from serialized data
211211
func _load(serialized_data: Dictionary) -> void:
212212
_load_stored_data(serialized_data.get("fixture_data", {}))
213213
_load_stored_global_data(serialized_data.get("global_data", {}))

core/components/fixtures/DMXFixture.gd

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func get_current_dmx() -> Dictionary:
9191
# Shutter1.Shutter1Strobe, 1.0, effect_uuid, root
9292

9393
## Sets a parameter to a float value
94-
func set_parameter(p_parameter: String, p_function: String, p_value: float, p_layer_id: String, p_zone: String = "root", p_disable_output: bool = false) -> void:
94+
func set_parameter(p_parameter: String, p_function: String, p_value: float, p_layer_id: String, p_zone: String = "root", p_disable_output: bool = false) -> bool:
9595
if _parameters.has(p_zone) and _parameters[p_zone].has(p_parameter) and _parameters[p_zone][p_parameter].functions.has(p_function):
9696
var offsets: Array = _parameters[p_zone][p_parameter].offsets
9797
_raw_layers.get_or_add(p_zone, {}).get_or_add(p_parameter, {})[p_layer_id] = {"value": p_value, "function": p_function}
@@ -119,6 +119,10 @@ func set_parameter(p_parameter: String, p_function: String, p_value: float, p_la
119119

120120
on_parameter_changed.emit(p_parameter, p_function, p_value, p_zone)
121121
_compile_output()
122+
123+
return true
124+
125+
return false
122126

123127

124128
## Erases the parameter on the given layer
@@ -155,7 +159,7 @@ func erase_parameter(p_parameter: String, p_layer_id: String, p_zone: String = "
155159

156160

157161
## Sets a parameter override to a float value
158-
func set_override(p_parameter: String, p_function: String, p_value: float, p_zone: String = "root", p_disable_output: bool = false) -> void:
162+
func set_override(p_parameter: String, p_function: String, p_value: float, p_zone: String = "root", p_disable_output: bool = false) -> bool:
159163
if _parameters.has(p_zone) and _parameters[p_zone].has(p_parameter) and _parameters[p_zone][p_parameter].functions.has(p_function):
160164
var offsets: Array = _parameters[p_zone][p_parameter].offsets
161165
_raw_override_layers.get_or_add(p_zone, {})[p_parameter] = {"value": p_value, "function": p_function}
@@ -187,6 +191,9 @@ func set_override(p_parameter: String, p_function: String, p_value: float, p_zon
187191
on_override_changed.emit(p_parameter, p_function, p_value, p_zone)
188192
_compile_output()
189193

194+
return true
195+
196+
return false
190197

191198

192199
## Erases the parameter override
@@ -261,6 +268,11 @@ func get_default(p_zone: String, p_parameter: String, p_function: String) -> flo
261268
return remap(dmx_value, range[0], range[1], 0.0, 1.0)
262269

263270

271+
## Gets a value from the given layer id, parameter, and zone
272+
func get_current_value(p_zone: String, p_parameter: String, p_layer_id: String, p_function: String = "", p_allow_default: bool = true) -> float:
273+
return _raw_layers.get(p_zone, {}).get(p_parameter, {}).get(p_layer_id, {}).get("value", get_default(p_zone, p_parameter, p_function) if p_allow_default else 0.0)
274+
275+
264276
## Sets the manifest for this fixture
265277
func set_manifest(p_manifest: FixtureManifest, p_mode: String) -> void:
266278
_parameters = p_manifest.get_mode(p_mode).zones

core/components/fixtures/Fixture.gd

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func _init(p_uuid: String = UUID_Util.v4(), p_name: String = name) -> void:
2929

3030

3131
## Sets a parameter to a float value
32-
func set_parameter(p_parameter: String, p_function: String, p_value: float, p_layer_id: String, p_zone: String = "root") -> void:
33-
pass
32+
func set_parameter(p_parameter: String, p_function: String, p_value: float, p_layer_id: String, p_zone: String = "root") -> bool:
33+
return false
3434

3535

3636
## Erases the parameter on the given layer
@@ -39,8 +39,8 @@ func erase_parameter(p_parameter: String, p_layer_id: String, p_zone: String = "
3939

4040

4141
## Sets a parameter override to a float value
42-
func set_override(p_parameter: String, p_function: String, p_value: float, p_zone: String = "root") -> void:
43-
pass
42+
func set_override(p_parameter: String, p_function: String, p_value: float, p_zone: String = "root") -> bool:
43+
return false
4444

4545

4646
## Erases the parameter override
@@ -74,7 +74,7 @@ func get_parameter_functions(p_zone: String, p_parameter: String) -> Array:
7474

7575

7676
## Checks if this fixture has a parameter
77-
func has_parameter(p_zone: String, p_parameter: String) -> bool:
77+
func has_parameter(p_zone: String, p_parameter: String, p_function: String = "") -> bool:
7878
return false
7979

8080

@@ -86,3 +86,8 @@ func function_can_fade(p_zone: String, p_parameter: String, p_function: String)
8686
## Gets the default value of a parameter
8787
func get_default(p_zone: String, p_parameter: String, p_function: String) -> float:
8888
return 0.0
89+
90+
91+
## Gets a value from the given layer id, parameter, and zone
92+
func get_current_value(p_zone: String, p_parameter: String, p_layer_id: String, p_function: String = "", p_allow_default: bool = true) -> float:
93+
return 0.0

core/components/functions/CueList.gd

Lines changed: 86 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ enum MODE {NORMAL, LOOP}
3939
var _mode: int = MODE.NORMAL
4040

4141
## Stores all fixtures that are currently being animated
42-
## str(fixture.uuid + method_name):{
42+
## str(fixture.uuid + zone + parameter):{
4343
## "current_value": Variant,
4444
## "animator": Animator
4545
## }
@@ -81,6 +81,7 @@ func _component_ready() -> void:
8181
_intensity = 1
8282
TC.frames_changed.connect(_find_keyframes)
8383

84+
8485
## Adds a pre-existing cue to this CueList
8586
## Returns false if the cue already exists in this list, or if the index is already in use
8687
func add_cue(cue: Cue, number: float = 0, rename: bool = false) -> bool:
@@ -154,7 +155,6 @@ func _on_cue_timecode_trigger_changed(timecode_trigger: int, cue: Cue) -> void:
154155
_add_cue_keyframe(cue)
155156

156157

157-
158158
func _add_cue_keyframe(cue: Cue) -> void:
159159
if not cue.timecode_trigger in _keyframes.keys():
160160
_keyframes[cue.timecode_trigger] = []
@@ -167,8 +167,6 @@ func _add_cue_keyframe(cue: Cue) -> void:
167167
cue.local_data[uuid+"old_timecode_trigger"] = cue.timecode_trigger
168168

169169

170-
171-
172170
func _on_cue_timecode_enabled_stage_changed(timecode_enabled: bool, cue: Cue) -> void:
173171
if timecode_enabled:
174172
_add_cue_keyframe(cue)
@@ -186,7 +184,6 @@ func _on_cue_timecode_enabled_stage_changed(timecode_enabled: bool, cue: Cue) ->
186184
print(_keyframes)
187185

188186

189-
190187
func _find_keyframes(frame: int) -> void:
191188
# Use binary search to find the closest frame <= frame
192189

@@ -311,24 +308,38 @@ func _seek_to_next_cue_after(seconds: float) -> void:
311308
func _reset_animated_fixtures(animator: Animator, accumulated_animated_data: Dictionary) -> void:
312309
for animation_id in _current_animated_fixtures.keys():
313310
var animating_fixture = _current_animated_fixtures[animation_id]
314-
var from_value: Variant = animating_fixture.fixture.get_value_from_layer_id(uuid, animating_fixture.method_name)
315-
var to_value: Variant = animating_fixture.fixture.get_zero_from_channel_key(animating_fixture.method_name)
311+
var from_value: float = animating_fixture.fixture.get_current_value(animating_fixture.zone, animating_fixture.parameter, uuid, animating_fixture.function)
312+
var to_value: float = animating_fixture.fixture.get_default(animating_fixture.zone, animating_fixture.parameter, animating_fixture.function)
316313

317314
if is_instance_valid(animating_fixture.animator):
318315
animating_fixture.animator.remove_track_from_id(animation_id, false)
319316

320317
accumulated_animated_data[animation_id] = {
321318
"method": func (new_value: Variant) -> void:
322319
_current_animated_fixtures[animation_id].current_value = new_value
323-
animating_fixture.fixture.get(animating_fixture.method_name).call(new_value, uuid),
320+
animating_fixture.fixture.set_parameter(
321+
animating_fixture.parameter,
322+
animating_fixture.function,
323+
new_value * _intensity,
324+
uuid,
325+
animating_fixture.zone
326+
),
324327
"from": from_value,
325328
"to": to_value,
326-
"current": from_value
329+
"current": from_value,
330+
"can_fade": animating_fixture.can_fade,
331+
"start": animating_fixture.start,
332+
"stop": animating_fixture.stop,
327333
}
328334

329335
_current_animated_fixtures[animation_id] = {
330-
"method_name": animating_fixture.method_name,
336+
"zone": animating_fixture.zone,
337+
"parameter": animating_fixture.parameter,
338+
"function": animating_fixture.function,
331339
"fixture": animating_fixture.fixture,
340+
"can_fade": animating_fixture.can_fade,
341+
"start": animating_fixture.start,
342+
"stop": animating_fixture.stop,
332343
"animator": animator,
333344
# "current_value": to_value
334345
}
@@ -339,39 +350,62 @@ func _remove_all_animators() -> void:
339350
_remove_animator(old_cue_number)
340351

341352

353+
## Builds animation data from the cue and updates current animations.
342354
func _accumulate_state(cue: Cue, accumulated_animated_data: Dictionary, animator: Animator) -> void:
343-
for fixture: Fixture in cue.get_fixture_data().keys():
344-
for method_name: String in cue.get_fixture_data()[fixture]:
345-
var stored_value: Dictionary = cue.get_fixture_data()[fixture][method_name]
346-
var from_value: Variant = fixture.get_value_from_layer_id(uuid, method_name)
347-
var to_value: Variant = stored_value.value
348-
print(stored_value)
349-
var animation_id: String = fixture.uuid + method_name
350-
accumulated_animated_data[animation_id] = {
351-
"method": func (new_value: Variant) -> void:
352-
_current_animated_fixtures[animation_id].current_value = new_value
353-
fixture.get(method_name).call(new_value * _intensity, uuid)
354-
,
355-
"from": from_value * (2 - _intensity),
356-
"to": to_value,
357-
"current": from_value * (2 - _intensity),
358-
}
359-
360-
if animation_id in _current_animated_fixtures:
361-
if _current_animated_fixtures[animation_id].has("current_value"):
362-
accumulated_animated_data[animation_id].from = _current_animated_fixtures[animation_id].current_value
363-
364-
var _animator = _current_animated_fixtures[animation_id].animator
365-
if is_instance_valid(_animator) and _animator != animator:
366-
_animator.remove_track_from_id(animation_id, false)
367-
368-
369-
_current_animated_fixtures[animation_id] = {
370-
"method_name": method_name,
371-
"fixture": fixture,
372-
"animator": animator,
373-
"current_value": from_value
374-
}
355+
var fixture_data: Dictionary = cue.get_fixture_data()
356+
357+
for fixture: Fixture in fixture_data:
358+
for zone: String in fixture_data[fixture]:
359+
for parameter: String in fixture_data[fixture][zone]:
360+
var value_config: Dictionary = fixture_data[fixture][zone][parameter]
361+
var from_value: float = fixture.get_current_value(zone, parameter, uuid, value_config.function)
362+
var to_value: Variant = value_config.value
363+
if parameter == "Zoom":
364+
print(from_value)
365+
print(to_value)
366+
print()
367+
368+
var animation_id: String = fixture.uuid + zone + parameter
369+
accumulated_animated_data[animation_id] = {
370+
"method": func (new_value: Variant) -> void:
371+
_current_animated_fixtures[animation_id].current_value = new_value
372+
if parameter == "Zoom":
373+
print(new_value * _intensity)
374+
fixture.set_parameter(
375+
parameter,
376+
value_config.function,
377+
new_value * _intensity,
378+
uuid,
379+
zone
380+
),
381+
"from": from_value * (2 - _intensity),
382+
"to": to_value,
383+
"current": from_value * (2 - _intensity),
384+
"can_fade": value_config.can_fade,
385+
"start": value_config.start,
386+
"stop": value_config.stop,
387+
}
388+
389+
if animation_id in _current_animated_fixtures:
390+
if _current_animated_fixtures[animation_id].has("current_value"):
391+
accumulated_animated_data[animation_id].from = _current_animated_fixtures[animation_id].current_value
392+
393+
var _animator = _current_animated_fixtures[animation_id].animator
394+
if is_instance_valid(_animator) and _animator != animator:
395+
_animator.remove_track_from_id(animation_id, false)
396+
397+
398+
_current_animated_fixtures[animation_id] = {
399+
"zone": zone,
400+
"parameter": parameter,
401+
"function": value_config.function,
402+
"can_fade": value_config.can_fade,
403+
"start": value_config.start,
404+
"stop": value_config.stop,
405+
"fixture": fixture,
406+
"animator": animator,
407+
"current_value": from_value
408+
}
375409

376410

377411
func _handle_animator_finished(animator: Animator, cue_number: float, fade_time: float) -> void:
@@ -518,7 +552,16 @@ func set_intensity(p_intensity: float) -> void:
518552
if _index != -1:
519553
for animated_fixture: Dictionary in _current_animated_fixtures.values():
520554
if not is_instance_valid(animated_fixture.animator) and animated_fixture.has("current_value"):
521-
animated_fixture.fixture.get(animated_fixture.method_name).call(animated_fixture.current_value * _intensity, uuid)
555+
var fixture: Fixture = animated_fixture.fixture
556+
557+
if fixture.function_can_fade(animated_fixture.zone, animated_fixture.parameter, animated_fixture.function):
558+
fixture.set_parameter(
559+
animated_fixture.parameter,
560+
animated_fixture.function,
561+
animated_fixture.current_value * _intensity,
562+
uuid,
563+
animated_fixture.zone
564+
)
522565

523566

524567
## Sets the fade time for all cues

0 commit comments

Comments
 (0)