All of the classes that currently perform Save/Load operations now log when a Property failed to be loaded correctly.

This commit is contained in:
Scionwest_cp 2012-03-10 19:48:41 -08:00
parent 32210124e0
commit a6d346da3d
5 changed files with 28 additions and 49 deletions

View file

@ -1,27 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MudEngine.Game;
namespace MudEngine.Game.Characters
{
class MyCharacter : StandardCharacter
{
public int Age { get; set; }
public MyCharacter(StandardGame game, String name, String desc)
: base(game, name, desc)
{
}
public override bool Save(string filename)
{
base.Save(filename, true);
this.SaveData.AddSaveData("Age", Age.ToString());
return this.SaveData.Save(filename);
}
}
}

View file

@ -167,12 +167,17 @@ namespace MudEngine.Game.Characters
try { this.Immovable = Convert.ToBoolean(this.SaveData.GetData("Immovable")); } try { this.Immovable = Convert.ToBoolean(this.SaveData.GetData("Immovable")); }
catch { this.LoadFailedMessage("Immovable"); } catch { this.LoadFailedMessage("Immovable"); }
this.Password = this.SaveData.GetData("Password"); try { this.Password = this.SaveData.GetData("Password"); }
catch { this.LoadFailedMessage("Password"); }
try
{
String role = this.SaveData.GetData("Role"); String role = this.SaveData.GetData("Role");
this.Role = GetRole(role); this.Role = GetRole(role);
} }
catch { this.LoadFailedMessage("Role"); }
}
#endregion #endregion
#region Networking Methods #region Networking Methods

View file

@ -74,12 +74,17 @@ namespace MudEngine.Game.Environment
try { this.Filename = this.SaveData.GetData("Filename"); } try { this.Filename = this.SaveData.GetData("Filename"); }
catch { LoadFailedMessage("Filename"); } catch { LoadFailedMessage("Filename"); }
this.Enabled = Convert.ToBoolean(this.SaveData.GetData("Enabled")); try { this.Enabled = Convert.ToBoolean(this.SaveData.GetData("Enabled")); }
catch { this.LoadFailedMessage("Enabled");}
try
{
String role = this.SaveData.GetData("RequiredRole"); String role = this.SaveData.GetData("RequiredRole");
this.RequiredRole = CharacterRole.GetRole(role); this.RequiredRole = CharacterRole.GetRole(role);
} }
catch { this.LoadFailedMessage("RequiredRole"); }
}
public void Update() public void Update()
{ {

View file

@ -66,23 +66,20 @@ namespace MudEngine.GameScripts
} }
public virtual void Load(String filename) public virtual void Load(String filename)
{
try
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))
return; return;
this.SaveData.Load(filename); this.SaveData.Load(filename);
this.Name = this.SaveData.GetData("Name"); try { this.Name = this.SaveData.GetData("Name"); }
this.ID = this.SaveData.GetData("ID"); catch { this.LoadFailedMessage("Name"); }
this.Description = this.SaveData.GetData("Description");
} try { this.ID = this.SaveData.GetData("ID"); }
catch (Exception ex) catch { this.LoadFailedMessage("ID"); }
{
Logger.WriteLine(ex.Message); try { this.Description = this.SaveData.GetData("Description"); }
return; catch { this.LoadFailedMessage("Description"); }
}
return;
} }
public void LoadFailedMessage(String property) public void LoadFailedMessage(String property)

View file

@ -78,7 +78,6 @@
</None> </None>
<Compile Include="Game\Characters\CharacterRoles.cs" /> <Compile Include="Game\Characters\CharacterRoles.cs" />
<Compile Include="Game\Characters\CharacterStats.cs" /> <Compile Include="Game\Characters\CharacterStats.cs" />
<Compile Include="Game\Characters\MyCharacter.cs" />
<Compile Include="Game\Characters\StandardCharacter.cs" /> <Compile Include="Game\Characters\StandardCharacter.cs" />
<Compile Include="GameScripts\BaseScript.cs" /> <Compile Include="GameScripts\BaseScript.cs" />
<Compile Include="Game\Environment\Doorway.cs" /> <Compile Include="Game\Environment\Doorway.cs" />