Compare commits

..

No commits in common. "655a188a697036d103c9b10708bf69df433d5932" and "cb2f016455d07e508fd23a8235ec55013b28ecdf" have entirely different histories.

6 changed files with 82 additions and 104 deletions

View File

@ -5,7 +5,7 @@ using System.Linq;
namespace KeepersCompound.LGS; 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 public class ResourcePathManager
{ {
private record CampaignResources private record CampaignResources
@ -84,81 +84,51 @@ public class ResourcePathManager
return false; return false;
} }
public List<string> GetCampaignNames() public string GetMissionPath(string missionName)
{ {
if (!_initialised) return null; if (!_initialised) return null;
var names = new List<string>(_fmResources.Keys); if (_omResources.missionPathMap.TryGetValue(missionName, out var path))
names.Sort(); {
return names; return path;
}
return null;
} }
public string GetMissionPath(string campaignName, string missionName) public string GetMissionPath(string campaignName, string missionName)
{ {
if (!_initialised) return null; 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 path;
{
return omPath;
} }
}
else if (
_fmResources.TryGetValue(campaignName, out var campaign) &&
campaign.missionPathMap.TryGetValue(missionName, out var fmPath))
{
return fmPath;
}
return null; return null;
} }
public List<string> GetMissionNames(string campaignName) public string GetTexturePath(string textureName)
{ {
if (!_initialised) return null; 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); return path;
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 null; 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) public string GetTexturePath(string campaignName, string textureName)
{ {
if (!_initialised) return null; if (!_initialised) return null;
textureName = textureName.ToLower(); textureName = textureName.ToLower();
if (campaignName == null || campaignName == "") if (_fmResources.TryGetValue(campaignName, out var campaign) &&
{ campaign.texturePathMap.TryGetValue(textureName, out var path))
if (_omResources.texturePathMap.TryGetValue(textureName, out var path))
{ {
return 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; return null;
} }
@ -262,7 +232,7 @@ public class ResourcePathManager
{ {
MatchCasing = MatchCasing.CaseInsensitive, 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(); var baseName = Path.GetFileName(path).ToLower();
map.Add(baseName, path); map.Add(baseName, path);

View File

@ -39,8 +39,6 @@ public partial class Mission : Node3D
[Export] [Export]
public bool Dump = false; public bool Dump = false;
string _campaignName;
string _missionName;
ResourcePathManager _installPaths; ResourcePathManager _installPaths;
DbFile _file; DbFile _file;
TextureLoader _textureLoader; TextureLoader _textureLoader;
@ -50,12 +48,11 @@ public partial class Mission : Node3D
var extractPath = ProjectSettings.GlobalizePath($"user://extracted/tmp"); var extractPath = ProjectSettings.GlobalizePath($"user://extracted/tmp");
_installPaths = new ResourcePathManager(extractPath); _installPaths = new ResourcePathManager(extractPath);
var missionSelector = GetNode<Control>("%MissionSelector") as MissionSelector; var missionSelector = GetNode<Control>("%MissionSelector") as MissionSelector;
missionSelector.pathManager = _installPaths; missionSelector.LoadMission += (string rootPath, string missionPath) =>
missionSelector.MissionSelected += (string campaign, string mission) =>
{ {
_campaignName = campaign; var inited = _installPaths.Init(rootPath);
_missionName = mission; GD.Print($"Inited paths: {inited}");
FileName = _installPaths.GetMissionPath(campaign, mission); FileName = missionPath;
Build = true; Build = true;
}; };
} }
@ -98,7 +95,8 @@ public partial class Mission : Node3D
ClearMap(); ClearMap();
// TODO: This shouldn't be set for things that aren't actually FMs // 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); _file = new(FileName);
UseChunk<TxList>("TXLIST", LoadTextures); UseChunk<TxList>("TXLIST", LoadTextures);
UseChunk<WorldRep>("WREXT", BuildWrMeshes); UseChunk<WorldRep>("WREXT", BuildWrMeshes);
@ -218,18 +216,20 @@ public partial class Mission : Node3D
objPath ??= _installPaths.GetObjectPath(modelName + ".bin"); objPath ??= _installPaths.GetObjectPath(modelName + ".bin");
var pos = brush.position.ToGodotVec3(); var pos = brush.position.ToGodotVec3();
var rawRot = brush.angle; var model = new Model();
var rot = new Vector3(rawRot.Y, rawRot.Z, rawRot.X) * 360 / ushort.MaxValue; model.Position = pos;
var model = new Model
{
Position = pos,
RotationDegrees = rot
};
if (objPath != null) if (objPath != null)
{ {
model.BuildModel("", objPath); model.BuildModel("", objPath);
} }
AddChild(model); AddChild(model);
// var pos = brush.position.ToGodotVec3();
// var cube = new CsgBox3D
// {
// Position = pos
// };
// AddChild(cube);
} }
} }

View File

@ -53,6 +53,7 @@ public partial class Model : Node3D
var b = (material.Handle) & 0xff; var b = (material.Handle) & 0xff;
var g = (material.Handle >> 8) & 0xff; var g = (material.Handle >> 8) & 0xff;
var r = (material.Handle >> 16) & 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); var colour = new Color(r / 255.0f, g / 255.0f, b / 255.0f, 1.0f);
materials.Add(new StandardMaterial3D 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 };
var meshInstance = new MeshInstance3D { Mesh = mesh, Position = pos };
AddChild(meshInstance); AddChild(meshInstance);
} }
} }

View File

@ -29,7 +29,16 @@ public partial class TextureLoader
public bool Load(ResourcePathManager installManager, int id, string path) public bool Load(ResourcePathManager installManager, int id, string path)
{ {
var loaded = false; 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) if (texPath != null)
{ {

View File

@ -1,14 +1,15 @@
using System.IO;
using System.Linq;
using Godot; using Godot;
using KeepersCompound.LGS;
namespace KeepersCompound.TMV.UI; namespace KeepersCompound.TMV.UI;
public partial class MissionSelector : Control public partial class MissionSelector : Control
{ {
public event MissionSelectedEventHandler MissionSelected; [Signal]
public delegate void MissionSelectedEventHandler(string campaign, string mission); public delegate void LoadMissionEventHandler(string rootPath, string missionPath);
public ResourcePathManager pathManager; private InstallPaths _installPaths;
private FileDialog _FolderSelect; private FileDialog _FolderSelect;
private LineEdit _FolderPath; private LineEdit _FolderPath;
@ -21,6 +22,7 @@ public partial class MissionSelector : Control
public override void _Ready() public override void _Ready()
{ {
// TODO: Load initial folderpath from config and prefil everything // TODO: Load initial folderpath from config and prefil everything
_FolderSelect = GetNode<FileDialog>("%FolderSelect"); _FolderSelect = GetNode<FileDialog>("%FolderSelect");
_FolderPath = GetNode<LineEdit>("%FolderPath"); _FolderPath = GetNode<LineEdit>("%FolderPath");
_BrowseButton = GetNode<Button>("%BrowseButton"); _BrowseButton = GetNode<Button>("%BrowseButton");
@ -30,8 +32,8 @@ public partial class MissionSelector : Control
_CancelButton = GetNode<Button>("%CancelButton"); _CancelButton = GetNode<Button>("%CancelButton");
_BrowseButton.Pressed += () => _FolderSelect.Visible = true; _BrowseButton.Pressed += () => _FolderSelect.Visible = true;
_FolderSelect.DirSelected += SetInstallPath; _FolderSelect.DirSelected += (string dir) => { _FolderPath.Text = dir; BuildCampaignList(dir); };
_FolderPath.TextSubmitted += SetInstallPath; _FolderPath.TextSubmitted += BuildCampaignList;
_Missions.ItemSelected += (long _) => _LoadButton.Disabled = false; _Missions.ItemSelected += (long _) => _LoadButton.Disabled = false;
_Campaigns.ItemSelected += BuildMissionList; _Campaigns.ItemSelected += BuildMissionList;
_LoadButton.Pressed += EmitLoadMission; _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; _installPaths = new InstallPaths(path);
if (pathManager.Init(path))
{
BuildCampaignList();
}
}
private void BuildCampaignList()
{
_Campaigns.Clear(); _Campaigns.Clear();
_Missions.Clear(); _Missions.Clear();
_LoadButton.Disabled = true; _LoadButton.Disabled = true;
_Campaigns.AddItem("Original Missions"); _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(); _Missions.Clear();
_LoadButton.Disabled = true; _LoadButton.Disabled = true;
var campaignName = _Campaigns.GetItemText((int)idx); var campaignPath = "";
var missionNames = pathManager.GetMissionNames(idx == 0 ? null : campaignName); if (idx == 0)
foreach (var mission in missionNames)
{ {
_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() private void EmitLoadMission()
{ {
var campaignIdxs = _Campaigns.GetSelectedItems(); var selectedCampaign = _Campaigns.GetSelectedItems()[0];
var missionIdxs = _Missions.GetSelectedItems(); var selected = _Missions.GetSelectedItems();
if (campaignIdxs.IsEmpty() || missionIdxs.IsEmpty()) if (selected.IsEmpty())
{ {
return; return;
} }
var campaignIdx = campaignIdxs[0]; var campaignPath = selectedCampaign == 0 ? _installPaths.omsPath : _installPaths.fmsPath + _Campaigns.GetItemText(selectedCampaign);
var missionIdx = missionIdxs[0]; var path = campaignPath + _Missions.GetItemText(selected[0]);
var campaignName = campaignIdx == 0 ? null : _Campaigns.GetItemText(campaignIdx); EmitSignal(SignalName.LoadMission, _installPaths.rootPath, path);
var missionName = _Missions.GetItemText(missionIdx);
MissionSelected(campaignName, missionName);
Visible = false; Visible = false;
} }

View File

@ -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/TMV/Mission.cs" id="1_3gnqe"]
[ext_resource type="Script" path="res://project/code/camera.gd" id="2_w5otl"] [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"] [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="Main" type="Node3D"]
[node name="Mission" type="Node3D" parent="."] [node name="Mission" type="Node3D" parent="."]
@ -22,6 +17,3 @@ script = ExtResource("2_w5otl")
[node name="MissionSelector" parent="UI" instance=ExtResource("3_hwfcj")] [node name="MissionSelector" parent="UI" instance=ExtResource("3_hwfcj")]
unique_name_in_owner = true unique_name_in_owner = true
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_cckyk")