using Godot; using System; public partial class Day : Node2D { [Export] public string NextScene; private enum State { Default, TransitionIn, TransitionOut } private State _state = State.TransitionIn; private Player _player; private ColorRect _colorRect; private AudioStreamPlayer _music; private Interactable _endDay; private double _transitionTimeout = 0; // Called when the node enters the scene tree for the first time. public override void _Ready() { _player = (Player)FindChild("Player"); _colorRect = _player.CRect; _music = (AudioStreamPlayer)FindChild("Music"); _endDay = (Interactable)FindChild("EndDay"); _colorRect.Color = new Color(0, 0, 0, 1f); _music.VolumeDb = -40; _player.CurrentState = Player.State.Wait; _endDay.Disable(); } public void AssignEndDay(Player player) { player.InteractableObjects.Add(_endDay); } public void RemoveEndDay(Player player) { player.InteractableObjects.Remove(_endDay); } public void ChangeDay() { _state = State.TransitionOut; } public void EnableEndDay() { _endDay.Enable(); } // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { if (_state == State.TransitionIn) { if (_transitionTimeout <= 2) { _transitionTimeout += delta; _music.VolumeDb = Mathf.Lerp(-40, 0, (float)_transitionTimeout/2); _colorRect.Color = new Color(0, 0, 0, Mathf.Lerp(1, 0, (float)_transitionTimeout/2)); } else { _state = State.Default; _player.CurrentState = Player.State.Normal; _transitionTimeout = 0; } } if (_state == State.TransitionOut) { _player.CurrentState = Player.State.Wait; if (_transitionTimeout <= 2) { _transitionTimeout += delta; _music.VolumeDb = Mathf.Lerp(0, -40, (float)_transitionTimeout/2); _colorRect.Color = new Color(0, 0, 0, Mathf.Lerp(0, 1, (float)_transitionTimeout/2)); } else { GetNode("/root/SceneManager").SwitchScene(NextScene); } } } }