Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
5c393d1
Add fuel system, integrate with player and tests
ikostan Apr 7, 2026
78b8c0d
Update player.gd
ikostan Apr 7, 2026
3c09275
Update globals.gd
ikostan Apr 7, 2026
bbe9181
Update game_settings_resource.gd
ikostan Apr 7, 2026
d8e69b4
Update player.gd
ikostan Apr 7, 2026
af4983f
Update main_scene.gd
ikostan Apr 7, 2026
5d90fe6
Use GameSettings for fuel and reset on spawn
ikostan Apr 7, 2026
5384388
Update test_player.gd
ikostan Apr 7, 2026
55416e8
Update test_difficulty.gd
ikostan Apr 7, 2026
cc1030e
Update test_difficulty_integration.gd
ikostan Apr 7, 2026
b54c44d
Reset speed on fuel out & update test helper
ikostan Apr 7, 2026
aa8b37b
Add GUT tests for fuel edge cases
ikostan Apr 7, 2026
686191c
Update test/gut/test_fuel_ui.gd
ikostan Apr 8, 2026
5dc44cf
test_fuel_initialization() can't fail right now.
ikostan Apr 8, 2026
aa03e99
Update test/gut/test_fuel_edge_cases.gd
ikostan Apr 8, 2026
7196efb
Update test/gut/test_fuel_resource.gd
ikostan Apr 8, 2026
4bf75bb
Use Globals.settings.max_fuel for the fuel fixtures and bar assertions.
ikostan Apr 8, 2026
8c755c1
Isolate the singleton fuel state in this test.
ikostan Apr 8, 2026
20d00e3
Restore the shared fuel state after this integration test.
ikostan Apr 8, 2026
c9a0e69
Update scripts/player.gd
ikostan Apr 8, 2026
c871aa9
Update scripts/game_settings_resource.gd
ikostan Apr 8, 2026
fba243a
Update game_settings_resource.gd
ikostan Apr 8, 2026
312b477
Avoid auto-saving current_fuel on every drain tick.
ikostan Apr 8, 2026
3073aee
Update globals.gd
ikostan Apr 8, 2026
d0d607a
Update globals.gd
ikostan Apr 8, 2026
2b3c364
suggestion (bug_risk): Handle max_fuel changes so the fuel bar’s max …
ikostan Apr 8, 2026
f0b3cc8
Introduce a Godot Resource that centralizes fuel configuration
ikostan Apr 9, 2026
b9807a3
Update player.gd
ikostan Apr 9, 2026
985e74c
Update player.gd
ikostan Apr 9, 2026
59c8027
Update player.gd
ikostan Apr 9, 2026
41d9de6
Add automated unit tests for core fuel logic
ikostan Apr 9, 2026
a080857
Add tests for persistence and UI integration of the fuel system
ikostan Apr 9, 2026
f17205c
Update test_fuel_persistence_integration.gd
ikostan Apr 9, 2026
0cf39f2
issue (bug_risk): The setters for max_fuel and current_fuel are recur…
ikostan Apr 9, 2026
d5d3da8
question (bug_risk): Resetting current_fuel to max on player spawn ma…
ikostan Apr 9, 2026
f98206b
Update test/gut/test_fuel_additional_edge_cases..gd
ikostan Apr 9, 2026
3c39448
Merge branch 'convert-hard-coded-fuel-elements-to-godot-resource' of …
ikostan Apr 9, 2026
4c800b7
Update test/gut/test_fuel_persistence_integration.gd
ikostan Apr 9, 2026
e2ba596
Need to explicitly sever the ties before the node leaves the tree
ikostan Apr 9, 2026
b99e75f
Merge branch 'convert-hard-coded-fuel-elements-to-godot-resource' of …
ikostan Apr 9, 2026
3687769
Update player.gd
ikostan Apr 9, 2026
1f90f7b
Update main_scene.tscn
ikostan Apr 9, 2026
e6ce226
Update player.gd
ikostan Apr 9, 2026
e3bf849
issue (bug_risk): The current_fuel setter recursively assigns to itse…
ikostan Apr 9, 2026
e34245c
Update game_settings_resource.gd
ikostan Apr 9, 2026
85a4a46
issue (bug_risk): Threshold setters assign to their own exported prop…
ikostan Apr 9, 2026
f8bb977
Update game_settings_resource.gd
ikostan Apr 9, 2026
5582ee4
Update game_settings_resource.gd
ikostan Apr 9, 2026
9c7318c
issue (bug_risk): Fuel warning uses absolute current_fuel vs a thresh…
ikostan Apr 9, 2026
69661e4
The new test file test_fuel_additional_edge_cases..gd has a double do…
ikostan Apr 9, 2026
049558b
Update test_fuel_persistence_integration.gd
ikostan Apr 9, 2026
60d3224
issue: The max_fuel setter can indirectly force current_fuel to 0 and…
ikostan Apr 9, 2026
8e17078
Update player.gd
ikostan Apr 9, 2026
60239e3
Update player.gd
ikostan Apr 9, 2026
6940141
issue: Guard against invalid or equal fuel threshold values that woul…
ikostan Apr 9, 2026
bbda2c3
Update test_fuel_additional_edge_cases.gd
ikostan Apr 9, 2026
3c08ad8
Update player.gd
ikostan Apr 9, 2026
b639983
Update player.gd
ikostan Apr 9, 2026
e65f0ff
suggestion (bug_risk): The cached _settings reference is not used con…
ikostan Apr 9, 2026
7f9da9c
Update game_settings_resource.gd
ikostan Apr 9, 2026
11712ee
Update game_settings_resource.gd
ikostan Apr 9, 2026
ed2064b
Update game_settings_resource.gd
ikostan Apr 9, 2026
b34983c
Update player.gd
ikostan Apr 9, 2026
25df0e2
Update player.gd
ikostan Apr 9, 2026
ce2ace0
Update test/gut/test_fuel_additional_edge_cases.gd
ikostan Apr 9, 2026
981857b
Update scripts/player.gd
ikostan Apr 9, 2026
ad8a596
Update player.gd
ikostan Apr 9, 2026
0f9350a
Update globals.gd
ikostan Apr 10, 2026
249c0c8
Update globals.gd
ikostan Apr 10, 2026
9de3148
Update globals.gd
ikostan Apr 10, 2026
87cb1f5
Update test_fuel_persistence_integration.gd
ikostan Apr 10, 2026
6fa8828
Update test_fuel_edge_cases.gd
ikostan Apr 10, 2026
231d117
issue (bug_risk): Direct access to Globals.settings.current_fuel assu…
ikostan Apr 10, 2026
18e1d7c
Update main_scene.gd
ikostan Apr 10, 2026
a94c9b2
issue (bug_risk): Fallback GameSettingsResource can desync player fue…
ikostan Apr 10, 2026
6f9ea4b
Update player.gd
ikostan Apr 10, 2026
9e6daa6
issue (bug_risk): Fuel timer never restarts after refuel, so fuel con…
ikostan Apr 10, 2026
c314ebc
Update game_settings_resource.gd
ikostan Apr 10, 2026
f0bfd62
Update player.gd
ikostan Apr 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions scripts/game_settings_resource.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ extends Resource
## without the UI having to explicitly call persistence or logging methods.
signal setting_changed(setting_name: String, new_value: Variant)

## SIGNAL: fuel_depleted
##
## Emitted when current_fuel reaches exactly 0.0.
## External systems (like the Player or UI) can connect to this to trigger
## game-over states or low-fuel warnings without polling every frame.
signal fuel_depleted

@export_group("Fuel System")
## Maximum fuel capacity.
@export var max_fuel: float = 100.0:
set(value):
max_fuel = max(0.0, value)
setting_changed.emit("max_fuel", max_fuel)
Comment thread
ikostan marked this conversation as resolved.
Outdated

## Current fuel level. Clamped between 0.0 and max_fuel.
@export var current_fuel: float = 100.0:
set(value):
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
var old_value: float = current_fuel
current_fuel = clamp(value, 0.0, max_fuel)
if old_value > 0.0 and current_fuel == 0.0:
fuel_depleted.emit()
setting_changed.emit("current_fuel", current_fuel)
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated

## Base rate of fuel consumption per second.
@export var base_consumption_rate: float = 1.0

@export_group("Logging")
# Current log level: 0=DEBUG, 1=INFO, 2=WARNING, 3=ERROR, 4=NONE
@export_range(0, 4, 1) var current_log_level: int = 1:
Expand Down Expand Up @@ -69,3 +95,10 @@ func _init() -> void:
key_mapping_scene = load("res://scenes/key_mapping_menu.tscn")
if not options_scene:
options_scene = load("res://scenes/options_menu.tscn")


## Helper method to increase fuel safely.
## Increases fuel level by specified amount, clamped to max_fuel.
func refuel(amount: float) -> void:
if amount > 0:
current_fuel += amount
24 changes: 24 additions & 0 deletions scripts/globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,26 @@ func _load_settings(path: String = Settings.CONFIG_PATH) -> void:
LogLevel.DEBUG
)

# NEW: Load the fuel related settings
if config.has_section_key("Settings", "max_fuel"):
var loaded_max: Variant = config.get_value("Settings", "max_fuel")
if loaded_max is float or loaded_max is int:
settings.max_fuel = float(loaded_max)
else:
log_message(
"Invalid type for max_fuel: " + str(typeof(loaded_max)), LogLevel.WARNING
)

if config.has_section_key("Settings", "current_fuel"):
var loaded_current: Variant = config.get_value("Settings", "current_fuel")
if loaded_current is float or loaded_current is int:
settings.current_fuel = float(loaded_current)
else:
log_message(
"Invalid type for current_fuel: " + str(typeof(loaded_current)),
LogLevel.WARNING
)

# Disable the guard and log a single summary instead
_is_loading_settings = false
log_message("All settings loaded and synchronized.", LogLevel.DEBUG)
Expand All @@ -226,6 +246,10 @@ func _save_settings(path: String = Settings.CONFIG_PATH) -> void:
config.set_value("Settings", "difficulty", settings.difficulty)
# NEW: Persist the debug logging flag
config.set_value("Settings", "enable_debug_logging", settings.enable_debug_logging)
# NEW: Persist the fuel settings
config.set_value("Settings", "max_fuel", settings.max_fuel)
config.set_value("Settings", "current_fuel", settings.current_fuel)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

err = config.save(path)
if err != OK:
log_message("Failed to save settings: " + str(err), LogLevel.ERROR)
Expand Down
9 changes: 8 additions & 1 deletion scripts/main_scene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,16 @@ func setup_decor_layer(viewport: Vector2) -> void:
func _process(delta: float) -> void:
var scroll_speed: float = player.speed["speed"] * delta * Globals.settings.difficulty * 0.8
background.scroll_offset.y += scroll_speed
if player.fuel["fuel"] <= 0:

# OLD: if player.fuel["fuel"] <= 0:
# NEW: Check the global settings resource for current fuel,
# since the local dictionary key was removed.
if Globals.settings.current_fuel <= 0:
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
background.scroll_offset = Vector2(0, 0)

# 1. Critical unbound controls warning (shown ONCE per session)
# Flag stays true until player fixes bindings (e.g., in key_mapping.gd after remap).

# 1. Critical unbound controls warning (shown ONCE per session)
# Flag stays true until player fixes bindings (e.g., in key_mapping.gd after remap).
# Do NOT reset here — that would make it repeat every 4s (bug fixed).
Expand Down
136 changes: 103 additions & 33 deletions scripts/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const BLINK_INTERVAL: float = 0.5 # Seconds between blinks
@export var acceleration: float = 200.0
@export var deceleration: float = 100.0
# Base fuel consumption
@export var base_fuel_drain: float = 1.0
var current_fuel: float
# OLD: @export var base_fuel_drain: float = 1.0
# OLD: var current_fuel: float

# Regular vars for computed boundaries (no export needed if set in code)
var screen_size: Vector2
Expand Down Expand Up @@ -139,18 +139,31 @@ func _ready() -> void:
# Initialize fuel bar style
fuel_bar_fill_style = StyleBoxFlat.new()
set_bar_fill_style(fuel_bar, fuel_bar_fill_style)
fuel_bar.max_value = MAX_FUEL
# OLD: fuel_bar.max_value = MAX_FUEL
# NEW: Ensure the UI max capacity pulls directly from
# the centralized GameSettingsResource.
fuel_bar.max_value = Globals.settings.max_fuel

# NEW: Reset the fuel to maximum every time the player spawns
# so a new game always starts with a full tank.
Globals.settings.current_fuel = Globals.settings.max_fuel
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated

# Initialize speed bar style and value
speed_bar_fill_style = StyleBoxFlat.new()
set_bar_fill_style(speed_bar, speed_bar_fill_style)
speed_bar.max_value = MAX_SPEED

# Initialize fuel bar style and value
current_fuel = MAX_FUEL
# OLD: current_fuel = MAX_FUEL
fuel_timer.timeout.connect(_on_fuel_timer_timeout)
fuel_timer.start()

# NEW: Connect to the global fuel_depleted signal to handle engine failure.
Globals.settings.fuel_depleted.connect(_on_player_out_of_fuel)
# NEW: Connect to the global setting_changed signal so the UI
# reacts to refuels/drains automatically.
Globals.settings.setting_changed.connect(_on_setting_changed)

speed = {
"speed": 250.0, # Initial speed value (mph); was current_speed
"lateral_speed": lateral_speed,
Expand All @@ -167,11 +180,11 @@ func _ready() -> void:
}

fuel = {
"fuel": current_fuel,
# OLD: "fuel": current_fuel,
"factor": 0.0,
"timer": fuel_label_blink_timer,
"label": fuel_label,
"max": MAX_FUEL,
# OLD: "max": MAX_FUEL,
"bar": fuel_bar,
"bar style": fuel_bar_fill_style,
"blinking": false,
Expand Down Expand Up @@ -210,6 +223,27 @@ func _ready() -> void:
push_error("Weapon node not found! Check player.tscn scene tree for $Weapon child.")


# NEW: Observer pattern handler to react when GameSettingsResource
# properties (like fuel) are updated externally.
func _on_setting_changed(setting_name: String, _value: Variant) -> void:
if setting_name == "current_fuel":
update_fuel_bar()
check_fuel_warning()
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
Comment thread
sourcery-ai[bot] marked this conversation as resolved.

Comment thread
ikostan marked this conversation as resolved.

# NEW: Handler for engine failure triggered by the global fuel_depleted signal from the resource.
func _on_player_out_of_fuel() -> void:
Globals.log_message("Player is out of fuel! Engine flameout.", Globals.LogLevel.WARNING)

# OLD: speed["speed"] = 0.0 (This was previously inside _on_fuel_timer_timeout)
# NEW: Migrated the speed reset to ensure the plane actually stops flying when fuel hits 0
speed["speed"] = 0.0

rotor_stop(rotor_right, rotor_right_sfx)
rotor_stop(rotor_left, rotor_left_sfx)
fuel_timer.stop()
Comment thread
sourcery-ai[bot] marked this conversation as resolved.


## Retrieves the effective text color of a Label, considering theme overrides.
## @param label: The Label node to query.
## @return: The effective font color.
Expand Down Expand Up @@ -284,8 +318,15 @@ func rotor_stop(rotor: Node2D, rotor_sfx: AudioStreamPlayer2D) -> void:


func update_fuel_bar() -> void:
fuel["bar"].value = fuel["fuel"]
var fuel_percent: float = (fuel["fuel"] / fuel["max"]) * 100.0
# OLD: fuel["bar"].value = fuel["fuel"]
# OLD: var fuel_percent: float = (fuel["fuel"] / fuel["max"]) * 100.0

# NEW: Explicitly read current and max fuel from the global settings resource.
var cur_fuel: float = Globals.settings.current_fuel
var m_fuel: float = Globals.settings.max_fuel

fuel["bar"].value = cur_fuel
var fuel_percent: float = (cur_fuel / m_fuel) * 100.0
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
Comment thread
ikostan marked this conversation as resolved.
Outdated

if fuel_percent > HIGH_FUEL_THRESHOLD:
fuel["factor"] = 0.0 # Reset for consistency, though not used here
Expand Down Expand Up @@ -355,33 +396,47 @@ func update_speed_bar() -> void:

# Connect Timer's timeout signal
func _on_fuel_timer_timeout() -> void:
# Scale base rate with clamped normalized speed
# to avoid excessive drain at out-of-range speeds
# OLD: # Scale base rate with clamped normalized speed
# OLD: # to avoid excessive drain at out-of-range speeds
# OLD: var normalized_speed: float = clamp(speed["speed"] / MAX_SPEED, 0.0, 1.0)
# OLD: var fuel_left: float = (
# OLD: fuel["fuel"] - ((base_fuel_drain * normalized_speed) * Globals.settings.difficulty)
# OLD: )
# OLD: #
# OLD: # Clamp and update current_fuel first
# OLD: fuel["fuel"] = clamp(fuel_left, 0, fuel["max"])
# OLD:
# OLD: if fuel["fuel"] <= 0:
# OLD: speed["speed"] = 0.0 # Or game over logic
# OLD: fuel_timer.stop()
# OLD: rotor_stop(rotor_right, rotor_right_sfx)
# OLD: rotor_stop(rotor_left, rotor_left_sfx)
# OLD:
# OLD: # Update UI from the clamped value
# OLD: update_fuel_bar()
# OLD: # Check fuel level and start/stop blinking
# OLD: check_fuel_warning()
# OLD: Globals.log_message("Fuel left: " + str(fuel["fuel"]), Globals.LogLevel.DEBUG)

# NEW: Calculate depletion based on Global settings and update the resource directly.
# NEW: Game over logic is now handled by _on_player_out_of_fuel via the fuel_depleted signal.
# NEW: UI updates are handled automatically via the setting_changed signal.
var normalized_speed: float = clamp(speed["speed"] / MAX_SPEED, 0.0, 1.0)
var fuel_left: float = (
fuel["fuel"] - ((base_fuel_drain * normalized_speed) * Globals.settings.difficulty)
var consumption: float = (
Globals.settings.base_consumption_rate * normalized_speed * Globals.settings.difficulty
)
#
# Clamp and update current_fuel first
fuel["fuel"] = clamp(fuel_left, 0, fuel["max"])

if fuel["fuel"] <= 0:
speed["speed"] = 0.0 # Or game over logic
fuel_timer.stop()
rotor_stop(rotor_right, rotor_right_sfx)
rotor_stop(rotor_left, rotor_left_sfx)

# Update UI from the clamped value
update_fuel_bar()
# Check fuel level and start/stop blinking
check_fuel_warning()
Globals.log_message("Fuel left: " + str(fuel["fuel"]), Globals.LogLevel.DEBUG)
Globals.settings.current_fuel -= consumption
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated
Globals.log_message("Fuel left: " + str(Globals.settings.current_fuel), Globals.LogLevel.DEBUG)
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Outdated


func check_fuel_warning() -> void:
if fuel["fuel"] <= LOW_FUEL_THRESHOLD and not fuel["blinking"]:
# OLD: if fuel["fuel"] <= LOW_FUEL_THRESHOLD and not fuel["blinking"]:
# NEW: Read from global resource instead of local dictionary
if Globals.settings.current_fuel <= LOW_FUEL_THRESHOLD and not fuel["blinking"]:
start_blinking(fuel)
elif fuel["fuel"] > LOW_FUEL_THRESHOLD and fuel["blinking"]:
# OLD: elif fuel["fuel"] > LOW_FUEL_THRESHOLD and fuel["blinking"]:
# NEW: Read from global resource instead of local dictionary
elif Globals.settings.current_fuel > LOW_FUEL_THRESHOLD and fuel["blinking"]:
stop_blinking(fuel)


Expand Down Expand Up @@ -435,29 +490,44 @@ func _toggle_label(param: Dictionary) -> void:

func _physics_process(_delta: float) -> void:
# Speed changes allowed only if fuel > 0
if Input.is_action_pressed("speed_up") and fuel["fuel"] > 0:
# OLD: if Input.is_action_pressed("speed_up") and fuel["fuel"] > 0:
# NEW: Check global resource fuel instead of local dictionary
if Input.is_action_pressed("speed_up") and Globals.settings.current_fuel > 0:
speed["speed"] += speed["acceleration"] * _delta
if Input.is_action_pressed("speed_down") and fuel["fuel"] > 0:

# OLD: if Input.is_action_pressed("speed_down") and fuel["fuel"] > 0:
# NEW: Check global resource fuel instead of local dictionary
if Input.is_action_pressed("speed_down") and Globals.settings.current_fuel > 0:
speed["speed"] -= speed["deceleration"] * _delta

# Clamp current_speed between MIN_SPEED and MAX_SPEED
if fuel["fuel"] == 0:
# OLD: if fuel["fuel"] == 0:
# NEW: Check global resource fuel instead of local dictionary
if Globals.settings.current_fuel == 0:
# No fuel left, airplane can't fly
speed["speed"] = clamp(speed["speed"], 0, speed["max"])
else:
speed["speed"] = clamp(speed["speed"], speed["min"], speed["max"])

# Left/Right movement
var lateral_input: float = Input.get_axis("move_left", "move_right")

# Left/Right movement, only allowed when fuel > 0 and the player is moving
if lateral_input and fuel["fuel"] > 0 and speed["speed"] > 0:
# OLD: if lateral_input and fuel["fuel"] > 0 and speed["speed"] > 0:
# NEW: Check global resource fuel instead of local dictionary
if lateral_input and Globals.settings.current_fuel > 0 and speed["speed"] > 0:
player.velocity.x = lateral_input * speed["lateral_speed"]
# Reset lateral velocity if no input
else:
player.velocity.x = 0.0

# Clamp player position within allowed ranged of coords
player.position.x = clamp(player.position.x, player_x_min, player_x_max)
player.position.y = clamp(player.position.y, player_y_min, player_y_max)

# Update UI
update_speed_bar()
check_speed_warning()

# Perform player movement
player.move_and_slide()
45 changes: 36 additions & 9 deletions test/gdunit4/test_difficulty.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,50 @@ func test_fuel_depletion_with_difficulty() -> void:
var original_difficulty: float = Globals.settings.difficulty

# Reset fuel before each sim for independent tests
player_inst.fuel["fuel"] = 100.0
# OLD: player_inst.fuel["fuel"] = 100.0
# NEW: Reset the global fuel resource instead of the local dictionary
Globals.settings.current_fuel = 100.0
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
Globals.settings.difficulty = 1.0
var normalized_speed: float = player_inst.speed["speed"] / player_inst.MAX_SPEED
var dep_1: float = player_inst.base_fuel_drain * normalized_speed * Globals.settings.difficulty

# OLD: var dep_1: float = player_inst.base_fuel_drain * normalized_speed * Globals.settings.difficulty
# NEW: Use the global base_consumption_rate instead of the removed local base_fuel_drain
var dep_1: float = Globals.settings.base_consumption_rate * normalized_speed * Globals.settings.difficulty

player_inst._on_fuel_timer_timeout()
assert_float(player_inst.fuel["fuel"]).is_equal_approx(100.0 - dep_1, 0.01) # Larger delta for precision

player_inst.fuel["fuel"] = 100.0
# OLD: assert_float(player_inst.fuel["fuel"]).is_equal_approx(100.0 - dep_1, 0.01) # Larger delta for precision
# NEW: Assert against the global fuel resource instead of the local dictionary
assert_float(Globals.settings.current_fuel).is_equal_approx(100.0 - dep_1, 0.01)

# OLD: player_inst.fuel["fuel"] = 100.0
# NEW: Reset the global fuel resource for the second test
Globals.settings.current_fuel = 100.0
Globals.settings.difficulty = 2.0
normalized_speed = player_inst.speed["speed"] / player_inst.MAX_SPEED # Re-derive
var dep_2: float = player_inst.base_fuel_drain * normalized_speed * Globals.settings.difficulty

# OLD: var dep_2: float = player_inst.base_fuel_drain * normalized_speed * Globals.settings.difficulty
# NEW: Use the global base_consumption_rate instead of the removed local base_fuel_drain
var dep_2: float = Globals.settings.base_consumption_rate * normalized_speed * Globals.settings.difficulty

player_inst._on_fuel_timer_timeout()
assert_float(player_inst.fuel["fuel"]).is_equal_approx(100.0 - dep_2, 0.01)

player_inst.fuel["fuel"] = 100.0
# OLD: assert_float(player_inst.fuel["fuel"]).is_equal_approx(100.0 - dep_2, 0.01)
# NEW: Assert against the global fuel resource
assert_float(Globals.settings.current_fuel).is_equal_approx(100.0 - dep_2, 0.01)

# OLD: player_inst.fuel["fuel"] = 100.0
# NEW: Reset the global fuel resource for the third test
Globals.settings.current_fuel = 100.0
Globals.settings.difficulty = 0.5
normalized_speed = player_inst.speed["speed"] / player_inst.MAX_SPEED
var dep_05: float = player_inst.base_fuel_drain * normalized_speed * Globals.settings.difficulty

# OLD: var dep_05: float = player_inst.base_fuel_drain * normalized_speed * Globals.settings.difficulty
# NEW: Use the global base_consumption_rate instead of the removed local base_fuel_drain
var dep_05: float = Globals.settings.base_consumption_rate * normalized_speed * Globals.settings.difficulty

player_inst._on_fuel_timer_timeout()
assert_float(player_inst.fuel["fuel"]).is_equal_approx(100.0 - dep_05, 0.01)

# OLD: assert_float(player_inst.fuel["fuel"]).is_equal_approx(100.0 - dep_05, 0.01)
# NEW: Assert against the global fuel resource
assert_float(Globals.settings.current_fuel).is_equal_approx(100.0 - dep_05, 0.01)
Loading
Loading