diff --git a/Assets/rules/test.2da b/Assets/rules/test.2da index 1b4430f..d331a76 100644 --- a/Assets/rules/test.2da +++ b/Assets/rules/test.2da @@ -1,3 +1,4 @@ id name value -0 test0 testvalue0 -1 test1 testvalue1 \ No newline at end of file +0 test testvalue0 +1 test1 testvalue1 +2 "Test Multiword" "Ddeedz fdes s fesq qs g sfddtrs" \ No newline at end of file diff --git a/Assets/src/TwoDA.cs b/Assets/src/TwoDA.cs index c2c8eb5..51cac2c 100644 --- a/Assets/src/TwoDA.cs +++ b/Assets/src/TwoDA.cs @@ -1,70 +1,80 @@ using UnityEngine; -using System.Collections; +using System.Collections.Generic; +using System.Text.RegularExpressions; public class TwoDA : Object { - + public TwoDA(string filepath) { - + // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(filepath); - + string line = file.ReadLine(); m_header = line.Split(); int nCols = m_header.Length; - m_data = new string[100, nCols-1];//TODO: make this array dynamic instead of 100 + m_data = new List(); int nFileLine = 1; while((line = file.ReadLine()) != null) { if(line[0] != '#'){//Ignore commented lines - string[] linedata = line.Split(); - if(linedata.Length == nCols){ - int nLine = int.Parse(linedata[0]); - + + MatchCollection matches = m_rgxField.Matches(line); + + if(matches.Count == nCols){ + int nLine = int.Parse(matches[0].Value); + + string[] buff = new string[nCols-1]; for(int i=0 ; i=0){ - return m_data[nRow, nCol]; + return m_data[nRow][nCol]; } else{ throw new UnityException("Column '"+sColumn+"' not found in 2DA"); } - + } - + public override string ToString(){ string sMsg = ""; foreach(string s in m_header){ sMsg += s+"\t"; } sMsg += "\n"; - for(int line=0 ; line m_data; +} \ No newline at end of file