BaseScript now has a method for reporting failed Script.Load() method invocations. It will log the class name and property field if used correctly.

Some classes have some protection in place now in the event the class attempts to load a property that does not exist in the save file.
CommandSystem instances now use their instanced CommandCollection property instead of the static class property.
This commit is contained in:
Scionwest_cp 2012-03-10 16:08:02 -08:00
parent 9b475691d5
commit f5cf0c1f6a
4 changed files with 17 additions and 5 deletions

View file

@ -105,13 +105,13 @@ namespace MudEngine.Core
string key = command.Insert(0, "Command"); string key = command.Insert(0, "Command");
//Loop through each Key in the Commands collection //Loop through each Key in the Commands collection
foreach (string k in CommandSystem.Commands.Keys) foreach (string k in this.CommandCollection.Keys)
{ {
//Check to see if the Key (Command Name) matches the Command we are looking for. //Check to see if the Key (Command Name) matches the Command we are looking for.
if (key.ToLower().Contains(k.ToLower())) if (key.ToLower().Contains(k.ToLower()))
{ {
//Grab a reference to the Command //Grab a reference to the Command
ICommand cmd = CommandSystem.Commands[k]; ICommand cmd = this.CommandCollection[k];
try try
{ {
//Execute the command //Execute the command
@ -120,7 +120,6 @@ namespace MudEngine.Core
catch (Exception ex) catch (Exception ex)
{ {
Logger.WriteLine("Error: " + ex.Message); Logger.WriteLine("Error: " + ex.Message);
Console.WriteLine("Error: " + ex.Message);
} }
} }
} }

View file

@ -164,7 +164,9 @@ namespace MudEngine.Game.Characters
{ {
base.Load(filename); base.Load(filename);
this.Immovable = Convert.ToBoolean(this.SaveData.GetData("Immovable")); try { this.Immovable = Convert.ToBoolean(this.SaveData.GetData("Immovable")); }
catch { this.LoadFailedMessage("Immovable"); }
this.Password = this.SaveData.GetData("Password"); this.Password = this.SaveData.GetData("Password");
String role = this.SaveData.GetData("Role"); String role = this.SaveData.GetData("Role");

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using MudEngine.Core;
using MudEngine.Core.Interfaces; using MudEngine.Core.Interfaces;
using MudEngine.Game.Characters; using MudEngine.Game.Characters;
using MudEngine.Game; using MudEngine.Game;
@ -70,7 +71,9 @@ namespace MudEngine.Game.Environment
{ {
base.Load(filename); base.Load(filename);
this.Filename = this.SaveData.GetData("Filename"); try { this.Filename = this.SaveData.GetData("Filename"); }
catch { LoadFailedMessage("Filename"); }
this.Enabled = Convert.ToBoolean(this.SaveData.GetData("Enabled")); this.Enabled = Convert.ToBoolean(this.SaveData.GetData("Enabled"));
String role = this.SaveData.GetData("RequiredRole"); String role = this.SaveData.GetData("RequiredRole");

View file

@ -5,6 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Xml.Linq; using System.Xml.Linq;
using System.IO; using System.IO;
using System.Diagnostics;
using MudEngine.Game; using MudEngine.Game;
using MudEngine.DAL; using MudEngine.DAL;
@ -84,6 +85,13 @@ namespace MudEngine.GameScripts
return; return;
} }
public void LoadFailedMessage(String property)
{
StackTrace trace = new StackTrace();
String callingType = trace.GetFrame(1).GetMethod().ReflectedType.Name;
Logger.WriteLine("Load failed for " + callingType + "." + property);
}
public override string ToString() public override string ToString()
{ {
if (String.IsNullOrEmpty(this.Name)) if (String.IsNullOrEmpty(this.Name))