/[MorrowindCustomClothingSlotCreator]/trunk/libTES3FileFormat/PlugingClothing.cs
ViewVC logotype

Diff of /trunk/libTES3FileFormat/PlugingClothing.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/libTES3FileFormat/PlugingClothing.cs	2011/07/30 09:15:16	30
+++ trunk/libTES3FileFormat/PlugingClothing.cs	2011/07/30 11:47:53	33
@@ -8,7 +8,7 @@
 
 namespace libTES3FileFormat
 {
-
+    
     public enum ClothingTypes
     {
         Pants,      /* 0 */
@@ -50,10 +50,59 @@
     }
     public class ClothingEntry : IClothingEntry, IComparable
     {
-        #region IComparable Members
+        internal EntryCommitEvent<ClothingEntry> OnEntryCommitEvent;
 
-        public int CompareTo(object obj) { return this.CLOT_NAME.CompareTo((obj as ClothingEntry).CLOT_NAME); }
+        //internal BinaryWriter writer = null;
+
+        public bool Commit(ICommitWriter commit_writer)
+        {
+            if (this.OnEntryCommitEvent != null)
+            {
+                return this.OnEntryCommitEvent.Invoke(this, commit_writer);
+            }
+            return false;
+        }
+
+
+        internal bool WriteCommit(ICommitWriter commit_writer)
+        {
+            bool ret = true;
+            BinaryWriter bw = commit_writer.GetWriter();
+            if (bw == null) return false;
+            bw.Seek(this.Offset, SeekOrigin.Begin);
+            // write out the data
+            try
+            {
+                bw.Write(this.CLOT_MAGIC);
+                bw.Write(this.CLOT_SIZE);
+
+                bw.Write(this.CLOT_NAME_MAGIC);
+                bw.Write(this.CLOT_NAME_LENGTH);
+                bw.Write(ASCIIEncoding.ASCII.GetBytes(this.CLOT_NAME));
+
+                bw.Write(this.CLOT_MODL_MAGIC);
+                bw.Write(this.CLOT_MODL_LENGTH);
+                bw.Write(ASCIIEncoding.ASCII.GetBytes(this.CLOT_MODL));
+
+                bw.Write(this.CLOT_FULLNAME_MAGIC);
+                bw.Write(this.CLOT_FULLNAME_LENGTH);
+                bw.Write(ASCIIEncoding.ASCII.GetBytes(this.CLOT_FULLNAME));
+
+                bw.Write(this.CLOT_CTDT_MAGIC);
+                bw.Write(this.CLOT_CTDT_SIZE);
+                bw.Write(this.CLOT_CTDT_TYPE);
+                bw.Write(this.CLOT_CTDT_WEIGHT);
+                bw.Write(this.CLOT_CTDT_VALUE);
+                bw.Write(this.CLOT_CTDT_ENCHANTPTS);
+                
+                bw.Write(this.CLOT_OTHER_DATA);
+            }
+            catch (Exception ex) { Console.WriteLine(ex.ToString()); ret = false; }
+            return ret;
+        }
 
+        #region IComparable Members
+        public int CompareTo(object obj) { return this.CLOT_NAME.CompareTo((obj as ClothingEntry).CLOT_NAME); }
         #endregion
         public ClothingEntry()
         {
@@ -117,6 +166,7 @@
     public interface IPlugingClothing : IParse, ICommit, IAsBytes, ISizeOffset
     {
         Dictionary<string, ClothingEntry> ClothingEntries { get; }
+        //bool CommitEntry(ClothingEntry entry);
     }
     public class PlugingClothing : IPlugingClothing, ICommitParseAsBytes
     {
@@ -153,6 +203,24 @@
         }
 
         #endregion
+
+        internal bool CommitEntry(ClothingEntry entry, ICommitWriter writer)
+        {
+            bool ret = false;
+            //if (writer == null) writer = new BinaryWriter(this.reader);
+            
+            ret = entry.WriteCommit(writer);
+            return ret;
+        }
+        internal bool CommitAllEntries(ICommitWriter writer)
+        {
+            bool ret = false;
+            foreach (KeyValuePair<string, ClothingEntry> key_pair in this.ClothingEntries)
+            {
+                ret = key_pair.Value.OnEntryCommitEvent(key_pair.Value, writer);
+            }
+            return ret;
+        }
         #region IParse Members
 
         public bool Parse(MemoryStream stream)
@@ -164,7 +232,7 @@
             for (int i = 0; i < this.SectionOffsets.Count; i++)
             {
                 ClothingEntry entry = new ClothingEntry();
-                
+                entry.OnEntryCommitEvent = new EntryCommitEvent<ClothingEntry>(this.CommitEntry); // commit callback
                 entry.Offset = this.SectionOffsets[i]; // set the offset for this entry
 
                 br.BaseStream.Seek(this.SectionOffsets[i], SeekOrigin.Begin);
@@ -286,9 +354,9 @@
 
         #region ICommit Members
 
-        public bool Commit(BinaryWriter writer)
+        public bool Commit(ICommitWriter writer)
         {
-            throw new NotImplementedException();
+            return this.CommitAllEntries(writer);
         }
 
         #endregion

 

  ViewVC Help
Powered by ViewVC 1.1.22