make (some) RALint errors nonfatal

This commit is contained in:
Chris Forbes
2010-07-30 08:35:38 +12:00
parent aba9942a85
commit 5d1ee145e1
2 changed files with 11 additions and 2 deletions

View File

@@ -81,6 +81,9 @@ namespace OpenRA
ModAssemblies = asms.ToArray(); ModAssemblies = asms.ToArray();
} }
public static Action<string> MissingTypeAction =
s => { throw new InvalidOperationException("Cannot locate type: {0}".F(s)); };
public static T CreateObject<T>(string classname) public static T CreateObject<T>(string classname)
{ {
foreach (var mod in ModAssemblies) foreach (var mod in ModAssemblies)
@@ -91,7 +94,8 @@ namespace OpenRA
return (T)obj; return (T)obj;
} }
throw new InvalidOperationException("Cannot locate type: {0}".F(classname)); MissingTypeAction(classname);
return default(T);
} }
public static Dictionary<string, MapStub> AvailableMaps; public static Dictionary<string, MapStub> AvailableMaps;

View File

@@ -15,6 +15,7 @@ using System.Reflection;
using OpenRA; using OpenRA;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.FileFormats;
namespace RALint namespace RALint
{ {
@@ -32,6 +33,10 @@ namespace RALint
static int Main(string[] args) static int Main(string[] args)
{ {
// bind some nonfatal error handling into FieldLoader, so we don't just *explode*.
Game.MissingTypeAction = s => EmitError("Missing Type: {0}".F(s));
FieldLoader.UnknownFieldAction = (s, f) => EmitError("FieldLoader: Missing field `{0}` on `{1}`".F(s, f.Name));
Game.InitializeEngineWithMods(args); Game.InitializeEngineWithMods(args);
// all the @something names which actually EXIST. // all the @something names which actually EXIST.