Skip to content

Commit 4a610e2

Browse files
authored
Rename and prepare release (#17)
* rename tool, make palette easier * update readmen * remove last vestigaes of *tool nomenclature * rename folders, namespaces, fix many code quality hints * remove some commented out code, other cleanup * add array length support to object annotator * cleanup some objects * start fixing unit tests * get object loading unit tests into a passing and usable state * start adding unit test for saving * add .editorconfig * fix track saving incorrectly * fix objdata directories not saving * fix building object saving * update readme * cleanup resources, add version.txt * remove useless variable
1 parent b14ecd8 commit 4a610e2

File tree

141 files changed

+3057
-2293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+3057
-2293
lines changed

.editorconfig

Lines changed: 436 additions & 3 deletions
Large diffs are not rendered by default.

OpenLocoTool/Annotation.cs renamed to Core/Annotation.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
namespace OpenLocoTool
1+
namespace OpenLoco.ObjectEditor
22
{
33
public class Annotation
44
{
5-
private int start = 0;
6-
private int end = 0;
7-
private int length = 0;
5+
private int start;
6+
private int end;
7+
private int length;
88

99
public Annotation(string name, Annotation? parent, int start, int length)
1010
{

Core/Core.csproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<AnalysisLevel>latest</AnalysisLevel>
9+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Zenith.Core" Version="1.0.20" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\Shared\Shared.csproj" />
18+
</ItemGroup>
19+
20+
</Project>

OpenLocoTool/DatFileParsing/AttributeHelper.cs renamed to Core/DatFileParsing/AttributeHelper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
using System.Reflection;
2-
using OpenLocoTool.Headers;
1+
using OpenLoco.ObjectEditor.Data;
2+
using System.Reflection;
33

4-
namespace OpenLocoTool.DatFileParsing
4+
namespace OpenLoco.ObjectEditor.DatFileParsing
55
{
66
public static class AttributeHelper
77
{
88
public static T? Get<T>(PropertyInfo p) where T : Attribute
99
{
10-
var attrs = p.GetCustomAttributes(typeof(T), inherit: false);
11-
return attrs.Length == 1 ? attrs[0] as T : null;
10+
var attributes = p.GetCustomAttributes(typeof(T), inherit: false);
11+
return attributes.Length == 1 ? attributes[0] as T : null;
1212
}
1313

1414
public static T? Get<T>(Type t) where T : Attribute

OpenLocoTool/DatFileParsing/ByteHelpers.cs renamed to Core/DatFileParsing/ByteHelpers.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace OpenLocoTool.DatFileParsing
1+
using Zenith.Core;
2+
3+
namespace OpenLoco.ObjectEditor.DatFileParsing
24
{
35
public static class ByteHelpers
46
{
@@ -23,10 +25,7 @@ public static int GetObjectSize(Type type)
2325
size = sizeAttr.Size;
2426
}
2527

26-
if (size == 0)
27-
{
28-
throw new ArgumentException("unknown primitive type with no size");
29-
}
28+
Verify.Positive(size, message: $"type {type.Name} has no size data associated with it");
3029

3130
return size;
3231
}

OpenLocoTool/DatFileParsing/ByteReader.cs renamed to Core/DatFileParsing/ByteReader.cs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace OpenLocoTool.DatFileParsing
1+
using Zenith.Core;
2+
3+
namespace OpenLoco.ObjectEditor.DatFileParsing
24
{
35
public static class ByteReader
46
{
@@ -41,7 +43,7 @@ public static object ReadT(ReadOnlySpan<byte> data, Type t, int offset, int arrL
4143

4244
if (t.IsArray)
4345
{
44-
var elementType = t.GetElementType();
46+
var elementType = t.GetElementType() ?? throw new ArgumentNullException(t.Name);
4547
var size = ByteHelpers.GetObjectSize(elementType);
4648

4749
var arr = Array.CreateInstance(elementType, arrLength);
@@ -65,7 +67,7 @@ public static object ReadT(ReadOnlySpan<byte> data, Type t, int offset, int arrL
6567

6668
foreach (var enumValue in enumValues)
6769
{
68-
var enumValueInt = Convert.ToInt32(Enum.Parse(t, enumValue.ToString())); // Convert to int
70+
var enumValueInt = Convert.ToInt32(Enum.Parse(t, enumValue.ToString()!)); // Convert to int
6971
if ((enumValueInt & Convert.ToInt32(underlyingValue)) != 0) // Convert to int
7072
{
7173
combinedValue |= enumValueInt;
@@ -127,13 +129,39 @@ public static ILocoStruct ReadLocoStruct(ReadOnlySpan<byte> data, Type t)
127129
var variableAttr = AttributeHelper.Get<LocoStructVariableLoadAttribute>(p);
128130
if (variableAttr != null)
129131
{
130-
if (p.PropertyType.IsArray && p.PropertyType.GetElementType() == typeof(uint8_t))
132+
if (p.PropertyType.IsArray)
131133
{
132-
args.Add(new uint8_t[arrLength]);
134+
// todo: find a generic way to do this
135+
if (p.PropertyType.GetElementType() == typeof(uint8_t))
136+
{
137+
args.Add(new uint8_t[arrLength]);
138+
}
139+
else if (p.PropertyType.GetElementType() == typeof(int8_t))
140+
{
141+
args.Add(new int8_t[arrLength]);
142+
}
143+
else if (p.PropertyType.GetElementType() == typeof(uint16_t))
144+
{
145+
args.Add(new uint16_t[arrLength]);
146+
}
147+
else if (p.PropertyType.GetElementType() == typeof(int16_t))
148+
{
149+
args.Add(new int16_t[arrLength]);
150+
}
151+
else if (p.PropertyType.GetElementType() == typeof(uint32_t))
152+
{
153+
args.Add(new uint32_t[arrLength]);
154+
}
155+
else if (p.PropertyType.GetElementType() == typeof(int32_t))
156+
{
157+
args.Add(new int32_t[arrLength]);
158+
}
133159
}
134160
else
135161
{
136-
args.Add(Activator.CreateInstance(p.PropertyType));
162+
var newInstance = Activator.CreateInstance(p.PropertyType);
163+
Verify.NotNull(newInstance, paramName: p.PropertyType.Name);
164+
args.Add(newInstance!);
137165
}
138166

139167
continue;

OpenLocoTool/DatFileParsing/ByteReaderT.cs renamed to Core/DatFileParsing/ByteReaderT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace OpenLocoTool.DatFileParsing
1+
namespace OpenLoco.ObjectEditor.DatFileParsing
22
{
33
public static class ByteReaderT
44
{

OpenLocoTool/DatFileParsing/ByteWriter.cs renamed to Core/DatFileParsing/ByteWriter.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace OpenLocoTool.DatFileParsing
1+
using Zenith.Core;
2+
3+
namespace OpenLoco.ObjectEditor.DatFileParsing
24
{
35
public static class ByteWriter
46
{
@@ -36,13 +38,13 @@ public static void WriteT(Span<byte> data, Type t, int offset, object val)
3638
}
3739
else if (t.IsArray)
3840
{
39-
var elementType = t.GetElementType() ?? throw new NullReferenceException();
41+
var elementType = t.GetElementType() ?? throw new ArgumentNullException(t.Name);
4042
var size = ByteHelpers.GetObjectSize(elementType);
4143
var arr = (Array)val;
4244

4345
for (var i = 0; i < arr.Length; i++)
4446
{
45-
var value = arr.GetValue(i) ?? throw new NullReferenceException();
47+
var value = arr.GetValue(i) ?? throw new ArgumentNullException($"{t.Name}[{i}]");
4648
WriteT(data, elementType, offset + (i * size), value);
4749
}
4850
}
@@ -72,10 +74,7 @@ public static void WriteT(Span<byte> data, Type t, int offset, object val)
7274

7375
public static ReadOnlySpan<byte> WriteLocoStruct(ILocoStruct obj)
7476
{
75-
if (obj == null)
76-
{
77-
throw new NullReferenceException();
78-
}
77+
Verify.NotNull(obj);
7978

8079
var t = obj.GetType();
8180
var objSize = ByteHelpers.GetObjectSize(t);
@@ -113,7 +112,7 @@ public static ReadOnlySpan<byte> WriteLocoStruct(ILocoStruct obj)
113112
arrLength = arrLengthAttr.Length;
114113
}
115114

116-
var propVal = p.GetValue(obj) ?? throw new NullReferenceException();
115+
var propVal = p.GetValue(obj) ?? throw new ArgumentNullException($"{p.Name} for {obj} was null");
117116
WriteT(buf, p.PropertyType, offsetAttr.Offset, propVal);
118117
}
119118

OpenLocoTool/DatFileParsing/ByteWriterT.cs renamed to Core/DatFileParsing/ByteWriterT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace OpenLocoTool.DatFileParsing
1+
namespace OpenLoco.ObjectEditor.DatFileParsing
22
{
33
public static class ByteWriterT
44
{

OpenLocoTool/DatFileParsing/LocoAttributes.cs renamed to Core/DatFileParsing/LocoAttributes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using OpenLocoTool.Headers;
1+
using OpenLoco.ObjectEditor.Data;
22

3-
namespace OpenLocoTool.DatFileParsing
3+
namespace OpenLoco.ObjectEditor.DatFileParsing
44
{
55
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false)]
66
public class LocoArrayLengthAttribute(int length) : Attribute

0 commit comments

Comments
 (0)