From 7a8bb4311b64c7e2b654ca496ee6cc4b8c03f435 Mon Sep 17 00:00:00 2001 From: Marco Date: Wed, 10 Sep 2025 16:16:05 +0200 Subject: [PATCH] Level Teleporters --- 3D/MapModels/actor_level_teleporter.glb | Bin 0 -> 4832 bytes 3D/MapScenes/Factory_003.tscn | 775 +++++++++--------- 3D/Maps/Factory3.map | 18 +- 3D/Scenes/Props/Level_Teleporter_3D.tscn | 31 + .../point/actors/Actor_Level_Teleporter.tres | 26 + .../EntityScripts/Triggers/TriggerArea.cs | 3 +- 3D/TrenchBroom/fgd_point.tres | 5 +- Resources/Maps/3D/IsoMapTest2.tres | 3 + Resources/Maps/3D/IsoMapTest3.tres | 3 + Resources/Maps/3D/MapsDatabase_3D.tres | 11 + Resources/Maps/3D/Tutorial_3D.tres | 3 + Resources/Maps/Briefing_1.tres | 1 + Resources/Maps/MapsDatabase.tres | 7 +- Resources/Maps/Tutorial.tres | 3 +- Scenes/Utils/GlobalMapsDatabase.tscn | 8 + Scripts/Activables/3D/LevelTeleporter3D.cs | 48 ++ .../Activables/3D/LevelTeleporter3D.cs.uid | 1 + Scripts/Activables/3D/Teleporter3D.cs | 2 +- Scripts/Activables/LevelTeleporter.cs | 5 +- Scripts/GameController.cs | 3 +- Scripts/GlobalState.cs | 23 +- Scripts/Resources/MapResource.cs | 10 + Scripts/Resources/MapsDatabase.cs | 13 +- Scripts/Utils/GlobalMapDatabase.cs | 27 + Scripts/Utils/GlobalMapDatabase.cs.uid | 1 + Scripts/Utils/SessionSettings.cs | 1 + 26 files changed, 601 insertions(+), 430 deletions(-) create mode 100644 3D/MapModels/actor_level_teleporter.glb create mode 100644 3D/Scenes/Props/Level_Teleporter_3D.tscn create mode 100644 3D/TrenchBroom/EntityDefinitions/point/actors/Actor_Level_Teleporter.tres create mode 100644 Resources/Maps/3D/MapsDatabase_3D.tres create mode 100644 Scenes/Utils/GlobalMapsDatabase.tscn create mode 100644 Scripts/Activables/3D/LevelTeleporter3D.cs create mode 100644 Scripts/Activables/3D/LevelTeleporter3D.cs.uid create mode 100644 Scripts/Utils/GlobalMapDatabase.cs create mode 100644 Scripts/Utils/GlobalMapDatabase.cs.uid diff --git a/3D/MapModels/actor_level_teleporter.glb b/3D/MapModels/actor_level_teleporter.glb new file mode 100644 index 0000000000000000000000000000000000000000..12b4e2c202c794e5dc204ed97f82548362c1ffc8 GIT binary patch literal 4832 zcmbVO4R9036+UBQ%wO$53Ta4#avgpOin#wDQ7jv5Yy*}ZOL!mzoRf5xE}V4YbOKz( z*pN&c2qiSohPDApThdNpAWd6-N{U@bQifzg+X(~+0h37xv@oPVO2C8Fw|9~)Z~}5} z=5F`xzW4UqZ{K@+LDf6GABJHa!!Rs57{g|GYTOB2^84jjOw(hyb6x`X#Ty%Cy!8<9+IV4k)TLH zq)EU8qoVl;0>O&}PufAX2Pd)vbjXe*7?S4*hG95{B<+u)DNFaRpqXBvscb+s@Dwl597hOZ-+899hb+R0 zG5}d*1Occ<`~ulLouZduy2%AvVU|JcQ#4O-1j}&u#76a^69TSxK$?KffTSTdt$?KH zjFW}M?@EJbTIsCPI=mT_q*zRb$WGuvIU?(lq3O62uh0UTVJnXWm56Lx%s5zw?k62# zEuuNJ#zw`jNNNco$fC^oC=ud?AOZqIGzu&$69JYHNm}p=97B_SI)K~p#j+k#G)N7c zauBe^jFihvK{Ne)O@=&6js%Smq?;gsE(~}KT?s%kk`P^nqz4gVnh`mwCuMpW(*kgZ zjB6Sj%`Nu!2IOVyt=l;5jpG5!*TqJPDdV&^k%P*U=?ylXEwnU{v@a5h!0p!bU1;Kv zawbhAMKLHatg@IopNvC+aOcpxyws2*=vYA|f!9=5HAF*AF~uKih=n9nITN_qNqNwq zYQhK;kd(l2BF{jo5FE)vE)gWp@`6=W1zw^mhTA=BUA&Uo~N(oCrImJW9Wdq2< zN?5k;8B1wWG!it^GAtRg4ryjtNoq7CO^X{^VKGBEgO=mD*iex9t=g`rbP7m zq?kNSQ#F0M!BsPg zudo~orAUkFN?0+J#VJu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lB+Z2cjph z)jhNAW^}T;ZsywUvls2Ys_O@pw~yR7IksZr%1UhYCvP5I`NBtMC;fJ_>$^E`B&oVZ z3tDcz{Q188f~(a9wgV4G>pCay2uwKoqhkZQZk?>HD5FWA zeeS7&Xz|ng_HI_+8GB*tx#qdpA^oqX<0qWI_(8!cPeRlHyi)tnw!*-mH!HC} j6&H0jm*l 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); + } +} \ No newline at end of file diff --git a/Scripts/Activables/3D/LevelTeleporter3D.cs.uid b/Scripts/Activables/3D/LevelTeleporter3D.cs.uid new file mode 100644 index 00000000..e3cb41de --- /dev/null +++ b/Scripts/Activables/3D/LevelTeleporter3D.cs.uid @@ -0,0 +1 @@ +uid://c4e21ceehvqap diff --git a/Scripts/Activables/3D/Teleporter3D.cs b/Scripts/Activables/3D/Teleporter3D.cs index 5c062209..f8807ffc 100644 --- a/Scripts/Activables/3D/Teleporter3D.cs +++ b/Scripts/Activables/3D/Teleporter3D.cs @@ -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 props) + public virtual void _func_godot_apply_properties(Dictionary props) { TargetGroup = props["target"].AsString(); diff --git a/Scripts/Activables/LevelTeleporter.cs b/Scripts/Activables/LevelTeleporter.cs index 3e78ab90..bc736598 100644 --- a/Scripts/Activables/LevelTeleporter.cs +++ b/Scripts/Activables/LevelTeleporter.cs @@ -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); } - } } \ No newline at end of file diff --git a/Scripts/GameController.cs b/Scripts/GameController.cs index 53f51c0c..4395ed21 100644 --- a/Scripts/GameController.cs +++ b/Scripts/GameController.cs @@ -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; } diff --git a/Scripts/GlobalState.cs b/Scripts/GlobalState.cs index c5935d31..476532f9 100644 --- a/Scripts/GlobalState.cs +++ b/Scripts/GlobalState.cs @@ -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(_menuMouseTexturePath); _menuMouseImage = _menuMouseTexture.GetImage(); - + _reticuleMouseTexture = ResourceLoader.Load(_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); } diff --git a/Scripts/Resources/MapResource.cs b/Scripts/Resources/MapResource.cs index 3397dac2..4b4bbee5 100644 --- a/Scripts/Resources/MapResource.cs +++ b/Scripts/Resources/MapResource.cs @@ -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 } \ No newline at end of file diff --git a/Scripts/Resources/MapsDatabase.cs b/Scripts/Resources/MapsDatabase.cs index 23c0477d..4c168b74 100644 --- a/Scripts/Resources/MapsDatabase.cs +++ b/Scripts/Resources/MapsDatabase.cs @@ -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 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); + } } \ No newline at end of file diff --git a/Scripts/Utils/GlobalMapDatabase.cs b/Scripts/Utils/GlobalMapDatabase.cs new file mode 100644 index 00000000..37bc1a01 --- /dev/null +++ b/Scripts/Utils/GlobalMapDatabase.cs @@ -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; + } +} \ No newline at end of file diff --git a/Scripts/Utils/GlobalMapDatabase.cs.uid b/Scripts/Utils/GlobalMapDatabase.cs.uid new file mode 100644 index 00000000..908ce510 --- /dev/null +++ b/Scripts/Utils/GlobalMapDatabase.cs.uid @@ -0,0 +1 @@ +uid://cegjwc0h7qenj diff --git a/Scripts/Utils/SessionSettings.cs b/Scripts/Utils/SessionSettings.cs index 31407c75..9a3bb7a9 100644 --- a/Scripts/Utils/SessionSettings.cs +++ b/Scripts/Utils/SessionSettings.cs @@ -17,6 +17,7 @@ public class SessionSettings public Godot.Collections.Dictionary 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; }