From ec7b46ebc90d708052052ac527811dd1df7d462e Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Mon, 3 Feb 2025 01:49:46 +0100 Subject: [PATCH] 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. --- autoloads/morse_state.gd | 2 +- scenes/morse_banner.gd | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/autoloads/morse_state.gd b/autoloads/morse_state.gd index d04c54f..2089af9 100644 --- a/autoloads/morse_state.gd +++ b/autoloads/morse_state.gd @@ -16,5 +16,5 @@ func set_state(state: bool) -> void: curr_state = state var now := Time.get_ticks_msec() - states.push_front(now - last_change) + states.push_back(now - last_change) last_change = now diff --git a/scenes/morse_banner.gd b/scenes/morse_banner.gd index 0869e78..df1a3ed 100644 --- a/scenes/morse_banner.gd +++ b/scenes/morse_banner.gd @@ -27,7 +27,8 @@ func _draw(): else: 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) curr_x -= rect_width if morse_on: