- Renamed FileSystem.FileSystem.cs to FileSystem.FileManager.cs

- Moved ValidateDataPaths() from Engine.cs to FileManager.cs
 - Moved GetDataPath() from Engine.cs to FileManager.cs
 - Moved SaveDataTypes out from Engine.cs into it's own file. MudEngine.FileSystem.SaveDataTypes.cs
 - Moved _CurrentRoom, _CurrentZone, _CurrentRealm and _ScriptEngine out from all editors containing those Fields, and placed them as static properties within Program.cs Room, Zone, Realm and ScriptEngine Properties
 - Created 3 new Interfaces. IGameObject, IQuest and IRuleSet.
 - Created QuestSetup class to begin working on Quest Editor at some point.
This commit is contained in:
Scionwest_cp 2009-12-02 18:57:03 -08:00
parent c1d60639f5
commit 379c6f844d
17 changed files with 327 additions and 239 deletions

View file

@ -25,7 +25,7 @@ namespace MudDesigner.Editors
InitializeComponent(); InitializeComponent();
_Currency = new Currency(); _Currency = new Currency();
propertyGrid1.SelectedObject = _Currency; propertyGrid1.SelectedObject = _Currency;
foreach (string currency in System.IO.Directory.GetFiles(Engine.GetDataPath(Engine.SaveDataTypes.Currency), "*.xml")) foreach (string currency in System.IO.Directory.GetFiles(FileManager.GetDataPath(SaveDataTypes.Currency), "*.xml"))
{ {
lstCurrencies.Items.Add(System.IO.Path.GetFileNameWithoutExtension(currency)); lstCurrencies.Items.Add(System.IO.Path.GetFileNameWithoutExtension(currency));
} }
@ -45,7 +45,7 @@ namespace MudDesigner.Editors
return; return;
} }
FileSystem.Save(Application.StartupPath + @"\Data\Currency\" + _Currency.Name + ".xml", _Currency); FileManager.Save(Application.StartupPath + @"\Data\Currency\" + _Currency.Name + ".xml", _Currency);
lstCurrencies.Items.Add(_Currency.Name); lstCurrencies.Items.Add(_Currency.Name);
} }
@ -55,7 +55,7 @@ namespace MudDesigner.Editors
if (lstCurrencies.SelectedIndex == -1) if (lstCurrencies.SelectedIndex == -1)
return; return;
_Currency = (Currency)FileSystem.Load(Application.StartupPath + @"\Data\Currency\" + lstCurrencies.SelectedItem.ToString() + ".xml", _Currency); _Currency = (Currency)FileManager.Load(Application.StartupPath + @"\Data\Currency\" + lstCurrencies.SelectedItem.ToString() + ".xml", _Currency);
propertyGrid1.SelectedObject = _Currency; propertyGrid1.SelectedObject = _Currency;
} }

View file

@ -32,7 +32,7 @@ namespace MudDesigner.Editors
private void frmMain_Load(object sender, EventArgs e) private void frmMain_Load(object sender, EventArgs e)
{ {
//Get all of the realms currently created. //Get all of the realms currently created.
string[] files = System.IO.Directory.GetFiles(Engine.GetDataPath(Engine.SaveDataTypes.Realms), "*.realm"); string[] files = System.IO.Directory.GetFiles(FileManager.GetDataPath(SaveDataTypes.Realms), "*.realm");
//Aquire the Project settings and show them. //Aquire the Project settings and show them.
propertyGrid1.SelectedObject = Program.Project; propertyGrid1.SelectedObject = Program.Project;
@ -44,7 +44,7 @@ namespace MudDesigner.Editors
//Instance a new realm //Instance a new realm
Realm newRealm = new Realm(); Realm newRealm = new Realm();
//De-serialize the current realm. //De-serialize the current realm.
newRealm = (Realm)FileSystem.Load(realm, newRealm); newRealm = (Realm)FileManager.Load(realm, newRealm);
//Add it to the available realms combo box. //Add it to the available realms combo box.
comRealms.Items.Add(newRealm.Name); comRealms.Items.Add(newRealm.Name);
} }
@ -76,7 +76,7 @@ namespace MudDesigner.Editors
{ {
Zone newZone = new Zone(); Zone newZone = new Zone();
//De-serialize the current zone. //De-serialize the current zone.
newZone = (Zone)FileSystem.Load(zone, newZone); newZone = (Zone)FileManager.Load(zone, newZone);
//Add it to the available zones list box //Add it to the available zones list box
lstZones.Items.Add(newZone.Name); lstZones.Items.Add(newZone.Name);
zones.Add(newZone); zones.Add(newZone);
@ -118,7 +118,7 @@ namespace MudDesigner.Editors
{ {
Room newRoom = new Room(); Room newRoom = new Room();
//De-serialize the current Room. //De-serialize the current Room.
newRoom = (Room)FileSystem.Load(room, newRoom); newRoom = (Room)FileManager.Load(room, newRoom);
//Add it to the available rooms list box //Add it to the available rooms list box
lstRooms.Items.Add(newRoom.Name); lstRooms.Items.Add(newRoom.Name);
rooms.Add(newRoom); rooms.Add(newRoom);
@ -148,8 +148,8 @@ namespace MudDesigner.Editors
private void ProjectSettings_FormClosing(object sender, FormClosingEventArgs e) private void ProjectSettings_FormClosing(object sender, FormClosingEventArgs e)
{ {
string filename = System.IO.Path.Combine(Engine.GetDataPath(Engine.SaveDataTypes.Root), "Project.xml"); string filename = System.IO.Path.Combine(FileManager.GetDataPath(SaveDataTypes.Root), "Project.xml");
FileSystem.Save(filename, Program.Project); FileManager.Save(filename, Program.Project);
} }
} }
} }

View file

@ -19,42 +19,39 @@ namespace MudDesigner.Editors
{ {
public partial class RealmExplorer : Form public partial class RealmExplorer : Form
{ {
Zone _Zone;
Realm _CurrentRealm;
List<Zone> _AvailableZones; List<Zone> _AvailableZones;
ScriptingEngine _ScriptEngine;
public RealmExplorer() public RealmExplorer()
{ {
InitializeComponent(); InitializeComponent();
_Zone = new Zone(); Program.Zone = new Zone();
_CurrentRealm = new Realm(); Program.Realm = new Realm();
_AvailableZones = new List<Zone>(); _AvailableZones = new List<Zone>();
_ScriptEngine = new ScriptingEngine(); Program.ScriptEngine = new ScriptingEngine();
_ScriptEngine.CompileStyle = ManagedScripting.Compilers.BaseCompiler.ScriptCompileStyle.CompileToMemory; Program.ScriptEngine.CompileStyle = ManagedScripting.Compilers.BaseCompiler.ScriptCompileStyle.CompileToMemory;
_ScriptEngine.KeepTempFiles = false; Program.ScriptEngine.KeepTempFiles = false;
BuildZoneLists(); BuildZoneLists();
SetupScript(); SetupScript();
propertyRealm.SelectedObject = _CurrentRealm; propertyRealm.SelectedObject = Program.Realm;
string[] existingRealms = System.IO.Directory.GetFiles(Engine.GetDataPath(Engine.SaveDataTypes.Realms)); string[] existingRealms = System.IO.Directory.GetFiles(FileManager.GetDataPath(SaveDataTypes.Realms));
foreach (string realm in existingRealms) foreach (string realm in existingRealms)
lstRealms.Items.Add(System.IO.Path.GetFileNameWithoutExtension(realm)); lstRealms.Items.Add(System.IO.Path.GetFileNameWithoutExtension(realm));
} }
private void BuildZoneLists() private void BuildZoneLists()
{ {
string[] zones = System.IO.Directory.GetFiles(Engine.GetDataPath(Engine.SaveDataTypes.Zones), "*.zone"); string[] zones = System.IO.Directory.GetFiles(FileManager.GetDataPath(SaveDataTypes.Zones), "*.zone");
bool available = true; bool available = true;
lstAvailableZones.Items.Clear(); lstAvailableZones.Items.Clear();
lstZonesInRealm.Items.Clear(); lstZonesInRealm.Items.Clear();
foreach (string zone in zones) foreach (string zone in zones)
{ {
string[] realms = System.IO.Directory.GetFiles(Engine.GetDataPath(Engine.SaveDataTypes.Realms), "*.realm"); string[] realms = System.IO.Directory.GetFiles(FileManager.GetDataPath(SaveDataTypes.Realms), "*.realm");
foreach (string realm in realms) foreach (string realm in realms)
{ {
@ -85,7 +82,7 @@ namespace MudDesigner.Editors
private void SetupScript() private void SetupScript()
{ {
//Check if the realm script is empty. If so then generate a standard script for it. //Check if the realm script is empty. If so then generate a standard script for it.
if (String.IsNullOrEmpty(_CurrentRealm.Script)) if (String.IsNullOrEmpty(Program.Realm.Script))
{ {
//Instance a new method helper class //Instance a new method helper class
ManagedScripting.CodeBuilding.MethodSetup method = new ManagedScripting.CodeBuilding.MethodSetup(); ManagedScripting.CodeBuilding.MethodSetup method = new ManagedScripting.CodeBuilding.MethodSetup();
@ -101,26 +98,26 @@ namespace MudDesigner.Editors
method.IsOverride = true; method.IsOverride = true;
method.Modifier = ManagedScripting.CodeBuilding.ClassGenerator.Modifiers.Public; method.Modifier = ManagedScripting.CodeBuilding.ClassGenerator.Modifiers.Public;
method.Code = new string[] { "base." + method.Name + "();" }; method.Code = new string[] { "base." + method.Name + "();" };
script = script.Insert(_CurrentRealm.Script.Length, method.Create() + "\n"); script = script.Insert(Program.Realm.Script.Length, method.Create() + "\n");
} }
_CurrentRealm.Script = script; Program.Realm.Script = script;
} }
} }
private void btnNewRealm_Click(object sender, EventArgs e) private void btnNewRealm_Click(object sender, EventArgs e)
{ {
_Zone = new Zone(); Program.Zone = new Zone();
_CurrentRealm = new Realm(); Program.Realm = new Realm();
SetupScript(); SetupScript();
propertyRealm.SelectedObject = _CurrentRealm; propertyRealm.SelectedObject = Program.Realm;
lstZonesInRealm.Items.Clear(); lstZonesInRealm.Items.Clear();
} }
private void btnSaveRealm_Click(object sender, EventArgs e) private void btnSaveRealm_Click(object sender, EventArgs e)
{ {
string path = Engine.GetDataPath(Engine.SaveDataTypes.Realms); string path = FileManager.GetDataPath(SaveDataTypes.Realms);
string filename = System.IO.Path.Combine(path, _CurrentRealm.Name + ".realm"); string filename = System.IO.Path.Combine(path, Program.Realm.Name + ".realm");
if (System.IO.File.Exists(filename)) if (System.IO.File.Exists(filename))
{ {
DialogResult result = MessageBox.Show("File exists!\nOverwrite?", "Realm Explorer", MessageBoxButtons.YesNo, MessageBoxIcon.Question); DialogResult result = MessageBox.Show("File exists!\nOverwrite?", "Realm Explorer", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
@ -129,10 +126,10 @@ namespace MudDesigner.Editors
return; return;
} }
FileSystem.Save(filename, _CurrentRealm); FileManager.Save(filename, Program.Realm);
if (!lstRealms.Items.Contains(_CurrentRealm.Name)) if (!lstRealms.Items.Contains(Program.Realm.Name))
lstRealms.Items.Add(_CurrentRealm.Name); lstRealms.Items.Add(Program.Realm.Name);
} }
private void lstRealms_SelectedIndexChanged(object sender, EventArgs e) private void lstRealms_SelectedIndexChanged(object sender, EventArgs e)
@ -140,19 +137,19 @@ namespace MudDesigner.Editors
if (lstRealms.SelectedIndex == -1) if (lstRealms.SelectedIndex == -1)
return; return;
string path = Engine.GetDataPath(Engine.SaveDataTypes.Realms); string path = FileManager.GetDataPath(SaveDataTypes.Realms);
string filename = System.IO.Path.Combine(path, lstRealms.SelectedItem.ToString() + ".realm"); string filename = System.IO.Path.Combine(path, lstRealms.SelectedItem.ToString() + ".realm");
_CurrentRealm = (Realm)FileSystem.Load(filename, _CurrentRealm); Program.Realm = (Realm)FileManager.Load(filename, Program.Realm);
propertyRealm.SelectedObject = _CurrentRealm; propertyRealm.SelectedObject = Program.Realm;
lstZonesInRealm.Items.Clear(); lstZonesInRealm.Items.Clear();
foreach (string file in System.IO.Directory.GetFiles(Engine.GetDataPath(Engine.SaveDataTypes.Zones), "*.zone")) foreach (string file in System.IO.Directory.GetFiles(FileManager.GetDataPath(SaveDataTypes.Zones), "*.zone"))
{ {
Zone zone = new Zone(); Zone zone = new Zone();
zone = (Zone)FileSystem.Load(file, zone); zone = (Zone)FileManager.Load(file, zone);
if (zone.Realm == _CurrentRealm.Name) if (zone.Realm == Program.Realm.Name)
lstZonesInRealm.Items.Add(zone.Name); lstZonesInRealm.Items.Add(zone.Name);
else if (String.IsNullOrEmpty(zone.Realm)) else if (String.IsNullOrEmpty(zone.Realm))
{ {
@ -175,7 +172,7 @@ namespace MudDesigner.Editors
if (result == DialogResult.No) if (result == DialogResult.No)
return; return;
string path = Engine.GetDataPath(Engine.SaveDataTypes.Realms); string path = FileManager.GetDataPath(SaveDataTypes.Realms);
string filename = System.IO.Path.Combine(path, lstRealms.SelectedItem.ToString() + ".realm"); string filename = System.IO.Path.Combine(path, lstRealms.SelectedItem.ToString() + ".realm");
System.IO.File.Delete(filename); System.IO.File.Delete(filename);
lstRealms.Items.Remove(lstRealms.SelectedItem); lstRealms.Items.Remove(lstRealms.SelectedItem);
@ -190,22 +187,22 @@ namespace MudDesigner.Editors
{ {
if (tabControl1.SelectedTab.Text == "Script") if (tabControl1.SelectedTab.Text == "Script")
{ {
txtScript.Text = _CurrentRealm.Script; txtScript.Text = Program.Realm.Script;
} }
} }
private void btnValidateScript_Click(object sender, EventArgs e) private void btnValidateScript_Click(object sender, EventArgs e)
{ {
_ScriptEngine.Compiler = ManagedScripting.ScriptingEngine.CompilerSelections.SourceCompiler; Program.ScriptEngine.Compiler = ManagedScripting.ScriptingEngine.CompilerSelections.SourceCompiler;
_ScriptEngine.AddReference(Application.StartupPath + "/MUDEngine.dll"); Program.ScriptEngine.AddReference(Application.StartupPath + "/MUDEngine.dll");
string code = "namespace MudDesigner.MudEngine.Objects.Environment\n" string code = "namespace MudDesigner.MudEngine.Objects.Environment\n"
+ "{\n" + "{\n"
+ " public class " + _CurrentRealm.Name.Replace(" ", "") + " : Realm\n" + " public class " + Program.Realm.Name.Replace(" ", "") + " : Realm\n"
+ " {\n" + " {\n"
+ " " + txtScript.Text + "\n" + " " + txtScript.Text + "\n"
+ " }\n" + " }\n"
+ "}\n"; + "}\n";
MessageBox.Show(_ScriptEngine.Compile(code), "Script Compiling", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show(Program.ScriptEngine.Compile(code), "Script Compiling", MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
private void btnBuildZone_Click(object sender, EventArgs e) private void btnBuildZone_Click(object sender, EventArgs e)
@ -222,14 +219,14 @@ namespace MudDesigner.Editors
return; return;
} }
string path = Engine.GetDataPath(Engine.SaveDataTypes.Zones); string path = FileManager.GetDataPath(SaveDataTypes.Zones);
string filename = System.IO.Path.Combine(path, lstAvailableZones.SelectedItem.ToString() + ".zone"); string filename = System.IO.Path.Combine(path, lstAvailableZones.SelectedItem.ToString() + ".zone");
Zone zone = new Zone(); Zone zone = new Zone();
zone = (Zone)FileSystem.Load(filename, zone); zone = (Zone)FileManager.Load(filename, zone);
zone.Realm = _CurrentRealm.Name; zone.Realm = Program.Realm.Name;
FileSystem.Save(filename, zone); FileManager.Save(filename, zone);
_CurrentRealm.Zones.Add(zone); Program.Realm.Zones.Add(zone);
lstZonesInRealm.Items.Add(zone.Name); lstZonesInRealm.Items.Add(zone.Name);
} }
} }

View file

@ -18,15 +18,9 @@ namespace MudDesigner.Editors
{ {
public partial class RoomDesigner : Form public partial class RoomDesigner : Form
{ {
//Current _CurrentRoom
Room _CurrentRoom;
//Doorway currently loaded. //Doorway currently loaded.
Door _CurrentDoor; Door _CurrentDoor;
//Scripting engine and it's components.
ManagedScripting.ScriptingEngine _ScriptEngine;
//Collection of plugins from within the 'plugins' folder //Collection of plugins from within the 'plugins' folder
List<System.Reflection.Assembly> _Plugins; List<System.Reflection.Assembly> _Plugins;
@ -39,7 +33,7 @@ namespace MudDesigner.Editors
private void SetupEditor(params object[] parameters) private void SetupEditor(params object[] parameters)
{ {
//Initialize the Room & Doorway //Initialize the Room & Doorway
_CurrentRoom = new Room(); Program.Room = new Room();
_CurrentDoor = new Door(AvailableTravelDirections.None); _CurrentDoor = new Door(AvailableTravelDirections.None);
//This instances a copy of AvailableTravelDirections which is a list of //This instances a copy of AvailableTravelDirections which is a list of
@ -55,10 +49,10 @@ namespace MudDesigner.Editors
LoadPlugins(); LoadPlugins();
//Instance the scripting engine and set it up. //Instance the scripting engine and set it up.
_ScriptEngine = new ManagedScripting.ScriptingEngine(); Program.ScriptEngine = new ManagedScripting.ScriptingEngine();
_ScriptEngine.Compiler = ManagedScripting.ScriptingEngine.CompilerSelections.SourceCompiler; Program.ScriptEngine.Compiler = ManagedScripting.ScriptingEngine.CompilerSelections.SourceCompiler;
_ScriptEngine.CompileStyle = ManagedScripting.Compilers.BaseCompiler.ScriptCompileStyle.CompileToMemory; Program.ScriptEngine.CompileStyle = ManagedScripting.Compilers.BaseCompiler.ScriptCompileStyle.CompileToMemory;
_ScriptEngine.KeepTempFiles = false; Program.ScriptEngine.KeepTempFiles = false;
//Get the current rooms scripts. //Get the current rooms scripts.
//TODO: Add Doorway script support //TODO: Add Doorway script support
@ -70,14 +64,14 @@ namespace MudDesigner.Editors
{ {
if (argument.ToString().ToLower().StartsWith("room=")) if (argument.ToString().ToLower().StartsWith("room="))
{ {
string roomPath = Engine.GetDataPath(Engine.SaveDataTypes.Rooms); string roomPath = FileManager.GetDataPath(SaveDataTypes.Rooms);
string room = argument.ToString().Substring("room=".Length); string room = argument.ToString().Substring("room=".Length);
string filename = System.IO.Path.Combine(roomPath, room.ToString()); string filename = System.IO.Path.Combine(roomPath, room.ToString());
//Room to load should always be the first arg. //Room to load should always be the first arg.
if (System.IO.File.Exists(filename)) if (System.IO.File.Exists(filename))
{ {
_CurrentRoom = (Room)FileSystem.Load(filename, _CurrentRoom); Program.Room = (Room)FileManager.Load(filename, Program.Room);
} }
} }
} }
@ -85,14 +79,14 @@ namespace MudDesigner.Editors
//Show the user(s) the rooms properties //Show the user(s) the rooms properties
propertyRoom.SelectedObject = _CurrentRoom; propertyRoom.SelectedObject = Program.Room;
txtScript.Text = _CurrentRoom.Script; txtScript.Text = Program.Room.Script;
} }
private void SetupRoomScript() private void SetupRoomScript()
{ {
//Check if the rooms script is empty. If so then generate a standard script for it. //Check if the rooms script is empty. If so then generate a standard script for it.
if (String.IsNullOrEmpty(_CurrentRoom.Script)) if (String.IsNullOrEmpty(Program.Room.Script))
{ {
//Instance a new method helper class //Instance a new method helper class
ManagedScripting.CodeBuilding.MethodSetup method = new ManagedScripting.CodeBuilding.MethodSetup(); ManagedScripting.CodeBuilding.MethodSetup method = new ManagedScripting.CodeBuilding.MethodSetup();
@ -108,9 +102,9 @@ namespace MudDesigner.Editors
method.IsOverride = true; method.IsOverride = true;
method.Modifier = ManagedScripting.CodeBuilding.ClassGenerator.Modifiers.Public; method.Modifier = ManagedScripting.CodeBuilding.ClassGenerator.Modifiers.Public;
method.Code = new string[] { "base." + method.Name + "();" }; method.Code = new string[] { "base." + method.Name + "();" };
script = script.Insert(_CurrentRoom.Script.Length, method.Create() + "\n"); script = script.Insert(Program.Room.Script.Length, method.Create() + "\n");
} }
_CurrentRoom.Script = script; Program.Room.Script = script;
} }
} }
@ -177,11 +171,11 @@ namespace MudDesigner.Editors
//and was found for editing //and was found for editing
bool IsFound = false; bool IsFound = false;
//Loop through each doorway installed within the _CurrentRoom and see if the user has //Loop through each doorway installed within the Program.Room and see if the user has
//selected a direction that belongs to a _CurrentDoor already created. If a _CurrentDoor with //selected a direction that belongs to a _CurrentDoor already created. If a _CurrentDoor with
//the selected direction is found, we display it's properties for editing instead //the selected direction is found, we display it's properties for editing instead
//of creating a new _CurrentDoor and overwriting the previously created doorway. //of creating a new _CurrentDoor and overwriting the previously created doorway.
foreach (Door newDoor in _CurrentRoom.InstalledDoors) foreach (Door newDoor in Program.Room.InstalledDoors)
{ {
//Check if the current _CurrentDoor in the loop matches the currently selected //Check if the current _CurrentDoor in the loop matches the currently selected
//travel direction the user has selected in the listbox. //travel direction the user has selected in the listbox.
@ -200,7 +194,7 @@ namespace MudDesigner.Editors
} }
} }
//There isn't a _CurrentDoor installed into the _CurrentRoom yet with a travel direction //There isn't a _CurrentDoor installed into the Program.Room yet with a travel direction
//matching that of the users currently selected travel direction within the listbox. //matching that of the users currently selected travel direction within the listbox.
//so we instance a new _CurrentDoor //so we instance a new _CurrentDoor
if (!IsFound) if (!IsFound)
@ -253,7 +247,7 @@ namespace MudDesigner.Editors
} }
/// <summary> /// <summary>
/// Installs the _CurrentDoor into the _CurrentRoom's collection of doorways /// Installs the _CurrentDoor into the Program.Room's collection of doorways
/// </summary> /// </summary>
private void InstallDoor() private void InstallDoor()
{ {
@ -262,10 +256,10 @@ namespace MudDesigner.Editors
bool IsInstalled = false; bool IsInstalled = false;
//Incase there are no existing doors, the foreach loop gets skipped. //Incase there are no existing doors, the foreach loop gets skipped.
if (_CurrentRoom.InstalledDoors.Count == 0) if (Program.Room.InstalledDoors.Count == 0)
{ {
//Add the new door to the room //Add the new door to the room
_CurrentRoom.InstalledDoors.Add(_CurrentDoor); Program.Room.InstalledDoors.Add(_CurrentDoor);
return; return;
} }
@ -274,19 +268,19 @@ namespace MudDesigner.Editors
//that the user has selected within the list box. If so then we //that the user has selected within the list box. If so then we
//need to prompt the user to ensure it's ok to overwrite the previous //need to prompt the user to ensure it's ok to overwrite the previous
//door with a new door. //door with a new door.
foreach (Door newDoor in _CurrentRoom.InstalledDoors) foreach (Door newDoor in Program.Room.InstalledDoors)
{ {
if (newDoor.TravelDirection == _CurrentDoor.TravelDirection) if (newDoor.TravelDirection == _CurrentDoor.TravelDirection)
{ {
_CurrentRoom.InstalledDoors.Remove(newDoor); Program.Room.InstalledDoors.Remove(newDoor);
_CurrentRoom.InstalledDoors.Add(_CurrentDoor); Program.Room.InstalledDoors.Add(_CurrentDoor);
IsInstalled = true; IsInstalled = true;
break; break;
} }
} }
if (!IsInstalled) if (!IsInstalled)
_CurrentRoom.InstalledDoors.Add(_CurrentDoor); Program.Room.InstalledDoors.Add(_CurrentDoor);
} }
/// <summary> /// <summary>
@ -294,11 +288,11 @@ namespace MudDesigner.Editors
/// </summary> /// </summary>
private void UninstallDoor() private void UninstallDoor()
{ {
foreach (Door door in _CurrentRoom.InstalledDoors) foreach (Door door in Program.Room.InstalledDoors)
{ {
if (door.TravelDirection == _CurrentDoor.TravelDirection) if (door.TravelDirection == _CurrentDoor.TravelDirection)
{ {
_CurrentRoom.InstalledDoors.Remove(door); Program.Room.InstalledDoors.Remove(door);
break; break;
} }
} }
@ -315,18 +309,18 @@ namespace MudDesigner.Editors
if (result == DialogResult.No) if (result == DialogResult.No)
return; return;
_CurrentRoom = new Room(); Program.Room = new Room();
_CurrentDoor = new Door(AvailableTravelDirections.None); _CurrentDoor = new Door(AvailableTravelDirections.None);
SetupRoomScript(); SetupRoomScript();
propertyDoor.SelectedObject = null; propertyDoor.SelectedObject = null;
propertyRoom.SelectedObject = _CurrentRoom; propertyRoom.SelectedObject = Program.Room;
} }
private void btnSaveRoom_Click(object sender, EventArgs e) private void btnSaveRoom_Click(object sender, EventArgs e)
{ {
string savePath = Engine.GetDataPath(Engine.SaveDataTypes.Rooms); string savePath = FileManager.GetDataPath(SaveDataTypes.Rooms);
string filePath = System.IO.Path.Combine(savePath, _CurrentRoom.Name + ".room"); string filePath = System.IO.Path.Combine(savePath, Program.Room.Name + ".room");
if (System.IO.File.Exists(filePath)) if (System.IO.File.Exists(filePath))
{ {
@ -336,7 +330,7 @@ namespace MudDesigner.Editors
return; return;
} }
FileSystem.Save(filePath, _CurrentRoom); FileManager.Save(filePath, Program.Room);
MessageBox.Show("Saved.", "Room Designer"); MessageBox.Show("Saved.", "Room Designer");
} }
@ -344,28 +338,28 @@ namespace MudDesigner.Editors
{ {
if (tabObjects.SelectedTab.Text == "Script") if (tabObjects.SelectedTab.Text == "Script")
{ {
txtScript.Text = _CurrentRoom.Script; txtScript.Text = Program.Room.Script;
} }
} }
private void btnCheckScript_Click(object sender, EventArgs e) private void btnCheckScript_Click(object sender, EventArgs e)
{ {
_ScriptEngine.Compiler = ManagedScripting.ScriptingEngine.CompilerSelections.SourceCompiler; Program.ScriptEngine.Compiler = ManagedScripting.ScriptingEngine.CompilerSelections.SourceCompiler;
_ScriptEngine.AddReference(Application.StartupPath + "/MUDEngine.dll"); Program.ScriptEngine.AddReference(Application.StartupPath + "/MUDEngine.dll");
string code = "namespace MudDesigner.MudEngine.Objects.Environment\n" string code = "namespace MudDesigner.MudEngine.Objects.Environment\n"
+ "{\n" + "{\n"
+ " public class " + _CurrentRoom.Name.Replace(" ", "") + " : Room\n" + " public class " + Program.Room.Name.Replace(" ", "") + " : Room\n"
+ " {\n" + " {\n"
+ " " + txtScript.Text + "\n" + " " + txtScript.Text + "\n"
+ " }\n" + " }\n"
+ "}\n"; + "}\n";
MessageBox.Show(_ScriptEngine.Compile(code), "Script Compiling", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show(Program.ScriptEngine.Compile(code), "Script Compiling", MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
private void txtScript_TextChanged(object sender, EventArgs e) private void txtScript_TextChanged(object sender, EventArgs e)
{ {
_CurrentRoom.Script = txtScript.Text; Program.Room.Script = txtScript.Text;
} }
} }
} }

View file

@ -30,7 +30,6 @@ namespace MudDesigner.Editors
ProjectSettings form = new ProjectSettings(); ProjectSettings form = new ProjectSettings();
form.Show(); form.Show();
} }
private void btnCurrencyEditor_Click(object sender, EventArgs e) private void btnCurrencyEditor_Click(object sender, EventArgs e)

View file

@ -19,23 +19,19 @@ namespace MudDesigner.Editors
{ {
public partial class ZoneBuilder : Form public partial class ZoneBuilder : Form
{ {
Zone _CurrentZone;
Room _CurrentRoom;
ScriptingEngine _ScriptEngine;
public ZoneBuilder() public ZoneBuilder()
{ {
InitializeComponent(); InitializeComponent();
_CurrentRoom = new Room(); Program.Room = new Room();
_CurrentZone = new Zone(); Program.Zone = new Zone();
_ScriptEngine = new ScriptingEngine(); Program.ScriptEngine = new ScriptingEngine();
_ScriptEngine.CompileStyle = ManagedScripting.Compilers.BaseCompiler.ScriptCompileStyle.CompileToMemory; Program.ScriptEngine.CompileStyle = ManagedScripting.Compilers.BaseCompiler.ScriptCompileStyle.CompileToMemory;
_ScriptEngine.Compiler = ScriptingEngine.CompilerSelections.SourceCompiler; Program.ScriptEngine.Compiler = ScriptingEngine.CompilerSelections.SourceCompiler;
propertyZone.SelectedObject = _CurrentZone; propertyZone.SelectedObject = Program.Zone;
txtScript.Text = _CurrentZone.Script; txtScript.Text = Program.Zone.Script;
string[] rooms = System.IO.Directory.GetFiles(MudEngine.Engine.GetDataPath(Engine.SaveDataTypes.Rooms), "*.room"); string[] rooms = System.IO.Directory.GetFiles(FileManager.GetDataPath(SaveDataTypes.Rooms), "*.room");
foreach (string room in rooms) foreach (string room in rooms)
{ {
@ -77,32 +73,32 @@ namespace MudDesigner.Editors
private void btnSaveZone_Click(object sender, EventArgs e) private void btnSaveZone_Click(object sender, EventArgs e)
{ {
string path = Engine.GetDataPath(Engine.SaveDataTypes.Zones); string path = FileManager.GetDataPath(SaveDataTypes.Zones);
string filename = System.IO.Path.Combine(path, _CurrentZone.Name + ".zone"); string filename = System.IO.Path.Combine(path, Program.Zone.Name + ".zone");
FileSystem.Save(filename, _CurrentZone); FileManager.Save(filename, Program.Zone);
} }
private void btnNewZone_Click(object sender, EventArgs e) private void btnNewZone_Click(object sender, EventArgs e)
{ {
_CurrentZone = new Zone(); Program.Zone = new Zone();
_CurrentRoom = new Room(); Program.Room = new Room();
propertyZone.SelectedObject = _CurrentZone; propertyZone.SelectedObject = Program.Zone;
} }
private void btnValidateScript_Click(object sender, EventArgs e) private void btnValidateScript_Click(object sender, EventArgs e)
{ {
_ScriptEngine.Compiler = ManagedScripting.ScriptingEngine.CompilerSelections.SourceCompiler; Program.ScriptEngine.Compiler = ManagedScripting.ScriptingEngine.CompilerSelections.SourceCompiler;
_ScriptEngine.AddReference(Application.StartupPath + "/MUDEngine.dll"); Program.ScriptEngine.AddReference(Application.StartupPath + "/MUDEngine.dll");
string code = "namespace MudDesigner.MudEngine.Objects.Environment\n" string code = "namespace MudDesigner.MudEngine.Objects.Environment\n"
+ "{\n" + "{\n"
+ " public class " + _CurrentZone.Name.Replace(" ", "") + " : Zone\n" + " public class " + Program.Zone.Name.Replace(" ", "") + " : Zone\n"
+ " {\n" + " {\n"
+ " " + txtScript.Text + "\n" + " " + txtScript.Text + "\n"
+ " }\n" + " }\n"
+ "}\n"; + "}\n";
MessageBox.Show(_ScriptEngine.Compile(code), "Script Compiling", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show(Program.ScriptEngine.Compile(code), "Script Compiling", MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
} }
} }

View file

@ -53,6 +53,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="MudEngine\Engine.cs" /> <Compile Include="MudEngine\Engine.cs" />
<Compile Include="MudEngine\FileSystem\SaveDataTypes.cs" />
<Compile Include="MudEngine\GameObjects\BaseObject.cs" /> <Compile Include="MudEngine\GameObjects\BaseObject.cs" />
<Compile Include="MudEngine\GameObjects\Currency.cs" /> <Compile Include="MudEngine\GameObjects\Currency.cs" />
<Compile Include="MudEngine\GameObjects\Environment\Door.cs" /> <Compile Include="MudEngine\GameObjects\Environment\Door.cs" />
@ -61,6 +62,9 @@
<Compile Include="MudEngine\GameObjects\Environment\Room.cs" /> <Compile Include="MudEngine\GameObjects\Environment\Room.cs" />
<Compile Include="MudEngine\GameObjects\Environment\TravelDirections.cs" /> <Compile Include="MudEngine\GameObjects\Environment\TravelDirections.cs" />
<Compile Include="MudEngine\GameObjects\Environment\Zone.cs" /> <Compile Include="MudEngine\GameObjects\Environment\Zone.cs" />
<Compile Include="MudEngine\Interfaces\IGameObject.cs" />
<Compile Include="MudEngine\Interfaces\IQuest.cs" />
<Compile Include="MudEngine\Interfaces\IRuleSet.cs" />
<Compile Include="MudEngine\ProjectInformation.cs" /> <Compile Include="MudEngine\ProjectInformation.cs" />
<Compile Include="MudEngine\Attributes\UnusableAttribute.cs" /> <Compile Include="MudEngine\Attributes\UnusableAttribute.cs" />
<Compile Include="Editors\CurrencyEditor.cs"> <Compile Include="Editors\CurrencyEditor.cs">
@ -99,7 +103,8 @@
<Compile Include="Editors\ProjectSettings.designer.cs"> <Compile Include="Editors\ProjectSettings.designer.cs">
<DependentUpon>ProjectSettings.cs</DependentUpon> <DependentUpon>ProjectSettings.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="MudEngine\FileSystem\FileSystem.cs" /> <Compile Include="MudEngine\FileSystem\FileManager.cs" />
<Compile Include="MudEngine\QuestSetup.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Editors\CurrencyEditor.resx"> <EmbeddedResource Include="Editors\CurrencyEditor.resx">

View file

@ -6,71 +6,5 @@ using System.Text;
namespace MudDesigner.MudEngine namespace MudDesigner.MudEngine
{ {
public class Engine public class Engine
{ { }
public enum SaveDataTypes
{
Root,
Currency,
Rooms,
Zones,
Realms,
}
/// <summary>
/// Used to ensure that the paths needed to run the game exists.
/// If no path is supplied, the engine uses it's current install path.
/// </summary>
/// <param name="validatedPath"></param>
public static void ValidateDataPaths()
{
string assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName;
string assemblyName = System.IO.Path.GetFileName(assemblyPath);
string installBase = assemblyPath.Substring(0, assemblyPath.Length - assemblyName.Length);
string rootPath = System.IO.Path.Combine(installBase, "Data");
ValidateDataPaths(rootPath);
}
/// <summary>
/// Checks the supplied directory to ensure that all of the engines needed
/// data folders are created
/// </summary>
/// <param name="InstallPath"></param>
public static void ValidateDataPaths(string InstallPath)
{
if (!InstallPath.EndsWith("data", true, null))
InstallPath = System.IO.Path.Combine(InstallPath, "Data");
if (!System.IO.Directory.Exists(InstallPath))
System.IO.Directory.CreateDirectory(InstallPath);
foreach (SaveDataTypes value in Enum.GetValues(typeof(SaveDataTypes)))
{
string dataType = value.ToString();
if (value.ToString() == "Root")
continue;
if (!System.IO.Directory.Exists(System.IO.Path.Combine(InstallPath, dataType)))
System.IO.Directory.CreateDirectory(System.IO.Path.Combine(InstallPath, dataType));
}
}
/// <summary>
/// Returns the complete path to the specified data's save folder.
/// </summary>
/// <param name="DataType"></param>
/// <returns></returns>
public static string GetDataPath(SaveDataTypes DataType)
{
string assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName;
string assemblyName = System.IO.Path.GetFileName(assemblyPath);
string installBase = assemblyPath.Substring(0, assemblyPath.Length - assemblyName.Length);
string rootPath = System.IO.Path.Combine(installBase, "Data");
if (DataType == SaveDataTypes.Root)
return rootPath;
else
return System.IO.Path.Combine(rootPath, DataType.ToString());
}
}
} }

View file

@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MudDesigner.MudEngine.FileSystem
{
public static class FileManager
{
public enum OutputFormats
{
XML = 0,
}
/// <summary>
/// The filetype that the MUDs files will be saved as
/// </summary>
public static OutputFormats FileType
{
get;
set;
}
/// <summary>
/// Saves the object using the specified output format
/// </summary>
/// <param name="Filename"></param>
/// <param name="o"></param>
public static void Save(string Filename, object o)
{
if (FileType == OutputFormats.XML)
{
XmlSerialization.Save(Filename, o);
}
}
/// <summary>
/// Loads the object using the specified FileType format
/// </summary>
/// <param name="Filename"></param>
/// <param name="o"></param>
/// <returns></returns>
public static object Load(string Filename, object o)
{
if (FileType == OutputFormats.XML)
{
return XmlSerialization.Load(Filename, o);
}
else return null;
}
/// <summary>
/// Used to ensure that the paths needed to run the game exists.
/// If no path is supplied, the engine uses it's current install path.
/// </summary>
/// <param name="validatedPath"></param>
public static void ValidateDataPaths()
{
string assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName;
string assemblyName = System.IO.Path.GetFileName(assemblyPath);
string installBase = assemblyPath.Substring(0, assemblyPath.Length - assemblyName.Length);
string rootPath = System.IO.Path.Combine(installBase, "Data");
ValidateDataPaths(rootPath);
}
/// <summary>
/// Checks the supplied directory to ensure that all of the engines needed
/// data folders are created. Only use if you want to point your projects in
/// different directory other than InstallBase\Data
/// </summary>
/// <param name="InstallPath"></param>
public static void ValidateDataPaths(string InstallPath)
{
if (!InstallPath.EndsWith("data", true, null))
InstallPath = System.IO.Path.Combine(InstallPath, "Data");
if (!System.IO.Directory.Exists(InstallPath))
System.IO.Directory.CreateDirectory(InstallPath);
foreach (SaveDataTypes value in Enum.GetValues(typeof(SaveDataTypes)))
{
string dataType = value.ToString();
if (value.ToString() == "Root")
continue;
if (!System.IO.Directory.Exists(System.IO.Path.Combine(InstallPath, dataType)))
System.IO.Directory.CreateDirectory(System.IO.Path.Combine(InstallPath, dataType));
}
}
/// <summary>
/// Returns the complete path to the specified data's save folder.
/// </summary>
/// <param name="DataType"></param>
/// <returns></returns>
public static string GetDataPath(SaveDataTypes DataType)
{
string assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName;
string assemblyName = System.IO.Path.GetFileName(assemblyPath);
string installBase = assemblyPath.Substring(0, assemblyPath.Length - assemblyName.Length);
string rootPath = System.IO.Path.Combine(installBase, "Data");
if (DataType == SaveDataTypes.Root)
return rootPath;
else
return System.IO.Path.Combine(rootPath, DataType.ToString());
}
}
}

View file

@ -1,52 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MudDesigner.MudEngine.FileSystem
{
public static class FileSystem
{
public enum OutputFormats
{
XML = 0,
}
/// <summary>
/// The filetype that the MUDs files will be saved as
/// </summary>
public static OutputFormats FileType
{
get;
set;
}
/// <summary>
/// Saves the object using the specified output format
/// </summary>
/// <param name="Filename"></param>
/// <param name="o"></param>
public static void Save(string Filename, object o)
{
if (FileType == OutputFormats.XML)
{
XmlSerialization.Save(Filename, o);
}
}
/// <summary>
/// Loads the object using the specified FileType format
/// </summary>
/// <param name="Filename"></param>
/// <param name="o"></param>
/// <returns></returns>
public static object Load(string Filename, object o)
{
if (FileType == OutputFormats.XML)
{
return XmlSerialization.Load(Filename, o);
}
else return null;
}
}
}

View file

@ -0,0 +1,11 @@
namespace MudDesigner.MudEngine.FileSystem
{
public enum SaveDataTypes
{
Root,
Currency,
Rooms,
Zones,
Realms,
}
}

View file

@ -5,10 +5,11 @@ using System.Text;
using System.ComponentModel; using System.ComponentModel;
using System.Windows.Forms; using System.Windows.Forms;
using System.Xml.Serialization; using System.Xml.Serialization;
using MudDesigner.MudEngine.Interfaces;
namespace MudDesigner.MudEngine.Objects namespace MudDesigner.MudEngine.Objects
{ {
public class BaseObject public class BaseObject : IGameObject
{ {
[Category("Object Setup")] [Category("Object Setup")]
[RefreshProperties(RefreshProperties.All)] //Required to refresh Filename property in the editors propertygrid [RefreshProperties(RefreshProperties.All)] //Required to refresh Filename property in the editors propertygrid
@ -107,5 +108,21 @@ namespace MudDesigner.MudEngine.Objects
public virtual void OnDestroy() public virtual void OnDestroy()
{ {
} }
public virtual void OnEquip()
{
}
public virtual void OnUnequip()
{
}
public virtual void OnMount()
{
}
public virtual void OnDismount()
{
}
} }
} }

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MudDesigner.MudEngine.Interfaces
{
public interface IGameObject
{
string Name { get; set; }
string Description { get; set; }
string Script { get; set; }
string Filename { get; }
void OnCreate();
void OnDestroy();
void OnEnter();
void OnExit();
void OnEquip();
void OnUnequip();
void OnMount();
void OnDismount();
}
}

View file

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MudDesigner.MudEngine.Objects;
namespace MudDesigner.MudEngine.Interfaces
{
interface IQuest
{
string Title { get; set; }
string Description { get; set; }
int ExperianceAward { get; set; }
int MinimumLevel { get; set; }
int MaximumLevel { get; set; }
//This or int? i'm not sure
Currency CurrencyAward { get; set; }
void AcceptQuest();
void CompleteQuest();
void TrashQuest();
}
}

View file

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MudDesigner.MudEngine.Interfaces
{
public interface IRuleSet
{
void Initialize();
}
}

View file

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MudDesigner.MudEngine
{
public class QuestSetup
{
}
}

View file

@ -14,19 +14,24 @@ namespace MudDesigner
static class Program static class Program
{ {
public static ProjectInformation Project{ get; set; } public static ProjectInformation Project{ get; set; }
public static Realm Realm { get; set; }
public static Zone Zone {get;set;}
public static Room Room { get; set; }
public static ManagedScripting.ScriptingEngine ScriptEngine { get; set; }
/// <summary> /// <summary>
/// The main entry point for the application. /// The main entry point for the application.
/// </summary> /// </summary>
[STAThread] [STAThread]
static void Main() static void Main()
{ {
Engine.ValidateDataPaths(); FileManager.ValidateDataPaths();
FileSystem.FileType = FileSystem.OutputFormats.XML; FileManager.FileType = FileManager.OutputFormats.XML;
Project = new ProjectInformation(); Project = new ProjectInformation();
string filename = System.IO.Path.Combine(Engine.GetDataPath(Engine.SaveDataTypes.Root), "Project.Xml"); string filename = System.IO.Path.Combine(FileManager.GetDataPath(SaveDataTypes.Root), "Project.Xml");
if (System.IO.File.Exists(filename)) if (System.IO.File.Exists(filename))
Project = (ProjectInformation)FileSystem.Load(filename, Project); Project = (ProjectInformation)FileManager.Load(filename, Project);
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);