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 ModelLoader ModelLoader { get; private set; }
public string CampaignName { get; set; }
public override void _Ready()
{
var extractPath = ProjectSettings.GlobalizePath($"user://extracted/tmp");
PathManager = new ResourcePathManager(extractPath);
ModelLoader = new ModelLoader();
CampaignName = "";
Instance = this;
}

View File

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

View File

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

View File

@ -9,8 +9,9 @@ public class ModelLoader
{
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 ??= "";
if (!forceLoad)