Designer:

- Corrected Project Information not being displayed when loaded for editing
 - Re-wrote Designer Save code to use the objects save code instead of FileManager. Resulted in 26% less code and cleaner source.
 - Project Explorer now checks Saved State of currently loaded object just like the Right-Click->Edit Object menu item does.

Engine:
 - ProjectInformation.Save() now implemented.
 - BaseObject.Save() now implemented. All objects inheriting from BaseObject can save itself. Including all Environment objects (Realms,Zones, Rooms) and Currency objects.
This commit is contained in:
Scionwest_cp 2010-01-18 21:31:47 -08:00
parent 42e6fef109
commit a98e2bc069
3 changed files with 52 additions and 49 deletions

View file

@ -64,6 +64,7 @@ namespace MudDesigner
//ensure the path exists //ensure the path exists
ValidatePath(projectPath); ValidatePath(projectPath);
//Display the Project directory structure in the Project Explorer
RefreshProjectExplorer(); RefreshProjectExplorer();
} }
@ -144,6 +145,7 @@ namespace MudDesigner
//Project Information file //Project Information file
case ObjectType.Project: case ObjectType.Project:
_Project = (ProjectInformation)_Project.Load(FileManager.GetDataPath(SaveDataTypes.Root)); _Project = (ProjectInformation)_Project.Load(FileManager.GetDataPath(SaveDataTypes.Root));
propertyObject.SelectedObject = _Project;
break; break;
//Currency File //Currency File
case ObjectType.Currency: case ObjectType.Currency:
@ -285,60 +287,43 @@ namespace MudDesigner
public void SaveSelected() public void SaveSelected()
{ {
//Get the object Type
Type t = propertyObject.SelectedObject.GetType();
//We can use to get a copy of the currently selected object //We can use to get a copy of the currently selected object
//if it is a BaseObject (Aquire it's BaseObject.Filename) //if it is a BaseObject (Aquire it's BaseObject.Filename)
var obj = new BaseObject(); var obj = (BaseObject)propertyObject.SelectedObject;
//Filepaths //Filepaths
string projectPath = Path.Combine(Application.StartupPath, "Project");
string objectPath = ""; string objectPath = "";
string filename = ""; string filename = "";
//Start checking to see what object we are saving switch (obj.GetType().Name)
if (t == typeof(ProjectInformation))
{ {
filename = Path.Combine(projectPath, "Game.xml"); case "ProjectInformation":
FileManager.Save(filename, _Project); filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Root), "Game.xml");
} _Project.Save(filename);
else if (t == typeof(Currency)) break;
{ case "Currency":
obj = (Currency)propertyObject.SelectedObject; filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Currencies), obj.Filename);
objectPath = Path.Combine(projectPath, "Currencies"); obj.Save(filename);
ValidatePath(objectPath); break;
filename = Path.Combine(objectPath, obj.Filename); case "Realm":
FileManager.Save(filename, obj); filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), obj.Filename);
} obj.Save(filename);
else if (t == typeof(Realm)) break;
{ case "Zone":
obj = (Realm)propertyObject.SelectedObject; Zone z = new Zone();
objectPath = Path.Combine(projectPath, "Realms"); z = (Zone)obj;
objectPath = Path.Combine(objectPath, obj.Name); if (String.IsNullOrEmpty(z.Realm))
filename = Path.Combine(objectPath, obj.Filename); {
objectPath = Path.Combine(objectPath, "Zones"); objectPath = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Zones), z.Name);
ValidatePath(objectPath); filename = Path.Combine(objectPath, z.Filename);
FileManager.Save(filename, obj); }
} else
else if (t == typeof(Zone)) {
{ objectPath = FileManager.GetDataPath(z.Realm, z.Name);
Zone zone = (Zone)propertyObject.SelectedObject; filename = Path.Combine(objectPath, z.Filename);
if (string.IsNullOrEmpty(zone.Realm)) }
{ obj.Save(filename);
objectPath = Path.Combine(projectPath, "Zones"); break;
objectPath = Path.Combine(objectPath, zone.Name);
}
else
{
objectPath = Path.Combine(projectPath, "Realms");
objectPath = Path.Combine(objectPath, zone.Realm);
objectPath = Path.Combine(objectPath, "Zones");
objectPath = Path.Combine(objectPath, zone.Name);
filename = Path.Combine(objectPath, zone.Filename);
}
ValidatePath(objectPath);
filename = Path.Combine(objectPath, zone.Filename);
FileManager.Save(filename, zone);
} }
RefreshProjectExplorer(); RefreshProjectExplorer();
@ -569,9 +554,8 @@ namespace MudDesigner
private void treeExplorer_DoubleClick(object sender, EventArgs e) private void treeExplorer_DoubleClick(object sender, EventArgs e)
{ {
if (treeExplorer.SelectedNode.Text == "Project") if (CheckSavedState())
return; LoadObject(treeExplorer.SelectedNode);
mnuEditObject_Click(sender, e);
} }
private void mnuNewRoom_Click(object sender, EventArgs e) private void mnuNewRoom_Click(object sender, EventArgs e)

View file

@ -146,6 +146,12 @@ namespace MudDesigner.MudEngine.GameManagement
public void Save(string filename) public void Save(string filename)
{ {
string directory = Path.GetDirectoryName(filename);
if (!Directory.Exists(directory))
Directory.CreateDirectory(directory);
FileManager.Save(filename, this);
} }
public object Load(string path) public object Load(string path)

View file

@ -159,6 +159,11 @@ namespace MudDesigner.MudEngine.GameObjects
#endregion #endregion
#region Public Methods #region Public Methods
/// <summary>
/// Loads the supplied filename and returns it.
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public object Load(string filename) public object Load(string filename)
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))
@ -169,8 +174,16 @@ namespace MudDesigner.MudEngine.GameObjects
return FileManager.Load(filename, this); return FileManager.Load(filename, this);
} }
/// <summary>
/// Saves the current object with the supplied filename
/// </summary>
/// <param name="filename"></param>
public void Save(string filename) public void Save(string filename)
{ {
string directory = Path.GetDirectoryName(filename);
if (!Directory.Exists(directory))
Directory.CreateDirectory(directory);
FileManager.Save(filename, this);
} }
public override string ToString() public override string ToString()
{ {