Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup environment project #518

Merged
merged 13 commits into from
Aug 8, 2023
123 changes: 60 additions & 63 deletions TREnvironmentEditor/EMEditorMapping.cs
Original file line number Diff line number Diff line change
@@ -1,81 +1,78 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using TREnvironmentEditor.Model;
using TREnvironmentEditor.Parsing;

namespace TREnvironmentEditor
namespace TREnvironmentEditor;

public class EMEditorMapping
{
public class EMEditorMapping
public static readonly EMConverter Converter = new();
public static readonly JsonSerializerSettings Serializer = new()
{
public static readonly EMConverter Converter = new EMConverter();
public static readonly JsonSerializerSettings Serializer = new JsonSerializerSettings
{
ContractResolver = new EMSerializationResolver(),
DefaultValueHandling = DefaultValueHandling.Ignore,
Formatting = Formatting.Indented
};
ContractResolver = new EMSerializationResolver(),
DefaultValueHandling = DefaultValueHandling.Ignore,
Formatting = Formatting.Indented
};

public EMEditorSet All { get; set; }
public EMEditorSet NonPurist { get; set; }
public List<EMEditorSet> Any { get; set; }
public List<List<EMEditorSet>> AllWithin { get; set; }
public List<EMEditorGroupedSet> OneOf { get; set; }
public List<EMConditionalEditorSet> ConditionalAllWithin { get; set; }
public List<EMConditionalSingleEditorSet> ConditionalAll { get; set; }
public List<EMConditionalGroupedSet> ConditionalOneOf { get; set; }
public EMEditorSet Mirrored { get; set; }
public Dictionary<ushort, ushort> AlternativeTextures { get; set; }

public EMEditorSet All { get; set; }
public EMEditorSet NonPurist { get; set; }
public List<EMEditorSet> Any { get; set; }
public List<List<EMEditorSet>> AllWithin { get; set; }
public List<EMEditorGroupedSet> OneOf { get; set; }
public List<EMConditionalEditorSet> ConditionalAllWithin { get; set; }
public List<EMConditionalSingleEditorSet> ConditionalAll { get; set; }
public List<EMConditionalGroupedSet> ConditionalOneOf { get; set; }
public EMEditorSet Mirrored { get; set; }
public Dictionary<ushort, ushort> AlternativeTextures { get; set; }
public EMEditorMapping()
{
All = new EMEditorSet();
ConditionalAll = new List<EMConditionalSingleEditorSet>();
NonPurist = new EMEditorSet();
Any = new List<EMEditorSet>();
AllWithin = new List<List<EMEditorSet>>();
ConditionalAllWithin = new List<EMConditionalEditorSet>();
OneOf = new List<EMEditorGroupedSet>();
ConditionalOneOf = new List<EMConditionalGroupedSet>();
Mirrored = new EMEditorSet();
}

public EMEditorMapping()
public static EMEditorMapping Get(string packPath)
{
if (File.Exists(packPath))
{
All = new EMEditorSet();
ConditionalAll = new List<EMConditionalSingleEditorSet>();
NonPurist = new EMEditorSet();
Any = new List<EMEditorSet>();
AllWithin = new List<List<EMEditorSet>>();
ConditionalAllWithin = new List<EMConditionalEditorSet>();
OneOf = new List<EMEditorGroupedSet>();
ConditionalOneOf = new List<EMConditionalGroupedSet>();
Mirrored = new EMEditorSet();
return JsonConvert.DeserializeObject<EMEditorMapping>(File.ReadAllText(packPath), Converter);
}

public static EMEditorMapping Get(string packPath)
{
if (File.Exists(packPath))
{
return JsonConvert.DeserializeObject<EMEditorMapping>(File.ReadAllText(packPath), Converter);
}
return null;
}

return null;
}
public void SerializeTo(string packPath)
{
File.WriteAllText(packPath, Serialize());
}

public void SerializeTo(string packPath)
{
File.WriteAllText(packPath, Serialize());
}
public string Serialize()
{
return JsonConvert.SerializeObject(this, Serializer);
}

public string Serialize()
public void AlternateTextures()
{
if (AlternativeTextures == null)
{
return JsonConvert.SerializeObject(this, Serializer);
return;
}

public void AlternateTextures()
{
if (AlternativeTextures == null)
{
return;
}

All?.RemapTextures(AlternativeTextures);
ConditionalAll?.ForEach(s => s.RemapTextures(AlternativeTextures));
NonPurist?.RemapTextures(AlternativeTextures);
Any?.ForEach(s => s.RemapTextures(AlternativeTextures));
AllWithin?.ForEach(a => a.ForEach(s => s.RemapTextures(AlternativeTextures)));
ConditionalAllWithin?.ForEach(s => s.RemapTextures(AlternativeTextures));
OneOf?.ForEach(s => s.RemapTextures(AlternativeTextures));
ConditionalOneOf?.ForEach(s => s.RemapTextures(AlternativeTextures));
Mirrored?.RemapTextures(AlternativeTextures);
}
All?.RemapTextures(AlternativeTextures);
ConditionalAll?.ForEach(s => s.RemapTextures(AlternativeTextures));
NonPurist?.RemapTextures(AlternativeTextures);
Any?.ForEach(s => s.RemapTextures(AlternativeTextures));
AllWithin?.ForEach(a => a.ForEach(s => s.RemapTextures(AlternativeTextures)));
ConditionalAllWithin?.ForEach(s => s.RemapTextures(AlternativeTextures));
OneOf?.ForEach(s => s.RemapTextures(AlternativeTextures));
ConditionalOneOf?.ForEach(s => s.RemapTextures(AlternativeTextures));
Mirrored?.RemapTextures(AlternativeTextures);
}
}
}
19 changes: 9 additions & 10 deletions TREnvironmentEditor/Helpers/EMDirection.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
namespace TREnvironmentEditor.Helpers
namespace TREnvironmentEditor.Helpers;

public enum Direction
{
public enum Direction
{
North,
East,
South,
West,
Up,
Down
}
North,
East,
South,
West,
Up,
Down
}
11 changes: 5 additions & 6 deletions TREnvironmentEditor/Helpers/EMExclusionMode.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
namespace TREnvironmentEditor.Helpers
namespace TREnvironmentEditor.Helpers;

public enum EMExclusionMode
{
public enum EMExclusionMode
{
BreakOnAny,
Individual,
}
BreakOnAny,
Individual,
}
117 changes: 58 additions & 59 deletions TREnvironmentEditor/Helpers/EMLevelData.cs
Original file line number Diff line number Diff line change
@@ -1,73 +1,72 @@
using TRLevelControl.Model;

namespace TREnvironmentEditor.Helpers
namespace TREnvironmentEditor.Helpers;

public class EMLevelData
{
public class EMLevelData
{
public uint NumCameras { get; set; }
public uint NumEntities { get; set; }
public uint NumRooms { get; set; }
public uint NumCameras { get; set; }
public uint NumEntities { get; set; }
public uint NumRooms { get; set; }

/// <summary>
/// Negative values will imply a backwards search against NumCameras.
/// e.g. camera = -2, NumCameras = 14 => Result = 12
/// </summary>
public short ConvertCamera(int camera)
{
return Convert(camera, NumCameras);
}
/// <summary>
/// Negative values will imply a backwards search against NumCameras.
/// e.g. camera = -2, NumCameras = 14 => Result = 12
/// </summary>
public short ConvertCamera(int camera)
{
return Convert(camera, NumCameras);
}

/// <summary>
/// Negative values will imply a backwards search against NumEntities.
/// e.g. entity = -2, NumEntities = 14 => Result = 12
/// </summary>
public short ConvertEntity(int entity)
{
return Convert(entity, NumEntities);
}
/// <summary>
/// Negative values will imply a backwards search against NumEntities.
/// e.g. entity = -2, NumEntities = 14 => Result = 12
/// </summary>
public short ConvertEntity(int entity)
{
return Convert(entity, NumEntities);
}

/// <summary>
/// Negative values will imply a backwards search against NumRoows.
/// e.g. room = -2, NumRooms = 14 => Result = 12
/// </summary>
public short ConvertRoom(int room)
{
return Convert(room, NumRooms);
}
/// <summary>
/// Negative values will imply a backwards search against NumRoows.
/// e.g. room = -2, NumRooms = 14 => Result = 12
/// </summary>
public short ConvertRoom(int room)
{
return Convert(room, NumRooms);
}

public short Convert(int itemIndex, uint numItems)
{
return (short)(itemIndex < 0 ? numItems + itemIndex : itemIndex);
}
public static short Convert(int itemIndex, uint numItems)
{
return (short)(itemIndex < 0 ? numItems + itemIndex : itemIndex);
}

public static EMLevelData GetData(TR1Level level)
public static EMLevelData GetData(TR1Level level)
{
return new EMLevelData
{
return new EMLevelData
{
NumCameras = level.NumCameras,
NumEntities = level.NumEntities,
NumRooms = level.NumRooms
};
}
NumCameras = level.NumCameras,
NumEntities = level.NumEntities,
NumRooms = level.NumRooms
};
}

public static EMLevelData GetData(TR2Level level)
public static EMLevelData GetData(TR2Level level)
{
return new EMLevelData
{
return new EMLevelData
{
NumCameras = level.NumCameras,
NumEntities = level.NumEntities,
NumRooms = level.NumRooms
};
}
NumCameras = level.NumCameras,
NumEntities = level.NumEntities,
NumRooms = level.NumRooms
};
}

public static EMLevelData GetData(TR3Level level)
public static EMLevelData GetData(TR3Level level)
{
return new EMLevelData
{
return new EMLevelData
{
NumCameras = level.NumCameras,
NumEntities = level.NumEntities,
NumRooms = level.NumRooms
};
}
NumCameras = level.NumCameras,
NumEntities = level.NumEntities,
NumRooms = level.NumRooms
};
}
}
}
19 changes: 9 additions & 10 deletions TREnvironmentEditor/Helpers/EMLocation.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace TREnvironmentEditor.Helpers
namespace TREnvironmentEditor.Helpers;

public class EMLocation
{
public class EMLocation
{
public int X { get; set; }
public int Y { get; set; }
public int Z { get; set; }
public short Room { get; set; }
public short Angle { get; set; }
}
}
public int X { get; set; }
public int Y { get; set; }
public int Z { get; set; }
public short Room { get; set; }
public short Angle { get; set; }
}
41 changes: 19 additions & 22 deletions TREnvironmentEditor/Helpers/EMLocationExpander.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
using System.Collections.Generic;
namespace TREnvironmentEditor.Helpers;

namespace TREnvironmentEditor.Helpers
public class EMLocationExpander
{
public class EMLocationExpander
{
public EMLocation Location { get; set; }
public uint ExpandX { get; set; }
public uint ExpandZ { get; set; }
public EMLocation Location { get; set; }
public uint ExpandX { get; set; }
public uint ExpandZ { get; set; }

public List<EMLocation> Expand()
public List<EMLocation> Expand()
{
List<EMLocation> locs = new() { Location };
for (int i = 0; i < ExpandX; i++)
{
List<EMLocation> locs = new List<EMLocation> { Location };
for (int i = 0; i < ExpandX; i++)
for (int j = 0; j < ExpandZ; j++)
{
for (int j = 0; j < ExpandZ; j++)
locs.Add(new EMLocation
{
locs.Add(new EMLocation
{
X = Location.X + i * 1024,
Y = Location.Y,
Z = Location.Z + j * 1024,
Room = Location.Room,
Angle = Location.Angle
});
}
X = Location.X + i * 1024,
Y = Location.Y,
Z = Location.Z + j * 1024,
Room = Location.Room,
Angle = Location.Angle
});
}
return locs;
}
return locs;
}
}
}
Loading