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:
Scionwest_cp 2011-09-13 20:20:12 -07:00
parent f8620d0f4d
commit 81f2ae91c0
6 changed files with 537 additions and 471 deletions

View 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;
}
}
}

View file

@ -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;

View file

@ -1,23 +1,24 @@
 //Microsoft .NET Framework
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
//Microsoft .NET Framework
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
//MUD Engine
using MudEngine.FileSystem;
using MudEngine.Commands;
using MudEngine.GameManagement;
using MudEngine.GameObjects;
using MudEngine.GameObjects.Environment;
using MudEngine.GameObjects.Items;
//MUD Engine
using MudEngine.Attributes;
using MudEngine.FileSystem;
using MudEngine.Commands;
using MudEngine.GameManagement;
using MudEngine.GameObjects;
using MudEngine.GameObjects.Environment;
using MudEngine.GameObjects.Items;
using System.Net;
using System.Net.Sockets;
using System.Net;
using System.Net.Sockets;
namespace MudEngine.GameObjects.Characters
{
namespace MudEngine.GameObjects.Characters
{
public class BaseCharacter : BaseObject
{
/// <summary>
@ -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;
@ -493,4 +496,4 @@
internal Socket client;
}
}
}

View file

@ -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" />

View file

@ -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"))

View file

@ -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" />