Move AvailableMaps into ModData

This commit is contained in:
Paul Chote
2010-08-21 20:07:28 +12:00
parent 94dd73cb48
commit 4e2d76f6ed
6 changed files with 27 additions and 52 deletions

View File

@@ -48,29 +48,7 @@ namespace OpenRA
static int2 clientSize;
static string mapName;
public static Session LobbyInfo = new Session();
static bool packageChangePending;
static bool mapChangePending;
public static Dictionary<string, MapStub> AvailableMaps;
// TODO: Do this nicer
static Dictionary<string, MapStub> FindMaps(string[] mods)
{
var paths = new[] { "maps/" }.Concat(mods.Select(m => "mods/" + m + "/maps/"))
.Where(p => Directory.Exists(p))
.SelectMany(p => Directory.GetDirectories(p)).ToList();
return paths.Select(p => new MapStub(new Folder(p))).ToDictionary(m => m.Uid);
}
static void ChangeMods()
{
AvailableMaps = FindMaps(LobbyInfo.GlobalSettings.Mods);
modData = new ModData( LobbyInfo.GlobalSettings.Mods );
ChromeProvider.Initialize( modData.Manifest.Chrome );
}
static void LoadMap(string mapName)
{
@@ -78,10 +56,10 @@ namespace OpenRA
modData = new ModData( LobbyInfo.GlobalSettings.Mods );
Timer.Time("manifest: {0}");
if (!Game.AvailableMaps.ContainsKey(mapName))
if (!modData.AvailableMaps.ContainsKey(mapName))
throw new InvalidDataException("Cannot find map with Uid {0}".F(mapName));
var map = new Map(Game.AvailableMaps[mapName].Package);
var map = new Map(modData.AvailableMaps[mapName].Package);
viewport = new Viewport(clientSize, map.TopLeft, map.BottomRight, Renderer);
world = null; // trying to access the old world will NRE, rather than silently doing it wrong.
@@ -153,14 +131,6 @@ namespace OpenRA
static void Tick()
{
if (packageChangePending)
{
// TODO: Only do this on mod change
ChangeMods();
packageChangePending = false;
return;
}
if (mapChangePending)
{
mapName = LobbyInfo.GlobalSettings.Map;
@@ -224,8 +194,6 @@ namespace OpenRA
internal static void SyncLobbyInfo(string data)
{
var oldLobbyInfo = LobbyInfo;
var session = new Session();
session.GlobalSettings.Mods = Settings.InitialMods;
@@ -265,13 +233,6 @@ namespace OpenRA
if (mapName != LobbyInfo.GlobalSettings.Map)
mapChangePending = true;
if (string.Join(",", oldLobbyInfo.GlobalSettings.Mods)
!= string.Join(",", LobbyInfo.GlobalSettings.Mods))
{
Debug("Mods list changed, reloading: {0}".F(string.Join(",", LobbyInfo.GlobalSettings.Mods)));
packageChangePending = true;
}
LobbyInfoChanged();
}
@@ -386,8 +347,6 @@ namespace OpenRA
PerfHistory.items["text"].hasNormalTick = false;
PerfHistory.items["cursor"].hasNormalTick = false;
ChangeMods();
Renderer = new Renderer();
clientSize = new int2(Renderer.Resolution);

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using System.IO;
namespace OpenRA
{
@@ -13,7 +14,8 @@ namespace OpenRA
public readonly ObjectCreator ObjectCreator;
public readonly SheetBuilder SheetBuilder;
public readonly CursorSheetBuilder CursorSheetBuilder;
public readonly Dictionary<string, MapStub> AvailableMaps;
public ModData( params string[] mods )
{
Manifest = new Manifest( mods );
@@ -21,6 +23,20 @@ namespace OpenRA
FileSystem.LoadFromManifest( Manifest );
SheetBuilder = new SheetBuilder( TextureChannel.Red );
CursorSheetBuilder = new CursorSheetBuilder( this );
ChromeProvider.Initialize( Manifest.Chrome );
AvailableMaps = FindMaps( mods );
}
// TODO: Do this nicer
static Dictionary<string, MapStub> FindMaps(string[] mods)
{
var paths = new[] { "maps/" }.Concat(mods.Select(m => "mods/" + m + "/maps/"))
.Where(p => Directory.Exists(p))
.SelectMany(p => Directory.GetDirectories(p)).ToList();
return paths.Select(p => new MapStub(new Folder(p))).ToDictionary(m => m.Uid);
}
}
}

View File

@@ -33,10 +33,10 @@ namespace OpenRA.Widgets.Delegates
r.OpenWindow("SERVER_LOBBY");
// TODO: Get this from a map chooser
string map = Game.AvailableMaps.Keys.FirstOrDefault();
string map = Game.modData.AvailableMaps.Keys.FirstOrDefault();
// TODO: Get this from a mod chooser
var mods = Game.Settings.InitialMods;
var mods = Game.LobbyInfo.GlobalSettings.Mods;
Game.Settings.LastServerTitle = cs.GetWidget<TextFieldWidget>("GAME_TITLE").Text;
Game.Settings.ListenPort = int.Parse(cs.GetWidget<TextFieldWidget>("LISTEN_PORT").Text);

View File

@@ -209,7 +209,7 @@ namespace OpenRA.Widgets.Delegates
{
if (MapUid == Game.LobbyInfo.GlobalSettings.Map) return;
MapUid = Game.LobbyInfo.GlobalSettings.Map;
Map = Game.AvailableMaps[MapUid];
Map = Game.modData.AvailableMaps[MapUid];
}

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Widgets.Delegates
var itemTemplate = ml.GetWidget<LabelWidget>("MAP_TEMPLATE");
int offset = itemTemplate.Bounds.Y;
foreach (var kv in Game.AvailableMaps)
foreach (var kv in Game.modData.AvailableMaps)
{
var map = kv.Value;
if (!map.Selectable)
@@ -72,9 +72,9 @@ namespace OpenRA.Widgets.Delegates
// Set the default selected map
var uid = uidobj as string;
if (uid != null)
Map = Game.AvailableMaps[uid];
Map = Game.modData.AvailableMaps[uid];
else
Map = Game.AvailableMaps.FirstOrDefault().Value;
Map = Game.modData.AvailableMaps.FirstOrDefault().Value;
}
}
}

View File

@@ -150,8 +150,8 @@ namespace OpenRA.Widgets.Delegates
MapStub CurrentMap()
{
return (currentServer == null || !Game.AvailableMaps.ContainsKey(currentServer.Map))
? null : Game.AvailableMaps[currentServer.Map];
return (currentServer == null || !Game.modData.AvailableMaps.ContainsKey(currentServer.Map))
? null : Game.modData.AvailableMaps[currentServer.Map];
}
void RefreshServerList(IEnumerable<GameServer> games)