Skip to content

Commit

Permalink
Fix drag n drop problems
Browse files Browse the repository at this point in the history
  • Loading branch information
BigBang1112 committed Nov 27, 2020
1 parent 84595cc commit 1be04c9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
9 changes: 9 additions & 0 deletions NationsConverter/Converter.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using GBX.NET.Engines.Game;
using NationsConverter.Stages;
using System.IO;
using System.Reflection;

namespace NationsConverter
{
public class Converter
{
public static string LocalDirectory { get; }

public ConverterParameters Parameters { get; set; } = new ConverterParameters();
public EmbedManager EmbedManager { get; set; } = new EmbedManager();

Expand Down Expand Up @@ -32,5 +36,10 @@ public void Convert(CGameCtnChallenge map, int version)
DefaultGroundRemover.Process(map, version, Parameters);
MetadataDefiner.Process(map, version, Parameters);
}

static Converter()
{
LocalDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
}
}
6 changes: 5 additions & 1 deletion NationsConverter/EmbedManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;

namespace NationsConverter
Expand All @@ -10,6 +11,9 @@ public class EmbedManager
{
public void CopyUsedEmbed(CGameCtnChallenge map, Definitions definitions)
{
var assembly = Assembly.GetExecutingAssembly();
var localDirectory = Path.GetDirectoryName(assembly.Location);

var previousEmbed = map.Embeds; // TODO: maybe later some kind of embed transfer support

map.CreateChunk<CGameCtnChallenge.Chunk03043054>();
Expand Down Expand Up @@ -46,7 +50,7 @@ void ImportBlock(ConversionBlock conversionBlock)
try
{
if (conversionBlock.Name.EndsWith(".Block.Gbx_CustomBlock"))
map.ImportFileToEmbed($"UserData/Blocks/{conversionBlock.Name}", $"Blocks/{Path.GetDirectoryName(conversionBlock.Name)}");
map.ImportFileToEmbed($"{localDirectory}UserData/Blocks/{conversionBlock.Name}", $"Blocks/{Path.GetDirectoryName(conversionBlock.Name)}");
}
catch (Exception e) when (e is DirectoryNotFoundException || e is FileNotFoundException)
{
Expand Down
4 changes: 2 additions & 2 deletions NationsConverter/Stages/BlockConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void PlaceItem(ConversionItem conversionItem)
if (conversion.Macroblock != null)
{
if (!macroblocks.TryGetValue(conversion.Macroblock, out CGameCtnMacroBlockInfo macro))
macro = macroblocks[conversion.Macroblock] = GameBox.Parse<CGameCtnMacroBlockInfo>($"Macroblocks/{conversion.Macroblock}").MainNode;
macro = macroblocks[conversion.Macroblock] = GameBox.Parse<CGameCtnMacroBlockInfo>($"{Converter.LocalDirectory}/Macroblocks/{conversion.Macroblock}").MainNode;
map.PlaceMacroblock(macro, referenceBlock.Coord + (0, conversion.OffsetY, 0), Dir.Add(referenceBlock.Direction, (Direction)conversion.OffsetDir));
}

Expand Down Expand Up @@ -273,7 +273,7 @@ void ConvertBlock(CGameCtnBlock referenceBlock, Conversion conversion, Conversio

var sortedLog = log.ToList();
sortedLog.Sort();
File.WriteAllText("missing_blocks.txt", string.Join("\n", sortedLog));
File.WriteAllText($"{Converter.LocalDirectory}/missing_blocks.txt", string.Join("\n", sortedLog));
}
}
}
2 changes: 1 addition & 1 deletion NationsConverter/Stages/DefaultGroundRemover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class DefaultGroundRemover : IStage
{
public void Process(CGameCtnChallenge map, int version, ConverterParameters parameters)
{
map.ImportFileToEmbed("UserData/Blocks/NationsConverter/NoGround.Block.Gbx", "Blocks/NationsConverter");
map.ImportFileToEmbed($"{Converter.LocalDirectory}/UserData/Blocks/NationsConverter/NoGround.Block.Gbx", "Blocks/NationsConverter");

for (var x = 0; x < 32; x++)
{
Expand Down
4 changes: 2 additions & 2 deletions NationsConverter/Stages/GroundPlacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public void Process(CGameCtnChallenge map, int version, ConverterParameters para
x.Coord -= (0, 8, 0);
});

map.ImportFileToEmbed("UserData/Materials/GrassTexGreenPhy.Mat.Gbx", "Materials", true); // False crashes GBX.NET
map.ImportFileToEmbed("UserData/Items/NationsConverter/z_terrain/w_grass/GrassGround.Item.Gbx", "Items/NationsConverter/z_terrain/w_grass");
map.ImportFileToEmbed($"{Converter.LocalDirectory}/UserData/Materials/GrassTexGreenPhy.Mat.Gbx", "Materials", true); // False crashes GBX.NET
map.ImportFileToEmbed($"{Converter.LocalDirectory}/UserData/Items/NationsConverter/z_terrain/w_grass/GrassGround.Item.Gbx", "Items/NationsConverter/z_terrain/w_grass");

var dirtBlocks = new string[] { "StadiumDirt", "StadiumDirtHill", "StadiumPool", "StadiumWater" };

Expand Down

0 comments on commit 1be04c9

Please sign in to comment.