Use Context in mission loader

This commit is contained in:
Jarrod Doyle 2024-09-05 17:39:54 +01:00
parent b89a4d6154
commit b223d53824
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
3 changed files with 14 additions and 21 deletions

View File

@ -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<ShaderMaterial> _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<ShaderMaterial>();
_lmLayerMask = new Vector2I(~0, ~0);
@ -60,12 +54,11 @@ public partial class Mission : Node3D
lightmapToggler.Setup(this);
var missionSelector = GetNode<Control>("%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>("TXLIST", RegisterTextures));
Timing.TimeStage("Build WR", () => UseChunk<WorldRep>("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;
}

View File

@ -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<ImageTexture> _textureCache = new();
private readonly Dictionary<int, int> _idMap = new();
private readonly Dictionary<int, string> _idPathMap = new();
private readonly Dictionary<string, int> _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)
{

View File

@ -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)