Switch direction of MorseState state array

Originally it was easier for the MorseBanner to have the states with
newest in front, but this makes the code harder to read and complicates
things in other places.

At some point it also might make sense to not use a range() in
MorseBanner, but use a int var + counter instead, as we often might only
consume a small number of elements. But as this is game programming,
"winging it" and getting something done seems to be the modus operandi.
This commit is contained in:
Sebastian Lohff 2025-02-03 01:49:46 +01:00
parent ca3b8dba62
commit ec7b46ebc9
2 changed files with 3 additions and 2 deletions

View File

@ -16,5 +16,5 @@ func set_state(state: bool) -> void:
curr_state = state curr_state = state
var now := Time.get_ticks_msec() var now := Time.get_ticks_msec()
states.push_front(now - last_change) states.push_back(now - last_change)
last_change = now last_change = now

View File

@ -27,7 +27,8 @@ func _draw():
else: else:
px_per_s = size.x / (Time.get_ticks_msec() - MorseState.start_time) * 1000.0 px_per_s = size.x / (Time.get_ticks_msec() - MorseState.start_time) * 1000.0
for duration in [first_time] + MorseState.states: for n in [-1] + range(MorseState.states.size() - 1, -1, -1):
var duration := first_time if n == -1 else MorseState.states[n]
var rect_width: float = min(duration / 1000.0 * px_per_s, curr_x) var rect_width: float = min(duration / 1000.0 * px_per_s, curr_x)
curr_x -= rect_width curr_x -= rect_width
if morse_on: if morse_on: