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")); }
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");
this.Role = GetRole(role);
}
catch { this.LoadFailedMessage("Role"); }
}
#endregion
#region Networking Methods

View file

@ -74,12 +74,17 @@ namespace MudEngine.Game.Environment
try { this.Filename = this.SaveData.GetData("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");
this.RequiredRole = CharacterRole.GetRole(role);
}
catch { this.LoadFailedMessage("RequiredRole"); }
}
public void Update()
{

View file

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

View file

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