git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1131 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
chrisf
2007-07-07 05:50:49 +00:00
parent f69eeb3468
commit 31a9197721
2 changed files with 43 additions and 5 deletions

View File

@@ -1,12 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using OpenRa.FileFormats;
using System.Drawing;
using System.IO;
namespace OpenRa.TechTreeTest
{
class Building
{
readonly string friendlyName;
readonly string tag;
public string FriendlyName
{
@@ -29,9 +33,10 @@ namespace OpenRa.TechTreeTest
set { techLevel = value; }
}
public Building(string friendlyName)
public Building(string tag, string friendlyName)
{
this.friendlyName = friendlyName;
this.tag = tag;
}
public bool ShouldMakeBuildable(IEnumerable<string> buildings)
@@ -62,5 +67,30 @@ namespace OpenRa.TechTreeTest
else if (!buildable && ShouldMakeBuildable(buildings))
buildable = true;
}
Bitmap icon;
public Bitmap Icon
{
get { return icon ?? (icon = LoadIcon(tag)); }
}
static Package package = new Package("../../../hires.mix");
static Palette palette = new Palette( File.OpenRead("../../../temperat.pal"));
static Bitmap LoadIcon(string tag)
{
string filename = tag + "icon.shp";
try
{
Stream s = package.GetContent(filename);
ShpReader reader = new ShpReader(s);
foreach (ImageHeader h in reader)
return BitmapBuilder.FromBytes(h.Image, reader.Width, reader.Height, palette);
return null;
}
catch (FileNotFoundException) { return LoadIcon("dog"); }
}
}
}

View File

@@ -9,8 +9,8 @@ namespace OpenRa.TechTreeTest
{
class TechTree
{
Dictionary<string, Building> buildings = new Dictionary<string,Building>();
List<string> built;
Dictionary<string, Building> buildings = new Dictionary<string, Building>();
public ICollection<string> built = new List<string>();
public TechTree()
{
LoadBuildings();
@@ -38,7 +38,7 @@ namespace OpenRa.TechTreeTest
Regex pattern = new Regex(@"^(\w+),([\w ]+)$");
Match m = pattern.Match(line);
if (!m.Success) continue;
buildings.Add(m.Groups[0].Value, new Building(m.Groups[1].Value));
buildings.Add(m.Groups[1].Value, new Building(m.Groups[1].Value, m.Groups[2].Value));
}
}
@@ -63,8 +63,16 @@ namespace OpenRa.TechTreeTest
void CheckAll()
{
foreach (Building building in buildings.Values)
{
building.CheckPrerequisites(built);
}
public IEnumerable<Building> BuildableItems
{
get
{
foreach (Building b in buildings.Values)
if (b.Buildable)
yield return b;
}
}
}