source: OniSplit/Objects/Trigger.cs@ 1177

Last change on this file since 1177 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.1 KB
RevLine 
[1114]1using System;
2using System.Xml;
3using Oni.Imaging;
4using Oni.Metadata;
5using Oni.Xml;
6
7namespace Oni.Objects
8{
9 internal class Trigger : GunkObject
10 {
11 public int ScriptId;
12 public TriggerFlags Flags;
13 public Color LaserColor;
14 public float StartPosition;
15 public float Speed;
16 public int EmitterCount;
17 public int TimeOn;
18 public int TimeOff;
19 public ObjectEvent[] Events;
20
21 public Trigger()
22 {
23 TypeId = ObjectType.Trigger;
24 }
25
26 protected override void WriteOsd(BinaryWriter writer)
27 {
28 writer.Write(ClassName, 63);
29 writer.WriteUInt16(ScriptId);
30 writer.WriteUInt16((ushort)Flags);
31 writer.Write(LaserColor);
32 writer.Write(StartPosition);
33 writer.Write(Speed);
34 writer.WriteUInt16(EmitterCount);
35 writer.WriteUInt16(TimeOn);
36 writer.WriteUInt16(TimeOff);
37 ObjectEvent.WriteEventList(writer, Events);
38 }
39
40 protected override void ReadOsd(BinaryReader reader)
41 {
42 ClassName = reader.ReadString(63);
43 ScriptId = reader.ReadUInt16();
44 Flags = (TriggerFlags)(reader.ReadUInt16() & ~0x84);
45 LaserColor = reader.ReadColor();
46 StartPosition = reader.ReadSingle();
47 Speed = reader.ReadSingle();
48 EmitterCount = reader.ReadUInt16();
49 TimeOn = reader.ReadUInt16();
50 TimeOff = reader.ReadUInt16();
51 Events = ObjectEvent.ReadEventList(reader);
52 }
53
54 protected override void WriteOsd(XmlWriter xml)
55 {
56 throw new NotImplementedException();
57 }
58
59 protected override void ReadOsd(XmlReader xml, ObjectLoadContext context)
60 {
61 string className = xml.ReadElementContentAsString("Class", "");
62
63 ScriptId = xml.ReadElementContentAsInt("TriggerId", "");
64 Flags = xml.ReadElementContentAsEnum<TriggerFlags>("Flags");
65
66 byte[] values = xml.ReadElementContentAsArray<byte>(XmlConvert.ToByte, "LaserColor");
67
68 if (values.Length > 3)
69 LaserColor = new Color(values[0], values[1], values[2], values[3]);
70 else
71 LaserColor = new Color(values[0], values[1], values[2]);
72
73 StartPosition = xml.ReadElementContentAsFloat("StartPosition", "");
74 Speed = xml.ReadElementContentAsFloat("Speed", "");
75 EmitterCount = xml.ReadElementContentAsInt("EmitterCount", "");
76
77 if (xml.IsStartElement("Offset_0075"))
78 TimeOn = xml.ReadElementContentAsInt();
79 else
80 TimeOn = xml.ReadElementContentAsInt("TimeOn", "");
81
82 if (xml.IsStartElement("Offset_0077"))
83 TimeOff = xml.ReadElementContentAsInt();
84 else
85 TimeOff = xml.ReadElementContentAsInt("TimeOff", "");
86
87 Events = ObjectEvent.ReadEventList(xml);
88
89 GunkClass = context.GetClass(TemplateTag.TRIG, className, TriggerClass.Read);
90 }
91 }
92}
Note: See TracBrowser for help on using the repository browser.