Add CampaignName to Context

This commit is contained in:
Jarrod Doyle 2024-09-08 13:24:10 +01:00
parent 3d9556b1e9
commit 63591c228b
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
4 changed files with 14 additions and 10 deletions

View File

@ -9,12 +9,14 @@ public partial class Context : Node
public ResourcePathManager PathManager { get; private set; } public ResourcePathManager PathManager { get; private set; }
public ModelLoader ModelLoader { get; private set; } public ModelLoader ModelLoader { get; private set; }
public string CampaignName { get; set; }
public override void _Ready() public override void _Ready()
{ {
var extractPath = ProjectSettings.GlobalizePath($"user://extracted/tmp"); var extractPath = ProjectSettings.GlobalizePath($"user://extracted/tmp");
PathManager = new ResourcePathManager(extractPath); PathManager = new ResourcePathManager(extractPath);
ModelLoader = new ModelLoader(); ModelLoader = new ModelLoader();
CampaignName = "";
Instance = this; Instance = this;
} }

View File

@ -41,7 +41,6 @@ public partial class Mission : Node3D
public bool Dump = false; public bool Dump = false;
public int LightmapLayers = 33; public int LightmapLayers = 33;
string _campaignName;
string _missionName; string _missionName;
DbFile _file; DbFile _file;
TextureLoader _textureLoader; TextureLoader _textureLoader;
@ -59,10 +58,10 @@ public partial class Mission : Node3D
var resourceSelector = GetNode<Control>("%ResourceSelector") as ResourceSelector; var resourceSelector = GetNode<Control>("%ResourceSelector") as ResourceSelector;
resourceSelector.ResourceSelected += (string campaign, string mission) => resourceSelector.ResourceSelected += (string campaign, string mission) =>
{ {
_campaignName = campaign; var context = Context.Instance;
context.CampaignName = campaign;
_missionName = mission; _missionName = mission;
var pathManager = Context.Instance.PathManager; var (newCampaign, missionPath) = context.PathManager.GetResourcePath(ResourceType.Mission, campaign, mission);
var (newCampaign, missionPath) = pathManager.GetResourcePath(ResourceType.Mission, campaign, mission);
if (newCampaign != campaign) if (newCampaign != campaign)
{ {
GD.Print($"Didn't find campaign mission: ({campaign}, {mission})"); GD.Print($"Didn't find campaign mission: ({campaign}, {mission})");
@ -121,7 +120,7 @@ public partial class Mission : Node3D
{ {
ClearMap(); ClearMap();
_textureLoader = new TextureLoader(_campaignName); _textureLoader = new TextureLoader(Context.Instance.CampaignName);
Timing.TimeStage("DbFile Parse", () => _file = new(FileName)); Timing.TimeStage("DbFile Parse", () => _file = new(FileName));
Timing.TimeStage("Register Textures", () => UseChunk<TxList>("TXLIST", RegisterTextures)); Timing.TimeStage("Register Textures", () => UseChunk<TxList>("TXLIST", RegisterTextures));
Timing.TimeStage("Build WR", () => UseChunk<WorldRep>("WREXT", BuildWrMeshes)); Timing.TimeStage("Build WR", () => UseChunk<WorldRep>("WREXT", BuildWrMeshes));
@ -268,7 +267,7 @@ public partial class Mission : Node3D
var scale = scaleProp == null ? Vector3.One : scaleProp.value.ToGodotVec3(false); var scale = scaleProp == null ? Vector3.One : scaleProp.value.ToGodotVec3(false);
var model = Timing.TimeStage("Get Models", () => var model = Timing.TimeStage("Get Models", () =>
{ {
return Context.Instance.ModelLoader.Load(_campaignName, modelName); return Context.Instance.ModelLoader.Load(modelName);
}); });
if (model != null) if (model != null)
{ {
@ -287,17 +286,18 @@ public partial class Mission : Node3D
path = prop.value; path = prop.value;
var pathManager = Context.Instance.PathManager; var pathManager = Context.Instance.PathManager;
var campaign = Context.Instance.CampaignName;
if (path.StartsWith("fam", StringComparison.OrdinalIgnoreCase)) if (path.StartsWith("fam", StringComparison.OrdinalIgnoreCase))
{ {
var resType = ResourceType.Texture; var resType = ResourceType.Texture;
path = pathManager.GetResourcePath(resType, _campaignName, prop.value).Item2; path = pathManager.GetResourcePath(resType, campaign, prop.value).Item2;
} }
else else
{ {
var resType = ResourceType.ObjectTexture; var resType = ResourceType.ObjectTexture;
var convertedValue = ResourcePathManager.ConvertSeparator(prop.value); var convertedValue = ResourcePathManager.ConvertSeparator(prop.value);
var resName = Path.GetFileNameWithoutExtension(convertedValue); var resName = Path.GetFileNameWithoutExtension(convertedValue);
path = pathManager.GetResourcePath(resType, _campaignName, resName).Item2; path = pathManager.GetResourcePath(resType, campaign, resName).Item2;
} }
return path != null; return path != null;

View File

@ -18,7 +18,8 @@ public partial class Model : Node3D
node.QueueFree(); node.QueueFree();
} }
var model = Context.Instance.ModelLoader.Load(campaignName, modelPath); Context.Instance.CampaignName = campaignName;
var model = Context.Instance.ModelLoader.Load(modelPath);
AddChild(model); AddChild(model);
} }
} }

View File

@ -9,8 +9,9 @@ public class ModelLoader
{ {
private readonly Dictionary<(string, string), MeshInstance3D> _cache = new(); private readonly Dictionary<(string, string), MeshInstance3D> _cache = new();
public MeshInstance3D Load(string campaignName, string modelName, bool forceLoad = false) public MeshInstance3D Load(string modelName, bool forceLoad = false)
{ {
var campaignName = Context.Instance.CampaignName;
campaignName ??= ""; campaignName ??= "";
if (!forceLoad) if (!forceLoad)