Skip to content

Commit

Permalink
Add ChunkIgnore attribute and obsolete LightTable2 property
Browse files Browse the repository at this point in the history
  • Loading branch information
Luzifix committed Jul 15, 2024
1 parent d40e5d0 commit 3ae6dad
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
8 changes: 7 additions & 1 deletion Warcraft.NET/Attribute/ChunkAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public ChunkOptionalAttribute(bool optional = true)
public bool Optional { get { return optional_; } }
}


[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
public sealed class ChunkArrayAttribute : System.Attribute
{
Expand All @@ -39,4 +38,11 @@ public ChunkArrayAttribute([CallerLineNumber]int length = 0)

public int Length { get { return length; } }
}

[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
public sealed class ChunkIgnoreAttribute : System.Attribute
{
private readonly bool optional_;

Check warning on line 45 in Warcraft.NET/Attribute/ChunkAttributes.cs

View workflow job for this annotation

GitHub Actions / tests

The field 'ChunkIgnoreAttribute.optional_' is never used

Check warning on line 45 in Warcraft.NET/Attribute/ChunkAttributes.cs

View workflow job for this annotation

GitHub Actions / tests

The field 'ChunkIgnoreAttribute.optional_' is never used
public ChunkIgnoreAttribute() { }
}
}
18 changes: 10 additions & 8 deletions Warcraft.NET/Files/ChunkedFile.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Warcraft.NET.Attribute;
using Warcraft.NET.Exceptions;
using Warcraft.NET.Extensions;
using Warcraft.NET.Files.Interfaces;
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System;
using Warcraft.NET.Attribute;
using Warcraft.NET.Exceptions;
using Warcraft.NET.Extensions;
using Warcraft.NET.Files.Interfaces;

namespace Warcraft.NET.Files
{
Expand Down Expand Up @@ -40,11 +40,12 @@ public void LoadBinaryData(byte[] inData)
using (var ms = new MemoryStream(inData))
using (var br = new BinaryReader(ms))
{
var terrainChunkProperties = GetType()
var chunkProperties = GetType()
.GetProperties()
.Where(p => (ChunkIgnoreAttribute)p.GetCustomAttribute(typeof(ChunkIgnoreAttribute), false) == null)
.OrderBy(p => ((ChunkOrderAttribute)p.GetCustomAttributes(typeof(ChunkOrderAttribute), false).Single()).Order);

foreach (PropertyInfo chunkProperty in terrainChunkProperties)
foreach (PropertyInfo chunkProperty in chunkProperties)
{
try
{
Expand Down Expand Up @@ -113,6 +114,7 @@ public byte[] Serialize(long offset = 0)
{
var terrainChunkProperties = GetType()
.GetProperties()
.Where(p => (ChunkIgnoreAttribute)p.GetCustomAttribute(typeof(ChunkIgnoreAttribute), false) == null)
.OrderBy(p => ((ChunkOrderAttribute)p.GetCustomAttributes(typeof(ChunkOrderAttribute), false).Single()).Order);

foreach (PropertyInfo chunkPropertie in terrainChunkProperties)
Expand Down Expand Up @@ -156,7 +158,7 @@ public byte[] Serialize(long offset = 0)
return ms.ToArray();
}
}

public virtual bool IsReverseSignature()
{
return true;
Expand Down
9 changes: 8 additions & 1 deletion Warcraft.NET/Files/WDT/Light/Legion/WorldLightTable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Warcraft.NET.Attribute;
using System;
using Warcraft.NET.Attribute;
using Warcraft.NET.Files.WDT.Chunks.Legion;
using WorldLightTableWoD = Warcraft.NET.Files.WDT.Light.WoD.WorldLightTable;

Expand All @@ -12,6 +13,12 @@ public class WorldLightTable : WorldLightTableWoD
[ChunkOrder(2), ChunkOptional]
public MPL2 PointLights2 { get; set; }

/// <summary>
/// (Obsolete) Legion Point Light Table
/// </summary>
[ChunkIgnore, Obsolete("Use PointLights2 instead.")]
public MPL2 LightTable2 { get { return PointLights2; } set { PointLights2 = value; } }

/// <summary>
/// Texture FileDataIDs
/// </summary>
Expand Down

0 comments on commit 3ae6dad

Please sign in to comment.