Skip to content

Commit 7a3bfb3

Browse files
committed
Fix for incorrectly formatted .map files when using the idTech2 hint
Fixes #43
1 parent 89a1573 commit 7a3bfb3

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

Sledge.Formats.Map.Tests/Units/TestQuakeMapFormat.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Globalization;
34
using System.IO;
45
using System.Linq;
6+
using System.Reflection;
57
using System.Text;
68
using System.Threading;
79
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -235,12 +237,12 @@ public void TestWhitespace()
235237
Assert.AreEqual(2, map.Worldspawn.Children.Count);
236238
}
237239

240+
[DataTestMethod]
238241
[DataRow(QuakeFormatFile, DisplayName = nameof(QuakeFormatFile))]
239242
[DataRow(ValveFormatFile, DisplayName = nameof(ValveFormatFile))]
240243
[DataRow(Quake2StandardFormatFile, DisplayName = nameof(Quake2StandardFormatFile))]
241244
[DataRow(Quake2ValveFormatFile, DisplayName = nameof(Quake2ValveFormatFile))]
242245
[DataRow(LotsOfWhitespace, DisplayName = nameof(LotsOfWhitespace))]
243-
[DataTestMethod]
244246
public void TestAddCommentToEveryRow(string file)
245247
{
246248
var commented = String.Join('\n', file.Split('\n').Select(x => x + " // this is a comment "));
@@ -263,4 +265,40 @@ public void TestLocales(string culture)
263265

264266
Assert.AreEqual(4, map.Worldspawn.Children.Count);
265267
}
268+
269+
private static readonly string[] ReparseHints = { "idTech2", "Worldcraft" };
270+
271+
public static IEnumerable<object[]> GetFileHintCombinations()
272+
{
273+
foreach (var h in ReparseHints)
274+
{
275+
yield return new object[] { nameof(QuakeFormatFile), h, QuakeFormatFile };
276+
yield return new object[] { nameof(ValveFormatFile), h, ValveFormatFile };
277+
yield return new object[] { nameof(Quake2StandardFormatFile), h, Quake2StandardFormatFile };
278+
yield return new object[] { nameof(Quake2ValveFormatFile), h, Quake2ValveFormatFile };
279+
yield return new object[] { nameof(LotsOfWhitespace), h, LotsOfWhitespace };
280+
}
281+
}
282+
283+
public static string GetFileHintCombinationDisplayName(MethodInfo method, object[] data)
284+
{
285+
return $"{method.Name} ({data[0]}, {data[1]})";
286+
}
287+
288+
[DataTestMethod]
289+
[DynamicData(nameof(GetFileHintCombinations), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetFileHintCombinationDisplayName))]
290+
public void TestReParse(string name, string hint, string file)
291+
{
292+
var format = new QuakeMapFormat();
293+
var stream = new MemoryStream(Encoding.ASCII.GetBytes(file));
294+
var expected = format.Read(stream);
295+
296+
using var ms = new MemoryStream();
297+
format.Write(ms, expected, hint);
298+
ms.Seek(0, SeekOrigin.Begin);
299+
Console.Write(Encoding.ASCII.GetString(ms.ToArray()));
300+
301+
var actual = format.Read(ms);
302+
TestUtils.AreEqualMap(expected, actual);
303+
}
266304
}

Sledge.Formats.Map/Formats/QuakeMapFormat.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ private static void WriteFace(StreamWriter sw, Face face, string styleHint)
398398
switch (styleHint)
399399
{
400400
case "idTech2":
401-
strings.Add("[");
402401
strings.Add(face.XShift.ToString("0.######", CultureInfo.InvariantCulture));
403402
strings.Add(face.YShift.ToString("0.######", CultureInfo.InvariantCulture));
404403
strings.Add(face.Rotation.ToString("0.######", CultureInfo.InvariantCulture));

Sledge.Formats.Map/Sledge.Formats.Map.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<RepositoryUrl>https://github.com/LogicAndTrick/sledge-formats</RepositoryUrl>
1212
<RepositoryType>Git</RepositoryType>
1313
<PackageTags>half-life quake valve hammer worldcraft jackhammer jack rmf vmf map jmf</PackageTags>
14-
<PackageReleaseNotes>Initial support for JACK prefab libraries (the JACK version with prefabs is in beta, so compatibility might change)</PackageReleaseNotes>
15-
<Version>1.2.5</Version>
14+
<PackageReleaseNotes>Fix for incorrectly formatted .map files when using the idTech2 hint</PackageReleaseNotes>
15+
<Version>1.2.6</Version>
1616
<DebugType>full</DebugType>
1717
<DebugSymbols>true</DebugSymbols>
1818
</PropertyGroup>

0 commit comments

Comments
 (0)