akadoc/Assets/src/RulesDatabase.cs

62 lines
1.2 KiB
C#
Raw Normal View History

using UnityEngine;
using System.IO;
using System.Collections.Generic;
public class RulesDatabase {
2015-03-04 14:03:15 +00:00
public static TwoDA GetTable(string name) {
2014-11-15 15:36:30 +00:00
TwoDA t = null;
2015-03-04 14:03:15 +00:00
if(Get().m_tables.TryGetValue(name, out t)) {
return t;
}
else
return null;
}
2015-03-04 14:03:15 +00:00
public static void SetLocale(string lang) {
m_inst.m_strref = GetTable("locale_"+lang);
}
2015-03-04 14:03:15 +00:00
public static string GetStrRef(int strref) {
RulesDatabase inst = Get();
return inst.m_strref.GetValue(strref, "text");
}
2015-03-04 14:03:15 +00:00
private RulesDatabase() {
m_tables = new Dictionary<string, TwoDA>();
string[] files = Directory.GetFiles(m_folder, "*.2da", SearchOption.AllDirectories);
2015-03-04 14:03:15 +00:00
foreach(string file in files) {
string name = Path.GetFileNameWithoutExtension(file);
m_tables.Add(name, new TwoDA(file));
2014-11-15 15:36:30 +00:00
//Debug.Log ("Found "+name);
}
//Set default locale table
m_tables.TryGetValue("locale_fr", out m_strref);
}
2015-03-04 14:03:15 +00:00
private static RulesDatabase m_inst = null;
private static object m_singlmutex = new Object();
2015-03-04 14:03:15 +00:00
private static RulesDatabase Get() {
lock(m_singlmutex) {
if(m_inst==null)
m_inst = new RulesDatabase();
}
return m_inst;
}
private Dictionary<string, TwoDA> m_tables;
private TwoDA m_strref = null;
private string m_folder = "Assets/rules";
}