cirnogodot/Scripts/Activables/LevelTeleporter.cs

49 lines
1.3 KiB
C#
Raw Normal View History

2025-02-21 22:48:12 +01:00
using System;
using System.Collections;
using System.Threading.Tasks;
2025-03-02 11:58:30 +01:00
using Cirno.Scripts.Components.FSM;
2025-04-02 17:42:55 +02:00
using Cirno.Scripts.Resources;
2025-02-21 22:48:12 +01:00
using Godot;
namespace Cirno.Scripts.Activables;
2025-03-24 16:56:35 +01:00
public partial class LevelTeleporter : Teleporter
2025-02-21 22:48:12 +01:00
{
2025-03-24 16:56:35 +01:00
[Export] public string LevelPath { get; private set; }
2025-04-02 17:42:55 +02:00
[Export] public MapResource Map { get; private set; }
2025-03-24 16:56:35 +01:00
[Export] public bool SaveInventory { get; private set; }
2025-02-21 22:48:12 +01:00
2025-03-05 10:55:14 +01:00
protected override async Task Teleport(IStateMachine<PlayerState, CharacterBody2D> player)
2025-02-21 22:48:12 +01:00
{
2025-04-02 17:42:55 +02:00
if (string.IsNullOrWhiteSpace(LevelPath) && Map is null) return;
2025-03-02 11:58:30 +01:00
//player.RequestMovementDisable(true);
2025-03-05 10:55:14 +01:00
player.SetState(PlayerState.Cutscene);
2025-02-21 22:48:12 +01:00
2025-03-05 10:55:14 +01:00
await TweenPlayer(player.MainObject);
2025-02-21 22:48:12 +01:00
_particles.Emitting = true;
2025-03-24 16:56:35 +01:00
2025-03-02 11:58:30 +01:00
//await player.Teleport();
2025-03-24 22:22:07 +01:00
player.SetState(PlayerState.Teleporting);
2025-03-02 11:58:30 +01:00
await Task.Delay((int)(0.6f * 1000));
2025-02-22 14:45:46 +01:00
2025-02-21 22:48:12 +01:00
await Task.Delay((int)(TeleportAnimationLength * 1000));
2025-03-24 16:56:35 +01:00
if (SaveInventory)
{
// Save inventory
GlobalState.Instance.SessionSettings.Items = InventoryManager.Instance.Save();
}
2025-04-02 17:42:55 +02:00
if (!string.IsNullOrWhiteSpace(LevelPath))
{
GlobalState.Instance.GotoScene(LevelPath);
}
else
{
GlobalState.Instance.GotoScene(Map);
}
2025-02-21 22:48:12 +01:00
}
}