From b223d53824b5c396c2bf40cf120434abe2586267 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Thu, 5 Sep 2024 17:39:54 +0100 Subject: [PATCH] Use Context in mission loader --- project/code/TMV/Mission.cs | 21 +++++++++------------ project/code/TMV/TextureLoader.cs | 7 ++----- project/code/TMV/UI/MissionSelector.cs | 7 +++---- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/project/code/TMV/Mission.cs b/project/code/TMV/Mission.cs index f903bcd..5c0f1e5 100644 --- a/project/code/TMV/Mission.cs +++ b/project/code/TMV/Mission.cs @@ -1,5 +1,4 @@ using Godot; -using KeepersCompound.LGS; using KeepersCompound.LGS.Database; using KeepersCompound.LGS.Database.Chunks; using KeepersCompound.TMV.UI; @@ -41,18 +40,13 @@ public partial class Mission : Node3D string _campaignName; string _missionName; - ResourcePathManager _installPaths; DbFile _file; TextureLoader _textureLoader; - ModelLoader _modelLoader; List _materials; Vector2I _lmLayerMask; public override void _Ready() { - var extractPath = ProjectSettings.GlobalizePath($"user://extracted/tmp"); - _installPaths = new ResourcePathManager(extractPath); - _modelLoader = new ModelLoader(_installPaths); _materials = new List(); _lmLayerMask = new Vector2I(~0, ~0); @@ -60,12 +54,11 @@ public partial class Mission : Node3D lightmapToggler.Setup(this); var missionSelector = GetNode("%MissionSelector") as MissionSelector; - missionSelector.pathManager = _installPaths; missionSelector.MissionSelected += (string campaign, string mission) => { _campaignName = campaign; _missionName = mission; - FileName = _installPaths.GetMissionPath(campaign, mission); + FileName = Context.Instance.PathManager.GetMissionPath(campaign, mission); Build = true; }; } @@ -115,7 +108,7 @@ public partial class Mission : Node3D { ClearMap(); - _textureLoader = new TextureLoader(_installPaths, _campaignName); + _textureLoader = new TextureLoader(_campaignName); Timing.TimeStage("DbFile Parse", () => _file = new(FileName)); Timing.TimeStage("Register Textures", () => UseChunk("TXLIST", RegisterTextures)); Timing.TimeStage("Build WR", () => UseChunk("WREXT", BuildWrMeshes)); @@ -249,7 +242,10 @@ public partial class Mission : Node3D var rawRot = brush.angle; var rot = new Vector3(rawRot.Y, rawRot.Z, rawRot.X) * 360 / ushort.MaxValue; var scale = scaleProp == null ? Vector3.One : scaleProp.scale.ToGodotVec3(false); - var model = Timing.TimeStage("Get Models", () => { return _modelLoader.Load(_campaignName, modelName); }); + var model = Timing.TimeStage("Get Models", () => + { + return Context.Instance.ModelLoader.Load(_campaignName, modelName); + }); if (model != null) { model.Position = pos; @@ -264,15 +260,16 @@ public partial class Mission : Node3D return false; } + var pathManager = Context.Instance.PathManager; path = prop.value; if (path.StartsWith("fam", StringComparison.OrdinalIgnoreCase)) { - path = _installPaths.GetTexturePath(_campaignName, path); + path = pathManager.GetTexturePath(_campaignName, path); return path != null; } // gonna assume obj lol - path = _installPaths.GetObjectTexturePath(_campaignName, path); + path = pathManager.GetObjectTexturePath(_campaignName, path); return path != null; } diff --git a/project/code/TMV/TextureLoader.cs b/project/code/TMV/TextureLoader.cs index d41cf39..ffb9925 100644 --- a/project/code/TMV/TextureLoader.cs +++ b/project/code/TMV/TextureLoader.cs @@ -1,22 +1,19 @@ using System.Collections.Generic; using System.Linq; using Godot; -using KeepersCompound.LGS; namespace KeepersCompound.TMV; public partial class TextureLoader { - private readonly ResourcePathManager _pathManager; private readonly string _fmName; private readonly List _textureCache = new(); private readonly Dictionary _idMap = new(); private readonly Dictionary _idPathMap = new(); private readonly Dictionary _pathMap = new(); - public TextureLoader(ResourcePathManager pathManager, string fmName) + public TextureLoader(string fmName) { - _pathManager = pathManager; _fmName = fmName; LoadDefaultTexture(); } @@ -37,7 +34,7 @@ public partial class TextureLoader private bool Load(int id, string path) { var loaded = false; - string texPath = _pathManager.GetTexturePath(_fmName, path); + string texPath = Context.Instance.PathManager.GetTexturePath(_fmName, path); if (texPath != null) { diff --git a/project/code/TMV/UI/MissionSelector.cs b/project/code/TMV/UI/MissionSelector.cs index ddd4e83..dcca2b3 100644 --- a/project/code/TMV/UI/MissionSelector.cs +++ b/project/code/TMV/UI/MissionSelector.cs @@ -1,5 +1,4 @@ using Godot; -using KeepersCompound.LGS; namespace KeepersCompound.TMV.UI; @@ -8,8 +7,6 @@ public partial class MissionSelector : Control public event MissionSelectedEventHandler MissionSelected; public delegate void MissionSelectedEventHandler(string campaign, string mission); - public ResourcePathManager pathManager; - private FileDialog _FolderSelect; private LineEdit _FolderPath; private Button _BrowseButton; @@ -52,7 +49,7 @@ public partial class MissionSelector : Control private void SetInstallPath(string path) { _FolderPath.Text = path; - if (pathManager.Init(path)) + if (Context.Instance.PathManager.Init(path)) { BuildCampaignList(); } @@ -64,6 +61,7 @@ public partial class MissionSelector : Control _Missions.Clear(); _LoadButton.Disabled = true; + var pathManager = Context.Instance.PathManager; _Campaigns.AddItem("Original Missions"); foreach (var campaign in pathManager.GetCampaignNames()) { @@ -76,6 +74,7 @@ public partial class MissionSelector : Control _Missions.Clear(); _LoadButton.Disabled = true; + var pathManager = Context.Instance.PathManager; var campaignName = _Campaigns.GetItemText((int)idx); var missionNames = pathManager.GetMissionNames(idx == 0 ? null : campaignName); foreach (var mission in missionNames)