Skip to content

Commit c05a622

Browse files
author
Liam Sherwin
committed
Updates DataContainer to use ContainerItem
1 parent 8c98d5e commit c05a622

File tree

13 files changed

+492
-307
lines changed

13 files changed

+492
-307
lines changed

core/animation/CueAnimator.gd

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func seek_to(time: float) -> void:
144144

145145
if animation_track.parameter in _allowed_intensity_parameters:
146146
new_data *= _intensity
147-
147+
148148
fixture.set_parameter(animation_track.parameter, animation_track.function, new_data, _layer_id, animation_track.zone)
149149

150150
_progress = time
@@ -167,6 +167,7 @@ func add_track(id: String, fixture: Fixture, parameter: String, function: String
167167
"first_time": true,
168168
"animator": self
169169
}
170+
print(_tracks[id].parameter, ": ", _tracks[id].to)
170171

171172

172173
## Removes an animated method, will reset all values to default if reset == true
@@ -183,33 +184,33 @@ func remove_track(id: String, reset: bool = true) -> void:
183184

184185

185186
## Tracks a cues fixtures
186-
func track(cue: Cue, pre_existing_data: Dictionary[String, Dictionary]) -> Dictionary[String, Dictionary]:
187-
var fixture_data: Dictionary = cue.get_fixture_data()
188-
189-
for fixture: Fixture in fixture_data:
190-
for zone: String in fixture_data[fixture]:
191-
for parameter: String in fixture_data[fixture][zone]:
192-
var data: Dictionary = fixture_data[fixture][zone][parameter]
193-
var id: String = fixture.uuid + zone + parameter + data.function
194-
var from: float = fixture.get_current_value_layered_or_force_default(zone, parameter, _layer_id, data.function)
195-
196-
add_track(
197-
id,
198-
fixture,
199-
parameter,
200-
data.function,
201-
zone,
202-
from * (2 - (_intensity if parameter in _allowed_intensity_parameters else 1.0)),
203-
data.value,
204-
data.can_fade,
205-
data.start,
206-
data.stop,
207-
)
208-
209-
if id in pre_existing_data:
210-
var animator: Variant = pre_existing_data[id].animator
211-
if is_instance_valid(animator) and animator != self:
212-
animator.remove_track(id, false)
187+
func track(p_cue: Cue, p_pre_existing_data: Dictionary[String, Dictionary]) -> Dictionary[String, Dictionary]:
188+
for item: ContainerItem in p_cue.get_items():
189+
var id: String = item.get_attribute_id()
190+
var from: float = item.get_fixture().get_current_value_layered_or_force_default(
191+
item.get_zone(),
192+
item.get_parameter(),
193+
_layer_id,
194+
item.get_function()
195+
)
196+
197+
add_track(
198+
id,
199+
item.get_fixture(),
200+
item.get_parameter(),
201+
item.get_function(),
202+
item.get_zone(),
203+
from * (2 - (_intensity if item.get_parameter() in _allowed_intensity_parameters else 1.0)),
204+
item.get_value(),
205+
item.get_can_fade(),
206+
item.get_start(),
207+
item.get_stop(),
208+
)
209+
210+
if id in p_pre_existing_data:
211+
var animator: Variant = p_pre_existing_data[id].animator
212+
if is_instance_valid(animator) and animator != self:
213+
animator.remove_track(id, false)
213214

214215
return _tracks
215216

core/animation/DataContainerAnimator.gd

Lines changed: 45 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var _progress: float = 0
2222
var _layer_id: String = ""
2323

2424
## Contains all the infomation for this animation
25-
var _tracks: Dictionary[int, Dictionary] = {}
25+
var _tracks: Dictionary[ContainerItem, Dictionary] = {}
2626

2727
## Previous time for the animation step
2828
var _previous_time: float = 0
@@ -33,10 +33,13 @@ var _container: DataContainer
3333
## Stores all track ids for containers
3434
var _container_track_ids: Dictionary[Fixture, Dictionary]
3535

36+
## Seek to queued state
37+
var _seek_queued: bool = false
38+
3639
## Signals to connect to the container
3740
var _container_signals: Dictionary[String, Callable] = {
38-
"on_data_stored": _on_data_stored,
39-
"on_data_erased": _on_data_erased
41+
"on_items_stored": _on_items_stored,
42+
"on_items_erased": _on_items_erased,
4043
}
4144

4245

@@ -56,7 +59,6 @@ func _process(delta: float) -> void:
5659
steped.emit(_progress)
5760

5861

59-
6062
## Sets the data container to use for storage
6163
func set_container(p_container: DataContainer) -> void:
6264
if is_instance_valid(_container):
@@ -94,13 +96,9 @@ func stop() -> void:
9496
set_process(false)
9597
_progress = 0
9698

97-
for track: Dictionary in _tracks.values():
98-
(track.fixture as Fixture).erase_parameter(
99-
track.parameter,
100-
_layer_id,
101-
track.zone
102-
)
103-
track.first_time = true
99+
for item: ContainerItem in _tracks.keys():
100+
item.get_fixture().erase_parameter(item.get_parameter(), _layer_id, item.get_zone())
101+
_tracks[item].first_time = true
104102

105103

106104
## Finishes the animation imdetaly
@@ -118,117 +116,63 @@ func finish() -> void:
118116

119117
## Internal function to seek to a point in the animation
120118
func seek_to(time: float) -> void:
121-
for animation_track in _tracks.values():
119+
for item: ContainerItem in _tracks.keys():
120+
var from: float = _tracks[item].from
121+
var current: float = _tracks[item].current
122+
var first_time: bool = _tracks[item].first_time
122123
var new_data: float = - 1
123124

124-
if animation_track.can_fade:
125-
if time < animation_track.start or time > animation_track.stop:
125+
if item.get_can_fade():
126+
if time < item.get_start() or time > item.get_stop():
126127
continue
127128

128-
var normalized_progress = (time - animation_track.start) / max(animation_track.stop - animation_track.start, 0.0001)
129+
var normalized_progress = (time - item.get_start()) / max(item.get_stop() - item.get_start(), 0.0001)
129130
new_data = Tween.interpolate_value(
130-
animation_track.from,
131-
animation_track.to - animation_track.from,
131+
from,
132+
item.get_value() - from,
132133
normalized_progress,
133134
1,
134135
Tween.TRANS_LINEAR,
135136
Tween.EASE_IN_OUT
136137
)
137138

138-
elif _previous_time > time and time <= animation_track.stop:
139-
new_data = animation_track.from
139+
elif _previous_time > time and time <= item.get_stop():
140+
new_data = from
140141

141-
elif time > _previous_time and time >= animation_track.start:
142-
new_data = animation_track.to
143-
144-
if new_data != - 1 and (animation_track.current != new_data or animation_track.first_time):
145-
animation_track.current = new_data
146-
animation_track.first_time = false
147-
148-
var fixture: Fixture = animation_track.fixture
149-
fixture.set_parameter(animation_track.parameter, animation_track.function, new_data, _layer_id, animation_track.zone)
142+
elif time > _previous_time and time >= item.get_start():
143+
new_data = item.get_value()
144+
145+
if new_data != - 1 and (current != new_data or first_time):
146+
_tracks[item].current = new_data
147+
_tracks[item].first_time = false
148+
149+
item.get_fixture().set_parameter(
150+
item.get_parameter(),
151+
item.get_function(),
152+
new_data,
153+
_layer_id,
154+
item.get_zone()
155+
)
150156

151157
_progress = time
152158
_previous_time = time
153159

154160

155-
## Adds a method animation, method animation will call a method for each step in the animation, with the interpolated Variant as the argument
156-
func add_track(fixture: Fixture, parameter: String, function: String, zone: String, to: float, can_fade: bool = true, start: float = 0.0, stop: float = 1.0) -> int:
157-
var ids: Array = _tracks.keys()
158-
ids.sort()
159-
var id: int = type_convert(ids.max(), TYPE_INT) + 1
160-
var from: float = fixture.get_current_value_layered_or_force_default(zone, parameter, _layer_id, function)
161-
162-
_tracks[id] = {
163-
"fixture": fixture,
164-
"parameter": parameter,
165-
"function": function,
166-
"zone": zone,
167-
"from": from,
168-
"to": to,
169-
"current": from,
170-
"can_fade": can_fade,
171-
"start": start,
172-
"stop": stop,
173-
"first_time": true
174-
}
175-
176-
return id
177-
178-
179-
## Removes an animated method, will reset all values to default if reset == true
180-
func remove_track(id: Variant, reset: bool = true) -> void:
181-
if _tracks.has(id):
182-
if reset:
183-
var track: Dictionary = _tracks[id]
184-
track.fixture.set_parameter(track.parameter, track.function, track.from, _layer_id, track.zone)
185-
186-
_tracks.erase(id)
187-
188-
189-
## Gets an animated track from the given id
190-
func get_track_from_id(id: Variant) -> Dictionary:
191-
return _tracks.get(id, {}).duplicate()
192-
193-
194-
## Returnes a copy of the animated data
195-
func get_animated_data(duplicate_data: bool = true) -> Dictionary:
196-
return _tracks.duplicate(true) if duplicate_data else _tracks
197-
198-
199-
## Sets the animated data
200-
func set_animated_data(animation_data: Dictionary) -> void:
201-
_tracks = animation_data.duplicate()
202-
203-
204161
## Called when data is stored to the container
205-
func _on_data_stored(fixture: Fixture, parameter: String, function: String, value: Variant, zone: String, can_fade: bool, start: float, stop: float) -> void:
206-
var id: int = add_track(
207-
fixture,
208-
parameter,
209-
function,
210-
zone,
211-
value,
212-
can_fade,
213-
start,
214-
stop
215-
)
216-
217-
_container_track_ids.get_or_add(fixture, {}).get_or_add(zone, {})[parameter] = id
162+
func _on_items_stored(items: Array) -> void:
163+
for item: ContainerItem in items:
164+
_tracks[item] = {
165+
"from": item.get_fixture().get_current_value_layered_or_force_default(item.get_zone(), item.get_parameter(), _layer_id, item.get_function()),
166+
"current": 0.0,
167+
"first_time": true,
168+
}
218169

219170

220171
## Called when data is stored to the container
221-
func _on_data_erased(fixture: Fixture, parameter: String, zone: String) -> void:
222-
remove_track(_container_track_ids[fixture][zone][parameter])
223-
224-
if not _container_track_ids[fixture][zone][parameter]:
225-
_container_track_ids[fixture][zone].erase(parameter)
226-
227-
if not _container_track_ids[fixture][zone]:
228-
_container_track_ids[fixture].erase(zone)
229-
230-
if not _container_track_ids[fixture]:
231-
_container_track_ids.erase(fixture)
172+
func _on_items_erased(items: Array) -> void:
173+
for item: ContainerItem in items:
174+
item.get_fixture().erase_parameter(item.get_parameter(), _layer_id, item.get_zone())
175+
_tracks.erase(item)
232176

233177

234178
## Deletes all the animated data

0 commit comments

Comments
 (0)