Skip to content

Commit

Permalink
Fix FileFormats/bin gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltris committed May 14, 2018
1 parent 73db6c1 commit b36a5e1
Show file tree
Hide file tree
Showing 4 changed files with 1,935 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ bld/
[Oo]bj/
[Ll]og/

!Lotd/FileFormats/[Bb]in

# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
Expand Down
59 changes: 59 additions & 0 deletions Lotd/FileFormats/bin/CardLimits.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Lotd.FileFormats
{
/// <summary>
/// Holds limited / banned card information (pd_limits.bin)
/// </summary>
public class CardLimits : FileData
{
public HashSet<short> Forbidden { get; private set; }
public HashSet<short> Limited { get; private set; }
public HashSet<short> SemiLimited { get; private set; }

public CardLimits()
{
Forbidden = new HashSet<short>();
Limited = new HashSet<short>();
SemiLimited = new HashSet<short>();
}

public override void Load(BinaryReader reader, long length)
{
ReadCardIds(reader, Forbidden);
ReadCardIds(reader, Limited);
ReadCardIds(reader, SemiLimited);
}

public override void Save(BinaryWriter writer)
{
WriteCardIds(writer, Forbidden);
WriteCardIds(writer, Limited);
WriteCardIds(writer, SemiLimited);
}

private void ReadCardIds(BinaryReader reader, HashSet<short> cardIds)
{
cardIds.Clear();

short count = reader.ReadInt16();
for (int i = 0; i < count; i++)
{
cardIds.Add(reader.ReadInt16());
}
}

private void WriteCardIds(BinaryWriter writer, HashSet<short> cardIds)
{
writer.Write((short)cardIds.Count);
foreach (ushort cardId in cardIds)
{
writer.Write(cardId);
}
}
}
}
Loading

0 comments on commit b36a5e1

Please sign in to comment.