Added beginning support for Dynamic Type Property Saving. Refer to my blog post for additional information in this: http://scionwest.net/2011/09/saving-type-data-dynamically/
Added new ParseProperty Attribute that must be used on any Type Property that will need to be saved during runtime.
This commit is contained in:
parent
f8620d0f4d
commit
81f2ae91c0
6 changed files with 537 additions and 471 deletions
23
MudEngine/Attributes/ParseProperty.cs
Normal file
23
MudEngine/Attributes/ParseProperty.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.ComponentModel;
|
||||
namespace MudEngine.Attributes
|
||||
{
|
||||
[System.AttributeUsage(System.AttributeTargets.Property)]
|
||||
public class ParseProperty
|
||||
: System.Attribute
|
||||
{
|
||||
Object obj;
|
||||
|
||||
public ParseProperty(Object var)
|
||||
{
|
||||
obj = var;
|
||||
}
|
||||
|
||||
public object GetObject()
|
||||
{
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -4,14 +4,17 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using System.Xml.Serialization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
//MUD Engine
|
||||
using MudEngine.FileSystem;
|
||||
using MudEngine.GameManagement;
|
||||
|
||||
using rScripting;
|
||||
using rScripting.LateBinding;
|
||||
|
||||
namespace MudEngine.GameObjects
|
||||
{
|
||||
public class BaseObject
|
||||
|
@ -175,6 +178,43 @@ namespace MudEngine.GameObjects
|
|||
{
|
||||
}
|
||||
|
||||
public virtual void NewSave()
|
||||
{
|
||||
ScriptObject obj = new ScriptObject(this);
|
||||
PropertyInfo[] prop = this.GetType().GetProperties();
|
||||
|
||||
string path = this.SavePath;
|
||||
|
||||
if (String.IsNullOrEmpty(path))
|
||||
return;
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
Directory.CreateDirectory(path);
|
||||
|
||||
string filename = Path.Combine(path, Filename);
|
||||
|
||||
if (File.Exists(filename))
|
||||
File.Delete(filename);
|
||||
|
||||
foreach (var p in prop)
|
||||
{
|
||||
object[] attributes = p.GetCustomAttributes(typeof(MudEngine.Attributes.ParseProperty), false);
|
||||
|
||||
foreach (Attribute a in attributes)
|
||||
{
|
||||
if (a.GetType().Name == "ParseProperty")
|
||||
{
|
||||
ParseProperty(p);
|
||||
}
|
||||
}
|
||||
FileManager.WriteLine(filename, obj.GetProperty(p.Name).ToString(), p.Name);
|
||||
}
|
||||
}
|
||||
|
||||
private void ParseProperty(PropertyInfo propety)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Save()
|
||||
{
|
||||
string path = this.SavePath;
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
using System.IO;
|
||||
|
||||
//MUD Engine
|
||||
using MudEngine.Attributes;
|
||||
using MudEngine.FileSystem;
|
||||
using MudEngine.Commands;
|
||||
using MudEngine.GameManagement;
|
||||
|
@ -39,6 +40,7 @@
|
|||
/// <summary>
|
||||
/// The current Room this Character is located at.
|
||||
/// </summary>
|
||||
[ParseProperty(typeof(Room))]
|
||||
public Room CurrentRoom { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -112,7 +114,8 @@
|
|||
/// </summary>
|
||||
public BaseStats Stats { get; set; }
|
||||
|
||||
public BaseCharacter(Game game) : base(game)
|
||||
public BaseCharacter(Game game)
|
||||
: base(game)
|
||||
{
|
||||
ActiveGame = game;
|
||||
IsActive = false;
|
||||
|
|
|
@ -40,9 +40,8 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="rScripting, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\rScript\rScripting\bin\Release\rScripting.dll</HintPath>
|
||||
<Reference Include="rScripting">
|
||||
<HintPath>..\..\rScripting\rScripting\bin\Release\rScripting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
|
@ -58,6 +57,7 @@
|
|||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Attributes\ParseProperty.cs" />
|
||||
<Compile Include="Commands\CommandRestart.cs" />
|
||||
<Compile Include="Commands\CommandLogin.cs" />
|
||||
<Compile Include="Commands\CommandSaveWorld.cs" />
|
||||
|
|
|
@ -139,7 +139,7 @@ namespace MudEngine.Scripting
|
|||
public Boolean Compile(CompilerParameters param, FileInfo scriptFile)
|
||||
{
|
||||
//TODO: Add single-file compilation support
|
||||
return false; //Single file compiling not implemented
|
||||
return false; //Single file compiling not implemented. TODO!
|
||||
|
||||
//Make sure we have a compiler version supplied.
|
||||
if (!CompilerOptions.ContainsKey("CompilerVersion"))
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<ItemGroup>
|
||||
<Reference Include="rScripting, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\rScript\rScripting\bin\Release\rScripting.dll</HintPath>
|
||||
<HintPath>..\..\rScripting\rScripting\bin\Release\rScripting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue