OSDN Git Service

re-load partial map metadata
[automap/automap.git] / Automap / Data / ColumnMeta.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Collections.ObjectModel;
4 using System.Linq;
5
6 using Vintagestory.API.MathTools;
7
8 namespace Automap
9 {
10
11         public struct ColumnMeta
12         {
13                 public Vec2i Location;
14                 public float Temperature;// Temperature
15                 public ushort YMax;// Y feature height
16                 public Dictionary<int,uint> RockRatio;//(surface) Geographic region (rock) Ratio. [BlockID * count]
17                 public float Fertility;
18                 public float ForestDensity;
19                 public float Rainfall;
20                 public float ShrubDensity;
21
22                 public ColumnMeta(Vec2i loc)
23                 {
24                 Location = loc;
25                 Temperature = 0f;
26                 YMax = 0;
27                 RockRatio = new Dictionary<int, uint>( 10 );
28                 Fertility = 0f;
29                 ForestDensity = 0f;
30                 Rainfall = 0f;
31                 ShrubDensity = 0f;
32                 }
33         }
34
35         public class ColumnsMetadata : KeyedCollection<Vec2i, ColumnMeta>
36         {
37                 private ColumnsMetadata( )
38                 {
39                         throw new NotSupportedException();
40                 }
41
42                 public ColumnsMetadata(Vec2i startChunkColumn)
43                 {
44                 North_mostChunk = startChunkColumn.Y;
45                 South_mostChunk = startChunkColumn.Y;
46                 East_mostChunk = startChunkColumn.X;
47                 West_mostChunk = startChunkColumn.X;
48                 }
49
50                 public int North_mostChunk {
51                         get; private set;
52                 }
53
54                 public int South_mostChunk {
55                         get; private set;
56                 }
57
58                 public int East_mostChunk {
59                         get; private set;
60                 }
61
62                 public int West_mostChunk {
63                         get; private set;
64                 }
65
66                 protected override Vec2i GetKeyForItem(ColumnMeta item)
67                 {
68                 return item.Location;
69                 }
70
71                 internal void Update(ColumnMeta metaData)
72                 {
73                 if (this.Contains(metaData.Location)) {
74                 this.Remove(metaData.Location);
75                 this.Add(metaData);
76                 }
77                 else {
78                 this.Add(metaData);
79                 }
80
81                 }
82
83                 public new void Add(ColumnMeta newItem)
84                 {
85                 if (North_mostChunk > newItem.Location.Y) {
86                 North_mostChunk = newItem.Location.Y;
87                 }
88
89                 if (South_mostChunk < newItem.Location.Y) {
90                 South_mostChunk = newItem.Location.Y;
91                 }
92
93                 if (East_mostChunk < newItem.Location.X) {
94                 East_mostChunk = newItem.Location.X;
95                 }
96
97                 if (West_mostChunk > newItem.Location.X) {
98                 West_mostChunk = newItem.Location.X;
99                 }
100
101                 base.Add(newItem);
102                 }
103
104         }
105 }
106