source: OniSplit/Particles/ImpactEffect.cs@ 1138

Last change on this file since 1138 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: 5.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Xml;
4using Oni.Metadata;
5
6namespace Oni.Particles
7{
8 internal class ImpactEffect
9 {
10 #region Private data
11 private string impactName;
12 private int impactIndex;
13 private string materialName;
14 private int materialIndex;
15 private ImpactEffectComponent component;
16 private ImpactEffectModifier modifier;
17 private ImpactEffectParticle[] particles;
18 private int particleIndex;
19 private ImpactEffectSound sound;
20 private int soundIndex;
21 #endregion
22
23 public ImpactEffect(BinaryReader reader, string[] impacts, string[] materials, ImpactEffectParticle[] particles, ImpactEffectSound[] sounds)
24 {
25 impactIndex = reader.ReadInt16();
26 impactName = impacts[impactIndex];
27 materialIndex = reader.ReadInt16();
28 materialName = materials[materialIndex];
29 component = (ImpactEffectComponent)reader.ReadInt16();
30 modifier = (ImpactEffectModifier)reader.ReadInt16();
31 int particleCount = reader.ReadInt16();
32 reader.Skip(2);
33 soundIndex = reader.ReadInt32();
34 particleIndex = reader.ReadInt32();
35
36 if (soundIndex != -1)
37 sound = sounds[soundIndex];
38
39 if (particleCount > 0)
40 {
41 this.particles = new ImpactEffectParticle[particleCount];
42 Array.Copy(particles, particleIndex, this.particles, 0, this.particles.Length);
43 }
44 }
45
46 public void Write(BinaryWriter writer)
47 {
48 writer.WriteInt16(impactIndex);
49 writer.WriteInt16(materialIndex);
50 writer.WriteInt16((short)component);
51 writer.WriteInt16((short)modifier);
52 writer.WriteInt16(particles.Length);
53 writer.Skip(2);
54 writer.Write(soundIndex);
55 writer.Write(particleIndex);
56 }
57
58 public ImpactEffect(XmlReader xml, string impact, string material)
59 {
60 impactName = impact;
61 materialName = material;
62 component = MetaEnum.Parse<ImpactEffectComponent>(xml.ReadElementContentAsString("Component", ""));
63 modifier = MetaEnum.Parse<ImpactEffectModifier>(xml.ReadElementContentAsString("Modifier", ""));
64
65 if (xml.IsStartElement("Sound"))
66 {
67 if (xml.IsEmptyElement)
68 {
69 xml.Skip();
70 }
71 else
72 {
73 xml.ReadStartElement();
74 sound = new ImpactEffectSound(xml);
75 xml.ReadEndElement();
76 }
77 }
78
79 var list = new List<ImpactEffectParticle>();
80
81 if (xml.IsStartElement("Particles"))
82 {
83 if (xml.IsEmptyElement)
84 {
85 xml.Skip();
86 }
87 else
88 {
89 xml.ReadStartElement();
90
91 while (xml.IsStartElement("Particle"))
92 {
93 xml.ReadStartElement();
94 list.Add(new ImpactEffectParticle(xml));
95 xml.ReadEndElement();
96 }
97
98 xml.ReadEndElement();
99 }
100 }
101
102 particles = list.ToArray();
103 }
104
105 public void Write(XmlWriter writer)
106 {
107 writer.WriteElementString("Component", component.ToString());
108 writer.WriteElementString("Modifier", modifier.ToString());
109
110 writer.WriteStartElement("Sound");
111
112 if (sound != null)
113 sound.Write(writer);
114
115 writer.WriteEndElement();
116
117 writer.WriteStartElement("Particles");
118
119 if (particles != null)
120 {
121 foreach (ImpactEffectParticle particle in particles)
122 {
123 writer.WriteStartElement("Particle");
124 particle.Write(writer);
125 writer.WriteEndElement();
126 }
127 }
128
129 writer.WriteEndElement();
130 }
131
132 public string ImpactName => impactName;
133
134 public int ImpactIndex
135 {
136 get { return impactIndex; }
137 set { impactIndex = value; }
138 }
139
140 public string MaterialName => materialName;
141
142 public int MaterialIndex
143 {
144 get { return materialIndex; }
145 set { materialIndex = value; }
146 }
147
148 public ImpactEffectComponent Component
149 {
150 get { return component; }
151 }
152
153 public ImpactEffectModifier Modifier
154 {
155 get { return modifier; }
156 }
157
158 public ImpactEffectSound Sound
159 {
160 get { return sound; }
161 }
162
163 public int SoundIndex
164 {
165 get { return soundIndex; }
166 set { soundIndex = value; }
167 }
168
169 public int ParticleIndex
170 {
171 get { return particleIndex; }
172 set { particleIndex = value; }
173 }
174
175 public ImpactEffectParticle[] Particles => particles;
176 }
177}
Note: See TracBrowser for help on using the repository browser.