source: OniSplit/Objects/Door.cs@ 1114

Last change on this file since 1114 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.7 KB
Line 
1using System;
2using System.Xml;
3using Oni.Metadata;
4using Oni.Xml;
5
6namespace Oni.Objects
7{
8 internal class Door : GunkObject
9 {
10 public DoorClass Class;
11 public int ScriptId;
12 public int KeyId;
13 public DoorFlags Flags;
14 public Vector3 Center;
15 public float ActivationRadius = 30.0f;
16 public readonly string[] Textures = new string[2];
17 public ObjectEvent[] Events;
18
19 public Door()
20 {
21 TypeId = ObjectType.Door;
22 }
23
24 protected override void WriteOsd(BinaryWriter writer)
25 {
26 writer.Write(ClassName, 63);
27 writer.WriteUInt16(ScriptId);
28 writer.WriteUInt16(KeyId);
29 writer.WriteUInt16((ushort)Flags);
30 writer.Write(Center);
31 writer.Write(ActivationRadius * ActivationRadius);
32 writer.Write(Textures[0], 63);
33 writer.Write(Textures[1], 63);
34 ObjectEvent.WriteEventList(writer, Events);
35 }
36
37 protected override void ReadOsd(BinaryReader reader)
38 {
39 ClassName = reader.ReadString(63);
40 ScriptId = reader.ReadUInt16();
41 KeyId = reader.ReadUInt16();
42 Flags = (DoorFlags)reader.ReadInt16();
43 Center = reader.ReadVector3();
44 ActivationRadius = FMath.Sqrt(reader.ReadSingle());
45 Textures[0] = reader.ReadString(63).ToUpperInvariant();
46 Textures[1] = reader.ReadString(63).ToUpperInvariant();
47 Events = ObjectEvent.ReadEventList(reader);
48 }
49
50 protected override void WriteOsd(XmlWriter xml)
51 {
52 throw new NotImplementedException();
53 }
54
55 protected override void ReadOsd(XmlReader xml, ObjectLoadContext context)
56 {
57 string className = null;
58
59 while (xml.IsStartElement())
60 {
61 switch (xml.LocalName)
62 {
63 case "Class":
64 className = xml.ReadElementContentAsString();
65 break;
66 case "DoorId":
67 ScriptId = xml.ReadElementContentAsInt();
68 break;
69 case "KeyId":
70 KeyId = xml.ReadElementContentAsInt();
71 break;
72 case "Flags":
73 Flags = xml.ReadElementContentAsEnum<DoorFlags>();
74 break;
75 case "Center":
76 Center = xml.ReadElementContentAsVector3();
77 break;
78 case "SquaredActivationRadius":
79 ActivationRadius = FMath.Sqrt(xml.ReadElementContentAsFloat());
80 break;
81 case "ActivationRadius":
82 ActivationRadius = xml.ReadElementContentAsFloat();
83 break;
84 case "Texture":
85 case "Texture1":
86 Textures[0] = xml.ReadElementContentAsString().ToUpperInvariant();
87 break;
88 case "Texture2":
89 Textures[1] = xml.ReadElementContentAsString().ToUpperInvariant();
90 break;
91 case "Events":
92 Events = ObjectEvent.ReadEventList(xml);
93 break;
94 default:
95 xml.Skip();
96 break;
97 }
98
99 }
100
101 Class = context.GetClass(TemplateTag.DOOR, className, DoorClass.Read);
102 GunkClass = Class;
103 }
104 }
105}
Note: See TracBrowser for help on using the repository browser.