source: OniSplit/Objects/Flag.cs@ 1152

Last change on this file since 1152 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: 2.5 KB
Line 
1using System;
2using System.Xml;
3using Oni.Imaging;
4using Oni.Xml;
5
6namespace Oni.Objects
7{
8 internal class Flag : ObjectBase
9 {
10 public Color Color;
11 public string Prefix;
12 public int ScriptId;
13 public string Notes;
14
15 public Flag()
16 {
17 TypeId = ObjectType.Flag;
18 }
19
20 protected override void WriteOsd(BinaryWriter writer)
21 {
22 writer.Write(Color);
23 writer.Write(Prefix, 2);
24 writer.WriteInt16(ScriptId);
25 writer.Write(Notes, 128);
26 }
27
28 protected override void ReadOsd(BinaryReader reader)
29 {
30 Color = reader.ReadColor();
31 Prefix = reader.ReadString(2);
32 ScriptId = reader.ReadInt16();
33 Notes = reader.ReadString(128);
34 Prefix = new string(new char[] { Prefix[1], Prefix[0] });
35 }
36
37 protected override void WriteOsd(XmlWriter xml)
38 {
39 throw new NotImplementedException();
40 }
41
42 protected override void ReadOsd(XmlReader xml, ObjectLoadContext context)
43 {
44 while (xml.IsStartElement())
45 {
46 switch (xml.LocalName)
47 {
48 case "Color":
49 byte[] values = xml.ReadElementContentAsArray<byte>(XmlConvert.ToByte);
50
51 if (values.Length > 3)
52 Color = new Color(values[0], values[1], values[2], values[3]);
53 else
54 Color = new Color(values[0], values[1], values[2]);
55
56 break;
57 case "Prefix":
58 string prefix = xml.ReadElementContentAsString();
59
60 if (prefix.Length > 2)
61 {
62 int prefixId = int.Parse(prefix);
63 prefix = new string(new char[2] { (char)((prefixId >> 8) & 0xff), (char)(prefixId & 0xff) });
64 }
65
66 Prefix = prefix;
67 break;
68 case "FlagId":
69 ScriptId = xml.ReadElementContentAsInt();
70 break;
71 case "Note":
72 Notes = xml.ReadElementContentAsString();
73 break;
74 default:
75 xml.Skip();
76 break;
77 }
78 }
79 }
80 }
81}
Note: See TracBrowser for help on using the repository browser.