diff --git a/Assets/rules/spells.2da b/Assets/rules/spells.2da index 0f83265..f4a5909 100644 --- a/Assets/rules/spells.2da +++ b/Assets/rules/spells.2da @@ -1,5 +1,5 @@ -id name description script -1 "veille nocturne" "se rend invincible pendant un tour" **** -2 "coup de crépière" "inflige 25 pv de dégats à un personnage" **** -3 "goulée de cidre" "soigne un personnage de 50 PV" **** -4 "omelette aux champignons" "rend un personnage malade pendant un tour, ne peux ni parler, ni rien faire pendant un tour" **** +id name description script +1 "veille nocturne" "se rend invincible pendant un tour" _ +2 "coup de crépière" "inflige 25 pv de dégats à un personnage" _ +3 "goulée de cidre" "soigne un personnage de 50 PV" _ +4 "omelette aux champignons" "rend un personnage malade pendant un tour, ne peux ni parler, ni rien faire pendant un tour" _ diff --git a/Assets/src/RulesDatabase.cs b/Assets/src/RulesDatabase.cs new file mode 100644 index 0000000..9dba536 --- /dev/null +++ b/Assets/src/RulesDatabase.cs @@ -0,0 +1,50 @@ +using UnityEngine; +using System.IO; +using System.Collections.Generic; + +public class RulesDatabase { + + public static TwoDA GetTable(string name){ + if(Get().m_tables.ContainsKey(name)){ + TwoDA t; + inst.m_tables.TryGetValue(name, out t); + return t; + } + else + return null; + } + + + + + + + private RulesDatabase(){ + m_tables = new Dictionary(); + + string[] files = Directory.GetFiles(m_folder, "*.2da", SearchOption.AllDirectories); + + foreach(string file in files){ + string name = Path.GetFileNameWithoutExtension(file); + m_tables.Add(name, new TwoDA(file)); + Debug.Log ("Found "+name); + } + + } + + + private static RulesDatabase inst = null; + private static object syncRoot = new Object(); + private static RulesDatabase Get(){ + lock(syncRoot){ + if(inst==null) + inst = new RulesDatabase(); + } + return inst; + } + + private Dictionary m_tables; + private string m_folder = "Assets/rules"; + + +} diff --git a/Assets/src/RulesDatabase.cs.meta b/Assets/src/RulesDatabase.cs.meta new file mode 100644 index 0000000..11261b0 --- /dev/null +++ b/Assets/src/RulesDatabase.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e6f28bb3bcb18384c92e7fda30dcda32 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/src/TwoDA.cs b/Assets/src/TwoDA.cs index 51cac2c..082af2e 100644 --- a/Assets/src/TwoDA.cs +++ b/Assets/src/TwoDA.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text.RegularExpressions; -public class TwoDA : Object { +public class TwoDA : UnityEngine.Object { public TwoDA(string filepath) { @@ -10,7 +10,7 @@ public class TwoDA : Object { System.IO.StreamReader file = new System.IO.StreamReader(filepath); string line = file.ReadLine(); - m_header = line.Split(); + m_header = line.Split((string[])null, System.StringSplitOptions.RemoveEmptyEntries); int nCols = m_header.Length; m_data = new List(); @@ -37,7 +37,7 @@ public class TwoDA : Object { m_data.Add(buff); } else - Debug.LogWarning(filepath+":"+nFileLine.ToString()+" ignored. Found "+matches.Count.ToString()+" columns instead of "+nCols.ToString()); + Debug.LogWarning(filepath+": line "+nFileLine.ToString()+" ignored. Found "+matches.Count.ToString()+" columns instead of "+nCols.ToString()); }