OSDN Git Service

55e770f1ba370e5d1f9b80dfbd95337f90c3fd36
[automap/automap.git] / Automap / Data / ColumnCounter.cs
1 using System;
2 using System.Linq;
3
4 using Vintagestory.API.MathTools;
5
6 namespace Automap
7 {
8         public struct ColumnCounter
9         {
10                 public bool NewOrLoaded;
11                 public byte[] EditTally;
12
13                 public uint WeightedSum 
14                 {
15                         get
16                         {//TODO: Rank deduction for lower chunks
17                                 return ( uint )(EditTally.Sum(ed => ed)) + (NewOrLoaded ? 100u : 0u);
18                         }
19                 }
20
21                 public ColumnCounter(int chunkSize)
22                 {
23                 NewOrLoaded = false;
24                 EditTally = new byte[chunkSize];
25                 }
26
27                 public ColumnCounter(int chunkSize, bool editLoaded)
28                 {
29                 NewOrLoaded = editLoaded;
30                 EditTally = new byte[chunkSize];
31                 }
32
33                 public ColumnCounter(int chunkSize, bool editLoaded, Vec3i chunkCoord)
34                 {
35                 int chunkY = chunkCoord.Y % chunkSize;
36
37                 NewOrLoaded = editLoaded;
38                 EditTally = new byte[chunkSize];
39
40                 EditTally[chunkY]++;
41                 }
42
43                 public ColumnCounter Update(Vec3i chunkCoord, int chunkSize)
44                 {
45                 int chunkY = chunkCoord.Y % chunkSize;
46                 EditTally[chunkY]++;
47
48                 return this;
49                 }
50
51                 public override string ToString( )
52                 {
53                         return $"{(NewOrLoaded?'N':'O')} W:{WeightedSum}";
54                 }
55 }
56 }
57