Level Teleporters

This commit is contained in:
Marco 2025-09-10 16:16:05 +02:00
commit 7a8bb4311b
26 changed files with 581 additions and 410 deletions

View file

@ -0,0 +1,48 @@
using System.Threading.Tasks;
using Cirno.Scripts.Components.FSM._3DPlayer;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Activables._3D;
[Tool]
public partial class LevelTeleporter3D : Teleporter3D
{
[Export] public bool SaveInventory { get; set; }
public override void _func_godot_apply_properties(Dictionary<string, Variant> props)
{
// TargetGroup = props["target"].AsString();
//
// TargetName = props["targetname"].AsString();
IsEnabled = props["enabled"].AsBool();
}
protected override async Task Teleport(IsoPlayerStateMachine player)
{
player.SetState(PlayerState.Cutscene);
await TweenPlayer(player.MainObject);
PlayTeleportStartSound();
FireParticles();
player.SetState(PlayerState.Teleporting);
await Task.Delay((int)(0.6f * 1000));
await Task.Delay((int)(TeleportAnimationLength * 1000));
if (SaveInventory)
{
// Save inventory
GlobalState.Instance.SessionSettings.Items = InventoryManager.Instance.Save();
}
else
{
GlobalState.Instance.SessionSettings.EquippedWeaponId = string.Empty;
}
var nextMap = GlobalState.Instance.MapsDatabase.FindNextMap(GlobalState.Instance.SessionSettings.MapId);
GlobalState.Instance.GotoScene(nextMap);
}
}

View file

@ -0,0 +1 @@
uid://c4e21ceehvqap

View file

@ -35,7 +35,7 @@ public partial class Teleporter3D : StaticBody3D, IActivable, ITargetable
[Export] public StringName DefaultAnimationName { get; private set; } = "Default";
public void _func_godot_apply_properties(Dictionary<string, Variant> props)
public virtual void _func_godot_apply_properties(Dictionary<string, Variant> props)
{
TargetGroup = props["target"].AsString();

View file

@ -11,7 +11,7 @@ namespace Cirno.Scripts.Activables;
public partial class LevelTeleporter : Teleporter
{
[Export] public string LevelPath { get; set; }
[Export] public MapResource Map { get; private set; }
[Export] public MapResource Map { get; private set; }
[Export] public bool SaveInventory { get; set; }
@ -47,13 +47,12 @@ public partial class LevelTeleporter : Teleporter
{
GlobalState.Instance.SessionSettings.LevelNumber += 1;
}
GlobalState.Instance.GotoScene(LevelPath);
}
else
{
GlobalState.Instance.GotoScene(Map);
}
}
}

View file

@ -68,7 +68,8 @@ public partial class GameController : Node
}
else
{
//GlobalState.Session.LevelNumber = MapResource.LevelId;
GlobalState.Session.LevelNumber = MapResource.LevelId;
GlobalState.Session.MapId = MapResource.MapId;
}

View file

@ -28,6 +28,8 @@ public partial class GlobalState : Node
private readonly StringName _mapsDatabaseResource = "uid://blf2ii0j3fqil";
private MapsDatabase _mapsDatabase;
public MapsDatabase MapsDatabase => _mapsDatabase;
private Texture2D _menuMouseTexture;
private Image _menuMouseImage;
@ -35,7 +37,7 @@ public partial class GlobalState : Node
private Image _reticuleMouseImage;
public bool UseMenuCursor { get; set; } = true;
public override void _Ready()
{
Instance = this;
@ -52,7 +54,7 @@ public partial class GlobalState : Node
_menuMouseTexture = ResourceLoader.Load<Texture2D>(_menuMouseTexturePath);
_menuMouseImage = _menuMouseTexture.GetImage();
_reticuleMouseTexture = ResourceLoader.Load<Texture2D>(_reticuleMouseTexturePath);
_reticuleMouseImage = _reticuleMouseTexture.GetImage();
@ -222,6 +224,7 @@ public partial class GlobalState : Node
{
{ "Items", items },
{ "Level", SessionSettings.LevelNumber },
{ "MapId", SessionSettings.MapId },
{ "Difficulty", (int)SessionSettings.Difficulty }
};
@ -259,9 +262,10 @@ public partial class GlobalState : Node
DifficultyLevel difficulty = (DifficultyLevel)deserializedSaveData["Difficulty"].AsInt32();
int levelNumber = (int)deserializedSaveData["Level"];
int levelNumber = deserializedSaveData["Level"].AsInt32();
StringName mapId = deserializedSaveData["MapId"].AsStringName();
var levelData = _mapsDatabase.Maps.FirstOrDefault(x => x.LevelId == levelNumber);
var levelData = _mapsDatabase.FindMap(mapId);
if (levelData is null)
{
return false;
@ -269,6 +273,7 @@ public partial class GlobalState : Node
this.SessionSettings.NewSession();
SessionSettings.LevelNumber = levelNumber;
SessionSettings.MapId = mapId;
SessionSettings.Items = items;
SessionSettings.Difficulty = difficulty;
@ -283,9 +288,8 @@ public partial class GlobalState : Node
Vector2I size;
if (useMenuCursor)
{
scaled = (Image)_menuMouseImage.Duplicate();
size = (Vector2I)(scale * _menuMouseTexture.GetSize());
scaled = (Image)_menuMouseImage.Duplicate();
size = (Vector2I)(scale * _menuMouseTexture.GetSize());
}
else
{
@ -295,8 +299,9 @@ public partial class GlobalState : Node
scaled.Resize(size.X, size.Y, Image.Interpolation.Nearest);
Input.SetCustomMouseCursor(scaled, Input.CursorShape.Arrow, useMenuCursor ? Vector2.Zero : new Vector2(size.X / 2,size.Y / 2));
Input.SetCustomMouseCursor(scaled, Input.CursorShape.Arrow,
useMenuCursor ? Vector2.Zero : new Vector2(size.X / 2, size.Y / 2));
//DisplayServer.CursorSetCustomImage(scaled);
}

View file

@ -6,9 +6,19 @@ namespace Cirno.Scripts.Resources;
public partial class MapResource : Resource
{
[Export] public int LevelId { get; set; }
[Export] public StringName MapId { get; set; }
[Export] public StringName MapName { get; set; }
[Export] public StringName MapDescription { get; set; }
[Export] public StringName ScenePath { get; set; }
[Export] public StringName NextMap { get; set; }
[Export] public bool WeaponsAllowed { get; set; }
[Export] public MapStartDataResource StartData { get; set; }
[Export] public MapType MapType { get; set; }
}
public enum MapType
{
Map2D,
Map3D
}

View file

@ -1,4 +1,5 @@
using Godot;
using System.Linq;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Resources;
@ -7,4 +8,14 @@ namespace Cirno.Scripts.Resources;
public partial class MapsDatabase : Resource
{
[Export] public Array<MapResource> Maps { get; set; }
public MapResource FindMap(StringName mapId)
{
return Maps.FirstOrDefault(x => x.MapId is not null && x.MapId.Equals(mapId));
}
public MapResource FindNextMap(StringName mapId)
{
return FindMap(FindMap(mapId).NextMap);
}
}

View file

@ -0,0 +1,27 @@
using Cirno.Scripts.Resources;
using Godot;
namespace Cirno.Scripts.Utils;
public partial class GlobalMapDatabase : Node
{
public static GlobalMapDatabase Instance { get; private set; }
[Export] public MapsDatabase Maps { get; private set; }
public MapResource FindMap(StringName mapId)
{
return Maps.FindMap(mapId);
}
public MapResource FindNextMap(StringName mapId)
{
return Maps.FindNextMap(mapId); //FindMap(Maps.FindMap(mapId).NextMap);
}
public override void _Ready()
{
Instance = this;
}
}

View file

@ -0,0 +1 @@
uid://cegjwc0h7qenj

View file

@ -17,6 +17,7 @@ public class SessionSettings
public Godot.Collections.Dictionary<string, int> Items { get; set; } = new();
public int LevelNumber { get; set; } = 0;
public StringName MapId { get; set; }
public float Health { get; set; }
public float Shield { get; set; }