source: OniSplit/Sound/SabdXmlExporter.cs@ 1191

Last change on this file since 1191 was 1114, checked in by iritscen, 5 years ago

Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

File size: 3.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Xml;
5using Oni.Xml;
6
7namespace Oni.Sound
8{
9 internal class SabdXmlExporter : RawXmlExporter
10 {
11 private SabdXmlExporter(BinaryReader reader, XmlWriter xml)
12 : base(reader, xml)
13 {
14 }
15
16 public static void Export(BinaryReader reader, XmlWriter xml)
17 {
18 var exporter = new SabdXmlExporter(reader, xml);
19 exporter.Export();
20 }
21
22 private void Export()
23 {
24 var data = new SoundAnimationData(Reader);
25 data.Write(Xml);
26 }
27
28 private class SoundAnimationData
29 {
30 private readonly string variant;
31 private readonly List<SoundAssignment> assignments;
32
33 private enum Tag
34 {
35 SAFT = 0x54464153,
36 SAVT = 0x54564153,
37 SASA = 0x41534153
38 }
39
40 public SoundAnimationData(BinaryReader reader)
41 {
42 int dataEnd = reader.ReadInt32() + reader.Position;
43
44 int tag = reader.ReadInt32();
45
46 if ((Tag)tag != Tag.SAFT)
47 throw new InvalidDataException(string.Format("Unknown tag {0:X} found in sound animation", tag));
48
49 int size = reader.ReadInt32();
50 int unknown = reader.ReadInt32();
51
52 tag = reader.ReadInt32();
53
54 if ((Tag)tag != Tag.SAVT)
55 throw new InvalidDataException(string.Format("Unknown tag {0:X} found in sound animation", tag));
56
57 size = reader.ReadInt32();
58 variant = reader.ReadString(32);
59
60 assignments = new List<SoundAssignment>();
61
62 while (reader.Position < dataEnd)
63 {
64 tag = reader.ReadInt32();
65
66 if ((Tag)tag != Tag.SASA)
67 throw new InvalidDataException(string.Format("Unknown tag {0:X} found in sound animation", tag));
68
69 size = reader.ReadInt32();
70 assignments.Add(new SoundAssignment(reader));
71 }
72 }
73
74 public void Write(XmlWriter xml)
75 {
76 xml.WriteStartElement("SoundAnimation");
77 xml.WriteAttributeString("Variant", variant);
78
79 foreach (var assignment in assignments)
80 assignment.Write(xml);
81
82 xml.WriteEndElement();
83 }
84 }
85
86 private class SoundAssignment
87 {
88 private readonly int frame;
89 private readonly string modifier;
90 private readonly string type;
91 private readonly string animationName;
92 private readonly string soundName;
93
94 public SoundAssignment(BinaryReader reader)
95 {
96 frame = reader.ReadInt32();
97 modifier = reader.ReadString(32);
98 type = reader.ReadString(32);
99 animationName = reader.ReadString(32);
100 soundName = reader.ReadString(32);
101 }
102
103 public void Write(XmlWriter xml)
104 {
105 xml.WriteStartElement("Assignment");
106 xml.WriteStartElement("Target");
107
108 if (type != "Animation")
109 xml.WriteElementString("Type", type.Replace(" ", ""));
110 else
111 xml.WriteElementString("Animation", animationName);
112
113 if (modifier != "Any")
114 xml.WriteElementString("Modifier", modifier.Replace(" ", ""));
115
116 xml.WriteElementString("Frame", XmlConvert.ToString(frame));
117 xml.WriteEndElement();
118
119 xml.WriteElementString("Sound", soundName);
120 xml.WriteEndElement();
121 }
122 }
123 }
124}
Note: See TracBrowser for help on using the repository browser.