XMLData class added. This will manage the saving and loading of all scripted objects during runtime. The saved files will be XML formatted.
Added rScript files to the engine. These have not been implemented and currently don't work with the engine. BaseScript has been modified to support the new XMLData class for saving data.
This commit is contained in:
parent
fc27d9fc22
commit
38bdf75bf1
16 changed files with 1174 additions and 25 deletions
139
MudEngine/WinPC_Engine/Core/ObjectCollection.cs
Normal file
139
MudEngine/WinPC_Engine/Core/ObjectCollection.cs
Normal file
|
@ -0,0 +1,139 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using MudEngine.Game;
|
||||
using MudEngine.GameScripts;
|
||||
using MudEngine.Scripting;
|
||||
|
||||
namespace MudEngine.Core
|
||||
{
|
||||
internal class ObjectCollection : ICollection<BaseScript>
|
||||
{
|
||||
#region Public Properties
|
||||
public Boolean IsReadOnly
|
||||
{
|
||||
get { return this.isReadOnly; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region public Methods
|
||||
|
||||
#endregion
|
||||
|
||||
#region public Interface Methods
|
||||
/// <summary>
|
||||
/// Adds a new Scripted Object to the games Object Manager.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
public void Add(BaseScript item)
|
||||
{
|
||||
//Checks if the Object Manager is currently in Read-Only mode.
|
||||
if (this.isReadOnly)
|
||||
{
|
||||
Logger.WriteLine("Warning: Attempted to add a scripted object while the Object Manager is Read Only.");
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO: Allow the same Scripts to be used provided different ID's are assigned.
|
||||
if (!this.Contains(item))
|
||||
this.scriptCollection.Add(item);
|
||||
else
|
||||
Logger.WriteLine("Warning: Scripted object (" + item.ID.ToString() + ")" + item.Name + " was not added to the Object Manager due to being a duplicate.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the Object Manager of all Scripted Objects
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
this.scriptCollection.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the Object Manager currently has a Scripted Object matching the supplied Object.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public Boolean Contains(BaseScript item)
|
||||
{
|
||||
bool isFound = false;
|
||||
|
||||
foreach (BaseScript script in this.scriptCollection)
|
||||
{
|
||||
if (script.Equals(item))
|
||||
{
|
||||
isFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isFound;
|
||||
}
|
||||
|
||||
public void CopyTo(BaseScript[] array, int arrayIndex)
|
||||
{
|
||||
this.scriptCollection.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
public Int32 Count
|
||||
{
|
||||
get { return this.scriptCollection.Count; }
|
||||
}
|
||||
|
||||
public bool Remove(BaseScript item)
|
||||
{
|
||||
if (this.Contains(item))
|
||||
{
|
||||
this.scriptCollection.Remove(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Int32 Length { get { return this.scriptCollection.Count; } }
|
||||
|
||||
public IEnumerator<BaseScript> GetEnumerator()
|
||||
{
|
||||
return new ScriptEnumerator(this);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return new ScriptEnumerator(this);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
public ObjectCollection(StandardGame game)
|
||||
{
|
||||
this.scriptCollection = new List<BaseScript>();
|
||||
this.isReadOnly = false;
|
||||
|
||||
this._Game = game;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get or Set a index value for this collection
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
public BaseScript this[Int32 index]
|
||||
{
|
||||
//TODO: Perform some exception handling here.
|
||||
//TODO: Don't allow setting if isReadOnly=true
|
||||
get { return (BaseScript)this.scriptCollection[index]; }
|
||||
set { this.scriptCollection[index] = value; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Fields
|
||||
private List<BaseScript> scriptCollection;
|
||||
private Boolean isReadOnly;
|
||||
private StandardGame _Game;
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue