Files
lllyasviel 72f9f431f4 first
2017-05-14 16:15:52 +08:00

104 lines
3.1 KiB
C#

using System.Collections.Generic;
using System.IO;
namespace YGOSharp
{
public static class BanlistManager
{
public static List<Banlist> Banlists { get; private set; }
public static void initialize(string fileName)
{
Banlists = new List<Banlist>();
Banlist current = null;
StreamReader reader = new StreamReader(fileName);
while (!reader.EndOfStream)
{
string line = reader.ReadLine();
try
{
if (line == null)
continue;
if (line.StartsWith("#"))
continue;
if (line.StartsWith("!"))
{
current = new Banlist();
current.Name = line.Substring(1, line.Length - 1);
Banlists.Add(current);
continue;
}
if (!line.Contains(" "))
continue;
if (current == null)
continue;
string[] data = line.Split(new char[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries);
int id = int.Parse(data[0]);
int count = int.Parse(data[1]);
current.Add(id, count);
}
catch (System.Exception e)
{
UnityEngine.Debug.Log(line);
UnityEngine.Debug.Log(e);
}
}
current = new Banlist();
current.Name ="N/A";
Banlists.Add(current);
}
public static int GetIndex(uint hash)
{
for (int i = 0; i < Banlists.Count; i++)
if (Banlists[i].Hash == hash)
return i;
return 0;
}
public static string GetName(uint hash)
{
for (int i = 0; i < Banlists.Count; i++)
if (Banlists[i].Hash == hash)
return Banlists[i].Name;
return InterString.Get("未知卡表");
}
public static List<string> getAllName()
{
List<string> returnValue = new List<string>();
foreach (var item in Banlists)
{
returnValue.Add(item.Name);
}
return returnValue;
}
public static Banlist GetByName(string name)
{
Banlist returnValue = Banlists[Banlists.Count - 1];
foreach (var item in Banlists)
{
if (item.Name == name)
{
returnValue = item;
}
}
return returnValue;
}
public static Banlist GetByHash(uint hash)
{
Banlist returnValue = Banlists[Banlists.Count - 1];
foreach (var item in Banlists)
{
if (item.Hash == hash)
{
returnValue = item;
}
}
return returnValue;
}
}
}