OSDN Git Service

W.I.P. VI: Automap Commanded by local event bus
[automap/automap.git] / Automap / Data / StatusData.cs
1 using System;
2 using System.IO;
3 using Vintagestory.API.Common;
4 using Vintagestory.API.Datastructures;
5
6 namespace Automap
7 {
8         public class StatusData : IAttribute
9         {
10                 public uint TotalUpdates { get; set; }
11                 public uint VoidChunks { get; set; }
12                 public uint Delta { get; set; }
13                 public uint Max_N, Max_E, Max_S, Max_W;
14                 public RunState CurrentState { get; set; }
15
16                 public StatusData(uint totalUpdates, uint voidChunks, uint delta, RunState currently  )
17                 {
18                 TotalUpdates = totalUpdates;
19                 VoidChunks = voidChunks;
20                 Delta = delta;
21                 CurrentState = currently;
22                 }
23
24                 public void FromBytes(BinaryReader stream)
25                 {
26                 TotalUpdates = stream.ReadUInt32( );
27                 VoidChunks = stream.ReadUInt32( );
28                 Delta = stream.ReadUInt32( );
29                 CurrentState = ( RunState )stream.ReadByte( );
30                 }
31
32                 public int GetAttributeId( )
33                 {
34                 return 12345;
35                 }
36
37                 public object GetValue( )
38                 {
39                 return this;
40                 }
41
42                 public void ToBytes(BinaryWriter stream)
43                 {
44                 stream.Write(TotalUpdates);
45                 stream.Write(VoidChunks);
46                 stream.Write(Delta);
47                 stream.Write((byte)CurrentState);
48                 }
49
50                 public string ToJsonToken( )
51                 {
52                 return $"TotalUpdate:{TotalUpdates}, VoidChunks:{VoidChunks}, Delta:{Delta}";
53                 }
54
55                 public bool Equals(IWorldAccessor worldForResolve, IAttribute attr)
56                 {
57                 StatusData other = attr.GetValue( ) as StatusData;
58
59                 if (this.TotalUpdates == other.TotalUpdates &&
60                         this.VoidChunks == other.VoidChunks &&
61                         this.Delta == other.Delta &&
62                         this.CurrentState == other.CurrentState) {
63                 return true;
64                 }
65                 return false;
66                 }
67         }
68 }
69