Skip to content

Commit

Permalink
Call UpdateMapFiles automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
Vegetal-Pole committed Apr 26, 2024
1 parent f9204e1 commit 1a2ff61
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
32 changes: 21 additions & 11 deletions TagTool/Commands/Files/UpdateMapFilesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@ public override object Execute(List<string> args)
return new TagToolError(CommandError.ArgCount);

bool forceUpdate = false;
bool hasMapInfo = false;
bool pathProvided = false;
string mapInfoPath = "";

if (args.Count >= 1)
hasMapInfo = true;
{
pathProvided = true;

if (!Directory.Exists(args[0]))
return new TagToolError(CommandError.ArgInvalid, "Given mapinfo directory does not exist.");
else
mapInfoPath = args[0];
}

if (args.Count == 2)
if (args[1].ToLower() == "forceupdate")
forceUpdate = true;
Expand All @@ -55,9 +64,9 @@ public override object Execute(List<string> args)
MapFile map;
Blf mapInfo = null;

if (hasMapInfo)
if (pathProvided)
{
var mapInfoDir = new DirectoryInfo(args[0]);
var mapInfoDir = new DirectoryInfo(mapInfoPath);
var files = mapInfoDir.GetFiles(mapInfoName);
if (files.Length != 0)
{
Expand Down Expand Up @@ -134,7 +143,7 @@ public override object Execute(List<string> args)
Console.WriteLine("Done!");
return true;
}
else if(Cache is GameCacheModPackage modPackCache)
else if(Cache is GameCacheModPackage modCache)
{
// Generate / update the map files
foreach (var scenario in Cache.TagCache.FindAllInGroup("scnr"))
Expand All @@ -150,9 +159,9 @@ public override object Execute(List<string> args)
MapFile map;
Blf mapInfo = null;

if (hasMapInfo)
if (pathProvided)
{
var mapInfoDir = new DirectoryInfo(args[0]);
var mapInfoDir = new DirectoryInfo(mapInfoPath);
var files = mapInfoDir.GetFiles(mapInfoName);
if (files.Length != 0)
{
Expand Down Expand Up @@ -196,13 +205,14 @@ public override object Execute(List<string> args)
map.Write(writer);

var header = (CacheFileHeaderGenHaloOnline)map.Header;
modPackCache.AddMapFile(mapStream, header.MapId);
modCache.AddMapFile(mapStream, header.MapId);

if (mapInfo != null)
Console.WriteLine($"Scenario tag index for {name}: 0x{scenario.Index:X4} (using map info)");
Console.WriteLine($"Scenario 0x{scenario.Index:X4} \"{name}\" using map info");
else if (args.Count == 0)
Console.WriteLine($"Scenario 0x{scenario.Index:X4} \"{name}\" NOT using map info");
else
Console.WriteLine($"Scenario tag index for {name}: 0x{scenario.Index:X4} (WARNING: not using map info)");

new TagToolWarning($"Scenario 0x{scenario.Index:X4} \"{name}\" NOT using map info");
}
Console.WriteLine("Done!");
return true;
Expand Down
6 changes: 6 additions & 0 deletions TagTool/Commands/Porting/PortTagCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using System.Collections.Concurrent;
using TagTool.Geometry.BspCollisionGeometry;
using TagTool.Commands.ScenarioStructureBSPs;
using TagTool.Commands.Files;

namespace TagTool.Commands.Porting
{
Expand Down Expand Up @@ -1207,6 +1208,11 @@ public CachedTag ConvertTagInternal(Stream cacheStream, Stream blamCacheStream,
block.Flags = block.FlagsReach.ConvertLexical<Scenario.StructureBspBlock.StructureBspFlags>();
}
}

_deferredActions.Add(() =>
{
new UpdateMapFilesCommand(CacheContext).Execute(new List<string> { });
});
}
break;

Expand Down

0 comments on commit 1a2ff61

Please sign in to comment.