OSDN Git Service

indentation
[automap/automap.git] / Automap / Data / CommandData.cs
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Drawing;
5 using System.IO;
6
7 using ProtoBuf;
8
9 using Vintagestory.API.Common;
10 using Vintagestory.API.Datastructures;
11
12 namespace Automap
13 {
14         [ProtoContract(SkipConstructor = true)]
15         //[ProtoInclude(5,typeof(DelegateState))]
16         public class CommandData : IAttribute
17         {
18                 [ProtoMember(1)]
19                 public RunState State { get; set; }//Run , Stop, SingleSnapshot -> Stop
20
21                 [ProtoMember(2)]
22                 private List<DelegateState> DelegatesFlags;
23
24                 [ProtoMember(3)]
25                 public string Notation { get; set; }
26
27                 //POI Delegate list {enabled/Disable}, color?
28                 //Other params...? Tick rate?
29                 //Choose : Renderer(s)
30
31
32                 public CommandData(RunState assumeState, bool[] theseDelegates)
33                 {
34                         State = assumeState;
35
36                         DelegatesFlags = new List<DelegateState>(theseDelegates.Length);
37                         foreach (var df in theseDelegates)
38                         {
39                                 DelegatesFlags.Add(new DelegateState()
40                                 {
41                                         Enabled = df,
42                                         AlternateColor = null,
43                                 });
44
45                         }
46
47                 }
48
49                 public CommandData(RunState assumeState)
50                 {
51                         State = assumeState;//Never RUN.
52
53                         DelegatesFlags = new List<DelegateState>();
54                 }
55
56
57                 public void FromBytes(BinaryReader stream)
58                 {
59                         var temp = ProtoBuf.Serializer.Deserialize<CommandData>(stream.BaseStream);
60                         this.State = temp.State;
61                         this.DelegatesFlags = temp.DelegatesFlags;
62
63                 }
64
65                 public void ToBytes(BinaryWriter stream)
66                 {
67                         ProtoBuf.Serializer.Serialize<CommandData>(stream.BaseStream, this);
68
69
70                 }
71
72
73
74                 public int GetAttributeId()
75                 {
76                         return 12346;
77                 }
78
79                 public object GetValue()
80                 {
81                         return this;
82                 }
83
84
85                 public string ToJsonToken()
86                 {
87                         return $"New-State:{State}, Delegates# {DelegatesFlags.Count} ";
88                 }
89
90                 public bool Equals(IWorldAccessor worldForResolve, IAttribute attr)
91                 {
92                         var other = attr.GetValue() as CommandData;
93
94                         if (this.State == other.State)
95                         {
96                                 return true;
97                         }
98
99                         return false;
100                 }
101         }
102
103         [ProtoContract]
104         internal struct DelegateState
105         {
106                 [ProtoMember(1)]
107                 public bool Enabled;
108
109                 [ProtoMember(2)]
110                 public Color? AlternateColor;
111
112
113
114         }
115 }
116