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:
parent
42e6fef109
commit
a98e2bc069
3 changed files with 52 additions and 49 deletions
|
@ -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":
|
||||||
|
filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Currencies), obj.Filename);
|
||||||
|
obj.Save(filename);
|
||||||
|
break;
|
||||||
|
case "Realm":
|
||||||
|
filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Realms), obj.Filename);
|
||||||
|
obj.Save(filename);
|
||||||
|
break;
|
||||||
|
case "Zone":
|
||||||
|
Zone z = new Zone();
|
||||||
|
z = (Zone)obj;
|
||||||
|
if (String.IsNullOrEmpty(z.Realm))
|
||||||
{
|
{
|
||||||
obj = (Currency)propertyObject.SelectedObject;
|
objectPath = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Zones), z.Name);
|
||||||
objectPath = Path.Combine(projectPath, "Currencies");
|
filename = Path.Combine(objectPath, z.Filename);
|
||||||
ValidatePath(objectPath);
|
|
||||||
filename = Path.Combine(objectPath, obj.Filename);
|
|
||||||
FileManager.Save(filename, obj);
|
|
||||||
}
|
|
||||||
else if (t == typeof(Realm))
|
|
||||||
{
|
|
||||||
obj = (Realm)propertyObject.SelectedObject;
|
|
||||||
objectPath = Path.Combine(projectPath, "Realms");
|
|
||||||
objectPath = Path.Combine(objectPath, obj.Name);
|
|
||||||
filename = Path.Combine(objectPath, obj.Filename);
|
|
||||||
objectPath = Path.Combine(objectPath, "Zones");
|
|
||||||
ValidatePath(objectPath);
|
|
||||||
FileManager.Save(filename, obj);
|
|
||||||
}
|
|
||||||
else if (t == typeof(Zone))
|
|
||||||
{
|
|
||||||
Zone zone = (Zone)propertyObject.SelectedObject;
|
|
||||||
if (string.IsNullOrEmpty(zone.Realm))
|
|
||||||
{
|
|
||||||
objectPath = Path.Combine(projectPath, "Zones");
|
|
||||||
objectPath = Path.Combine(objectPath, zone.Name);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
objectPath = Path.Combine(projectPath, "Realms");
|
objectPath = FileManager.GetDataPath(z.Realm, z.Name);
|
||||||
objectPath = Path.Combine(objectPath, zone.Realm);
|
filename = Path.Combine(objectPath, z.Filename);
|
||||||
objectPath = Path.Combine(objectPath, "Zones");
|
|
||||||
objectPath = Path.Combine(objectPath, zone.Name);
|
|
||||||
filename = Path.Combine(objectPath, zone.Filename);
|
|
||||||
}
|
}
|
||||||
ValidatePath(objectPath);
|
obj.Save(filename);
|
||||||
filename = Path.Combine(objectPath, zone.Filename);
|
break;
|
||||||
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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue