Amélioration chargement 2DA & database qui charge automatiquement tous les 2DA
This commit is contained in:
parent
fc5e9b7bd2
commit
8bfb5974d5
|
@ -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" _
|
||||
|
|
|
@ -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, TwoDA>();
|
||||
|
||||
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<string, TwoDA> m_tables;
|
||||
private string m_folder = "Assets/rules";
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e6f28bb3bcb18384c92e7fda30dcda32
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -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<string[]>();
|
||||
|
@ -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());
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue