Compare commits
	
		
			No commits in common. "655a188a697036d103c9b10708bf69df433d5932" and "cb2f016455d07e508fd23a8235ec55013b28ecdf" have entirely different histories.
		
	
	
		
			655a188a69
			...
			cb2f016455
		
	
		| 
						 | 
				
			
			@ -5,7 +5,7 @@ using System.Linq;
 | 
			
		|||
 | 
			
		||||
namespace KeepersCompound.LGS;
 | 
			
		||||
 | 
			
		||||
// TODO: Merge the two versions of GetXXX and handle null campaign string as OM
 | 
			
		||||
// TODO: Support FMs resource paths!
 | 
			
		||||
public class ResourcePathManager
 | 
			
		||||
{
 | 
			
		||||
    private record CampaignResources
 | 
			
		||||
| 
						 | 
				
			
			@ -84,81 +84,51 @@ public class ResourcePathManager
 | 
			
		|||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<string> GetCampaignNames()
 | 
			
		||||
    public string GetMissionPath(string missionName)
 | 
			
		||||
    {
 | 
			
		||||
        if (!_initialised) return null;
 | 
			
		||||
 | 
			
		||||
        var names = new List<string>(_fmResources.Keys);
 | 
			
		||||
        names.Sort();
 | 
			
		||||
        return names;
 | 
			
		||||
        if (_omResources.missionPathMap.TryGetValue(missionName, out var path))
 | 
			
		||||
        {
 | 
			
		||||
            return path;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public string GetMissionPath(string campaignName, string missionName)
 | 
			
		||||
    {
 | 
			
		||||
        if (!_initialised) return null;
 | 
			
		||||
 | 
			
		||||
        if (campaignName == null || campaignName == "")
 | 
			
		||||
        if (_fmResources.TryGetValue(campaignName, out var campaign) &&
 | 
			
		||||
            campaign.missionPathMap.TryGetValue(missionName, out var path))
 | 
			
		||||
        {
 | 
			
		||||
            if (_omResources.missionPathMap.TryGetValue(missionName, out var omPath))
 | 
			
		||||
            {
 | 
			
		||||
                return omPath;
 | 
			
		||||
            return path;
 | 
			
		||||
        }
 | 
			
		||||
        }
 | 
			
		||||
        else if (
 | 
			
		||||
            _fmResources.TryGetValue(campaignName, out var campaign) &&
 | 
			
		||||
            campaign.missionPathMap.TryGetValue(missionName, out var fmPath))
 | 
			
		||||
        {
 | 
			
		||||
            return fmPath;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<string> GetMissionNames(string campaignName)
 | 
			
		||||
    public string GetTexturePath(string textureName)
 | 
			
		||||
    {
 | 
			
		||||
        if (!_initialised) return null;
 | 
			
		||||
 | 
			
		||||
        if (campaignName == null || campaignName == "")
 | 
			
		||||
        textureName = textureName.ToLower();
 | 
			
		||||
        if (_omResources.texturePathMap.TryGetValue(textureName, out var path))
 | 
			
		||||
        {
 | 
			
		||||
            var names = new List<string>(_omResources.missionPathMap.Keys);
 | 
			
		||||
            names.Sort();
 | 
			
		||||
            return names;
 | 
			
		||||
        }
 | 
			
		||||
        else if (_fmResources.TryGetValue(campaignName, out var campaign))
 | 
			
		||||
        {
 | 
			
		||||
            var names = new List<string>(campaign.missionPathMap.Keys);
 | 
			
		||||
            names.Sort();
 | 
			
		||||
            return names;
 | 
			
		||||
            return path;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // TODO: OMs fail to find a path, but FMs using OM textures do  find them
 | 
			
		||||
    // The OMs still fail even if I put them in a folder with FMs that work=??
 | 
			
		||||
    public string GetTexturePath(string campaignName, string textureName)
 | 
			
		||||
    {
 | 
			
		||||
        if (!_initialised) return null;
 | 
			
		||||
 | 
			
		||||
        textureName = textureName.ToLower();
 | 
			
		||||
        if (campaignName == null || campaignName == "")
 | 
			
		||||
        {
 | 
			
		||||
            if (_omResources.texturePathMap.TryGetValue(textureName, out var path))
 | 
			
		||||
        if (_fmResources.TryGetValue(campaignName, out var campaign) &&
 | 
			
		||||
            campaign.texturePathMap.TryGetValue(textureName, out var path))
 | 
			
		||||
        {
 | 
			
		||||
            return path;
 | 
			
		||||
        }
 | 
			
		||||
        }
 | 
			
		||||
        else if (_fmResources.TryGetValue(campaignName, out var campaign))
 | 
			
		||||
        {
 | 
			
		||||
            if (campaign.texturePathMap.TryGetValue(textureName, out var fmPath))
 | 
			
		||||
            {
 | 
			
		||||
                return fmPath;
 | 
			
		||||
            }
 | 
			
		||||
            else if (_omResources.texturePathMap.TryGetValue(textureName, out var omPath))
 | 
			
		||||
            {
 | 
			
		||||
                return omPath;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -262,7 +232,7 @@ public class ResourcePathManager
 | 
			
		|||
        {
 | 
			
		||||
            MatchCasing = MatchCasing.CaseInsensitive,
 | 
			
		||||
        };
 | 
			
		||||
        foreach (var path in Directory.GetFiles(omsPath, "*.mis", searchOptions))
 | 
			
		||||
        foreach (var path in Directory.GetFiles(root, "*.mis", searchOptions))
 | 
			
		||||
        {
 | 
			
		||||
            var baseName = Path.GetFileName(path).ToLower();
 | 
			
		||||
            map.Add(baseName, path);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,8 +39,6 @@ public partial class Mission : Node3D
 | 
			
		|||
	[Export]
 | 
			
		||||
	public bool Dump = false;
 | 
			
		||||
 | 
			
		||||
	string _campaignName;
 | 
			
		||||
	string _missionName;
 | 
			
		||||
	ResourcePathManager _installPaths;
 | 
			
		||||
	DbFile _file;
 | 
			
		||||
	TextureLoader _textureLoader;
 | 
			
		||||
| 
						 | 
				
			
			@ -50,12 +48,11 @@ public partial class Mission : Node3D
 | 
			
		|||
		var extractPath = ProjectSettings.GlobalizePath($"user://extracted/tmp");
 | 
			
		||||
		_installPaths = new ResourcePathManager(extractPath);
 | 
			
		||||
		var missionSelector = GetNode<Control>("%MissionSelector") as MissionSelector;
 | 
			
		||||
		missionSelector.pathManager = _installPaths;
 | 
			
		||||
		missionSelector.MissionSelected += (string campaign, string mission) =>
 | 
			
		||||
		missionSelector.LoadMission += (string rootPath, string missionPath) =>
 | 
			
		||||
		{
 | 
			
		||||
			_campaignName = campaign;
 | 
			
		||||
			_missionName = mission;
 | 
			
		||||
			FileName = _installPaths.GetMissionPath(campaign, mission);
 | 
			
		||||
			var inited = _installPaths.Init(rootPath);
 | 
			
		||||
			GD.Print($"Inited paths: {inited}");
 | 
			
		||||
			FileName = missionPath;
 | 
			
		||||
			Build = true;
 | 
			
		||||
		};
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -98,7 +95,8 @@ public partial class Mission : Node3D
 | 
			
		|||
		ClearMap();
 | 
			
		||||
 | 
			
		||||
		// TODO: This shouldn't be set for things that aren't actually FMs
 | 
			
		||||
		_textureLoader = new TextureLoader(_campaignName);
 | 
			
		||||
		var fmName = FileName.GetBaseDir().GetFile();
 | 
			
		||||
		_textureLoader = new TextureLoader(fmName);
 | 
			
		||||
		_file = new(FileName);
 | 
			
		||||
		UseChunk<TxList>("TXLIST", LoadTextures);
 | 
			
		||||
		UseChunk<WorldRep>("WREXT", BuildWrMeshes);
 | 
			
		||||
| 
						 | 
				
			
			@ -218,18 +216,20 @@ public partial class Mission : Node3D
 | 
			
		|||
			objPath ??= _installPaths.GetObjectPath(modelName + ".bin");
 | 
			
		||||
 | 
			
		||||
			var pos = brush.position.ToGodotVec3();
 | 
			
		||||
			var rawRot = brush.angle;
 | 
			
		||||
			var rot = new Vector3(rawRot.Y, rawRot.Z, rawRot.X) * 360 / ushort.MaxValue;
 | 
			
		||||
			var model = new Model
 | 
			
		||||
			{
 | 
			
		||||
				Position = pos,
 | 
			
		||||
				RotationDegrees = rot
 | 
			
		||||
			};
 | 
			
		||||
			var model = new Model();
 | 
			
		||||
			model.Position = pos;
 | 
			
		||||
			if (objPath != null)
 | 
			
		||||
			{
 | 
			
		||||
				model.BuildModel("", objPath);
 | 
			
		||||
			}
 | 
			
		||||
			AddChild(model);
 | 
			
		||||
 | 
			
		||||
			// var pos = brush.position.ToGodotVec3();
 | 
			
		||||
			// var cube = new CsgBox3D
 | 
			
		||||
			// {
 | 
			
		||||
			// 	Position = pos
 | 
			
		||||
			// };
 | 
			
		||||
			// AddChild(cube);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -53,6 +53,7 @@ public partial class Model : Node3D
 | 
			
		|||
                var b = (material.Handle) & 0xff;
 | 
			
		||||
                var g = (material.Handle >> 8) & 0xff;
 | 
			
		||||
                var r = (material.Handle >> 16) & 0xff;
 | 
			
		||||
                GD.Print($"Handle: {material.Handle}, R: {r}, G: {g}, B: {b}");
 | 
			
		||||
                var colour = new Color(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f);
 | 
			
		||||
                materials.Add(new StandardMaterial3D
 | 
			
		||||
                {
 | 
			
		||||
| 
						 | 
				
			
			@ -107,8 +108,7 @@ public partial class Model : Node3D
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        var pos = -modelFile.Header.Center.ToGodotVec3();
 | 
			
		||||
        var meshInstance = new MeshInstance3D { Mesh = mesh, Position = pos };
 | 
			
		||||
        var meshInstance = new MeshInstance3D { Mesh = mesh };
 | 
			
		||||
        AddChild(meshInstance);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,7 +29,16 @@ public partial class TextureLoader
 | 
			
		|||
    public bool Load(ResourcePathManager installManager, int id, string path)
 | 
			
		||||
    {
 | 
			
		||||
        var loaded = false;
 | 
			
		||||
        string texPath = installManager.GetTexturePath(_fmName, path);
 | 
			
		||||
        string texPath;
 | 
			
		||||
        if (_fmName != null)
 | 
			
		||||
        {
 | 
			
		||||
            texPath = installManager.GetTexturePath(_fmName, path);
 | 
			
		||||
            texPath ??= installManager.GetTexturePath(path);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            texPath = installManager.GetTexturePath(path);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (texPath != null)
 | 
			
		||||
        {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,14 +1,15 @@
 | 
			
		|||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using Godot;
 | 
			
		||||
using KeepersCompound.LGS;
 | 
			
		||||
 | 
			
		||||
namespace KeepersCompound.TMV.UI;
 | 
			
		||||
 | 
			
		||||
public partial class MissionSelector : Control
 | 
			
		||||
{
 | 
			
		||||
	public event MissionSelectedEventHandler MissionSelected;
 | 
			
		||||
	public delegate void MissionSelectedEventHandler(string campaign, string mission);
 | 
			
		||||
	[Signal]
 | 
			
		||||
	public delegate void LoadMissionEventHandler(string rootPath, string missionPath);
 | 
			
		||||
 | 
			
		||||
	public ResourcePathManager pathManager;
 | 
			
		||||
	private InstallPaths _installPaths;
 | 
			
		||||
 | 
			
		||||
	private FileDialog _FolderSelect;
 | 
			
		||||
	private LineEdit _FolderPath;
 | 
			
		||||
| 
						 | 
				
			
			@ -21,6 +22,7 @@ public partial class MissionSelector : Control
 | 
			
		|||
	public override void _Ready()
 | 
			
		||||
	{
 | 
			
		||||
		// TODO: Load initial folderpath from config and prefil everything
 | 
			
		||||
 | 
			
		||||
		_FolderSelect = GetNode<FileDialog>("%FolderSelect");
 | 
			
		||||
		_FolderPath = GetNode<LineEdit>("%FolderPath");
 | 
			
		||||
		_BrowseButton = GetNode<Button>("%BrowseButton");
 | 
			
		||||
| 
						 | 
				
			
			@ -30,8 +32,8 @@ public partial class MissionSelector : Control
 | 
			
		|||
		_CancelButton = GetNode<Button>("%CancelButton");
 | 
			
		||||
 | 
			
		||||
		_BrowseButton.Pressed += () => _FolderSelect.Visible = true;
 | 
			
		||||
		_FolderSelect.DirSelected += SetInstallPath;
 | 
			
		||||
		_FolderPath.TextSubmitted += SetInstallPath;
 | 
			
		||||
		_FolderSelect.DirSelected += (string dir) => { _FolderPath.Text = dir; BuildCampaignList(dir); };
 | 
			
		||||
		_FolderPath.TextSubmitted += BuildCampaignList;
 | 
			
		||||
		_Missions.ItemSelected += (long _) => _LoadButton.Disabled = false;
 | 
			
		||||
		_Campaigns.ItemSelected += BuildMissionList;
 | 
			
		||||
		_LoadButton.Pressed += EmitLoadMission;
 | 
			
		||||
| 
						 | 
				
			
			@ -49,25 +51,19 @@ public partial class MissionSelector : Control
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void SetInstallPath(string path)
 | 
			
		||||
	private void BuildCampaignList(string path)
 | 
			
		||||
	{
 | 
			
		||||
		_FolderPath.Text = path;
 | 
			
		||||
		if (pathManager.Init(path))
 | 
			
		||||
		{
 | 
			
		||||
			BuildCampaignList();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
		_installPaths = new InstallPaths(path);
 | 
			
		||||
 | 
			
		||||
	private void BuildCampaignList()
 | 
			
		||||
	{
 | 
			
		||||
		_Campaigns.Clear();
 | 
			
		||||
		_Missions.Clear();
 | 
			
		||||
		_LoadButton.Disabled = true;
 | 
			
		||||
 | 
			
		||||
		_Campaigns.AddItem("Original Missions");
 | 
			
		||||
		foreach (var campaign in pathManager.GetCampaignNames())
 | 
			
		||||
		var paths = Directory.GetDirectories(_installPaths.fmsPath);
 | 
			
		||||
		foreach (var c in paths.OrderBy(s => s))
 | 
			
		||||
		{
 | 
			
		||||
			_Campaigns.AddItem(campaign);
 | 
			
		||||
			_Campaigns.AddItem(c.TrimPrefix(_installPaths.fmsPath));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -76,28 +72,39 @@ public partial class MissionSelector : Control
 | 
			
		|||
		_Missions.Clear();
 | 
			
		||||
		_LoadButton.Disabled = true;
 | 
			
		||||
 | 
			
		||||
		var campaignName = _Campaigns.GetItemText((int)idx);
 | 
			
		||||
		var missionNames = pathManager.GetMissionNames(idx == 0 ? null : campaignName);
 | 
			
		||||
		foreach (var mission in missionNames)
 | 
			
		||||
		var campaignPath = "";
 | 
			
		||||
		if (idx == 0)
 | 
			
		||||
		{
 | 
			
		||||
			_Missions.AddItem(mission);
 | 
			
		||||
			campaignPath = _installPaths.omsPath;
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			campaignPath = _installPaths.fmsPath + _Campaigns.GetItemText((int)idx);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		string[] extensions = { "mis", "cow" };
 | 
			
		||||
		var paths = Directory.GetFiles(campaignPath);
 | 
			
		||||
		foreach (var f in paths.OrderBy(s => s))
 | 
			
		||||
		{
 | 
			
		||||
			if (extensions.Contains(f.GetExtension().ToLower()))
 | 
			
		||||
			{
 | 
			
		||||
				_Missions.AddItem(f.TrimPrefix(campaignPath));
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private void EmitLoadMission()
 | 
			
		||||
	{
 | 
			
		||||
		var campaignIdxs = _Campaigns.GetSelectedItems();
 | 
			
		||||
		var missionIdxs = _Missions.GetSelectedItems();
 | 
			
		||||
		if (campaignIdxs.IsEmpty() || missionIdxs.IsEmpty())
 | 
			
		||||
		var selectedCampaign = _Campaigns.GetSelectedItems()[0];
 | 
			
		||||
		var selected = _Missions.GetSelectedItems();
 | 
			
		||||
		if (selected.IsEmpty())
 | 
			
		||||
		{
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		var campaignIdx = campaignIdxs[0];
 | 
			
		||||
		var missionIdx = missionIdxs[0];
 | 
			
		||||
		var campaignName = campaignIdx == 0 ? null : _Campaigns.GetItemText(campaignIdx);
 | 
			
		||||
		var missionName = _Missions.GetItemText(missionIdx);
 | 
			
		||||
		MissionSelected(campaignName, missionName);
 | 
			
		||||
		var campaignPath = selectedCampaign == 0 ? _installPaths.omsPath : _installPaths.fmsPath + _Campaigns.GetItemText(selectedCampaign);
 | 
			
		||||
		var path = campaignPath + _Missions.GetItemText(selected[0]);
 | 
			
		||||
		EmitSignal(SignalName.LoadMission, _installPaths.rootPath, path);
 | 
			
		||||
 | 
			
		||||
		Visible = false;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,14 +1,9 @@
 | 
			
		|||
[gd_scene load_steps=5 format=3 uid="uid://boxi211q3kx6c"]
 | 
			
		||||
[gd_scene load_steps=4 format=3 uid="uid://boxi211q3kx6c"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="Script" path="res://project/code/TMV/Mission.cs" id="1_3gnqe"]
 | 
			
		||||
[ext_resource type="Script" path="res://project/code/camera.gd" id="2_w5otl"]
 | 
			
		||||
[ext_resource type="PackedScene" uid="uid://cekg1xb5f0ux1" path="res://project/scenes/ui/mission_selector.tscn" id="3_hwfcj"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="Environment" id="Environment_cckyk"]
 | 
			
		||||
ambient_light_source = 2
 | 
			
		||||
ambient_light_color = Color(1, 1, 1, 1)
 | 
			
		||||
ssao_enabled = true
 | 
			
		||||
 | 
			
		||||
[node name="Main" type="Node3D"]
 | 
			
		||||
 | 
			
		||||
[node name="Mission" type="Node3D" parent="."]
 | 
			
		||||
| 
						 | 
				
			
			@ -22,6 +17,3 @@ script = ExtResource("2_w5otl")
 | 
			
		|||
 | 
			
		||||
[node name="MissionSelector" parent="UI" instance=ExtResource("3_hwfcj")]
 | 
			
		||||
unique_name_in_owner = true
 | 
			
		||||
 | 
			
		||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
 | 
			
		||||
environment = SubResource("Environment_cckyk")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue