Began work on Environment save code.

Restructured the project save data folder layout when the engine starts.
The XMLData class now creates directories if they are missing.  Individual classes no longer need to check if a path is valid before saving.
Filenames are now automatically generated and no longer assigned by developers.  This change has been made across all classes that are savable which required some changing of the Save() method arguments.
This commit is contained in:
Scionwest_cp 2012-03-10 20:47:12 -08:00
parent a6d346da3d
commit ee3cd897f2
12 changed files with 101 additions and 28 deletions

View file

@ -86,7 +86,7 @@ namespace MudEngine.GameScripts.Commands
character.Move(game.World.StartLocation);
//TODO: Create a class and setup Stats.
character.Save(character.Filename, false);
character.Save(false);
}
catch (Exception ex)
{

View file

@ -18,6 +18,14 @@ namespace MudEngine.GameScripts
[DefaultValue("Scripted Object")]
public String Name { get; set; }
public String Filename
{
get
{
return Path.Combine(this.Game.SavePaths.GetPath(DataTypes.Root), this.Name + "." + this.Game.SavePaths.GetExtension(DataTypes.Root));
}
}
public String ID { get; set; }
public String Description { get; set; }
@ -37,15 +45,15 @@ namespace MudEngine.GameScripts
this.SaveData = new XMLData(this.GetType().Name);
}
public virtual Boolean Save(String filename)
public virtual Boolean Save()
{
return this.Save(filename, false);
return this.Save(false);
}
public virtual Boolean Save(String filename, Boolean ignoreFileWrite)
public virtual Boolean Save(Boolean ignoreFileWrite)
{
if (File.Exists(filename))
File.Delete(filename);
if (File.Exists(this.Filename))
File.Delete(this.Filename);
try
{
@ -55,7 +63,7 @@ namespace MudEngine.GameScripts
this.SaveData.AddSaveData("Description", Description);
if (!ignoreFileWrite)
this.SaveData.Save(filename);
this.SaveData.Save(this.Filename);
}
catch
{

View file

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using MudEngine.Game;
using MudEngine.DAL;
using MudEngine.Game.Environment;
using MudEngine.Game;
@ -24,6 +23,7 @@ namespace MudEngine.GameScripts
public override Boolean Start(Int32 maxPlayers, Int32 maxQueueSize)
{
this.Server.ServerOwner = "Admin";
base.Start(maxPlayers, maxQueueSize);
//Quick demonstration on how to create the initial starting room for new players.
this.World.CreateRealm("Azeroth", "Starting Realm for beginning players");
@ -43,6 +43,7 @@ namespace MudEngine.GameScripts
if (startOK && linked)
{
this.World.StartLocation = bedroom;
this.World.Save();
return true;
}
//Otherwise return false and prevent the game from running.