ajout d'une animation de recharge et réparation du crash au chargement de chunk

This commit is contained in:
2026-01-16 12:28:36 +01:00
parent 74d2d0de3a
commit ff4feacea3
25 changed files with 431 additions and 236 deletions

View File

@@ -0,0 +1,113 @@
@tool
extends Control
class_name PassDay
const BLUR_STRENGTH = 10
const BLUR_MIX_PERCENTAGE = 0.8
const TIME_BY_ENERGY = 0.7
const TIME_MARGIN = 0.5
signal max_energy_reached()
signal animation_appeared
signal animation_disappeared
@export_tool_button("Pass Day", "Callable") var pass_day_action = pass_day_animation
@export_tool_button("Appear", "Callable") var appear_action = appear
@export var from_energy = 0
@export var max_energy = 3
var current_energy = 0
var time_since_recharging = 0.
var recharging = false
var is_animation_appeared := false
var is_animation_disappeared := false
func _ready():
hide()
setup_energy_values()
func _process(delta):
if recharging:
time_since_recharging += delta
var new_current_energy = from_energy + roundi(time_since_recharging/TIME_BY_ENERGY)
if new_current_energy > max_energy:
max_energy_reached.emit()
elif (new_current_energy != current_energy):
%EnergyPassDayInfo.update(new_current_energy, max_energy, true)
print("Call energy info with %d/%d" % [new_current_energy, max_energy])
current_energy = new_current_energy
func setup_energy_values():
if not Engine.is_editor_hint():
from_energy = GameInfo.game_data.player_data.energy
max_energy = GameInfo.game_data.player_data.max_energy
current_energy = from_energy
func pass_day_animation():
setup_energy_values()
is_animation_appeared=false
is_animation_disappeared=false
%EnergyPassDayInfo.update(from_energy, max_energy, false)
print("Call energy info with %d/%d" % [from_energy, max_energy])
await appear()
is_animation_appeared = true
animation_appeared.emit()
await get_tree().create_timer(TIME_MARGIN).timeout
recharging = true
time_since_recharging = 0.
await max_energy_reached
await get_tree().create_timer(TIME_MARGIN).timeout
await disappear()
is_animation_disappeared=true
animation_disappeared.emit()
recharging = false
func appear():
show()
add_tween(
"blur_mix_percentage",
%Blur,
BLUR_MIX_PERCENTAGE,
0.5
)
await add_tween(
"blur_strength",
%Blur,
BLUR_STRENGTH,
0.5
).finished
await %EnergyPassDayInfo.appear()
func disappear():
await %EnergyPassDayInfo.disappear()
add_tween(
"blur_mix_percentage",
%Blur,
0.0,
0.5
)
await add_tween(
"blur_strength",
%Blur,
0.1,
0.5
).finished
hide()
func add_tween(
property : String,
target: Node,
value : Variant,
seconds: float = 1.,
transition_type: Tween.TransitionType = Tween.TransitionType.TRANS_LINEAR
) -> Tween:
var tween : Tween = get_tree().create_tween()
tween.set_trans(transition_type)
tween.tween_property(target, property, value, seconds)
tween.set_pause_mode(Tween.TWEEN_PAUSE_PROCESS)
return tween