summaryrefslogtreecommitdiff
path: root/WADCollection.cs
diff options
context:
space:
mode:
Diffstat (limited to 'WADCollection.cs')
-rw-r--r--WADCollection.cs196
1 files changed, 196 insertions, 0 deletions
diff --git a/WADCollection.cs b/WADCollection.cs
new file mode 100644
index 0000000..ba6eb5b
--- /dev/null
+++ b/WADCollection.cs
@@ -0,0 +1,196 @@
+// Noddybox.DOOM - DOOM WAD Wrapper
+// Copyright (C) 2004 Ian Cowburn
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+//
+using System;
+using System.Collections;
+
+namespace Noddybox.DOOM
+{
+ /// <summary>
+ /// Performs operations on a collection of WADs
+ /// </summary>
+ public class WADCollection : IEnumerable, IEnumerator
+ {
+ // ====================================
+ // PUBLIC
+ // ====================================
+
+ /// <summary>
+ /// Delegate for WAD added event
+ /// </summary>
+ public delegate void WadAddedEvent(WADCollection collection, WAD wad);
+
+ /// <summary>
+ /// Delegate for WAD removed event
+ /// </summary>
+ public delegate void WadRemovedEvent(WADCollection collection);
+
+ /// <summary>
+ /// Create an empty collection of WADs
+ /// </summary>
+ public WADCollection()
+ {
+ m_wads=new ArrayList();
+ m_iter_index=-1;
+ }
+
+ /// <summary>
+ /// Add a WAD to the collection
+ /// </summary>
+ /// <param name="w">The WAD</param>
+ public void AddWad(WAD w)
+ {
+ m_wads.Add(w);
+
+ if (WadAdded!=null)
+ {
+ WadAdded(this,w);
+ }
+ }
+
+ /// <summary>
+ /// Remove a WAD from the collection
+ /// </summary>
+ /// <param name="w">The WAD</param>
+ public void RemoveWad(WAD w)
+ {
+ m_wads.Remove(w);
+
+ if (WadRemoved!=null)
+ {
+ WadRemoved(this);
+ }
+ }
+
+
+ /// <summary>
+ /// Get the first palette (PLAYPAL) lump from the WAD files
+ /// </summary>
+ /// <returns>The lump containing the palette, or null if not found</returns>
+ public WADEntry GetPalette()
+ {
+ return QueryDirectory("PLAYPAL");
+ }
+
+
+ /// <summary>
+ /// Queries the WAD directories for the named lump. Note it searches
+ /// back from the last loaded WAD as DOOM does.
+ /// </summary>
+ /// <param name="name">The lump name</param>
+ /// <returns>The lump, or null if it doesn't exist</returns>
+ public WADEntry QueryDirectory(string name)
+ {
+ for(int f=m_wads.Count-1;f>=0;f--)
+ {
+ WAD w=(WAD)m_wads[f];
+
+ WADEntry e=w.FindEntry("PLAYPAL");
+
+ if (e!=null)
+ {
+ return e;
+ }
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// Called when a WAD is added to the collection
+ /// </summary>
+ public event WadAddedEvent WadAdded;
+
+ /// <summary>
+ /// Called when a WAD is removed from the collection
+ /// </summary>
+ public event WadRemovedEvent WadRemoved;
+
+ /// <summary>
+ /// Returns the number of WADs in the collection
+ /// </summary>
+ public int Count
+ {
+ get {return m_wads.Count;}
+ }
+
+ /// <summary>
+ /// Index into the WADs
+ /// </summary>
+ public WAD this[int index]
+ {
+ get {return (WAD)m_wads[index];}
+ }
+
+ /// <summary>
+ /// Gets an enumerator
+ /// </summary>
+ /// <returns>The enumerator</returns>
+ public IEnumerator GetEnumerator()
+ {
+ Reset();
+ return this;
+ }
+
+ /// <summary>
+ /// Get the current object from the enumerator
+ /// </summary>
+ public object Current
+ {
+ get
+ {
+ if (m_iter_index==-1)
+ {
+ throw new InvalidOperationException();
+ }
+
+ return m_wads[m_iter_index];
+ }
+ }
+
+ /// <summary>
+ /// Reset the enumerator to the start of the collection.
+ /// </summary>
+ public void Reset()
+ {
+ m_iter_index=-1;
+ }
+
+ /// <summary>
+ /// Move the enumerator to the next item.
+ /// </summary>
+ /// <returns>True if there are more objects to enumerate over</returns>
+ public bool MoveNext()
+ {
+ m_iter_index++;
+
+ if (m_iter_index>=m_wads.Count)
+ {
+ m_iter_index=-1;
+ }
+
+ return m_iter_index!=-1;
+ }
+
+
+ // ====================================
+ // PRIVATE
+ // ====================================
+ private ArrayList m_wads;
+ private int m_iter_index;
+ }
+}