Basic (zomg hacked) shellmap script [commit hacked by chrisf to remove 3MB AUD]

This commit is contained in:
Paul Chote
2010-04-09 23:20:18 +12:00
committed by Chris Forbes
parent 0e459877c2
commit 803076caf9
8 changed files with 95 additions and 8 deletions

View File

@@ -135,8 +135,6 @@ namespace OpenRA
SheetBuilder.Initialize(renderer);
LoadModPackages(manifest);
Timer.Time( "load assemblies, packages: {0}" );
Rules.LoadRules(manifest);
Timer.Time( "load rules: {0}" );
Game.packageChangePending = false;
LoadMap(manifest.ShellmapUid);
@@ -157,7 +155,7 @@ namespace OpenRA
world = null; // trying to access the old world will NRE, rather than silently doing it wrong.
ChromeProvider.Initialize(manifest.Chrome);
world = new World(mapName);
world = new World(manifest,mapName);
Timer.Time( "world: {0}" );
SequenceProvider.Initialize(manifest.Sequences);
@@ -170,6 +168,11 @@ namespace OpenRA
Timer.Time( "----end LoadMap" );
Debug("Map change {0} -> {1}".F(Game.mapName, mapName));
}
public static void MoveViewport(int2 loc)
{
viewport.Center(loc);
}
internal static void Initialize(Renderer renderer, int2 clientSize, int localPlayer, Controller controller)
{

View File

@@ -49,12 +49,34 @@ namespace OpenRA
TechTree = new TechTree();
}
static Dictionary<string, T> LoadYamlRules<T>(string[] files, Func<KeyValuePair<string, MiniYaml>, Dictionary<string, MiniYaml>, T> f)
{
var y = files.Select(a => MiniYaml.FromFile(a)).Aggregate(MiniYaml.Merge);
return y.ToDictionary(kv => kv.Key.ToLowerInvariant(), kv => f(kv, y));
}
public static void LoadRules(Manifest m, Map map)
{
Log.Write("Using rules files: ");
foreach (var y in m.Rules)
Log.Write(" -- {0}", y);
Log.Write("Using Map: {0}",map.Uid);
Info = LoadYamlRules(m.Rules, map.Rules, (k, y) => new ActorInfo(k.Key.ToLowerInvariant(), k.Value, y));
Weapons = LoadYamlRules(m.Weapons, map.Weapons, (k, _) => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value));
Voices = LoadYamlRules(m.Voices, map.Voices, (k, _) => new VoiceInfo(k.Value));
TerrainTypes = LoadYamlRules(m.Terrain, map.Terrain, (k, _) => new TerrainCost(k.Value))
.ToDictionary(kv => (TerrainType)Enum.Parse(typeof(TerrainType), kv.Key, true), kv => kv.Value);
TechTree = new TechTree();
}
static Dictionary<string, T> LoadYamlRules<T>(string[] files, Dictionary<string,MiniYaml>dict, Func<KeyValuePair<string, MiniYaml>, Dictionary<string, MiniYaml>, T> f)
{
var y = files.Select(a => MiniYaml.FromFile(a)).Aggregate(dict,MiniYaml.Merge);
return y.ToDictionary(kv => kv.Key.ToLowerInvariant(), kv => f(kv, y));
}
public static IEnumerable<string> Categories()
{

View File

@@ -165,6 +165,11 @@ namespace OpenRA.Graphics
{
return (1 / 24.0f) * (new float2(mi.Location.X, mi.Location.Y) + Location);
}
public void Center(int2 loc)
{
scrollPosition = (Game.CellSize*loc - .5f * new float2(Width, Height)).ToInt2();
}
public void Center(IEnumerable<Actor> actors)
{

View File

@@ -75,7 +75,7 @@ namespace OpenRA
public readonly WorldRenderer WorldRenderer;
internal readonly Minimap Minimap;
public World(string mapUid)
public World(Manifest manifest, string mapUid)
{
Timer.Time( "----World.ctor" );
@@ -83,9 +83,14 @@ namespace OpenRA
throw new InvalidDataException("Cannot find map with Uid {0}".F(mapUid));
Map = new Map( Game.AvailableMaps[mapUid].Package );
customTerrain = new ICustomTerrain[Map.MapSize.X, Map.MapSize.Y];
Timer.Time( "new Map: {0}" );
Rules.LoadRules(manifest,Map);
Timer.Time( "load rules: {0}" );
var theaterInfo = Rules.Info["world"].Traits.WithInterface<TheaterInfo>()
.FirstOrDefault(t => t.Theater == Map.Theater);
TileSet = new TileSet(theaterInfo.Tileset, theaterInfo.Templates, theaterInfo.Suffix);