walkability, thanks to freera's templates.ini, although it was broken :D
git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1303 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
42
OpenRa.FileFormats/Walkability.cs
Normal file
42
OpenRa.FileFormats/Walkability.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace OpenRa.FileFormats
|
||||
{
|
||||
public class Walkability
|
||||
{
|
||||
const string src = "../../../templates.ini";
|
||||
|
||||
Dictionary<string, Dictionary<int, int>> walkability =
|
||||
new Dictionary<string, Dictionary<int, int>>();
|
||||
|
||||
public Walkability()
|
||||
{
|
||||
IniFile file = new IniFile(File.OpenRead(src));
|
||||
Regex pattern = new Regex(@"tiletype(\d+)");
|
||||
|
||||
foreach (IniSection section in file.Sections)
|
||||
{
|
||||
string name = section.GetValue("Name", null).ToLowerInvariant();
|
||||
|
||||
Dictionary<int, int> tileWalkability = new Dictionary<int, int>();
|
||||
foreach (KeyValuePair<string, string> p in section)
|
||||
{
|
||||
Match m = pattern.Match(p.Key);
|
||||
if (m != null && m.Success)
|
||||
tileWalkability.Add(int.Parse(m.Groups[1].Value), int.Parse(p.Value));
|
||||
}
|
||||
|
||||
walkability[name] = tileWalkability;
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<int, int> GetWalkability(string terrainName)
|
||||
{
|
||||
return walkability[terrainName];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user