MudEngine:

- BaseObject Saving and Loading fully implemented.
 - BaseCharacter Saving and Loading fully implemented.
 - Game.cs now contains SaveDataPaths property for allowing users to define where their data will be saved.
 -
This commit is contained in:
Scionwest_cp 2010-07-30 19:02:05 -07:00
parent 7f39821216
commit 4be5a831b1
8 changed files with 137 additions and 125 deletions

View file

@ -19,37 +19,17 @@ namespace MudEngine.GameObjects
[Description("The Display Name assigned to this object.")]
//Required to refresh Filename property in the editors propertygrid
[RefreshProperties(RefreshProperties.All)]
public string Name
{
get
{
return this._Name;
}
set
{
this._Name = value;
this.Filename = value + "." + this.GetType().Name;
}
}
public string Name { get; set; }
[Category("Object Setup")]
[Description("A brief description of this object. The description is displayed to users when they use a command for investigating an object")]
public string Description
{
get;
set;
}
public string Description { get; set; }
/// <summary>
/// A detailed description that treats each entry as a seperete line when outputted to the player
/// </summary>
public List<string> DetailedDescription { get; set; }
[Category("Object Setup")]
[Description("The object script that can manipulate the object during the games life.")]
//[EditorAttribute(typeof(UIScriptEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string Script { get; set; }
[Category("Object Setup")]
[ReadOnly(true)]
[Description("The filename of the current object. This is assigned by the engine and not editable.")]
@ -59,60 +39,47 @@ namespace MudEngine.GameObjects
//Filenames are generated by the class itself, users can not assign it.
get
{
return this._Filename;
}
set
{
string extension = "." + this.GetType().Name;
if (extension.StartsWith("Base"))
extension = extension.Substring("Base".Length);
if (!value.EndsWith(extension))
value += extension;
this._Filename = value;
if (this.GetType().Name.StartsWith("Base"))
{
return this.Name + "." + GetType().Name.Substring("Base".Length);
}
else
return this.Name + "." + GetType().Name;
}
}
[Category("Environment Information")]
[Description("If a user asks to use his/her senses to investigate an area, this is one of the results that will be displayed. Senses can be used to assist blind characters.")]
[DefaultValue("You don't smell anything unsual.")]
public string Smell
{
get;
set;
}
public string Smell { get; set; }
[Category("Environment Information")]
[Description("If a user asks to use his/her senses to investigate an area, this is one of the results that will be displayed. Senses can be used to assist blind characters.")]
[DefaultValue("You hear nothing of interest.")]
public string Listen
{
get;
set;
}
public string Listen { get; set; }
[Category("Environment Information")]
[Description("If a user asks to use his/her senses to investigate an area, this is one of the results that will be displayed. Senses can be used to assist blind characters.")]
[DefaultValue("You feel nothing.")]
public string Feel
{
get;
set;
}
public string Feel { get; set; }
private string _Filename = "";
private string _Name = "";
internal Game ActiveGame { get; set; }
public Game ActiveGame { get; set; }
/// <summary>
/// used for serialization only.
/// </summary>
internal BaseObject()
{
}
/// <summary>
/// Initializes the base object
/// </summary>
public BaseObject(Game game)
{
Script = "";
_Name = "New " + this.GetType().Name;
_Filename = _Name + "." + this.GetType().Name;
Name = "New " + this.GetType().Name;
ActiveGame = game;
DetailedDescription = new List<string>();
this.Feel = "You feel nothing.";
this.Listen = "You hear nothing of interest.";
@ -136,35 +103,6 @@ namespace MudEngine.GameObjects
}
#region Public Methods
/// <summary>
/// Loads the supplied filename and returns it.
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public virtual object Load(string filename)
{
if (!File.Exists(filename))
{
return null;
}
return FileManager.Load(filename, this);
}
/// <summary>
/// Saves the current object with the supplied filename
/// </summary>
/// <param name="filename"></param>
public void Save()
{
string directory = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Root), "Saved", "Players");
if (!Directory.Exists(directory))
Directory.CreateDirectory(directory);
FileManager.Save(Filename, this);
}
public override string ToString()
{
return this.Name;
@ -201,6 +139,32 @@ namespace MudEngine.GameObjects
public virtual void OnDismount()
{
}
public virtual void Save(string filename)
{
string path = Path.GetDirectoryName(filename);
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
if (File.Exists(filename))
File.Delete(filename);
FileManager.WriteLine(filename, this.Name, "Name");
FileManager.WriteLine(filename, this.Description, "Description");
FileManager.WriteLine(filename, this.Feel, "Feel");
FileManager.WriteLine(filename, this.Listen, "Listen");
FileManager.WriteLine(filename, this.Smell, "Smell");
}
public virtual void Load(string filename)
{
this.Name = FileManager.GetData(filename, "Name");
this.Description = FileManager.GetData(filename, "Description");
this.Feel = FileManager.GetData(filename, "Feel");
this.Listen = FileManager.GetData(filename, "Listen");
this.Smell = FileManager.GetData(filename, "Smell");
}
#endregion
}
}