Automap (client) [VS plugin mod]
Revisión | e928c814ee4fd92ef6ad708947e33e4d8ad6f726 (tree) |
---|---|
Tiempo | 2020-02-21 09:00:41 |
Autor | The Grand Dog <alex.h@me.c...> |
Commiter | The Grand Dog |
indentation
@@ -20,36 +20,37 @@ namespace Automap | ||
20 | 20 | } |
21 | 21 | |
22 | 22 | public override void StartClientSide(ICoreClientAPI api) |
23 | - { | |
23 | + { | |
24 | 24 | this.API = api; |
25 | 25 | |
26 | - if (api.Side == EnumAppSide.Client) { | |
27 | - this.ClientAPI = api as ICoreClientAPI; | |
28 | - this.Logger = Mod.Logger; | |
26 | + if (api.Side == EnumAppSide.Client) | |
27 | + { | |
28 | + this.ClientAPI = api as ICoreClientAPI; | |
29 | + this.Logger = Mod.Logger; | |
29 | 30 | |
30 | 31 | |
31 | - ClientAPI.Logger.VerboseDebug("Automap Present!"); | |
32 | - _localAutomap = new AutomapSystem( this.ClientAPI, this.Logger); | |
33 | - _automapDialog = new AutomapGUIDialog(ClientAPI, _localAutomap); | |
32 | + ClientAPI.Logger.VerboseDebug("Automap Present!"); | |
33 | + _localAutomap = new AutomapSystem(this.ClientAPI, this.Logger); | |
34 | + _automapDialog = new AutomapGUIDialog(ClientAPI, _localAutomap); | |
34 | 35 | |
35 | - ClientAPI.Input.RegisterHotKey(AutomapGUIDialog._automapControlPanelKey, "Automap control panel", GlKeys.M, HotkeyType.GUIOrOtherControls, shiftPressed: true); | |
36 | - ClientAPI.Input.SetHotKeyHandler(AutomapGUIDialog._automapControlPanelKey, ToggleAM_Dialog); | |
36 | + ClientAPI.Input.RegisterHotKey(AutomapGUIDialog._automapControlPanelKey, "Automap control panel", GlKeys.M, HotkeyType.GUIOrOtherControls, shiftPressed: true); | |
37 | + ClientAPI.Input.SetHotKeyHandler(AutomapGUIDialog._automapControlPanelKey, ToggleAM_Dialog); | |
37 | 38 | } |
38 | 39 | |
39 | 40 | base.StartClientSide(api); |
40 | 41 | } |
41 | 42 | |
42 | - public override double ExecuteOrder( ) | |
43 | + public override double ExecuteOrder() | |
43 | 44 | { |
44 | - return 0.2; | |
45 | + return 0.2; | |
45 | 46 | } |
46 | 47 | |
47 | 48 | private bool ToggleAM_Dialog(KeyCombination comb) |
48 | 49 | { |
49 | - if (_automapDialog.IsOpened( )) _automapDialog.TryClose( ); | |
50 | - else _automapDialog.TryOpen( ); | |
50 | + if (_automapDialog.IsOpened()) _automapDialog.TryClose(); | |
51 | + else _automapDialog.TryOpen(); | |
51 | 52 | |
52 | - return true; | |
53 | + return true; | |
53 | 54 | } |
54 | 55 | } |
55 | 56 | } |
@@ -15,38 +15,38 @@ namespace Automap | ||
15 | 15 | /// Point of Interest Rule Designator |
16 | 16 | /// </summary> |
17 | 17 | public class BlockDesignator |
18 | - { | |
18 | + { | |
19 | 19 | public Color OverwriteColor; |
20 | 20 | public BlockDesignatonAction SpecialAction; |
21 | 21 | public AssetLocation Pattern; |
22 | 22 | public EnumBlockMaterial? Material; |
23 | 23 | public bool Enabled { get; set; } |
24 | 24 | |
25 | - private BlockDesignator( ) | |
25 | + private BlockDesignator() | |
26 | 26 | { |
27 | - throw new NotSupportedException( ); | |
27 | + throw new NotSupportedException(); | |
28 | 28 | } |
29 | 29 | |
30 | - public BlockDesignator( AssetLocation pattern , Color overwriteColor, EnumBlockMaterial? material) | |
31 | - { | |
30 | + public BlockDesignator(AssetLocation pattern, Color overwriteColor, EnumBlockMaterial? material) | |
31 | + { | |
32 | 32 | this.Pattern = pattern; |
33 | 33 | this.OverwriteColor = overwriteColor; |
34 | 34 | this.Material = material; |
35 | 35 | this.Enabled = true; |
36 | 36 | } |
37 | 37 | |
38 | - public BlockDesignator(AssetLocation pattern, Color overwriteColor, EnumBlockMaterial? material ,BlockDesignatonAction specialAct ) | |
38 | + public BlockDesignator(AssetLocation pattern, Color overwriteColor, EnumBlockMaterial? material, BlockDesignatonAction specialAct) | |
39 | 39 | { |
40 | - this.Pattern = pattern; | |
41 | - this.OverwriteColor = overwriteColor; | |
42 | - this.Material = material; | |
43 | - this.SpecialAction = specialAct; | |
44 | - this.Enabled = true; | |
40 | + this.Pattern = pattern; | |
41 | + this.OverwriteColor = overwriteColor; | |
42 | + this.Material = material; | |
43 | + this.SpecialAction = specialAct; | |
44 | + this.Enabled = true; | |
45 | 45 | } |
46 | 46 | |
47 | - public override string ToString( ) | |
47 | + public override string ToString() | |
48 | 48 | { |
49 | - return Pattern.ToShortString() +"|"+ OverwriteColor.Name + "|" + Material ?? ""; | |
49 | + return Pattern.ToShortString() + "|" + OverwriteColor.Name + "|" + Material ?? ""; | |
50 | 50 | } |
51 | 51 | } |
52 | 52 | } |
@@ -27,7 +27,7 @@ namespace Automap | ||
27 | 27 | public ushort YMax;// Y feature height |
28 | 28 | |
29 | 29 | [ProtoMember(5)] |
30 | - public Dictionary<int,uint> RockRatio;//[Column] Geographic region (rock) Ratio. [BlockID * count] | |
30 | + public Dictionary<int, uint> RockRatio;//[Column] Geographic region (rock) Ratio. [BlockID * count] | |
31 | 31 | |
32 | 32 | [ProtoMember(6)] |
33 | 33 | public float Fertility; |
@@ -49,105 +49,115 @@ namespace Automap | ||
49 | 49 | |
50 | 50 | //[ProtoMember(12,OverwriteList = true)] |
51 | 51 | [ProtoIgnore] |
52 | - public ushort[ , ] HeightMap; | |
52 | + public ushort[,] HeightMap; | |
53 | 53 | |
54 | 54 | public ColumnMeta(Vec2i loc, int chunkSize = 32) |
55 | 55 | { |
56 | - Location = loc; | |
57 | - ChunkAge = TimeSpan.Zero; | |
58 | - Temperature = 0f; | |
59 | - YMax = 0; | |
60 | - RockRatio = new Dictionary<int, uint>( 10 ); | |
61 | - Fertility = 0f; | |
62 | - ForestDensity = 0f; | |
63 | - Rainfall = 0f; | |
64 | - ShrubDensity = 0f; | |
65 | - AirBlocks = 0; | |
66 | - NonAirBlocks = 0; | |
67 | - HeightMap = new ushort[chunkSize, chunkSize]; | |
68 | - } | |
69 | - | |
70 | - internal void UpdateFieldsFrom(ClimateCondition climate, IMapChunk mapChunk ,TimeSpan chunkAge) | |
56 | + Location = loc; | |
57 | + ChunkAge = TimeSpan.Zero; | |
58 | + Temperature = 0f; | |
59 | + YMax = 0; | |
60 | + RockRatio = new Dictionary<int, uint>(10); | |
61 | + Fertility = 0f; | |
62 | + ForestDensity = 0f; | |
63 | + Rainfall = 0f; | |
64 | + ShrubDensity = 0f; | |
65 | + AirBlocks = 0; | |
66 | + NonAirBlocks = 0; | |
67 | + HeightMap = new ushort[chunkSize, chunkSize]; | |
68 | + } | |
69 | + | |
70 | + internal void UpdateFieldsFrom(ClimateCondition climate, IMapChunk mapChunk, TimeSpan chunkAge) | |
71 | 71 | { |
72 | - this.ChunkAge = chunkAge; | |
73 | - this.Temperature = climate.Temperature; | |
74 | - this.Fertility = climate.Fertility; | |
75 | - this.ForestDensity = climate.ForestDensity; | |
76 | - this.Rainfall = climate.Rainfall; | |
77 | - this.ShrubDensity = climate.ShrubDensity; | |
78 | - | |
79 | - this.YMax = mapChunk.YMax; | |
80 | - | |
72 | + this.ChunkAge = chunkAge; | |
73 | + this.Temperature = climate.Temperature; | |
74 | + this.Fertility = climate.Fertility; | |
75 | + this.ForestDensity = climate.ForestDensity; | |
76 | + this.Rainfall = climate.Rainfall; | |
77 | + this.ShrubDensity = climate.ShrubDensity; | |
78 | + | |
79 | + this.YMax = mapChunk.YMax; | |
80 | + | |
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | 84 | public class ColumnsMetadata : KeyedCollection<Vec2i, ColumnMeta> |
85 | 85 | { |
86 | - private ColumnsMetadata( ) | |
86 | + private ColumnsMetadata() | |
87 | 87 | { |
88 | 88 | throw new NotSupportedException(); |
89 | 89 | } |
90 | 90 | |
91 | 91 | public ColumnsMetadata(Vec2i startChunkColumn) |
92 | 92 | { |
93 | - North_mostChunk = startChunkColumn.Y; | |
94 | - South_mostChunk = startChunkColumn.Y; | |
95 | - East_mostChunk = startChunkColumn.X; | |
96 | - West_mostChunk = startChunkColumn.X; | |
93 | + North_mostChunk = startChunkColumn.Y; | |
94 | + South_mostChunk = startChunkColumn.Y; | |
95 | + East_mostChunk = startChunkColumn.X; | |
96 | + West_mostChunk = startChunkColumn.X; | |
97 | 97 | } |
98 | 98 | |
99 | - public int North_mostChunk { | |
99 | + public int North_mostChunk | |
100 | + { | |
100 | 101 | get; private set; |
101 | 102 | } |
102 | 103 | |
103 | - public int South_mostChunk { | |
104 | + public int South_mostChunk | |
105 | + { | |
104 | 106 | get; private set; |
105 | 107 | } |
106 | 108 | |
107 | - public int East_mostChunk { | |
109 | + public int East_mostChunk | |
110 | + { | |
108 | 111 | get; private set; |
109 | 112 | } |
110 | 113 | |
111 | - public int West_mostChunk { | |
114 | + public int West_mostChunk | |
115 | + { | |
112 | 116 | get; private set; |
113 | 117 | } |
114 | 118 | |
115 | 119 | protected override Vec2i GetKeyForItem(ColumnMeta item) |
116 | 120 | { |
117 | - return item.Location; | |
121 | + return item.Location; | |
118 | 122 | } |
119 | 123 | |
120 | 124 | internal void Update(ColumnMeta metaData) |
121 | 125 | { |
122 | - if (this.Contains(metaData.Location)) { | |
123 | - this.Remove(metaData.Location); | |
124 | - this.Add(metaData); | |
125 | - } | |
126 | - else { | |
127 | - this.Add(metaData); | |
128 | - } | |
126 | + if (this.Contains(metaData.Location)) | |
127 | + { | |
128 | + this.Remove(metaData.Location); | |
129 | + this.Add(metaData); | |
130 | + } | |
131 | + else | |
132 | + { | |
133 | + this.Add(metaData); | |
134 | + } | |
129 | 135 | |
130 | 136 | } |
131 | 137 | |
132 | 138 | public new void Add(ColumnMeta newItem) |
133 | 139 | { |
134 | - if (North_mostChunk > newItem.Location.Y) { | |
135 | - North_mostChunk = newItem.Location.Y; | |
136 | - } | |
137 | - | |
138 | - if (South_mostChunk < newItem.Location.Y) { | |
139 | - South_mostChunk = newItem.Location.Y; | |
140 | - } | |
141 | - | |
142 | - if (East_mostChunk < newItem.Location.X) { | |
143 | - East_mostChunk = newItem.Location.X; | |
144 | - } | |
145 | - | |
146 | - if (West_mostChunk > newItem.Location.X) { | |
147 | - West_mostChunk = newItem.Location.X; | |
148 | - } | |
149 | - | |
150 | - base.Add(newItem); | |
140 | + if (North_mostChunk > newItem.Location.Y) | |
141 | + { | |
142 | + North_mostChunk = newItem.Location.Y; | |
143 | + } | |
144 | + | |
145 | + if (South_mostChunk < newItem.Location.Y) | |
146 | + { | |
147 | + South_mostChunk = newItem.Location.Y; | |
148 | + } | |
149 | + | |
150 | + if (East_mostChunk < newItem.Location.X) | |
151 | + { | |
152 | + East_mostChunk = newItem.Location.X; | |
153 | + } | |
154 | + | |
155 | + if (West_mostChunk > newItem.Location.X) | |
156 | + { | |
157 | + West_mostChunk = newItem.Location.X; | |
158 | + } | |
159 | + | |
160 | + base.Add(newItem); | |
151 | 161 | } |
152 | 162 | |
153 | 163 | } |
@@ -29,72 +29,74 @@ namespace Automap | ||
29 | 29 | //Choose : Renderer(s) |
30 | 30 | |
31 | 31 | |
32 | - public CommandData( RunState assumeState, bool[] theseDelegates) | |
32 | + public CommandData(RunState assumeState, bool[] theseDelegates) | |
33 | 33 | { |
34 | - State = assumeState; | |
34 | + State = assumeState; | |
35 | 35 | |
36 | - DelegatesFlags = new List<DelegateState>(theseDelegates.Length); | |
37 | - foreach (var df in theseDelegates) { | |
38 | - DelegatesFlags.Add(new DelegateState( ) { | |
36 | + DelegatesFlags = new List<DelegateState>(theseDelegates.Length); | |
37 | + foreach (var df in theseDelegates) | |
38 | + { | |
39 | + DelegatesFlags.Add(new DelegateState() | |
40 | + { | |
39 | 41 | Enabled = df, |
40 | 42 | AlternateColor = null, |
41 | - }); | |
43 | + }); | |
42 | 44 | |
43 | - } | |
45 | + } | |
44 | 46 | |
45 | 47 | } |
46 | 48 | |
47 | 49 | public CommandData(RunState assumeState) |
48 | 50 | { |
49 | - State = assumeState;//Never RUN. | |
51 | + State = assumeState;//Never RUN. | |
50 | 52 | |
51 | - DelegatesFlags = new List<DelegateState>(); | |
53 | + DelegatesFlags = new List<DelegateState>(); | |
52 | 54 | } |
53 | 55 | |
54 | 56 | |
55 | 57 | public void FromBytes(BinaryReader stream) |
56 | 58 | { |
57 | - var temp = ProtoBuf.Serializer.Deserialize<CommandData>(stream.BaseStream); | |
58 | - this.State = temp.State; | |
59 | - this.DelegatesFlags = temp.DelegatesFlags; | |
59 | + var temp = ProtoBuf.Serializer.Deserialize<CommandData>(stream.BaseStream); | |
60 | + this.State = temp.State; | |
61 | + this.DelegatesFlags = temp.DelegatesFlags; | |
60 | 62 | |
61 | 63 | } |
62 | 64 | |
63 | 65 | public void ToBytes(BinaryWriter stream) |
64 | 66 | { |
65 | - ProtoBuf.Serializer.Serialize<CommandData>(stream.BaseStream, this); | |
66 | - | |
67 | + ProtoBuf.Serializer.Serialize<CommandData>(stream.BaseStream, this); | |
68 | + | |
67 | 69 | |
68 | 70 | } |
69 | 71 | |
70 | 72 | |
71 | 73 | |
72 | - public int GetAttributeId( ) | |
74 | + public int GetAttributeId() | |
73 | 75 | { |
74 | - return 12346; | |
76 | + return 12346; | |
75 | 77 | } |
76 | 78 | |
77 | - public object GetValue( ) | |
79 | + public object GetValue() | |
78 | 80 | { |
79 | - return this; | |
81 | + return this; | |
80 | 82 | } |
81 | 83 | |
82 | 84 | |
83 | - public string ToJsonToken( ) | |
85 | + public string ToJsonToken() | |
84 | 86 | { |
85 | 87 | return $"New-State:{State}, Delegates# {DelegatesFlags.Count} "; |
86 | 88 | } |
87 | 89 | |
88 | 90 | public bool Equals(IWorldAccessor worldForResolve, IAttribute attr) |
89 | 91 | { |
90 | - var other = attr.GetValue( ) as CommandData; | |
92 | + var other = attr.GetValue() as CommandData; | |
91 | 93 | |
92 | - if (this.State == other.State ) | |
93 | - { | |
94 | - return true; | |
94 | + if (this.State == other.State) | |
95 | + { | |
96 | + return true; | |
95 | 97 | } |
96 | 98 | |
97 | - return false; | |
99 | + return false; | |
98 | 100 | } |
99 | 101 | } |
100 | 102 |
@@ -12,33 +12,35 @@ namespace Automap | ||
12 | 12 | /// Entities of interest. |
13 | 13 | /// </summary> |
14 | 14 | /// <remarks>Tracked by ID - these never leave.</remarks> |
15 | - public class EntitiesOfInterest | |
15 | + public class EntitiesOfInterest | |
16 | 16 | { |
17 | 17 | private Dictionary<long, PointOfInterest> entitySet = new Dictionary<long, PointOfInterest>(50); |
18 | 18 | |
19 | 19 | |
20 | 20 | internal void Upsert(Entity something, string message = @"") |
21 | 21 | { |
22 | - if (entitySet.ContainsKey(something.EntityId)) { | |
23 | - var movingPOI = entitySet[something.EntityId]; | |
24 | - movingPOI.Location = something.Pos.AsBlockPos.Copy( ); | |
25 | - movingPOI.Timestamp = DateTimeOffset.UtcNow; | |
26 | - } | |
27 | - else { | |
28 | - PointOfInterest newPOI = new PointOfInterest( ); | |
29 | - newPOI.EntityId = something.EntityId; | |
30 | - newPOI.Location = something.Pos.AsBlockPos.Copy( ); | |
31 | - newPOI.Timestamp = DateTimeOffset.UtcNow; | |
32 | - newPOI.Notes = message; | |
33 | - entitySet.Add(something.EntityId, newPOI ); | |
34 | - } | |
35 | - | |
22 | + if (entitySet.ContainsKey(something.EntityId)) | |
23 | + { | |
24 | + var movingPOI = entitySet[something.EntityId]; | |
25 | + movingPOI.Location = something.Pos.AsBlockPos.Copy(); | |
26 | + movingPOI.Timestamp = DateTimeOffset.UtcNow; | |
27 | + } | |
28 | + else | |
29 | + { | |
30 | + PointOfInterest newPOI = new PointOfInterest(); | |
31 | + newPOI.EntityId = something.EntityId; | |
32 | + newPOI.Location = something.Pos.AsBlockPos.Copy(); | |
33 | + newPOI.Timestamp = DateTimeOffset.UtcNow; | |
34 | + newPOI.Notes = message; | |
35 | + entitySet.Add(something.EntityId, newPOI); | |
36 | + } | |
37 | + | |
36 | 38 | } |
37 | 39 | |
38 | 40 | |
39 | - public List<PointOfInterest> PointsList { | |
40 | - get | |
41 | - { | |
41 | + public List<PointOfInterest> PointsList | |
42 | + { | |
43 | + get { | |
42 | 44 | return entitySet.Values.ToList(); |
43 | 45 | } |
44 | 46 | } |
@@ -23,31 +23,31 @@ namespace Automap | ||
23 | 23 | public EnumEntityState? StateCheck;//Needed? |
24 | 24 | public bool Enabled { get; set; } |
25 | 25 | |
26 | - private EntityDesignator( ) | |
26 | + private EntityDesignator() | |
27 | 27 | { |
28 | - throw new NotSupportedException( ); | |
28 | + throw new NotSupportedException(); | |
29 | 29 | } |
30 | 30 | |
31 | 31 | public EntityDesignator(AssetLocation pattern, Color overwriteColor, EnumEntityState? state) |
32 | 32 | { |
33 | - this.Pattern = pattern; | |
34 | - this.OverwriteColor = overwriteColor; | |
35 | - this.StateCheck = state; | |
36 | - this.Enabled = true; | |
33 | + this.Pattern = pattern; | |
34 | + this.OverwriteColor = overwriteColor; | |
35 | + this.StateCheck = state; | |
36 | + this.Enabled = true; | |
37 | 37 | } |
38 | 38 | |
39 | 39 | public EntityDesignator(AssetLocation pattern, Color overwriteColor, EnumEntityState? state, EntityDesignatonAction specialAct) |
40 | 40 | { |
41 | - this.Pattern = pattern; | |
42 | - this.OverwriteColor = overwriteColor; | |
43 | - this.StateCheck = state; | |
44 | - this.SpecialAction = specialAct; | |
45 | - this.Enabled = true; | |
41 | + this.Pattern = pattern; | |
42 | + this.OverwriteColor = overwriteColor; | |
43 | + this.StateCheck = state; | |
44 | + this.SpecialAction = specialAct; | |
45 | + this.Enabled = true; | |
46 | 46 | } |
47 | 47 | |
48 | - public override string ToString( ) | |
48 | + public override string ToString() | |
49 | 49 | { |
50 | - return Pattern.ToShortString( ) + "|" + OverwriteColor.Name + "|" + StateCheck ?? ""; | |
50 | + return Pattern.ToShortString() + "|" + OverwriteColor.Name + "|" + StateCheck ?? ""; | |
51 | 51 | } |
52 | 52 | } |
53 | 53 | } |
@@ -21,33 +21,33 @@ namespace Automap | ||
21 | 21 | |
22 | 22 | public PngMetadataChunk(ImageInfo info) : base(ID, info) |
23 | 23 | { |
24 | - | |
24 | + | |
25 | 25 | } |
26 | 26 | |
27 | - public override ChunkOrderingConstraint GetOrderingConstraint( ) | |
27 | + public override ChunkOrderingConstraint GetOrderingConstraint() | |
28 | 28 | { |
29 | - return ChunkOrderingConstraint.NONE; | |
29 | + return ChunkOrderingConstraint.NONE; | |
30 | 30 | } |
31 | 31 | |
32 | - public override ChunkRaw CreateRawChunk( ) | |
33 | - { | |
34 | - var datas = SerializerUtil.Serialize<ColumnMeta>(ChunkMetadata); | |
32 | + public override ChunkRaw CreateRawChunk() | |
33 | + { | |
34 | + var datas = SerializerUtil.Serialize<ColumnMeta>(ChunkMetadata); | |
35 | 35 | |
36 | - ChunkRaw rawChunk = createEmptyChunk(datas.Length, true); | |
37 | - rawChunk.Data = datas; | |
36 | + ChunkRaw rawChunk = createEmptyChunk(datas.Length, true); | |
37 | + rawChunk.Data = datas; | |
38 | 38 | |
39 | - return rawChunk; | |
39 | + return rawChunk; | |
40 | 40 | } |
41 | 41 | |
42 | 42 | public override void ParseFromRaw(ChunkRaw rawChunk) |
43 | 43 | { |
44 | - this.ChunkMetadata = SerializerUtil.Deserialize<ColumnMeta>(rawChunk.Data); | |
44 | + this.ChunkMetadata = SerializerUtil.Deserialize<ColumnMeta>(rawChunk.Data); | |
45 | 45 | } |
46 | 46 | |
47 | 47 | public override void CloneDataFromRead(PngChunk other) |
48 | 48 | { |
49 | - PngMetadataChunk clone = ( PngMetadataChunk )other; | |
50 | - this.ChunkMetadata = clone.ChunkMetadata; | |
49 | + PngMetadataChunk clone = (PngMetadataChunk) other; | |
50 | + this.ChunkMetadata = clone.ChunkMetadata; | |
51 | 51 | } |
52 | 52 | |
53 | 53 | } |
@@ -10,7 +10,7 @@ namespace Automap | ||
10 | 10 | /// Actual Physical Point in space - that is interesting. |
11 | 11 | /// </summary> |
12 | 12 | public struct PointOfInterest |
13 | - { | |
13 | + { | |
14 | 14 | public string Notes; |
15 | 15 | public BlockPos Location; |
16 | 16 | public DateTimeOffset Timestamp; |
@@ -21,18 +21,20 @@ namespace Automap | ||
21 | 21 | { |
22 | 22 | protected override BlockPos GetKeyForItem(PointOfInterest item) |
23 | 23 | { |
24 | - return item.Location; | |
24 | + return item.Location; | |
25 | 25 | } |
26 | 26 | |
27 | 27 | internal void AddReplace(PointOfInterest poi) |
28 | 28 | { |
29 | - if (this.Contains(poi.Location)) { | |
30 | - this.Remove(poi.Location); | |
31 | - this.Add(poi); | |
32 | - } | |
33 | - else { | |
34 | - this.Add(poi); | |
35 | - } | |
29 | + if (this.Contains(poi.Location)) | |
30 | + { | |
31 | + this.Remove(poi.Location); | |
32 | + this.Add(poi); | |
33 | + } | |
34 | + else | |
35 | + { | |
36 | + this.Add(poi); | |
37 | + } | |
36 | 38 | |
37 | 39 | } |
38 | 40 | } |
@@ -3,66 +3,57 @@ using System.IO; | ||
3 | 3 | using Vintagestory.API.Common; |
4 | 4 | using Vintagestory.API.Datastructures; |
5 | 5 | |
6 | -namespace Automap | |
7 | -{ | |
8 | - public class StatusData : IAttribute | |
9 | - { | |
6 | +namespace Automap { | |
7 | + public class StatusData : IAttribute { | |
10 | 8 | public uint TotalUpdates { get; set; } |
11 | 9 | public uint VoidChunks { get; set; } |
12 | 10 | public uint Delta { get; set; } |
13 | 11 | public uint Max_N, Max_E, Max_S, Max_W; |
14 | 12 | public RunState CurrentState { get; set; } |
15 | 13 | |
16 | - public StatusData(uint totalUpdates, uint voidChunks, uint delta, RunState currently ) | |
17 | - { | |
18 | - TotalUpdates = totalUpdates; | |
19 | - VoidChunks = voidChunks; | |
20 | - Delta = delta; | |
21 | - CurrentState = currently; | |
14 | + public StatusData(uint totalUpdates, uint voidChunks, uint delta, RunState currently) { | |
15 | + TotalUpdates = totalUpdates; | |
16 | + VoidChunks = voidChunks; | |
17 | + Delta = delta; | |
18 | + CurrentState = currently; | |
22 | 19 | } |
23 | 20 | |
24 | - public void FromBytes(BinaryReader stream) | |
25 | - { | |
26 | - TotalUpdates = stream.ReadUInt32( ); | |
27 | - VoidChunks = stream.ReadUInt32( ); | |
28 | - Delta = stream.ReadUInt32( ); | |
29 | - CurrentState = ( RunState )stream.ReadByte( ); | |
21 | + public void FromBytes(BinaryReader stream) { | |
22 | + TotalUpdates = stream.ReadUInt32(); | |
23 | + VoidChunks = stream.ReadUInt32(); | |
24 | + Delta = stream.ReadUInt32(); | |
25 | + CurrentState = (RunState) stream.ReadByte(); | |
30 | 26 | } |
31 | 27 | |
32 | - public int GetAttributeId( ) | |
33 | - { | |
34 | - return 12345; | |
28 | + public int GetAttributeId() { | |
29 | + return 12345; | |
35 | 30 | } |
36 | 31 | |
37 | - public object GetValue( ) | |
38 | - { | |
39 | - return this; | |
32 | + public object GetValue() { | |
33 | + return this; | |
40 | 34 | } |
41 | 35 | |
42 | - public void ToBytes(BinaryWriter stream) | |
43 | - { | |
44 | - stream.Write(TotalUpdates); | |
45 | - stream.Write(VoidChunks); | |
46 | - stream.Write(Delta); | |
47 | - stream.Write((byte)CurrentState); | |
36 | + public void ToBytes(BinaryWriter stream) { | |
37 | + stream.Write(TotalUpdates); | |
38 | + stream.Write(VoidChunks); | |
39 | + stream.Write(Delta); | |
40 | + stream.Write((byte) CurrentState); | |
48 | 41 | } |
49 | 42 | |
50 | - public string ToJsonToken( ) | |
51 | - { | |
52 | - return $"TotalUpdate:{TotalUpdates}, VoidChunks:{VoidChunks}, Delta:{Delta}"; | |
43 | + public string ToJsonToken() { | |
44 | + return $"TotalUpdate:{TotalUpdates}, VoidChunks:{VoidChunks}, Delta:{Delta}"; | |
53 | 45 | } |
54 | 46 | |
55 | - public bool Equals(IWorldAccessor worldForResolve, IAttribute attr) | |
56 | - { | |
57 | - StatusData other = attr.GetValue( ) as StatusData; | |
47 | + public bool Equals(IWorldAccessor worldForResolve, IAttribute attr) { | |
48 | + StatusData other = attr.GetValue() as StatusData; | |
58 | 49 | |
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; | |
50 | + if (this.TotalUpdates == other.TotalUpdates && | |
51 | + this.VoidChunks == other.VoidChunks && | |
52 | + this.Delta == other.Delta && | |
53 | + this.CurrentState == other.CurrentState) { | |
54 | + return true; | |
55 | + } | |
56 | + return false; | |
66 | 57 | } |
67 | 58 | } |
68 | 59 | } |
@@ -55,7 +55,7 @@ namespace Automap | ||
55 | 55 | new EntityDesignator( |
56 | 56 | new AssetLocation("game", "humanoid-trader"), |
57 | 57 | Color.LightGoldenrodYellow, |
58 | - EnumEntityState.Active, | |
58 | + EnumEntityState.Active, | |
59 | 59 | KeepTrackOfMerchant |
60 | 60 | ); |
61 | 61 |
@@ -63,9 +63,9 @@ namespace Automap | ||
63 | 63 | /// Not just blocks, but block-entities as well! |
64 | 64 | /// </summary> |
65 | 65 | /// <returns>The block designators.</returns> |
66 | - public static List<BlockDesignator> DefaultBlockDesignators( ) | |
66 | + public static List<BlockDesignator> DefaultBlockDesignators() | |
67 | 67 | { |
68 | - return new List<BlockDesignator>{ | |
68 | + return new List<BlockDesignator>{ | |
69 | 69 | DefaultDesignators.Roads, |
70 | 70 | DefaultDesignators.GroundSigns, |
71 | 71 | DefaultDesignators.WallSigns, |
@@ -74,7 +74,7 @@ namespace Automap | ||
74 | 74 | }; |
75 | 75 | } |
76 | 76 | |
77 | - public static List<EntityDesignator> DefaultEntityDesignators( ) | |
77 | + public static List<EntityDesignator> DefaultEntityDesignators() | |
78 | 78 | { |
79 | 79 | return new List<EntityDesignator>{ |
80 | 80 | DefaultDesignators.Traders, |
@@ -83,86 +83,92 @@ namespace Automap | ||
83 | 83 | |
84 | 84 | internal static void DecodeSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block) |
85 | 85 | { |
86 | - #if DEBUG | |
87 | - clientAPI.Logger.VerboseDebug("Sign Designator Invoked!"); | |
88 | - #endif | |
89 | - //sign Text into a POI field... | |
90 | - BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign; | |
91 | - | |
92 | - if (signEntity != null && !String.IsNullOrEmpty(signEntity.text)) | |
93 | - { | |
94 | - | |
95 | - poi.AddReplace( | |
96 | - new PointOfInterest { | |
97 | - Location = posn.Copy( ), | |
98 | - Notes = signEntity.text, | |
99 | - Timestamp = DateTimeOffset.UtcNow, | |
100 | - } | |
101 | - ); | |
102 | - | |
103 | - } | |
86 | +#if DEBUG | |
87 | + clientAPI.Logger.VerboseDebug("Sign Designator Invoked!"); | |
88 | +#endif | |
89 | + //sign Text into a POI field... | |
90 | + BlockEntitySign signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySign; | |
91 | + | |
92 | + if (signEntity != null && !String.IsNullOrEmpty(signEntity.text)) | |
93 | + { | |
94 | + | |
95 | + poi.AddReplace( | |
96 | + new PointOfInterest | |
97 | + { | |
98 | + Location = posn.Copy(), | |
99 | + Notes = signEntity.text, | |
100 | + Timestamp = DateTimeOffset.UtcNow, | |
101 | + } | |
102 | + ); | |
103 | + | |
104 | + } | |
104 | 105 | |
105 | 106 | } |
106 | 107 | |
107 | 108 | |
108 | 109 | internal static void DecodePostSign(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block) |
109 | 110 | { |
110 | - #if DEBUG | |
111 | - clientAPI.Logger.VerboseDebug("Post-sign Designator Invoked!"); | |
112 | - #endif | |
113 | - //sign post Text into a POI field... | |
114 | - BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost; | |
115 | - | |
116 | - if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0 ) { | |
117 | - | |
118 | - poi.AddReplace( | |
119 | - new PointOfInterest { | |
120 | - Location = posn.Copy( ), | |
121 | - Notes = string.Join(",", signEntity.textByCardinalDirection), | |
122 | - Timestamp = DateTimeOffset.UtcNow, | |
123 | - } | |
124 | - ); | |
125 | - | |
126 | - } | |
111 | +#if DEBUG | |
112 | + clientAPI.Logger.VerboseDebug("Post-sign Designator Invoked!"); | |
113 | +#endif | |
114 | + //sign post Text into a POI field... | |
115 | + BlockEntitySignPost signEntity = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntitySignPost; | |
116 | + | |
117 | + if (signEntity != null && signEntity.textByCardinalDirection?.Length > 0) | |
118 | + { | |
119 | + | |
120 | + poi.AddReplace( | |
121 | + new PointOfInterest | |
122 | + { | |
123 | + Location = posn.Copy(), | |
124 | + Notes = string.Join(",", signEntity.textByCardinalDirection), | |
125 | + Timestamp = DateTimeOffset.UtcNow, | |
126 | + } | |
127 | + ); | |
128 | + | |
129 | + } | |
127 | 130 | } |
128 | 131 | |
129 | 132 | internal static void KeepTrackOfMerchant(ICoreClientAPI clientAPI, EntitiesOfInterest poi, BlockPos posn, Entity entity) |
130 | 133 | { |
131 | - clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName( ), posn); | |
132 | - | |
133 | - var message = $"{entity.GetName( )}"; | |
134 | - var traderJoe = entity as EntityTrader; | |
135 | - if (traderJoe.TradeProps != null) { | |
136 | - message = $"{traderJoe.GetName( )} Alive:{traderJoe.Alive} - Gears: {traderJoe.TradeProps.Money}, "; | |
137 | - } | |
138 | - poi.Upsert(entity, message); | |
134 | + clientAPI.Logger.VerboseDebug("Trader: {0} @ {1}", entity.GetName(), posn); | |
135 | + | |
136 | + var message = $"{entity.GetName()}"; | |
137 | + var traderJoe = entity as EntityTrader; | |
138 | + if (traderJoe.TradeProps != null) | |
139 | + { | |
140 | + message = $"{traderJoe.GetName()} Alive:{traderJoe.Alive} - Gears: {traderJoe.TradeProps.Money}, "; | |
141 | + } | |
142 | + poi.Upsert(entity, message); | |
139 | 143 | } |
140 | 144 | |
141 | 145 | internal static void DecodeTranslocator(ICoreClientAPI clientAPI, PointsOfInterest poi, BlockPos posn, Block block) |
142 | 146 | { |
143 | - clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!"); | |
144 | - //Where to? and from! | |
145 | - | |
146 | - BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator; | |
147 | + clientAPI.Logger.VerboseDebug("TRANSLOCATOR Designator Invoked!"); | |
148 | + //Where to? and from! | |
147 | 149 | |
148 | - if (te != null ) { | |
150 | + BlockEntityStaticTranslocator te = clientAPI.World.BlockAccessor.GetBlockEntity(posn) as BlockEntityStaticTranslocator; | |
149 | 151 | |
150 | - StringBuilder textTarget = new StringBuilder( ); | |
151 | - //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget); | |
152 | + if (te != null) | |
153 | + { | |
152 | 154 | |
153 | - textTarget.Append(te.Activated ? "Online " : "offline "); | |
154 | - textTarget.Append(" Dest.: "); | |
155 | - textTarget.Append(te.TargetLocation != null ? te.TargetLocation.PrettyCoords(clientAPI) : "???");//Or ABS coords? | |
155 | + StringBuilder textTarget = new StringBuilder(); | |
156 | + //translocatorEntity.GetBlockInfo(clientAPI.World.Player, textTarget); | |
156 | 157 | |
157 | - poi.AddReplace( | |
158 | - new PointOfInterest { | |
159 | - Location = posn.Copy( ), | |
160 | - Notes = textTarget.ToString(), | |
161 | - Timestamp = DateTimeOffset.UtcNow, | |
162 | - } | |
163 | - ); | |
158 | + textTarget.Append(te.Activated ? "Online " : "offline "); | |
159 | + textTarget.Append(" Dest.: "); | |
160 | + textTarget.Append(te.TargetLocation != null ? te.TargetLocation.PrettyCoords(clientAPI) : "???");//Or ABS coords? | |
164 | 161 | |
165 | - } | |
162 | + poi.AddReplace( | |
163 | + new PointOfInterest | |
164 | + { | |
165 | + Location = posn.Copy(), | |
166 | + Notes = textTarget.ToString(), | |
167 | + Timestamp = DateTimeOffset.UtcNow, | |
168 | + } | |
169 | + ); | |
170 | + | |
171 | + } | |
166 | 172 | } |
167 | 173 | } |
168 | 174 | } |
@@ -21,106 +21,114 @@ namespace Automap | ||
21 | 21 | /// <param name="logger">Logger.</param> |
22 | 22 | public AlternateRenderer(ICoreClientAPI clientAPI, ILogger logger) : base(clientAPI, logger) |
23 | 23 | { |
24 | - chunkSize = ClientAPI.World.BlockAccessor.ChunkSize; | |
24 | + chunkSize = ClientAPI.World.BlockAccessor.ChunkSize; | |
25 | 25 | } |
26 | 26 | |
27 | 27 | public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount) |
28 | - { | |
29 | - pixelCount = 0; | |
30 | - BlockPos tmpPos = new BlockPos( ); | |
31 | - Vec2i localpos = new Vec2i( ); | |
32 | - var chunksColumn = new IWorldChunk[ClientAPI.World.BlockAccessor.MapSizeY / chunkSize]; | |
33 | - | |
34 | - int topChunkY = mc.YMax / chunkSize;//Heywaitaminute -- this isn't a highest FEATURE, if Rainmap isn't accurate! | |
35 | - //Metadata of DateTime chunk was edited, chunk coords.,world-seed? Y-Max feature height | |
36 | - //Grab a chunk COLUMN... Topmost Y down... | |
37 | - for (int chunkY = 0; chunkY <= topChunkY; chunkY++) { | |
38 | - chunksColumn[chunkY] = ClientAPI.World.BlockAccessor.GetChunk(chunkPos.X, chunkY, chunkPos.Y); | |
39 | - //What to do if chunk is a void? invalid? | |
40 | - } | |
41 | - | |
42 | - //pre-create PNG line slices... | |
43 | - ImageLine[ ] lines = Enumerable.Repeat(new object( ), chunkSize).Select(l => new ImageLine(pngWriter.ImgInfo)).ToArray( ); | |
44 | - ushort[ ] allMapYs = mc.RainHeightMap; | |
45 | - for (int posIndex = 0; posIndex < (chunkSize * chunkSize); posIndex++) { | |
46 | - int currY = allMapYs[posIndex]; | |
47 | - int localChunkY = currY / chunkSize; | |
48 | - if (localChunkY >= (chunksColumn.Length)) continue; //Out of range! | |
49 | - if (chunksColumn[localChunkY] == null) continue; | |
50 | - | |
51 | - MapUtil.PosInt2d(posIndex, chunkSize, localpos); | |
52 | - int localX = localpos.X; | |
53 | - int localZ = localpos.Y; | |
54 | - | |
55 | - chunksColumn[localChunkY].Unpack( ); | |
56 | - int blockId = chunksColumn[localChunkY].Blocks[MapUtil.Index3d(localX, currY % chunkSize, localZ, chunkSize, chunkSize)]; | |
57 | - | |
58 | - Block block = ClientAPI.World.Blocks[blockId]; | |
59 | - | |
60 | - tmpPos.Set(chunkSize * chunkPos.X + localX, currY, chunkSize * chunkPos.Y + localZ); | |
61 | - | |
62 | - int red; | |
63 | - int green; | |
64 | - int blue; | |
65 | - | |
66 | - //============ POI Population ================= | |
67 | - if (BlockID_Designators.ContainsKey(blockId)) { | |
68 | - var desig = BlockID_Designators[blockId]; | |
69 | - red = desig.OverwriteColor.R; | |
70 | - green = desig.OverwriteColor.G; | |
71 | - blue = desig.OverwriteColor.B; | |
72 | - | |
73 | - | |
74 | - ImageLineHelper.SetPixel(lines[localZ], localX, red, green, blue); | |
75 | - continue; | |
76 | - } | |
77 | - | |
78 | - float b = GetSlope(localX, localZ, allMapYs); | |
79 | - | |
80 | - int col = block.GetColor(ClientAPI, tmpPos); | |
81 | - int packedFormat = ColorUtil.ColorMultiply3Clamped(col, b); | |
82 | - | |
83 | - red = ColorUtil.ColorB(packedFormat); | |
84 | - green = ColorUtil.ColorG(packedFormat); | |
85 | - blue = ColorUtil.ColorR(packedFormat); | |
86 | - ImageLineHelper.SetPixel(lines[localZ], localX, red, green, blue); | |
87 | - | |
88 | - //chunkImage.SetPixel(localX, localZ, pixelColor); | |
89 | - pixelCount++; | |
90 | - } | |
91 | - | |
92 | - for (int row = 0; row < pngWriter.ImgInfo.Rows; row++) { | |
93 | - pngWriter.WriteRow(lines[row], row); | |
94 | - } | |
95 | - | |
96 | - pngWriter.End( ); | |
28 | + { | |
29 | + pixelCount = 0; | |
30 | + BlockPos tmpPos = new BlockPos(); | |
31 | + Vec2i localpos = new Vec2i(); | |
32 | + var chunksColumn = new IWorldChunk[ClientAPI.World.BlockAccessor.MapSizeY / chunkSize]; | |
33 | + | |
34 | + int topChunkY = mc.YMax / chunkSize;//Heywaitaminute -- this isn't a highest FEATURE, if Rainmap isn't accurate! | |
35 | + //Metadata of DateTime chunk was edited, chunk coords.,world-seed? Y-Max feature height | |
36 | + //Grab a chunk COLUMN... Topmost Y down... | |
37 | + for (int chunkY = 0; chunkY <= topChunkY; chunkY++) | |
38 | + { | |
39 | + chunksColumn[chunkY] = ClientAPI.World.BlockAccessor.GetChunk(chunkPos.X, chunkY, chunkPos.Y); | |
40 | + //What to do if chunk is a void? invalid? | |
41 | + } | |
42 | + | |
43 | + //pre-create PNG line slices... | |
44 | + ImageLine[] lines = Enumerable.Repeat(new object(), chunkSize).Select(l => new ImageLine(pngWriter.ImgInfo)).ToArray(); | |
45 | + ushort[] allMapYs = mc.RainHeightMap; | |
46 | + for (int posIndex = 0; posIndex < (chunkSize * chunkSize); posIndex++) | |
47 | + { | |
48 | + int currY = allMapYs[posIndex]; | |
49 | + int localChunkY = currY / chunkSize; | |
50 | + if (localChunkY >= (chunksColumn.Length)) continue; //Out of range! | |
51 | + if (chunksColumn[localChunkY] == null) continue; | |
52 | + | |
53 | + MapUtil.PosInt2d(posIndex, chunkSize, localpos); | |
54 | + int localX = localpos.X; | |
55 | + int localZ = localpos.Y; | |
56 | + | |
57 | + chunksColumn[localChunkY].Unpack(); | |
58 | + int blockId = chunksColumn[localChunkY].Blocks[MapUtil.Index3d(localX, currY % chunkSize, localZ, chunkSize, chunkSize)]; | |
59 | + | |
60 | + Block block = ClientAPI.World.Blocks[blockId]; | |
61 | + | |
62 | + tmpPos.Set(chunkSize * chunkPos.X + localX, currY, chunkSize * chunkPos.Y + localZ); | |
63 | + | |
64 | + int red; | |
65 | + int green; | |
66 | + int blue; | |
67 | + | |
68 | + //============ POI Population ================= | |
69 | + if (BlockID_Designators.ContainsKey(blockId)) | |
70 | + { | |
71 | + var desig = BlockID_Designators[blockId]; | |
72 | + red = desig.OverwriteColor.R; | |
73 | + green = desig.OverwriteColor.G; | |
74 | + blue = desig.OverwriteColor.B; | |
75 | + | |
76 | + | |
77 | + ImageLineHelper.SetPixel(lines[localZ], localX, red, green, blue); | |
78 | + continue; | |
79 | + } | |
80 | + | |
81 | + float b = GetSlope(localX, localZ, allMapYs); | |
82 | + | |
83 | + int col = block.GetColor(ClientAPI, tmpPos); | |
84 | + int packedFormat = ColorUtil.ColorMultiply3Clamped(col, b); | |
85 | + | |
86 | + red = ColorUtil.ColorB(packedFormat); | |
87 | + green = ColorUtil.ColorG(packedFormat); | |
88 | + blue = ColorUtil.ColorR(packedFormat); | |
89 | + ImageLineHelper.SetPixel(lines[localZ], localX, red, green, blue); | |
90 | + | |
91 | + //chunkImage.SetPixel(localX, localZ, pixelColor); | |
92 | + pixelCount++; | |
93 | + } | |
94 | + | |
95 | + for (int row = 0; row < pngWriter.ImgInfo.Rows; row++) | |
96 | + { | |
97 | + pngWriter.WriteRow(lines[row], row); | |
98 | + } | |
99 | + | |
100 | + pngWriter.End(); | |
97 | 101 | } |
98 | 102 | |
99 | - private float GetSlope(int x, int y, ushort[ ] heightMap) | |
103 | + private float GetSlope(int x, int y, ushort[] heightMap) | |
100 | 104 | { |
101 | - int baseY = heightMap[MapUtil.Index2d(x, y, chunkSize)]; | |
102 | - float runningY = 0; | |
103 | - // check bounds. i hate this. | |
104 | - int locIndex; | |
105 | - if (x > 0) { | |
106 | - locIndex = MapUtil.Index2d(x - 1, y, chunkSize); | |
107 | - runningY += (baseY - heightMap[locIndex]); | |
108 | - } | |
109 | - if (x < chunkSize - 1) { | |
110 | - locIndex = MapUtil.Index2d(x + 1, y, chunkSize); | |
111 | - runningY += (baseY - heightMap[locIndex]); | |
112 | - } | |
113 | - if (y > 0) { | |
114 | - locIndex = MapUtil.Index2d(x, y - 1, chunkSize); | |
115 | - runningY += (baseY - heightMap[locIndex]); | |
116 | - } | |
117 | - if (y < chunkSize - 1) { | |
118 | - locIndex = MapUtil.Index2d(x, y + 1, chunkSize); | |
119 | - runningY += (baseY - heightMap[locIndex]); | |
120 | - } | |
121 | - runningY /= 4; // average now | |
122 | - runningY /= 5; // idk | |
123 | - return 1 + runningY; | |
105 | + int baseY = heightMap[MapUtil.Index2d(x, y, chunkSize)]; | |
106 | + float runningY = 0; | |
107 | + // check bounds. i hate this. | |
108 | + int locIndex; | |
109 | + if (x > 0) | |
110 | + { | |
111 | + locIndex = MapUtil.Index2d(x - 1, y, chunkSize); | |
112 | + runningY += (baseY - heightMap[locIndex]); | |
113 | + } | |
114 | + if (x < chunkSize - 1) | |
115 | + { | |
116 | + locIndex = MapUtil.Index2d(x + 1, y, chunkSize); | |
117 | + runningY += (baseY - heightMap[locIndex]); | |
118 | + } | |
119 | + if (y > 0) | |
120 | + { | |
121 | + locIndex = MapUtil.Index2d(x, y - 1, chunkSize); | |
122 | + runningY += (baseY - heightMap[locIndex]); | |
123 | + } | |
124 | + if (y < chunkSize - 1) | |
125 | + { | |
126 | + locIndex = MapUtil.Index2d(x, y + 1, chunkSize); | |
127 | + runningY += (baseY - heightMap[locIndex]); | |
128 | + } | |
129 | + runningY /= 4; // average now | |
130 | + runningY /= 5; // idk | |
131 | + return 1 + runningY; | |
124 | 132 | } |
125 | 133 | } |
126 | 134 | } |
@@ -17,8 +17,8 @@ namespace Automap | ||
17 | 17 | |
18 | 18 | protected IChunkRenderer(ICoreClientAPI clientAPI, ILogger logger) |
19 | 19 | { |
20 | - this.ClientAPI = clientAPI; | |
21 | - this.Logger = logger; | |
20 | + this.ClientAPI = clientAPI; | |
21 | + this.Logger = logger; | |
22 | 22 | } |
23 | 23 | |
24 | 24 | public abstract void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mapChunk, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount); |
@@ -19,133 +19,142 @@ namespace Automap | ||
19 | 19 | /// </summary> |
20 | 20 | /// <param name="clientAPI">Client API.</param> |
21 | 21 | /// <param name="logger">Logger.</param> |
22 | - public StandardRenderer(ICoreClientAPI clientAPI, ILogger logger) : base (clientAPI, logger) | |
22 | + public StandardRenderer(ICoreClientAPI clientAPI, ILogger logger) : base(clientAPI, logger) | |
23 | 23 | { |
24 | - chunkSize = ClientAPI.World.BlockAccessor.ChunkSize; | |
24 | + chunkSize = ClientAPI.World.BlockAccessor.ChunkSize; | |
25 | 25 | } |
26 | 26 | |
27 | 27 | public override void GenerateChunkPngShard(Vec2i chunkPos, IMapChunk mc, ColumnMeta metaData, PngWriter pngWriter, out uint pixelCount) |
28 | 28 | { |
29 | - pixelCount = 0; | |
30 | - BlockPos tmpPos = new BlockPos( ); | |
31 | - Vec2i localpos = new Vec2i( ); | |
32 | - | |
33 | - var chunksColumn = new IWorldChunk[ClientAPI.World.BlockAccessor.MapSizeY / chunkSize]; | |
29 | + pixelCount = 0; | |
30 | + BlockPos tmpPos = new BlockPos(); | |
31 | + Vec2i localpos = new Vec2i(); | |
34 | 32 | |
35 | - int topChunkY = mc.YMax / chunkSize;//Heywaitaminute -- this isn't a highest FEATURE, if Rainmap isn't accurate! | |
33 | + var chunksColumn = new IWorldChunk[ClientAPI.World.BlockAccessor.MapSizeY / chunkSize]; | |
36 | 34 | |
37 | - for (int chunkY = 0; chunkY <= topChunkY; chunkY++) { | |
38 | - chunksColumn[chunkY] = ClientAPI.World.BlockAccessor.GetChunk(chunkPos.X, chunkY, chunkPos.Y); | |
39 | - //What to do if chunk is a void? invalid? | |
40 | - } | |
35 | + int topChunkY = mc.YMax / chunkSize;//Heywaitaminute -- this isn't a highest FEATURE, if Rainmap isn't accurate! | |
41 | 36 | |
42 | - // Prefetch map chunks, in pattern | |
43 | - IMapChunk[ ] mapChunks = new IMapChunk[ ] | |
44 | - { | |
37 | + for (int chunkY = 0; chunkY <= topChunkY; chunkY++) | |
38 | + { | |
39 | + chunksColumn[chunkY] = ClientAPI.World.BlockAccessor.GetChunk(chunkPos.X, chunkY, chunkPos.Y); | |
40 | + //What to do if chunk is a void? invalid? | |
41 | + } | |
42 | + | |
43 | + // Prefetch map chunks, in pattern | |
44 | + IMapChunk[] mapChunks = new IMapChunk[] | |
45 | + { | |
45 | 46 | ClientAPI.World.BlockAccessor.GetMapChunk(chunkPos.X - 1, chunkPos.Y - 1), |
46 | 47 | ClientAPI.World.BlockAccessor.GetMapChunk(chunkPos.X - 1, chunkPos.Y), |
47 | 48 | ClientAPI.World.BlockAccessor.GetMapChunk(chunkPos.X, chunkPos.Y - 1) |
48 | - }; | |
49 | - | |
50 | - //pre-create PNG line slices... | |
51 | - ImageLine[ ] lines = Enumerable.Repeat(new object( ), chunkSize).Select(l => new ImageLine(pngWriter.ImgInfo)).ToArray( ); | |
52 | - | |
53 | - for (int posIndex = 0; posIndex < (chunkSize * chunkSize); posIndex++) { | |
54 | - int mapY = mc.RainHeightMap[posIndex]; | |
55 | - int localChunkY = mapY / chunkSize; | |
56 | - if (localChunkY >= (chunksColumn.Length)) continue;//Out of range! | |
57 | - | |
58 | - MapUtil.PosInt2d(posIndex, chunkSize, localpos); | |
59 | - int localX = localpos.X; | |
60 | - int localZ = localpos.Y; | |
61 | - | |
62 | - float b = 1; | |
63 | - int leftTop, rightTop, leftBot; | |
64 | - | |
65 | - IMapChunk leftTopMapChunk = mc; | |
66 | - IMapChunk rightTopMapChunk = mc; | |
67 | - IMapChunk leftBotMapChunk = mc; | |
68 | - | |
69 | - int topX = localX - 1; | |
70 | - int botX = localX; | |
71 | - int leftZ = localZ - 1; | |
72 | - int rightZ = localZ; | |
73 | - | |
74 | - if (topX < 0 && leftZ < 0) { | |
75 | - leftTopMapChunk = mapChunks[0]; | |
76 | - rightTopMapChunk = mapChunks[1]; | |
77 | - leftBotMapChunk = mapChunks[2]; | |
78 | - } | |
79 | - else { | |
80 | - if (topX < 0) { | |
81 | - leftTopMapChunk = mapChunks[1]; | |
82 | - rightTopMapChunk = mapChunks[1]; | |
83 | - } | |
84 | - if (leftZ < 0) { | |
85 | - leftTopMapChunk = mapChunks[2]; | |
86 | - leftBotMapChunk = mapChunks[2]; | |
87 | - } | |
88 | - } | |
89 | - | |
90 | - topX = GameMath.Mod(topX, chunkSize); | |
91 | - leftZ = GameMath.Mod(leftZ, chunkSize); | |
92 | - | |
93 | - leftTop = leftTopMapChunk == null ? 0 : Math.Sign(mapY - leftTopMapChunk.RainHeightMap[leftZ * chunkSize + topX]); | |
94 | - rightTop = rightTopMapChunk == null ? 0 : Math.Sign(mapY - rightTopMapChunk.RainHeightMap[rightZ * chunkSize + topX]); | |
95 | - leftBot = leftBotMapChunk == null ? 0 : Math.Sign(mapY - leftBotMapChunk.RainHeightMap[leftZ * chunkSize + botX]); | |
49 | + }; | |
96 | 50 | |
97 | - float slopeness = (leftTop + rightTop + leftBot); | |
51 | + //pre-create PNG line slices... | |
52 | + ImageLine[] lines = Enumerable.Repeat(new object(), chunkSize).Select(l => new ImageLine(pngWriter.ImgInfo)).ToArray(); | |
98 | 53 | |
99 | - if (slopeness > 0) b = 1.2f; | |
100 | - if (slopeness < 0) b = 0.8f; | |
101 | - | |
102 | - b -= 0.15f; //Slope boost value | |
103 | - | |
104 | - if (chunksColumn[localChunkY] == null) { | |
105 | - | |
106 | - continue; | |
107 | - } | |
108 | - | |
109 | - chunksColumn[localChunkY].Unpack( ); | |
110 | - int blockId = chunksColumn[localChunkY].Blocks[MapUtil.Index3d(localpos.X, mapY % chunkSize, localpos.Y, chunkSize, chunkSize)]; | |
111 | - | |
112 | - Block block = ClientAPI.World.Blocks[blockId]; | |
113 | - | |
114 | - tmpPos.Set(chunkSize * chunkPos.X + localpos.X, mapY, chunkSize * chunkPos.Y + localpos.Y); | |
115 | - | |
116 | - int avgCol = block.GetColor(ClientAPI, tmpPos); | |
117 | - int rndCol = block.GetRandomColor(ClientAPI, tmpPos, BlockFacing.UP); | |
118 | - int col = ColorUtil.ColorOverlay(avgCol, rndCol, 0.125f); | |
119 | - var packedFormat = ColorUtil.ColorMultiply3Clamped(col, b); | |
120 | - | |
121 | - int red = ColorUtil.ColorB(packedFormat); | |
122 | - int green = ColorUtil.ColorG(packedFormat); | |
123 | - int blue = ColorUtil.ColorR(packedFormat); | |
124 | - | |
125 | - | |
126 | - //============ POI Population ================= | |
127 | - if (BlockID_Designators.ContainsKey(blockId)) { | |
128 | - var desig = BlockID_Designators[blockId]; | |
129 | - | |
130 | - if (desig.Enabled) | |
54 | + for (int posIndex = 0; posIndex < (chunkSize * chunkSize); posIndex++) | |
131 | 55 | { |
132 | - red = desig.OverwriteColor.R; | |
133 | - green = desig.OverwriteColor.G; | |
134 | - blue = desig.OverwriteColor.B; | |
56 | + int mapY = mc.RainHeightMap[posIndex]; | |
57 | + int localChunkY = mapY / chunkSize; | |
58 | + if (localChunkY >= (chunksColumn.Length)) continue;//Out of range! | |
59 | + | |
60 | + MapUtil.PosInt2d(posIndex, chunkSize, localpos); | |
61 | + int localX = localpos.X; | |
62 | + int localZ = localpos.Y; | |
63 | + | |
64 | + float b = 1; | |
65 | + int leftTop, rightTop, leftBot; | |
66 | + | |
67 | + IMapChunk leftTopMapChunk = mc; | |
68 | + IMapChunk rightTopMapChunk = mc; | |
69 | + IMapChunk leftBotMapChunk = mc; | |
70 | + | |
71 | + int topX = localX - 1; | |
72 | + int botX = localX; | |
73 | + int leftZ = localZ - 1; | |
74 | + int rightZ = localZ; | |
75 | + | |
76 | + if (topX < 0 && leftZ < 0) | |
77 | + { | |
78 | + leftTopMapChunk = mapChunks[0]; | |
79 | + rightTopMapChunk = mapChunks[1]; | |
80 | + leftBotMapChunk = mapChunks[2]; | |
81 | + } | |
82 | + else | |
83 | + { | |
84 | + if (topX < 0) | |
85 | + { | |
86 | + leftTopMapChunk = mapChunks[1]; | |
87 | + rightTopMapChunk = mapChunks[1]; | |
88 | + } | |
89 | + if (leftZ < 0) | |
90 | + { | |
91 | + leftTopMapChunk = mapChunks[2]; | |
92 | + leftBotMapChunk = mapChunks[2]; | |
93 | + } | |
94 | + } | |
95 | + | |
96 | + topX = GameMath.Mod(topX, chunkSize); | |
97 | + leftZ = GameMath.Mod(leftZ, chunkSize); | |
98 | + | |
99 | + leftTop = leftTopMapChunk == null ? 0 : Math.Sign(mapY - leftTopMapChunk.RainHeightMap[leftZ * chunkSize + topX]); | |
100 | + rightTop = rightTopMapChunk == null ? 0 : Math.Sign(mapY - rightTopMapChunk.RainHeightMap[rightZ * chunkSize + topX]); | |
101 | + leftBot = leftBotMapChunk == null ? 0 : Math.Sign(mapY - leftBotMapChunk.RainHeightMap[leftZ * chunkSize + botX]); | |
102 | + | |
103 | + float slopeness = (leftTop + rightTop + leftBot); | |
104 | + | |
105 | + if (slopeness > 0) b = 1.2f; | |
106 | + if (slopeness < 0) b = 0.8f; | |
107 | + | |
108 | + b -= 0.15f; //Slope boost value | |
109 | + | |
110 | + if (chunksColumn[localChunkY] == null) | |
111 | + { | |
112 | + | |
113 | + continue; | |
114 | + } | |
115 | + | |
116 | + chunksColumn[localChunkY].Unpack(); | |
117 | + int blockId = chunksColumn[localChunkY].Blocks[MapUtil.Index3d(localpos.X, mapY % chunkSize, localpos.Y, chunkSize, chunkSize)]; | |
118 | + | |
119 | + Block block = ClientAPI.World.Blocks[blockId]; | |
120 | + | |
121 | + tmpPos.Set(chunkSize * chunkPos.X + localpos.X, mapY, chunkSize * chunkPos.Y + localpos.Y); | |
122 | + | |
123 | + int avgCol = block.GetColor(ClientAPI, tmpPos); | |
124 | + int rndCol = block.GetRandomColor(ClientAPI, tmpPos, BlockFacing.UP); | |
125 | + int col = ColorUtil.ColorOverlay(avgCol, rndCol, 0.125f); | |
126 | + var packedFormat = ColorUtil.ColorMultiply3Clamped(col, b); | |
127 | + | |
128 | + int red = ColorUtil.ColorB(packedFormat); | |
129 | + int green = ColorUtil.ColorG(packedFormat); | |
130 | + int blue = ColorUtil.ColorR(packedFormat); | |
131 | + | |
132 | + | |
133 | + //============ POI Population ================= | |
134 | + if (BlockID_Designators.ContainsKey(blockId)) | |
135 | + { | |
136 | + var desig = BlockID_Designators[blockId]; | |
137 | + | |
138 | + if (desig.Enabled) | |
139 | + { | |
140 | + red = desig.OverwriteColor.R; | |
141 | + green = desig.OverwriteColor.G; | |
142 | + blue = desig.OverwriteColor.B; | |
143 | + } | |
144 | + } | |
145 | + | |
146 | + ImageLineHelper.SetPixel(lines[localZ], localX, red, green, blue); | |
147 | + | |
148 | + //chunkImage.SetPixel(localX, localZ, pixelColor); | |
149 | + pixelCount++; | |
135 | 150 | } |
136 | - } | |
137 | 151 | |
138 | - ImageLineHelper.SetPixel(lines[localZ], localX, red, green, blue); | |
139 | - | |
140 | - //chunkImage.SetPixel(localX, localZ, pixelColor); | |
141 | - pixelCount++; | |
142 | - } | |
143 | - | |
144 | - for (int row = 0; row < pngWriter.ImgInfo.Rows; row++) { | |
145 | - pngWriter.WriteRow(lines[row], row); | |
146 | - } | |
152 | + for (int row = 0; row < pngWriter.ImgInfo.Rows; row++) | |
153 | + { | |
154 | + pngWriter.WriteRow(lines[row], row); | |
155 | + } | |
147 | 156 | |
148 | - pngWriter.End( ); | |
157 | + pngWriter.End(); | |
149 | 158 | } |
150 | 159 | } |
151 | 160 | } |
@@ -17,9 +17,9 @@ namespace Automap | ||
17 | 17 | |
18 | 18 | private long dashTickHandle; |
19 | 19 | |
20 | - public override string ToggleKeyCombinationCode { | |
21 | - get | |
22 | - { | |
20 | + public override string ToggleKeyCombinationCode | |
21 | + { | |
22 | + get { | |
23 | 23 | return _automapControlPanelKey; |
24 | 24 | } |
25 | 25 | } |
@@ -28,53 +28,53 @@ namespace Automap | ||
28 | 28 | private RunState lastState; |
29 | 29 | |
30 | 30 | |
31 | - public AutomapGUIDialog(ICoreClientAPI capi,AutomapSystem ams) : base(capi) | |
32 | - { | |
31 | + public AutomapGUIDialog(ICoreClientAPI capi, AutomapSystem ams) : base(capi) | |
32 | + { | |
33 | + | |
34 | + Logger = capi.Logger; | |
35 | + SetupDialog(); | |
36 | + capi.Event.RegisterEventBusListener(AutomapStatusMsg, 1.0D, AutomapSystem.AutomapStatusEventKey); | |
33 | 37 | |
34 | - Logger = capi.Logger; | |
35 | - SetupDialog( ); | |
36 | - capi.Event.RegisterEventBusListener(AutomapStatusMsg, 1.0D, AutomapSystem.AutomapStatusEventKey); | |
37 | - | |
38 | 38 | } |
39 | 39 | |
40 | 40 | //Event for GUI status display |
41 | 41 | |
42 | - private void SetupDialog( ) | |
42 | + private void SetupDialog() | |
43 | 43 | { |
44 | - ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle); | |
45 | - | |
46 | - ElementBounds textBounds = ElementBounds.Fixed(0, 40, 500, 300); | |
47 | - | |
48 | - ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding); | |
49 | - bgBounds.BothSizing = ElementSizing.FitToChildren; | |
50 | - bgBounds.WithChildren(textBounds); | |
51 | - | |
52 | - ElementBounds toggleBounds = textBounds.CopyOffsetedSibling(0, 72, 5, 2); | |
53 | - toggleBounds.fixedHeight = 24; | |
54 | - toggleBounds.fixedWidth = 64; | |
55 | - | |
56 | - ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 26, 2, 4); | |
57 | - txtStatusBounds.fixedHeight = 16; | |
58 | - txtStatusBounds.percentWidth = 1; | |
59 | - | |
60 | - ElementBounds btnNoteArea = textBounds.CopyOffsetedSibling(0, 42, 2, 5); | |
61 | - btnNoteArea.fixedHeight = 24; | |
62 | - btnNoteArea.fixedWidth = 20; | |
63 | - | |
64 | - ElementBounds txtNoteArea = btnNoteArea.CopyOffsetedSibling(64, 0, 1, 6); | |
65 | - txtNoteArea.fixedHeight = 24; | |
66 | - txtNoteArea.fixedWidth = 256; | |
67 | - | |
68 | - | |
69 | - this.SingleComposer = capi.Gui.CreateCompo("automapControlPanel", dialogBounds) | |
70 | - .AddShadedDialogBG(bgBounds) | |
71 | - .AddDialogTitleBar("Automap Controls", OnTitleBarCloseClicked) | |
72 | - .AddStaticText("Configure Automap settings:", CairoFont.WhiteDetailText( ), textBounds) | |
73 | - .AddToggleButton("Run", CairoFont.ButtonText( ), RunToggle, toggleBounds, "btnRun") | |
74 | - .AddDynamicText("Idle.", CairoFont.WhiteSmallText( ).WithFontSize(12), EnumTextOrientation.Left, txtStatusBounds, _statusTextKey) | |
75 | - .AddTextInput(txtNoteArea,null,CairoFont.WhiteMediumText().WithFontSize(16),_noteTextKey) | |
76 | - .AddButton("Note:",CreateNote,btnNoteArea,CairoFont.ButtonText()) | |
77 | - .Compose( ); | |
44 | + ElementBounds dialogBounds = ElementStdBounds.AutosizedMainDialog.WithAlignment(EnumDialogArea.CenterMiddle); | |
45 | + | |
46 | + ElementBounds textBounds = ElementBounds.Fixed(0, 40, 500, 300); | |
47 | + | |
48 | + ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(GuiStyle.ElementToDialogPadding); | |
49 | + bgBounds.BothSizing = ElementSizing.FitToChildren; | |
50 | + bgBounds.WithChildren(textBounds); | |
51 | + | |
52 | + ElementBounds toggleBounds = textBounds.CopyOffsetedSibling(0, 72, 5, 2); | |
53 | + toggleBounds.fixedHeight = 24; | |
54 | + toggleBounds.fixedWidth = 64; | |
55 | + | |
56 | + ElementBounds txtStatusBounds = textBounds.CopyOffsetedSibling(0, 26, 2, 4); | |
57 | + txtStatusBounds.fixedHeight = 16; | |
58 | + txtStatusBounds.percentWidth = 1; | |
59 | + | |
60 | + ElementBounds btnNoteArea = textBounds.CopyOffsetedSibling(0, 42, 2, 5); | |
61 | + btnNoteArea.fixedHeight = 24; | |
62 | + btnNoteArea.fixedWidth = 20; | |
63 | + | |
64 | + ElementBounds txtNoteArea = btnNoteArea.CopyOffsetedSibling(64, 0, 1, 6); | |
65 | + txtNoteArea.fixedHeight = 24; | |
66 | + txtNoteArea.fixedWidth = 256; | |
67 | + | |
68 | + | |
69 | + this.SingleComposer = capi.Gui.CreateCompo("automapControlPanel", dialogBounds) | |
70 | + .AddShadedDialogBG(bgBounds) | |
71 | + .AddDialogTitleBar("Automap Controls", OnTitleBarCloseClicked) | |
72 | + .AddStaticText("Configure Automap settings:", CairoFont.WhiteDetailText(), textBounds) | |
73 | + .AddToggleButton("Run", CairoFont.ButtonText(), RunToggle, toggleBounds, "btnRun") | |
74 | + .AddDynamicText("Idle.", CairoFont.WhiteSmallText().WithFontSize(12), EnumTextOrientation.Left, txtStatusBounds, _statusTextKey) | |
75 | + .AddTextInput(txtNoteArea, null, CairoFont.WhiteMediumText().WithFontSize(16), _noteTextKey) | |
76 | + .AddButton("Note:", CreateNote, btnNoteArea, CairoFont.ButtonText()) | |
77 | + .Compose(); | |
78 | 78 | |
79 | 79 | //Controls for ALL Block & Entity Designators (Enable/Disable) |
80 | 80 | //_automapSystem.BlockID_Designators |
@@ -86,9 +86,9 @@ namespace Automap | ||
86 | 86 | |
87 | 87 | } |
88 | 88 | |
89 | - private void OnTitleBarCloseClicked( ) | |
89 | + private void OnTitleBarCloseClicked() | |
90 | 90 | { |
91 | - TryClose( ); | |
91 | + TryClose(); | |
92 | 92 | } |
93 | 93 | |
94 | 94 | /// <summary> |
@@ -98,51 +98,54 @@ namespace Automap | ||
98 | 98 | /// <param name="toggle">Run.</param> |
99 | 99 | internal void RunToggle(bool toggle) |
100 | 100 | { |
101 | - Logger.VerboseDebug("Dialog Changed; [ Automap Enabled: {0} ]", toggle); | |
102 | - var statusText = this.SingleComposer.GetDynamicText(_statusTextKey); | |
103 | - statusText.SetNewText($"State: {(toggle? "Run": "Halt" )}, Total: {totalShards}, Nulls: {voidShards} " ); | |
101 | + Logger.VerboseDebug("Dialog Changed; [ Automap Enabled: {0} ]", toggle); | |
102 | + var statusText = this.SingleComposer.GetDynamicText(_statusTextKey); | |
103 | + statusText.SetNewText($"State: {(toggle ? "Run" : "Halt")}, Total: {totalShards}, Nulls: {voidShards} "); | |
104 | 104 | |
105 | - CommandData cmd; | |
105 | + CommandData cmd; | |
106 | 106 | |
107 | - if (toggle) { | |
108 | - dashTickHandle = capi.Event.RegisterGameTickListener(UpdateDashDisplay, 6001); | |
109 | - cmd = new CommandData(toggle ? RunState.Run : RunState.Stop, new bool[ ] { true, true, true, true, true }); | |
110 | - } | |
111 | - else { | |
112 | - capi.Event.UnregisterGameTickListener(dashTickHandle); | |
113 | - cmd = new CommandData(toggle ? RunState.Run : RunState.Stop); | |
114 | - } | |
115 | - | |
116 | - capi.Event.PushEvent(AutomapSystem.AutomapCommandEventKey, cmd); | |
107 | + if (toggle) | |
108 | + { | |
109 | + dashTickHandle = capi.Event.RegisterGameTickListener(UpdateDashDisplay, 6001); | |
110 | + cmd = new CommandData(toggle ? RunState.Run : RunState.Stop, new bool[] { true, true, true, true, true }); | |
111 | + } | |
112 | + else | |
113 | + { | |
114 | + capi.Event.UnregisterGameTickListener(dashTickHandle); | |
115 | + cmd = new CommandData(toggle ? RunState.Run : RunState.Stop); | |
116 | + } | |
117 | + | |
118 | + capi.Event.PushEvent(AutomapSystem.AutomapCommandEventKey, cmd); | |
117 | 119 | } |
118 | 120 | |
119 | - private bool CreateNote( ) | |
121 | + private bool CreateNote() | |
120 | 122 | { |
121 | - var noteCmd = new CommandData(RunState.Notation); | |
122 | - var txtNote = this.SingleComposer.GetTextInput(_noteTextKey); | |
123 | - if (!String.IsNullOrWhiteSpace(txtNote.GetText( ))) { | |
124 | - noteCmd.Notation = txtNote.GetText( ); | |
125 | - txtNote.SetValue(string.Empty); | |
123 | + var noteCmd = new CommandData(RunState.Notation); | |
124 | + var txtNote = this.SingleComposer.GetTextInput(_noteTextKey); | |
125 | + if (!String.IsNullOrWhiteSpace(txtNote.GetText())) | |
126 | + { | |
127 | + noteCmd.Notation = txtNote.GetText(); | |
128 | + txtNote.SetValue(string.Empty); | |
126 | 129 | |
127 | - capi.Event.PushEvent(AutomapSystem.AutomapCommandEventKey, noteCmd); | |
128 | - } | |
129 | - return false;//??? | |
130 | + capi.Event.PushEvent(AutomapSystem.AutomapCommandEventKey, noteCmd); | |
131 | + } | |
132 | + return false;//??? | |
130 | 133 | } |
131 | 134 | |
132 | 135 | private void AutomapStatusMsg(string eventName, ref EnumHandling handling, IAttribute data) |
133 | 136 | { |
134 | - Logger.VerboseDebug("MsgBus RX: AutomapStatusMsg"); | |
135 | - StatusData realData = data as StatusData; | |
136 | - totalShards = realData.TotalUpdates; | |
137 | - voidShards = realData.VoidChunks; | |
138 | - changesThisTick = realData.Delta; | |
139 | - lastState = realData.CurrentState; | |
137 | + Logger.VerboseDebug("MsgBus RX: AutomapStatusMsg"); | |
138 | + StatusData realData = data as StatusData; | |
139 | + totalShards = realData.TotalUpdates; | |
140 | + voidShards = realData.VoidChunks; | |
141 | + changesThisTick = realData.Delta; | |
142 | + lastState = realData.CurrentState; | |
140 | 143 | } |
141 | 144 | |
142 | - private void UpdateDashDisplay(float delay ) | |
145 | + private void UpdateDashDisplay(float delay) | |
143 | 146 | { |
144 | - var statusText = this.SingleComposer.GetDynamicText(_statusTextKey); | |
145 | - statusText.SetNewText($"State: {lastState}, Total: {totalShards}, Delta: {changesThisTick} Nulls: {voidShards} "); | |
147 | + var statusText = this.SingleComposer.GetDynamicText(_statusTextKey); | |
148 | + statusText.SetNewText($"State: {lastState}, Total: {totalShards}, Delta: {changesThisTick} Nulls: {voidShards} "); | |
146 | 149 | |
147 | 150 | |
148 | 151 | } |
@@ -22,7 +22,7 @@ using Vintagestory.API.MathTools; | ||
22 | 22 | using Vintagestory.Common; |
23 | 23 | |
24 | 24 | namespace Automap |
25 | -{ | |
25 | +{ | |
26 | 26 | public class AutomapSystem |
27 | 27 | { |
28 | 28 | private Thread cartographer_thread; |
@@ -36,12 +36,12 @@ namespace Automap | ||
36 | 36 | private const string chunkFile_filter = @"*_*.png"; |
37 | 37 | private static Regex chunkShardRegex = new Regex(@"(?<X>[\d]+)_(?<Z>[\d]+).png", RegexOptions.Singleline); |
38 | 38 | |
39 | - private ConcurrentDictionary<Vec2i, uint> columnCounter = new ConcurrentDictionary<Vec2i, uint>(3, 150 ); | |
39 | + private ConcurrentDictionary<Vec2i, uint> columnCounter = new ConcurrentDictionary<Vec2i, uint>(3, 150); | |
40 | 40 | private ColumnsMetadata chunkTopMetadata; |
41 | 41 | private PointsOfInterest POIs = new PointsOfInterest(); |
42 | 42 | private EntitiesOfInterest EOIs = new EntitiesOfInterest(); |
43 | 43 | |
44 | - internal Dictionary<int, BlockDesignator> BlockID_Designators { get; private set;} | |
44 | + internal Dictionary<int, BlockDesignator> BlockID_Designators { get; private set; } | |
45 | 45 | internal Dictionary<AssetLocation, EntityDesignator> Entity_Designators { get; private set; } |
46 | 46 | internal Dictionary<int, string> RockIdCodes { get; private set; } |
47 | 47 |
@@ -60,49 +60,49 @@ namespace Automap | ||
60 | 60 | |
61 | 61 | public AutomapSystem(ICoreClientAPI clientAPI, ILogger logger) |
62 | 62 | { |
63 | - this.ClientAPI = clientAPI; | |
64 | - this.Logger = logger; | |
65 | - chunkSize = ClientAPI.World.BlockAccessor.ChunkSize; | |
66 | - ClientAPI.Event.LevelFinalize += EngageAutomap; | |
63 | + this.ClientAPI = clientAPI; | |
64 | + this.Logger = logger; | |
65 | + chunkSize = ClientAPI.World.BlockAccessor.ChunkSize; | |
66 | + ClientAPI.Event.LevelFinalize += EngageAutomap; | |
67 | 67 | |
68 | - //TODO:Choose which one from GUI | |
69 | - this.ChunkRenderer = new StandardRenderer(clientAPI, logger); | |
68 | + //TODO:Choose which one from GUI | |
69 | + this.ChunkRenderer = new StandardRenderer(clientAPI, logger); | |
70 | 70 | |
71 | - //Listen on bus for commands | |
72 | - ClientAPI.Event.RegisterEventBusListener(CommandListener, 1.0, AutomapSystem.AutomapCommandEventKey); | |
71 | + //Listen on bus for commands | |
72 | + ClientAPI.Event.RegisterEventBusListener(CommandListener, 1.0, AutomapSystem.AutomapCommandEventKey); | |
73 | 73 | |
74 | 74 | } |
75 | 75 | |
76 | 76 | |
77 | 77 | #region Internals |
78 | - private void EngageAutomap( ) | |
78 | + private void EngageAutomap() | |
79 | 79 | { |
80 | - path = ClientAPI.GetOrCreateDataPath(_mapPath); | |
81 | - path = ClientAPI.GetOrCreateDataPath(Path.Combine(path, "World_" + ClientAPI.World.Seed));//Add name of World too...'ServerApi.WorldManager.CurrentWorldName' | |
80 | + path = ClientAPI.GetOrCreateDataPath(_mapPath); | |
81 | + path = ClientAPI.GetOrCreateDataPath(Path.Combine(path, "World_" + ClientAPI.World.Seed));//Add name of World too...'ServerApi.WorldManager.CurrentWorldName' | |
82 | 82 | |
83 | - stylesFile = ClientAPI.World.AssetManager.Get(new AssetLocation(_domain, "config/automap_format.css")); | |
84 | - Logger.VerboseDebug("CSS loaded: {0} size: {1}",stylesFile.IsLoaded() ,stylesFile.ToText( ).Length); | |
83 | + stylesFile = ClientAPI.World.AssetManager.Get(new AssetLocation(_domain, "config/automap_format.css")); | |
84 | + Logger.VerboseDebug("CSS loaded: {0} size: {1}", stylesFile.IsLoaded(), stylesFile.ToText().Length); | |
85 | 85 | |
86 | - Prefill_POI_Designators( ); | |
87 | - startChunkColumn = new Vec2i((ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.X / chunkSize), (ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.Z / chunkSize)); | |
88 | - chunkTopMetadata = new ColumnsMetadata(startChunkColumn); | |
86 | + Prefill_POI_Designators(); | |
87 | + startChunkColumn = new Vec2i((ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.X / chunkSize), (ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.Z / chunkSize)); | |
88 | + chunkTopMetadata = new ColumnsMetadata(startChunkColumn); | |
89 | 89 | |
90 | - Logger.Notification("AUTOMAP Start {0}", startChunkColumn); | |
91 | - Reload_Metadata( ); | |
90 | + Logger.Notification("AUTOMAP Start {0}", startChunkColumn); | |
91 | + Reload_Metadata(); | |
92 | 92 | |
93 | - ClientAPI.Event.ChunkDirty += ChunkAChanging; | |
93 | + ClientAPI.Event.ChunkDirty += ChunkAChanging; | |
94 | 94 | |
95 | - cartographer_thread = new Thread(Cartographer); | |
96 | - cartographer_thread.Name = "Cartographer"; | |
97 | - cartographer_thread.Priority = ThreadPriority.Lowest; | |
98 | - cartographer_thread.IsBackground = true; | |
95 | + cartographer_thread = new Thread(Cartographer); | |
96 | + cartographer_thread.Name = "Cartographer"; | |
97 | + cartographer_thread.Priority = ThreadPriority.Lowest; | |
98 | + cartographer_thread.IsBackground = true; | |
99 | 99 | |
100 | - ClientAPI.Event.RegisterGameTickListener(AwakenCartographer, 6000); | |
100 | + ClientAPI.Event.RegisterGameTickListener(AwakenCartographer, 6000); | |
101 | 101 | } |
102 | 102 | |
103 | 103 | private void ChunkAChanging(Vec3i chunkCoord, IWorldChunk chunk, EnumChunkDirtyReason reason) |
104 | - { | |
105 | - Vec2i topPosition = new Vec2i(chunkCoord.X, chunkCoord.Z); | |
104 | + { | |
105 | + Vec2i topPosition = new Vec2i(chunkCoord.X, chunkCoord.Z); | |
106 | 106 | |
107 | 107 | columnCounter.AddOrUpdate(topPosition, 1, (key, colAct) => colAct + 1); |
108 | 108 | } |
@@ -110,490 +110,529 @@ namespace Automap | ||
110 | 110 | private void AwakenCartographer(float delayed) |
111 | 111 | { |
112 | 112 | |
113 | - if (CurrentState == RunState.Run && (ClientAPI.IsGamePaused != false || ClientAPI.IsShuttingDown != true)) { | |
114 | - #if DEBUG | |
115 | - Logger.VerboseDebug("Cartographer re-trigger from [{0}]", cartographer_thread.ThreadState); | |
116 | - #endif | |
113 | + if (CurrentState == RunState.Run && (ClientAPI.IsGamePaused != false || ClientAPI.IsShuttingDown != true)) | |
114 | + { | |
115 | +#if DEBUG | |
116 | + Logger.VerboseDebug("Cartographer re-trigger from [{0}]", cartographer_thread.ThreadState); | |
117 | +#endif | |
117 | 118 | |
118 | - if (cartographer_thread.ThreadState.HasFlag(ThreadState.Unstarted)) { | |
119 | - cartographer_thread.Start( ); | |
120 | - } | |
121 | - else if (cartographer_thread.ThreadState.HasFlag(ThreadState.WaitSleepJoin)) { | |
122 | - //Time to (re)write chunk shards | |
123 | - cartographer_thread.Interrupt( ); | |
124 | - } | |
125 | - //#if DEBUG | |
126 | - //ClientAPI.TriggerChatMessage($"Automap {updatedChunksTotal} Updates - MAX (N:{chunkTopMetadata.North_mostChunk},S:{chunkTopMetadata.South_mostChunk},E:{chunkTopMetadata.East_mostChunk}, W:{chunkTopMetadata.West_mostChunk} - TOTAL: {chunkTopMetadata.Count})"); | |
127 | - //#endif | |
128 | - } | |
129 | - else if (CurrentState == RunState.Snapshot) { | |
130 | - //TODO: Snapshot generator second thread... | |
131 | - } | |
119 | + if (cartographer_thread.ThreadState.HasFlag(ThreadState.Unstarted)) | |
120 | + { | |
121 | + cartographer_thread.Start(); | |
122 | + } | |
123 | + else if (cartographer_thread.ThreadState.HasFlag(ThreadState.WaitSleepJoin)) | |
124 | + { | |
125 | + //Time to (re)write chunk shards | |
126 | + cartographer_thread.Interrupt(); | |
127 | + } | |
128 | + //#if DEBUG | |
129 | + //ClientAPI.TriggerChatMessage($"Automap {updatedChunksTotal} Updates - MAX (N:{chunkTopMetadata.North_mostChunk},S:{chunkTopMetadata.South_mostChunk},E:{chunkTopMetadata.East_mostChunk}, W:{chunkTopMetadata.West_mostChunk} - TOTAL: {chunkTopMetadata.Count})"); | |
130 | + //#endif | |
131 | + } | |
132 | + else if (CurrentState == RunState.Snapshot) | |
133 | + { | |
134 | + //TODO: Snapshot generator second thread... | |
135 | + } | |
132 | 136 | |
133 | 137 | } |
134 | 138 | |
135 | 139 | |
136 | - private void Cartographer( ) | |
140 | + private void Cartographer() | |
137 | 141 | { |
138 | - wake: | |
139 | - Logger.VerboseDebug("Cartographer thread awoken"); | |
140 | - | |
141 | - try { | |
142 | - uint ejectedItem = 0; | |
143 | - uint updatedChunks = 0; | |
142 | + wake: | |
143 | + Logger.VerboseDebug("Cartographer thread awoken"); | |
144 | 144 | |
145 | - //-- Should dodge enumerator changing underfoot....at a cost. | |
146 | - if (!columnCounter.IsEmpty) { | |
147 | - var tempSet = columnCounter.ToArray( ).OrderByDescending(kvp => kvp.Value); | |
148 | - foreach (var mostActiveCol in tempSet) { | |
149 | - | |
150 | - var mapChunk = ClientAPI.World.BlockAccessor.GetMapChunk(mostActiveCol.Key); | |
151 | - | |
152 | - if (mapChunk == null) { | |
153 | - Logger.Warning("SKIP CHUNK: ({0}) - Map Chunk NULL!", mostActiveCol.Key); | |
154 | - nullChunkCount++; | |
155 | - columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem ); | |
156 | - continue; | |
157 | - } | |
158 | - | |
159 | - ColumnMeta chunkMeta = CreateColumnMetadata(mostActiveCol,mapChunk); | |
160 | - PngWriter pngWriter = SetupPngImage(mostActiveCol.Key, chunkMeta); | |
161 | - UpdateEntityMetadata( ); | |
162 | - ProcessChunkBlocks(mostActiveCol.Key, mapChunk, chunkMeta); | |
163 | - | |
164 | - uint updatedPixels = 0; | |
165 | - | |
166 | - ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, pngWriter , out updatedPixels); | |
167 | - | |
168 | - if (updatedPixels > 0) { | |
169 | - | |
170 | - #if DEBUG | |
171 | - Logger.VerboseDebug("Wrote chunk shard: ({0}) - Edits#:{1}, Pixels#:{2}", mostActiveCol.Key, mostActiveCol.Value, updatedPixels); | |
172 | - #endif | |
173 | - updatedChunks++; | |
174 | - chunkTopMetadata.Update(chunkMeta); | |
175 | - columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem); | |
176 | - } | |
177 | - else { | |
178 | - columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem); | |
179 | - Logger.VerboseDebug("Un-painted chunk: ({0}) ", mostActiveCol.Key); | |
180 | - } | |
145 | + try | |
146 | + { | |
147 | + uint ejectedItem = 0; | |
148 | + uint updatedChunks = 0; | |
181 | 149 | |
182 | - } | |
183 | - } | |
150 | + //-- Should dodge enumerator changing underfoot....at a cost. | |
151 | + if (!columnCounter.IsEmpty) | |
152 | + { | |
153 | + var tempSet = columnCounter.ToArray().OrderByDescending(kvp => kvp.Value); | |
154 | + foreach (var mostActiveCol in tempSet) | |
155 | + { | |
156 | + | |
157 | + var mapChunk = ClientAPI.World.BlockAccessor.GetMapChunk(mostActiveCol.Key); | |
158 | + | |
159 | + if (mapChunk == null) | |
160 | + { | |
161 | + Logger.Warning("SKIP CHUNK: ({0}) - Map Chunk NULL!", mostActiveCol.Key); | |
162 | + nullChunkCount++; | |
163 | + columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem); | |
164 | + continue; | |
165 | + } | |
166 | + | |
167 | + ColumnMeta chunkMeta = CreateColumnMetadata(mostActiveCol, mapChunk); | |
168 | + PngWriter pngWriter = SetupPngImage(mostActiveCol.Key, chunkMeta); | |
169 | + UpdateEntityMetadata(); | |
170 | + ProcessChunkBlocks(mostActiveCol.Key, mapChunk, chunkMeta); | |
171 | + | |
172 | + uint updatedPixels = 0; | |
173 | + | |
174 | + ChunkRenderer.GenerateChunkPngShard(mostActiveCol.Key, mapChunk, chunkMeta, pngWriter, out updatedPixels); | |
175 | + | |
176 | + if (updatedPixels > 0) | |
177 | + { | |
178 | + | |
179 | +#if DEBUG | |
180 | + Logger.VerboseDebug("Wrote chunk shard: ({0}) - Edits#:{1}, Pixels#:{2}", mostActiveCol.Key, mostActiveCol.Value, updatedPixels); | |
181 | +#endif | |
182 | + updatedChunks++; | |
183 | + chunkTopMetadata.Update(chunkMeta); | |
184 | + columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem); | |
185 | + } | |
186 | + else | |
187 | + { | |
188 | + columnCounter.TryRemove(mostActiveCol.Key, out ejectedItem); | |
189 | + Logger.VerboseDebug("Un-painted chunk: ({0}) ", mostActiveCol.Key); | |
190 | + } | |
191 | + | |
192 | + } | |
193 | + } | |
184 | 194 | |
185 | - UpdateStatus(this.updatedChunksTotal, this.nullChunkCount, updatedChunks); | |
195 | + UpdateStatus(this.updatedChunksTotal, this.nullChunkCount, updatedChunks); | |
186 | 196 | |
187 | - if (updatedChunks > 0) { | |
188 | - //What about chunk updates themselves; a update bitmap isn't kept... | |
189 | - updatedChunksTotal += updatedChunks; | |
190 | - GenerateMapHTML( ); | |
191 | - GenerateJSONMetadata( ); | |
192 | - updatedChunks = 0; | |
193 | - } | |
197 | + if (updatedChunks > 0) | |
198 | + { | |
199 | + //What about chunk updates themselves; a update bitmap isn't kept... | |
200 | + updatedChunksTotal += updatedChunks; | |
201 | + GenerateMapHTML(); | |
202 | + GenerateJSONMetadata(); | |
203 | + updatedChunks = 0; | |
204 | + } | |
194 | 205 | |
195 | - //Then sleep until interupted again, and repeat | |
206 | + //Then sleep until interupted again, and repeat | |
196 | 207 | |
197 | - Logger.VerboseDebug("Thread '{0}' about to sleep indefinitely.", Thread.CurrentThread.Name); | |
208 | + Logger.VerboseDebug("Thread '{0}' about to sleep indefinitely.", Thread.CurrentThread.Name); | |
198 | 209 | |
199 | - Thread.Sleep(Timeout.Infinite); | |
210 | + Thread.Sleep(Timeout.Infinite); | |
200 | 211 | |
201 | - } catch (ThreadInterruptedException) { | |
212 | + } | |
213 | + catch (ThreadInterruptedException) | |
214 | + { | |
202 | 215 | |
203 | - Logger.VerboseDebug("Thread '{0}' interupted [awoken]", Thread.CurrentThread.Name); | |
204 | - goto wake; | |
216 | + Logger.VerboseDebug("Thread '{0}' interupted [awoken]", Thread.CurrentThread.Name); | |
217 | + goto wake; | |
205 | 218 | |
206 | - } catch (ThreadAbortException) { | |
207 | - Logger.VerboseDebug("Thread '{0}' aborted.", Thread.CurrentThread.Name); | |
219 | + } | |
220 | + catch (ThreadAbortException) | |
221 | + { | |
222 | + Logger.VerboseDebug("Thread '{0}' aborted.", Thread.CurrentThread.Name); | |
208 | 223 | |
209 | - } finally { | |
210 | - Logger.VerboseDebug("Thread '{0}' executing finally block.", Thread.CurrentThread.Name); | |
211 | - } | |
224 | + } | |
225 | + finally | |
226 | + { | |
227 | + Logger.VerboseDebug("Thread '{0}' executing finally block.", Thread.CurrentThread.Name); | |
228 | + } | |
212 | 229 | } |
213 | 230 | |
214 | - private void UpdateStatus( uint totalUpdates, uint voidChunks, uint delta) | |
231 | + private void UpdateStatus(uint totalUpdates, uint voidChunks, uint delta) | |
215 | 232 | { |
216 | - StatusData updateData = new StatusData(totalUpdates, voidChunks, delta, RunState.Run); | |
233 | + StatusData updateData = new StatusData(totalUpdates, voidChunks, delta, RunState.Run); | |
217 | 234 | |
218 | - this.ClientAPI.Event.PushEvent(AutomapStatusEventKey, updateData); | |
235 | + this.ClientAPI.Event.PushEvent(AutomapStatusEventKey, updateData); | |
219 | 236 | } |
220 | 237 | |
221 | - private void Prefill_POI_Designators( ) | |
238 | + private void Prefill_POI_Designators() | |
222 | 239 | { |
223 | 240 | |
224 | - this.BlockID_Designators = new Dictionary<int, BlockDesignator>( ); | |
225 | - this.Entity_Designators = new Dictionary<AssetLocation, EntityDesignator>( ); | |
226 | - this.RockIdCodes = Helpers.ArbitrarytBlockIdHunter(ClientAPI, new AssetLocation(GlobalConstants.DefaultDomain, "rock"), EnumBlockMaterial.Stone); | |
241 | + this.BlockID_Designators = new Dictionary<int, BlockDesignator>(); | |
242 | + this.Entity_Designators = new Dictionary<AssetLocation, EntityDesignator>(); | |
243 | + this.RockIdCodes = Helpers.ArbitrarytBlockIdHunter(ClientAPI, new AssetLocation(GlobalConstants.DefaultDomain, "rock"), EnumBlockMaterial.Stone); | |
227 | 244 | |
228 | - //Add special marker types for BlockID's of "Interest", overwrite colour, and method | |
245 | + //Add special marker types for BlockID's of "Interest", overwrite colour, and method | |
229 | 246 | |
230 | - Install_POI_Designators(DefaultDesignators.DefaultBlockDesignators(), DefaultDesignators.DefaultEntityDesignators()); | |
247 | + Install_POI_Designators(DefaultDesignators.DefaultBlockDesignators(), DefaultDesignators.DefaultEntityDesignators()); | |
231 | 248 | } |
232 | 249 | |
233 | 250 | private void Install_POI_Designators(ICollection<BlockDesignator> blockDesig, List<EntityDesignator> entDesig) |
234 | 251 | { |
235 | - Logger.VerboseDebug("Connecting {0} standard Block-Designators", blockDesig.Count); | |
236 | - foreach (var designator in blockDesig) { | |
237 | - var blockIDs = Helpers.ArbitrarytBlockIdHunter(ClientAPI, designator.Pattern, designator.Material); | |
238 | - if (blockIDs.Count > 0) { Logger.VerboseDebug("Designator {0} has {1} associated blockIDs", designator.ToString( ), blockIDs.Count); } | |
239 | - foreach (var entry in blockIDs) { | |
240 | - BlockID_Designators.Add(entry.Key, designator); | |
252 | + Logger.VerboseDebug("Connecting {0} standard Block-Designators", blockDesig.Count); | |
253 | + foreach (var designator in blockDesig) | |
254 | + { | |
255 | + var blockIDs = Helpers.ArbitrarytBlockIdHunter(ClientAPI, designator.Pattern, designator.Material); | |
256 | + if (blockIDs.Count > 0) { Logger.VerboseDebug("Designator {0} has {1} associated blockIDs", designator.ToString(), blockIDs.Count); } | |
257 | + foreach (var entry in blockIDs) | |
258 | + { | |
259 | + BlockID_Designators.Add(entry.Key, designator); | |
260 | + } | |
241 | 261 | } |
242 | - } | |
243 | - this.ChunkRenderer.BlockID_Designators = BlockID_Designators; | |
244 | - | |
245 | - | |
246 | - Logger.VerboseDebug("Connecting {0} standard Entity-Designators", entDesig.Count); | |
247 | - foreach (var designator in entDesig) { | |
248 | - //Get Variants first, from EntityTypes...better be populated! | |
249 | - var matched = ClientAPI.World.EntityTypes.FindAll(entp => entp.Code.BeginsWith(designator.Pattern.Domain, designator.Pattern.Path)); | |
250 | - | |
251 | - foreach (var match in matched) { | |
252 | - Logger.VerboseDebug("Linked Entity: {0} Designator: {1}", match.Code, designator); | |
253 | - this.Entity_Designators.Add(match.Code, designator); | |
254 | - } | |
255 | - | |
256 | - | |
257 | - | |
258 | - //EntityProperties props = ClientAPI.World.GetEntityType(designator.Pattern); | |
259 | - } | |
260 | - | |
261 | - | |
262 | - } | |
263 | - | |
264 | - | |
265 | - private void GenerateMapHTML( ) | |
266 | - { | |
267 | - string mapFilename = Path.Combine(path, "Automap.html"); | |
268 | - | |
269 | - int TopNorth = chunkTopMetadata.North_mostChunk; | |
270 | - int TopSouth = chunkTopMetadata.South_mostChunk; | |
271 | - int TopEast = chunkTopMetadata.East_mostChunk; | |
272 | - int TopWest = chunkTopMetadata.West_mostChunk; | |
273 | - | |
274 | - using (StreamWriter outputText = new StreamWriter(File.Open(mapFilename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))) { | |
275 | - using (HtmlTextWriter tableWriter = new HtmlTextWriter(outputText)) { | |
276 | - tableWriter.BeginRender( ); | |
277 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Html); | |
278 | - | |
279 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Head); | |
280 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Title); | |
281 | - tableWriter.WriteEncodedText("Generated Automap"); | |
282 | - tableWriter.RenderEndTag( ); | |
283 | - //CSS style here | |
284 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Style); | |
285 | - tableWriter.Write(stylesFile.ToText( )); | |
286 | - tableWriter.RenderEndTag( );//</style> | |
287 | - | |
288 | - //## JSON map-state data ###################### | |
289 | - tableWriter.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript"); | |
290 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Script); | |
291 | - | |
292 | - tableWriter.Write("var available_images = ["); | |
293 | - | |
294 | - foreach (var shard in this.chunkTopMetadata) { | |
295 | - tableWriter.Write("{{X:{0},Y:{1} }}, ", shard.Location.X, shard.Location.Y); | |
296 | - } | |
297 | - | |
298 | - tableWriter.Write(" ];\n"); | |
299 | - | |
300 | - tableWriter.RenderEndTag( ); | |
301 | - | |
302 | - tableWriter.RenderEndTag( ); | |
303 | - | |
304 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Body); | |
305 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.P); | |
306 | - tableWriter.WriteEncodedText($"Created {DateTimeOffset.UtcNow.ToString("u")}"); | |
307 | - tableWriter.RenderEndTag( ); | |
308 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.P); | |
309 | - tableWriter.WriteEncodedText($"W:{TopWest}, E: {TopEast}, N:{TopNorth}, S:{TopSouth} "); | |
310 | - tableWriter.RenderEndTag( ); | |
311 | - tableWriter.WriteLine( ); | |
312 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Table); | |
313 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Caption); | |
314 | - tableWriter.WriteEncodedText($"Start: {startChunkColumn}, Seed: {ClientAPI.World.Seed}\n"); | |
315 | - tableWriter.RenderEndTag( ); | |
316 | - | |
317 | - //################ X-Axis <thead> ####################### | |
318 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Thead); | |
319 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr); | |
320 | - | |
321 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Th); | |
322 | - tableWriter.Write("N, W"); | |
323 | - tableWriter.RenderEndTag( ); | |
324 | - | |
325 | - for (int xAxisT = TopWest; xAxisT <= TopEast; xAxisT++) { | |
326 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Th); | |
327 | - tableWriter.Write(xAxisT); | |
328 | - tableWriter.RenderEndTag( ); | |
329 | - } | |
330 | - | |
331 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Th); | |
332 | - tableWriter.Write("N, E"); | |
333 | - tableWriter.RenderEndTag( ); | |
334 | - | |
335 | - tableWriter.RenderEndTag( ); | |
336 | - tableWriter.RenderEndTag( ); | |
337 | - //###### </thead> ################################ | |
338 | - | |
339 | - //###### <tbody> - Chunk rows & Y-axis cols | |
340 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tbody); | |
341 | - | |
342 | - //######## <tr> for every vertical row | |
343 | - for (int yAxis = TopNorth; yAxis <= TopSouth; yAxis++) { | |
344 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr); | |
345 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
346 | - tableWriter.Write(yAxis);//legend: Y-axis | |
347 | - tableWriter.RenderEndTag( ); | |
348 | - | |
349 | - for (int xAxis = TopWest; xAxis <= TopEast; xAxis++) { | |
350 | - //###### <td> #### for chunk shard | |
351 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
352 | - var colLoc = new Vec2i(xAxis, yAxis); | |
353 | - if (chunkTopMetadata.Contains( colLoc)){ | |
354 | - ColumnMeta meta = chunkTopMetadata[colLoc]; | |
355 | - //Tooltip first | |
356 | - tableWriter.AddAttribute(HtmlTextWriterAttribute.Class, "tooltip"); | |
357 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Div); | |
358 | - | |
359 | - tableWriter.AddAttribute(HtmlTextWriterAttribute.Src, $"{xAxis}_{yAxis}.png"); | |
360 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Img); | |
361 | - tableWriter.RenderEndTag( ); | |
362 | - // <span class="tooltiptext">Tooltip text | |
363 | - tableWriter.AddAttribute(HtmlTextWriterAttribute.Class, "tooltiptext"); | |
364 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Span); | |
365 | - | |
366 | - StringBuilder tooltipText = new StringBuilder( ); | |
367 | - tooltipText.Append($"{meta.Location.PrettyCoords(ClientAPI)} "); | |
368 | - tooltipText.Append($" Max-Height: {meta.YMax}, Temp: {meta.Temperature.ToString("F1")} " ); | |
369 | - tooltipText.Append($" Rainfall: {meta.Rainfall.ToString("F1")}, "); | |
370 | - tooltipText.Append($" Shrubs: {meta.ShrubDensity.ToString("F1")}, "); | |
371 | - tooltipText.Append($" Forest: {meta.ForestDensity.ToString("F1")}, "); | |
372 | - tooltipText.Append($" Fertility: {meta.Fertility.ToString("F1")}, "); | |
373 | - | |
374 | - if (meta.RockRatio != null) { | |
375 | - foreach (KeyValuePair<int, uint> blockID in meta.RockRatio) { | |
376 | - var block = ClientAPI.World.GetBlock(blockID.Key); | |
377 | - tooltipText.AppendFormat(" {0} × {1},\t", block.Code.GetName( ), meta.RockRatio[blockID.Key]); | |
378 | - } | |
379 | - } | |
262 | + this.ChunkRenderer.BlockID_Designators = BlockID_Designators; | |
380 | 263 | |
381 | - tableWriter.WriteEncodedText(tooltipText.ToString() ); | |
382 | - | |
383 | - tableWriter.RenderEndTag( );//</span> | |
384 | - | |
385 | 264 | |
386 | - tableWriter.RenderEndTag( );//</div> --tooltip enclosure | |
387 | - } | |
388 | - else { | |
389 | - tableWriter.Write("?"); | |
390 | - } | |
265 | + Logger.VerboseDebug("Connecting {0} standard Entity-Designators", entDesig.Count); | |
266 | + foreach (var designator in entDesig) | |
267 | + { | |
268 | + //Get Variants first, from EntityTypes...better be populated! | |
269 | + var matched = ClientAPI.World.EntityTypes.FindAll(entp => entp.Code.BeginsWith(designator.Pattern.Domain, designator.Pattern.Path)); | |
391 | 270 | |
392 | - tableWriter.RenderEndTag( ); | |
393 | - }//############ </td> ########### | |
271 | + foreach (var match in matched) | |
272 | + { | |
273 | + Logger.VerboseDebug("Linked Entity: {0} Designator: {1}", match.Code, designator); | |
274 | + this.Entity_Designators.Add(match.Code, designator); | |
275 | + } | |
394 | 276 | |
395 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
396 | - tableWriter.Write(yAxis);//legend: Y-axis | |
397 | - tableWriter.RenderEndTag( ); | |
398 | 277 | |
399 | - tableWriter.RenderEndTag( ); | |
400 | - | |
401 | - } | |
402 | - tableWriter.RenderEndTag( ); | |
403 | 278 | |
404 | - //################ X-Axis <tfoot> ####################### | |
405 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tfoot); | |
406 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr); | |
279 | + //EntityProperties props = ClientAPI.World.GetEntityType(designator.Pattern); | |
280 | + } | |
407 | 281 | |
408 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
409 | - tableWriter.Write("S, W"); | |
410 | - tableWriter.RenderEndTag( ); | |
411 | 282 | |
412 | - for (int xAxisB = TopWest; xAxisB <= TopEast; xAxisB++) { | |
413 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
414 | - tableWriter.Write(xAxisB); | |
415 | - tableWriter.RenderEndTag( ); | |
416 | 283 | } |
417 | 284 | |
418 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
419 | - tableWriter.Write("S, E"); | |
420 | - tableWriter.RenderEndTag( ); | |
421 | - | |
422 | - tableWriter.RenderEndTag( ); | |
423 | - tableWriter.RenderEndTag( ); | |
424 | - //###### </tfoot> ################################ | |
425 | - | |
426 | - | |
427 | - tableWriter.RenderEndTag( );//</table> | |
428 | 285 | |
429 | - //############## POI list ##################### | |
430 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.P); | |
431 | - tableWriter.WriteLine("Points of Interest"); | |
432 | - tableWriter.RenderEndTag( ); | |
433 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Ul); | |
434 | - foreach (var poi in this.POIs) { | |
435 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Li); | |
436 | - tableWriter.WriteEncodedText(poi.Location.PrettyCoords(this.ClientAPI)+"\t"); | |
437 | - tableWriter.WriteEncodedText(poi.Notes+ "\t"); | |
438 | - tableWriter.WriteEncodedText(poi.Timestamp.ToString("u")); | |
439 | - tableWriter.RenderEndTag( ); | |
440 | - } | |
441 | - | |
442 | - foreach (var eoi in this.EOIs.PointsList) { | |
443 | - tableWriter.RenderBeginTag(HtmlTextWriterTag.Li); | |
444 | - tableWriter.WriteEncodedText(eoi.Location.PrettyCoords(this.ClientAPI)+ "\t"); | |
445 | - tableWriter.WriteEncodedText(eoi.Notes+ "\t"); | |
446 | - tableWriter.WriteEncodedText(eoi.Timestamp.ToString("u") ); | |
447 | - tableWriter.RenderEndTag( ); | |
448 | - } | |
286 | + private void GenerateMapHTML() | |
287 | + { | |
288 | + string mapFilename = Path.Combine(path, "Automap.html"); | |
449 | 289 | |
450 | - tableWriter.RenderEndTag( ); | |
290 | + int TopNorth = chunkTopMetadata.North_mostChunk; | |
291 | + int TopSouth = chunkTopMetadata.South_mostChunk; | |
292 | + int TopEast = chunkTopMetadata.East_mostChunk; | |
293 | + int TopWest = chunkTopMetadata.West_mostChunk; | |
294 | + | |
295 | + using (StreamWriter outputText = new StreamWriter(File.Open(mapFilename, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))) | |
296 | + { | |
297 | + using (HtmlTextWriter tableWriter = new HtmlTextWriter(outputText)) | |
298 | + { | |
299 | + tableWriter.BeginRender(); | |
300 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Html); | |
301 | + | |
302 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Head); | |
303 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Title); | |
304 | + tableWriter.WriteEncodedText("Generated Automap"); | |
305 | + tableWriter.RenderEndTag(); | |
306 | + //CSS style here | |
307 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Style); | |
308 | + tableWriter.Write(stylesFile.ToText()); | |
309 | + tableWriter.RenderEndTag();//</style> | |
310 | + | |
311 | + //## JSON map-state data ###################### | |
312 | + tableWriter.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript"); | |
313 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Script); | |
314 | + | |
315 | + tableWriter.Write("var available_images = ["); | |
316 | + | |
317 | + foreach (var shard in this.chunkTopMetadata) | |
318 | + { | |
319 | + tableWriter.Write("{{X:{0},Y:{1} }}, ", shard.Location.X, shard.Location.Y); | |
320 | + } | |
321 | + | |
322 | + tableWriter.Write(" ];\n"); | |
323 | + | |
324 | + tableWriter.RenderEndTag(); | |
325 | + | |
326 | + tableWriter.RenderEndTag(); | |
327 | + | |
328 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Body); | |
329 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.P); | |
330 | + tableWriter.WriteEncodedText($"Created {DateTimeOffset.UtcNow.ToString("u")}"); | |
331 | + tableWriter.RenderEndTag(); | |
332 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.P); | |
333 | + tableWriter.WriteEncodedText($"W:{TopWest}, E: {TopEast}, N:{TopNorth}, S:{TopSouth} "); | |
334 | + tableWriter.RenderEndTag(); | |
335 | + tableWriter.WriteLine(); | |
336 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Table); | |
337 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Caption); | |
338 | + tableWriter.WriteEncodedText($"Start: {startChunkColumn}, Seed: {ClientAPI.World.Seed}\n"); | |
339 | + tableWriter.RenderEndTag(); | |
340 | + | |
341 | + //################ X-Axis <thead> ####################### | |
342 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Thead); | |
343 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr); | |
344 | + | |
345 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Th); | |
346 | + tableWriter.Write("N, W"); | |
347 | + tableWriter.RenderEndTag(); | |
348 | + | |
349 | + for (int xAxisT = TopWest; xAxisT <= TopEast; xAxisT++) | |
350 | + { | |
351 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Th); | |
352 | + tableWriter.Write(xAxisT); | |
353 | + tableWriter.RenderEndTag(); | |
354 | + } | |
355 | + | |
356 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Th); | |
357 | + tableWriter.Write("N, E"); | |
358 | + tableWriter.RenderEndTag(); | |
359 | + | |
360 | + tableWriter.RenderEndTag(); | |
361 | + tableWriter.RenderEndTag(); | |
362 | + //###### </thead> ################################ | |
363 | + | |
364 | + //###### <tbody> - Chunk rows & Y-axis cols | |
365 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Tbody); | |
366 | + | |
367 | + //######## <tr> for every vertical row | |
368 | + for (int yAxis = TopNorth; yAxis <= TopSouth; yAxis++) | |
369 | + { | |
370 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr); | |
371 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
372 | + tableWriter.Write(yAxis);//legend: Y-axis | |
373 | + tableWriter.RenderEndTag(); | |
374 | + | |
375 | + for (int xAxis = TopWest; xAxis <= TopEast; xAxis++) | |
376 | + { | |
377 | + //###### <td> #### for chunk shard | |
378 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
379 | + var colLoc = new Vec2i(xAxis, yAxis); | |
380 | + if (chunkTopMetadata.Contains(colLoc)) | |
381 | + { | |
382 | + ColumnMeta meta = chunkTopMetadata[colLoc]; | |
383 | + //Tooltip first | |
384 | + tableWriter.AddAttribute(HtmlTextWriterAttribute.Class, "tooltip"); | |
385 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Div); | |
386 | + | |
387 | + tableWriter.AddAttribute(HtmlTextWriterAttribute.Src, $"{xAxis}_{yAxis}.png"); | |
388 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Img); | |
389 | + tableWriter.RenderEndTag(); | |
390 | + // <span class="tooltiptext">Tooltip text | |
391 | + tableWriter.AddAttribute(HtmlTextWriterAttribute.Class, "tooltiptext"); | |
392 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Span); | |
393 | + | |
394 | + StringBuilder tooltipText = new StringBuilder(); | |
395 | + tooltipText.Append($"{meta.Location.PrettyCoords(ClientAPI)} "); | |
396 | + tooltipText.Append($" Max-Height: {meta.YMax}, Temp: {meta.Temperature.ToString("F1")} "); | |
397 | + tooltipText.Append($" Rainfall: {meta.Rainfall.ToString("F1")}, "); | |
398 | + tooltipText.Append($" Shrubs: {meta.ShrubDensity.ToString("F1")}, "); | |
399 | + tooltipText.Append($" Forest: {meta.ForestDensity.ToString("F1")}, "); | |
400 | + tooltipText.Append($" Fertility: {meta.Fertility.ToString("F1")}, "); | |
401 | + | |
402 | + if (meta.RockRatio != null) | |
403 | + { | |
404 | + foreach (KeyValuePair<int, uint> blockID in meta.RockRatio) | |
405 | + { | |
406 | + var block = ClientAPI.World.GetBlock(blockID.Key); | |
407 | + tooltipText.AppendFormat(" {0} × {1},\t", block.Code.GetName(), meta.RockRatio[blockID.Key]); | |
408 | + } | |
409 | + } | |
410 | + | |
411 | + tableWriter.WriteEncodedText(tooltipText.ToString()); | |
412 | + | |
413 | + tableWriter.RenderEndTag();//</span> | |
414 | + | |
415 | + | |
416 | + tableWriter.RenderEndTag();//</div> --tooltip enclosure | |
417 | + } | |
418 | + else | |
419 | + { | |
420 | + tableWriter.Write("?"); | |
421 | + } | |
422 | + | |
423 | + tableWriter.RenderEndTag(); | |
424 | + }//############ </td> ########### | |
425 | + | |
426 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
427 | + tableWriter.Write(yAxis);//legend: Y-axis | |
428 | + tableWriter.RenderEndTag(); | |
429 | + | |
430 | + tableWriter.RenderEndTag(); | |
431 | + | |
432 | + } | |
433 | + tableWriter.RenderEndTag(); | |
434 | + | |
435 | + //################ X-Axis <tfoot> ####################### | |
436 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Tfoot); | |
437 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Tr); | |
438 | + | |
439 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
440 | + tableWriter.Write("S, W"); | |
441 | + tableWriter.RenderEndTag(); | |
442 | + | |
443 | + for (int xAxisB = TopWest; xAxisB <= TopEast; xAxisB++) | |
444 | + { | |
445 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
446 | + tableWriter.Write(xAxisB); | |
447 | + tableWriter.RenderEndTag(); | |
448 | + } | |
449 | + | |
450 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Td); | |
451 | + tableWriter.Write("S, E"); | |
452 | + tableWriter.RenderEndTag(); | |
453 | + | |
454 | + tableWriter.RenderEndTag(); | |
455 | + tableWriter.RenderEndTag(); | |
456 | + //###### </tfoot> ################################ | |
457 | + | |
458 | + | |
459 | + tableWriter.RenderEndTag();//</table> | |
460 | + | |
461 | + //############## POI list ##################### | |
462 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.P); | |
463 | + tableWriter.WriteLine("Points of Interest"); | |
464 | + tableWriter.RenderEndTag(); | |
465 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Ul); | |
466 | + foreach (var poi in this.POIs) | |
467 | + { | |
468 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Li); | |
469 | + tableWriter.WriteEncodedText(poi.Location.PrettyCoords(this.ClientAPI) + "\t"); | |
470 | + tableWriter.WriteEncodedText(poi.Notes + "\t"); | |
471 | + tableWriter.WriteEncodedText(poi.Timestamp.ToString("u")); | |
472 | + tableWriter.RenderEndTag(); | |
473 | + } | |
474 | + | |
475 | + foreach (var eoi in this.EOIs.PointsList) | |
476 | + { | |
477 | + tableWriter.RenderBeginTag(HtmlTextWriterTag.Li); | |
478 | + tableWriter.WriteEncodedText(eoi.Location.PrettyCoords(this.ClientAPI) + "\t"); | |
479 | + tableWriter.WriteEncodedText(eoi.Notes + "\t"); | |
480 | + tableWriter.WriteEncodedText(eoi.Timestamp.ToString("u")); | |
481 | + tableWriter.RenderEndTag(); | |
482 | + } | |
483 | + | |
484 | + tableWriter.RenderEndTag(); | |
451 | 485 | |
452 | - | |
453 | 486 | |
454 | 487 | |
455 | - tableWriter.RenderEndTag( );//### </BODY> ### | |
456 | - | |
457 | - tableWriter.EndRender( ); | |
458 | - tableWriter.Flush( ); | |
459 | - } | |
460 | - outputText.Flush( ); | |
461 | - } | |
462 | 488 | |
463 | - Logger.VerboseDebug("Generated HTML map"); | |
489 | + tableWriter.RenderEndTag();//### </BODY> ### | |
490 | + | |
491 | + tableWriter.EndRender(); | |
492 | + tableWriter.Flush(); | |
493 | + } | |
494 | + outputText.Flush(); | |
495 | + } | |
496 | + | |
497 | + Logger.VerboseDebug("Generated HTML map"); | |
464 | 498 | } |
465 | 499 | |
466 | 500 | /// <summary> |
467 | 501 | /// Generates the JSON Metadata. (in MAP object format ) |
468 | 502 | /// </summary> |
469 | - private void GenerateJSONMetadata( ) | |
503 | + private void GenerateJSONMetadata() | |
470 | 504 | { |
471 | - string jsonFilename = Path.Combine(path, "Metadata.js"); | |
505 | + string jsonFilename = Path.Combine(path, "Metadata.js"); | |
472 | 506 | |
473 | - StreamWriter jsonWriter = new StreamWriter(jsonFilename, false, Encoding.UTF8); | |
474 | - using (jsonWriter) | |
507 | + StreamWriter jsonWriter = new StreamWriter(jsonFilename, false, Encoding.UTF8); | |
508 | + using (jsonWriter) | |
475 | 509 | { |
476 | - jsonWriter.WriteLine("var worldSeedNum = {0};", ClientAPI.World.Seed); | |
477 | - jsonWriter.WriteLine("var genTime = new Date('{0}');", DateTimeOffset.UtcNow.ToString("O")); | |
478 | - jsonWriter.WriteLine("var startCoords = {{X:{0},Y:{1}}};", startChunkColumn.X, startChunkColumn.Y); | |
479 | - jsonWriter.WriteLine("var chunkSize = {0};", chunkSize); | |
480 | - jsonWriter.WriteLine("var northMostChunk ={0};", chunkTopMetadata.North_mostChunk); | |
481 | - jsonWriter.WriteLine("var southMostChunk ={0};", chunkTopMetadata.South_mostChunk); | |
482 | - jsonWriter.WriteLine("var eastMostChunk ={0};", chunkTopMetadata.East_mostChunk); | |
483 | - jsonWriter.WriteLine("var westMostChunk ={0};", chunkTopMetadata.West_mostChunk); | |
484 | - //MAP object format - [key, value]: key is "x_y" | |
485 | - jsonWriter.Write("let shardsMetadata = new Map(["); | |
486 | - foreach (var shard in chunkTopMetadata) | |
510 | + jsonWriter.WriteLine("var worldSeedNum = {0};", ClientAPI.World.Seed); | |
511 | + jsonWriter.WriteLine("var genTime = new Date('{0}');", DateTimeOffset.UtcNow.ToString("O")); | |
512 | + jsonWriter.WriteLine("var startCoords = {{X:{0},Y:{1}}};", startChunkColumn.X, startChunkColumn.Y); | |
513 | + jsonWriter.WriteLine("var chunkSize = {0};", chunkSize); | |
514 | + jsonWriter.WriteLine("var northMostChunk ={0};", chunkTopMetadata.North_mostChunk); | |
515 | + jsonWriter.WriteLine("var southMostChunk ={0};", chunkTopMetadata.South_mostChunk); | |
516 | + jsonWriter.WriteLine("var eastMostChunk ={0};", chunkTopMetadata.East_mostChunk); | |
517 | + jsonWriter.WriteLine("var westMostChunk ={0};", chunkTopMetadata.West_mostChunk); | |
518 | + //MAP object format - [key, value]: key is "x_y" | |
519 | + jsonWriter.Write("let shardsMetadata = new Map(["); | |
520 | + foreach (var shard in chunkTopMetadata) | |
487 | 521 | { |
488 | - jsonWriter.Write("['{0}_{1}',", shard.Location.X, shard.Location.Y); | |
489 | - jsonWriter.Write("{"); | |
490 | - jsonWriter.Write("ChunkAge: '{0}',", shard.ChunkAge);//World age - relative? or last edit ?? | |
491 | - jsonWriter.Write("Temperature: {0},", shard.Temperature.ToString("F1")); | |
492 | - jsonWriter.Write("YMax: {0},", shard.YMax); | |
493 | - jsonWriter.Write("Fertility: {0},", shard.Fertility.ToString("F1")); | |
494 | - jsonWriter.Write("ForestDensity: {0},", shard.ForestDensity.ToString("F1")); | |
495 | - jsonWriter.Write("Rainfall: {0},", shard.Rainfall.ToString("F1")); | |
496 | - jsonWriter.Write("ShrubDensity: {0},", shard.ShrubDensity.ToString("F1")); | |
497 | - jsonWriter.Write("AirBlocks: {0},", shard.AirBlocks); | |
498 | - jsonWriter.Write("NonAirBlocks: {0},", shard.NonAirBlocks); | |
499 | - //TODO: Heightmap | |
500 | - //TODO: Rock-ratio | |
501 | - jsonWriter.Write("}],"); | |
522 | + jsonWriter.Write("['{0}_{1}',", shard.Location.X, shard.Location.Y); | |
523 | + jsonWriter.Write("{"); | |
524 | + jsonWriter.Write("ChunkAge: '{0}',", shard.ChunkAge);//World age - relative? or last edit ?? | |
525 | + jsonWriter.Write("Temperature: {0},", shard.Temperature.ToString("F1")); | |
526 | + jsonWriter.Write("YMax: {0},", shard.YMax); | |
527 | + jsonWriter.Write("Fertility: {0},", shard.Fertility.ToString("F1")); | |
528 | + jsonWriter.Write("ForestDensity: {0},", shard.ForestDensity.ToString("F1")); | |
529 | + jsonWriter.Write("Rainfall: {0},", shard.Rainfall.ToString("F1")); | |
530 | + jsonWriter.Write("ShrubDensity: {0},", shard.ShrubDensity.ToString("F1")); | |
531 | + jsonWriter.Write("AirBlocks: {0},", shard.AirBlocks); | |
532 | + jsonWriter.Write("NonAirBlocks: {0},", shard.NonAirBlocks); | |
533 | + //TODO: Heightmap | |
534 | + //TODO: Rock-ratio | |
535 | + jsonWriter.Write("}],"); | |
502 | 536 | } |
503 | - jsonWriter.Write("]);\n\n"); | |
537 | + jsonWriter.Write("]);\n\n"); | |
538 | + | |
504 | 539 | |
505 | - | |
506 | - jsonWriter.Write("let pointsOfInterest = new Map(["); | |
507 | - foreach (var poi in POIs) | |
540 | + jsonWriter.Write("let pointsOfInterest = new Map(["); | |
541 | + foreach (var poi in POIs) | |
508 | 542 | { |
509 | 543 | jsonWriter.Write("['{0}_{1}',", poi.Location.X, poi.Location.Y); |
510 | 544 | jsonWriter.Write("{"); |
511 | - jsonWriter.Write("notes: '{0}',", poi.Notes.Replace("'"," ")); | |
545 | + jsonWriter.Write("notes: '{0}',", poi.Notes.Replace("'", " ")); | |
512 | 546 | jsonWriter.Write("timestamp : new Date('{0}'),", poi.Timestamp.ToString("O")); |
513 | - jsonWriter.Write("chunkPos:'{0}_{1}',", (poi.Location.X/chunkSize), (poi.Location.Y/chunkSize)); | |
547 | + jsonWriter.Write("chunkPos:'{0}_{1}',", (poi.Location.X / chunkSize), (poi.Location.Y / chunkSize)); | |
514 | 548 | jsonWriter.Write("}],"); |
515 | 549 | } |
516 | 550 | |
517 | - foreach (var poi in EOIs.PointsList) | |
551 | + foreach (var poi in EOIs.PointsList) | |
518 | 552 | { |
519 | - jsonWriter.Write("['{0}_{1}',", poi.Location.X, poi.Location.Y); | |
520 | - jsonWriter.Write("{"); | |
521 | - jsonWriter.Write("notes: '{0}',", poi.Notes.Replace("'", " ")); | |
522 | - jsonWriter.Write("timestamp : new Date('{0}'),", poi.Timestamp.ToString("O")); | |
523 | - jsonWriter.Write("chunkPos:'{0}_{1}',", (poi.Location.X / chunkSize), (poi.Location.Y / chunkSize)); | |
524 | - jsonWriter.Write("}],"); | |
553 | + jsonWriter.Write("['{0}_{1}',", poi.Location.X, poi.Location.Y); | |
554 | + jsonWriter.Write("{"); | |
555 | + jsonWriter.Write("notes: '{0}',", poi.Notes.Replace("'", " ")); | |
556 | + jsonWriter.Write("timestamp : new Date('{0}'),", poi.Timestamp.ToString("O")); | |
557 | + jsonWriter.Write("chunkPos:'{0}_{1}',", (poi.Location.X / chunkSize), (poi.Location.Y / chunkSize)); | |
558 | + jsonWriter.Write("}],"); | |
525 | 559 | } |
526 | - jsonWriter.Write("]);\n\n"); | |
560 | + jsonWriter.Write("]);\n\n"); | |
527 | 561 | |
528 | - jsonWriter.Flush( ); | |
529 | - } | |
562 | + jsonWriter.Flush(); | |
563 | + } | |
530 | 564 | |
531 | 565 | } |
532 | 566 | |
533 | 567 | |
534 | 568 | private ColumnMeta CreateColumnMetadata(KeyValuePair<Vec2i, uint> mostActiveCol, IMapChunk mapChunk) |
535 | 569 | { |
536 | - ColumnMeta data = new ColumnMeta(mostActiveCol.Key.Copy(), chunkSize); | |
537 | - BlockPos equivBP = new BlockPos(mostActiveCol.Key.X * chunkSize, | |
538 | - mapChunk.YMax, | |
539 | - mostActiveCol.Key.Y * chunkSize); | |
570 | + ColumnMeta data = new ColumnMeta(mostActiveCol.Key.Copy(), chunkSize); | |
571 | + BlockPos equivBP = new BlockPos(mostActiveCol.Key.X * chunkSize, | |
572 | + mapChunk.YMax, | |
573 | + mostActiveCol.Key.Y * chunkSize); | |
540 | 574 | |
541 | - var climate = ClientAPI.World.BlockAccessor.GetClimateAt(equivBP); | |
542 | - data.UpdateFieldsFrom(climate, mapChunk,TimeSpan.FromHours(ClientAPI.World.Calendar.TotalHours)); | |
575 | + var climate = ClientAPI.World.BlockAccessor.GetClimateAt(equivBP); | |
576 | + data.UpdateFieldsFrom(climate, mapChunk, TimeSpan.FromHours(ClientAPI.World.Calendar.TotalHours)); | |
543 | 577 | |
544 | - return data; | |
578 | + return data; | |
545 | 579 | } |
546 | 580 | |
547 | 581 | /// <summary> |
548 | 582 | /// Reload chunk bounds from chunk shards |
549 | 583 | /// </summary> |
550 | 584 | /// <returns>The metadata.</returns> |
551 | - private void Reload_Metadata( ) | |
552 | - { | |
553 | - var worldmapDir = new DirectoryInfo(path); | |
585 | + private void Reload_Metadata() | |
586 | + { | |
587 | + var worldmapDir = new DirectoryInfo(path); | |
554 | 588 | |
555 | - if (worldmapDir.Exists) { | |
589 | + if (worldmapDir.Exists) | |
590 | + { | |
556 | 591 | |
557 | - var files = worldmapDir.GetFiles(chunkFile_filter); | |
592 | + var files = worldmapDir.GetFiles(chunkFile_filter); | |
558 | 593 | |
559 | - if (files.Length > 0) { | |
560 | - #if DEBUG | |
561 | - Logger.VerboseDebug("{0} Existing world chunk shards", files.Length); | |
562 | - #endif | |
594 | + if (files.Length > 0) | |
595 | + { | |
596 | +#if DEBUG | |
597 | + Logger.VerboseDebug("{0} Existing world chunk shards", files.Length); | |
598 | +#endif | |
563 | 599 | |
564 | - | |
565 | 600 | |
566 | - foreach (var shardFile in files) { | |
567 | 601 | |
568 | - if (shardFile.Length < 512) continue; | |
569 | - var result = chunkShardRegex.Match(shardFile.Name); | |
570 | - if (result.Success) { | |
571 | - int X_chunk_pos = int.Parse(result.Groups["X"].Value ); | |
572 | - int Z_chunk_pos = int.Parse(result.Groups["Z"].Value ); | |
573 | - | |
574 | - //Parse PNG chunks for METADATA in shard | |
575 | - using (var fileStream = shardFile.OpenRead( )) | |
576 | - { | |
577 | - //TODO: Add corrupted PNG Exception handing HERE ! | |
578 | - PngReader pngRead = new PngReader(fileStream ); | |
579 | - pngRead.ReadSkippingAllRows( ); | |
580 | - pngRead.End( ); | |
602 | + foreach (var shardFile in files) | |
603 | + { | |
581 | 604 | |
582 | - PngMetadataChunk metadataFromPng = pngRead.GetChunksList( ).GetById1(PngMetadataChunk.ID) as PngMetadataChunk; | |
605 | + if (shardFile.Length < 512) continue; | |
606 | + var result = chunkShardRegex.Match(shardFile.Name); | |
607 | + if (result.Success) | |
608 | + { | |
609 | + int X_chunk_pos = int.Parse(result.Groups["X"].Value); | |
610 | + int Z_chunk_pos = int.Parse(result.Groups["Z"].Value); | |
583 | 611 | |
584 | - chunkTopMetadata.Add(metadataFromPng.ChunkMetadata); | |
585 | - } | |
586 | - | |
587 | - } | |
588 | - } | |
612 | + //Parse PNG chunks for METADATA in shard | |
613 | + using (var fileStream = shardFile.OpenRead()) | |
614 | + { | |
615 | + //TODO: Add corrupted PNG Exception handing HERE ! | |
616 | + PngReader pngRead = new PngReader(fileStream); | |
617 | + pngRead.ReadSkippingAllRows(); | |
618 | + pngRead.End(); | |
589 | 619 | |
590 | - } | |
591 | - } | |
592 | - else { | |
593 | - #if DEBUG | |
594 | - Logger.VerboseDebug("Could not open world map directory"); | |
595 | - #endif | |
596 | - } | |
620 | + PngMetadataChunk metadataFromPng = pngRead.GetChunksList().GetById1(PngMetadataChunk.ID) as PngMetadataChunk; | |
621 | + | |
622 | + chunkTopMetadata.Add(metadataFromPng.ChunkMetadata); | |
623 | + } | |
624 | + | |
625 | + } | |
626 | + } | |
627 | + | |
628 | + } | |
629 | + } | |
630 | + else | |
631 | + { | |
632 | +#if DEBUG | |
633 | + Logger.VerboseDebug("Could not open world map directory"); | |
634 | +#endif | |
635 | + } | |
597 | 636 | |
598 | 637 | |
599 | 638 |
@@ -601,22 +640,22 @@ namespace Automap | ||
601 | 640 | |
602 | 641 | private PngWriter SetupPngImage(Vec2i coord, ColumnMeta metadata) |
603 | 642 | { |
604 | - ImageInfo imageInf = new ImageInfo(chunkSize, chunkSize, 8, false); | |
605 | - | |
606 | - string filename = $"{coord.X}_{coord.Y}.png"; | |
607 | - filename = Path.Combine(path, filename); | |
608 | - | |
609 | - PngWriter pngWriter = FileHelper.CreatePngWriter(filename, imageInf, true); | |
610 | - PngMetadata meta = pngWriter.GetMetadata( ); | |
611 | - meta.SetTimeNow( ); | |
612 | - meta.SetText("Chunk_X", coord.X.ToString("D")); | |
613 | - meta.SetText("Chunk_Y", coord.Y.ToString("D")); | |
614 | - //Setup specialized meta-data PNG chunks here... | |
615 | - PngMetadataChunk pngChunkMeta = new PngMetadataChunk(pngWriter.ImgInfo); | |
616 | - pngChunkMeta.ChunkMetadata = metadata; | |
617 | - pngWriter.GetChunksList( ).Queue(pngChunkMeta); | |
618 | - | |
619 | - return pngWriter; | |
643 | + ImageInfo imageInf = new ImageInfo(chunkSize, chunkSize, 8, false); | |
644 | + | |
645 | + string filename = $"{coord.X}_{coord.Y}.png"; | |
646 | + filename = Path.Combine(path, filename); | |
647 | + | |
648 | + PngWriter pngWriter = FileHelper.CreatePngWriter(filename, imageInf, true); | |
649 | + PngMetadata meta = pngWriter.GetMetadata(); | |
650 | + meta.SetTimeNow(); | |
651 | + meta.SetText("Chunk_X", coord.X.ToString("D")); | |
652 | + meta.SetText("Chunk_Y", coord.Y.ToString("D")); | |
653 | + //Setup specialized meta-data PNG chunks here... | |
654 | + PngMetadataChunk pngChunkMeta = new PngMetadataChunk(pngWriter.ImgInfo); | |
655 | + pngChunkMeta.ChunkMetadata = metadata; | |
656 | + pngWriter.GetChunksList().Queue(pngChunkMeta); | |
657 | + | |
658 | + return pngWriter; | |
620 | 659 | } |
621 | 660 | |
622 | 661 | /// <summary> |
@@ -628,149 +667,164 @@ namespace Automap | ||
628 | 667 | private void ProcessChunkBlocks(Vec2i key, IMapChunk mapChunk, ColumnMeta chunkMeta) |
629 | 668 | { |
630 | 669 | |
631 | - int targetChunkY = mapChunk.YMax / chunkSize;//Surface ... | |
632 | - for (; targetChunkY > 0; targetChunkY--) { | |
633 | - WorldChunk chunkData = ClientAPI.World.BlockAccessor.GetChunk(key.X, targetChunkY, key.Y) as WorldChunk; | |
670 | + int targetChunkY = mapChunk.YMax / chunkSize;//Surface ... | |
671 | + for (; targetChunkY > 0; targetChunkY--) | |
672 | + { | |
673 | + WorldChunk chunkData = ClientAPI.World.BlockAccessor.GetChunk(key.X, targetChunkY, key.Y) as WorldChunk; | |
634 | 674 | |
635 | - if (chunkData == null || chunkData.BlockEntities == null) { | |
636 | - #if DEBUG | |
637 | - Logger.VerboseDebug("Chunk null or empty X{0} Y{1} Z{2}", key.X,targetChunkY,key.Y); | |
638 | - #endif | |
639 | - continue; | |
640 | - } | |
675 | + if (chunkData == null || chunkData.BlockEntities == null) | |
676 | + { | |
677 | +#if DEBUG | |
678 | + Logger.VerboseDebug("Chunk null or empty X{0} Y{1} Z{2}", key.X, targetChunkY, key.Y); | |
679 | +#endif | |
680 | + continue; | |
681 | + } | |
641 | 682 | |
642 | - /*************** Chunk Entities Scanning *********************/ | |
643 | - if (chunkData.BlockEntities != null && chunkData.BlockEntities.Length > 0) { | |
644 | - #if DEBUG | |
645 | - Logger.VerboseDebug("Surface@ {0} = BlockEntities: {1}", key, chunkData.BlockEntities.Length); | |
646 | - #endif | |
683 | + /*************** Chunk Entities Scanning *********************/ | |
684 | + if (chunkData.BlockEntities != null && chunkData.BlockEntities.Length > 0) | |
685 | + { | |
686 | +#if DEBUG | |
687 | + Logger.VerboseDebug("Surface@ {0} = BlockEntities: {1}", key, chunkData.BlockEntities.Length); | |
688 | +#endif | |
647 | 689 | |
648 | - foreach (var blockEnt in chunkData.BlockEntities) { | |
649 | - | |
650 | - if (blockEnt != null && blockEnt.Block != null && BlockID_Designators.ContainsKey(blockEnt.Block.BlockId)) | |
651 | - { | |
652 | - var designator = BlockID_Designators[blockEnt.Block.BlockId]; | |
653 | - designator.SpecialAction(ClientAPI, POIs, blockEnt.Pos.Copy( ), blockEnt.Block); | |
654 | - } | |
655 | - } | |
656 | - | |
657 | - } | |
658 | - /********************* Chunk/Column BLOCKs scanning ****************/ | |
659 | - //Heightmap, Stats, block tally | |
660 | - chunkData.Unpack( ); | |
661 | - | |
662 | - int X_index, Y_index, Z_index; | |
663 | - X_index = Y_index = Z_index = 0; | |
664 | - | |
665 | - do { | |
666 | - do { | |
667 | - do { | |
668 | - /* Encode packed indicie | |
669 | - (y * chunksize + z) * chunksize + x | |
670 | - */ | |
671 | - var indicie = Helpers.ChunkBlockIndicie16(X_index, Y_index, Z_index); | |
672 | - int aBlockId = chunkData.Blocks[indicie]; | |
673 | - | |
674 | - if (aBlockId == 0) {//Air | |
675 | - chunkMeta.AirBlocks++; | |
676 | - continue; | |
677 | - } | |
690 | + foreach (var blockEnt in chunkData.BlockEntities) | |
691 | + { | |
678 | 692 | |
679 | - if (RockIdCodes.ContainsKey(aBlockId)) { | |
680 | - if (chunkMeta.RockRatio.ContainsKey(aBlockId)) { chunkMeta.RockRatio[aBlockId]++; } else { chunkMeta.RockRatio.Add(aBlockId, 1); } | |
681 | - } | |
682 | - | |
683 | - chunkMeta.NonAirBlocks++; | |
693 | + if (blockEnt != null && blockEnt.Block != null && BlockID_Designators.ContainsKey(blockEnt.Block.BlockId)) | |
694 | + { | |
695 | + var designator = BlockID_Designators[blockEnt.Block.BlockId]; | |
696 | + designator.SpecialAction(ClientAPI, POIs, blockEnt.Pos.Copy(), blockEnt.Block); | |
697 | + } | |
698 | + } | |
684 | 699 | |
685 | - //Heightmap | |
686 | - if (chunkMeta.HeightMap[X_index, Z_index] == 0) | |
687 | - { chunkMeta.HeightMap[X_index, Z_index] = ( ushort )(Y_index + (targetChunkY * chunkSize)); } | |
700 | + } | |
701 | + /********************* Chunk/Column BLOCKs scanning ****************/ | |
702 | + //Heightmap, Stats, block tally | |
703 | + chunkData.Unpack(); | |
688 | 704 | |
689 | - } | |
690 | - while (X_index++ < (chunkSize - 1)); | |
691 | - X_index = 0; | |
692 | - } | |
693 | - while (Z_index++ < (chunkSize - 1)); | |
694 | - Z_index = 0; | |
695 | - } | |
696 | - while (Y_index++ < (chunkSize - 1)); | |
705 | + int X_index, Y_index, Z_index; | |
706 | + X_index = Y_index = Z_index = 0; | |
697 | 707 | |
698 | - } | |
708 | + do | |
709 | + { | |
710 | + do | |
711 | + { | |
712 | + do | |
713 | + { | |
714 | + /* Encode packed indicie | |
715 | + (y * chunksize + z) * chunksize + x | |
716 | + */ | |
717 | + var indicie = Helpers.ChunkBlockIndicie16(X_index, Y_index, Z_index); | |
718 | + int aBlockId = chunkData.Blocks[indicie]; | |
719 | + | |
720 | + if (aBlockId == 0) | |
721 | + {//Air | |
722 | + chunkMeta.AirBlocks++; | |
723 | + continue; | |
724 | + } | |
725 | + | |
726 | + if (RockIdCodes.ContainsKey(aBlockId)) | |
727 | + { | |
728 | + if (chunkMeta.RockRatio.ContainsKey(aBlockId)) { chunkMeta.RockRatio[aBlockId]++; } else { chunkMeta.RockRatio.Add(aBlockId, 1); } | |
729 | + } | |
730 | + | |
731 | + chunkMeta.NonAirBlocks++; | |
732 | + | |
733 | + //Heightmap | |
734 | + if (chunkMeta.HeightMap[X_index, Z_index] == 0) | |
735 | + { chunkMeta.HeightMap[X_index, Z_index] = (ushort) (Y_index + (targetChunkY * chunkSize)); } | |
736 | + | |
737 | + } | |
738 | + while (X_index++ < (chunkSize - 1)); | |
739 | + X_index = 0; | |
740 | + } | |
741 | + while (Z_index++ < (chunkSize - 1)); | |
742 | + Z_index = 0; | |
743 | + } | |
744 | + while (Y_index++ < (chunkSize - 1)); | |
745 | + | |
746 | + } | |
699 | 747 | } |
700 | 748 | |
701 | - private void UpdateEntityMetadata( ) | |
749 | + private void UpdateEntityMetadata() | |
702 | 750 | { |
703 | - Logger.Debug("Presently {0} Entities", ClientAPI.World.LoadedEntities.Count); | |
704 | - //Mabey scan only for 'new' entities by tracking ID in set? | |
705 | - foreach (var loadedEntity in ClientAPI.World.LoadedEntities.ToList()) { | |
706 | - | |
707 | - #if DEBUG | |
708 | - //Logger.VerboseDebug($"ENTITY: ({loadedEntity.Value.Code}) = #{loadedEntity.Value.EntityId} {loadedEntity.Value.State} {loadedEntity.Value.LocalPos} <<<<<<<<<<<<"); | |
709 | - #endif | |
710 | - | |
711 | - var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Value.Code)); | |
712 | - if (dMatch.Value != null) { | |
713 | - dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Value.LocalPos.AsBlockPos.Copy( ), loadedEntity.Value); | |
714 | - } | |
751 | + Logger.Debug("Presently {0} Entities", ClientAPI.World.LoadedEntities.Count); | |
752 | + //Mabey scan only for 'new' entities by tracking ID in set? | |
753 | + foreach (var loadedEntity in ClientAPI.World.LoadedEntities.ToList()) | |
754 | + { | |
715 | 755 | |
716 | - } | |
756 | +#if DEBUG | |
757 | + //Logger.VerboseDebug($"ENTITY: ({loadedEntity.Value.Code}) = #{loadedEntity.Value.EntityId} {loadedEntity.Value.State} {loadedEntity.Value.LocalPos} <<<<<<<<<<<<"); | |
758 | +#endif | |
759 | + | |
760 | + var dMatch = Entity_Designators.SingleOrDefault(se => se.Key.Equals(loadedEntity.Value.Code)); | |
761 | + if (dMatch.Value != null) | |
762 | + { | |
763 | + dMatch.Value.SpecialAction(ClientAPI, this.EOIs, loadedEntity.Value.LocalPos.AsBlockPos.Copy(), loadedEntity.Value); | |
764 | + } | |
765 | + | |
766 | + } | |
717 | 767 | |
718 | 768 | |
719 | 769 | } |
720 | 770 | |
721 | 771 | private void AddNote(string notation) |
722 | - { | |
723 | - var playerNodePoi = new PointOfInterest( ) { | |
724 | - Location = ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.Copy(), | |
725 | - Notes = notation, | |
726 | - Timestamp = DateTimeOffset.UtcNow, | |
727 | - }; | |
728 | - | |
729 | - this.POIs.AddReplace(playerNodePoi); | |
772 | + { | |
773 | + var playerNodePoi = new PointOfInterest() | |
774 | + { | |
775 | + Location = ClientAPI.World.Player.Entity.LocalPos.AsBlockPos.Copy(), | |
776 | + Notes = notation, | |
777 | + Timestamp = DateTimeOffset.UtcNow, | |
778 | + }; | |
779 | + | |
780 | + this.POIs.AddReplace(playerNodePoi); | |
730 | 781 | } |
731 | 782 | |
732 | 783 | |
733 | 784 | |
734 | 785 | private void CommandListener(string eventName, ref EnumHandling handling, IAttribute data) |
735 | 786 | { |
736 | - Logger.VerboseDebug("MsgBus RX: AutomapCommandMsg: {0}", data.ToJsonToken() ); | |
787 | + Logger.VerboseDebug("MsgBus RX: AutomapCommandMsg: {0}", data.ToJsonToken()); | |
737 | 788 | |
738 | - CommandData cmdData = data as CommandData; | |
789 | + CommandData cmdData = data as CommandData; | |
739 | 790 | |
740 | 791 | |
741 | - if (CurrentState != RunState.Snapshot) { | |
742 | - switch (cmdData.State) { | |
743 | - case RunState.Run: | |
744 | - CurrentState = cmdData.State; | |
745 | - AwakenCartographer(0.0f); | |
746 | - break; | |
792 | + if (CurrentState != RunState.Snapshot) | |
793 | + { | |
794 | + switch (cmdData.State) | |
795 | + { | |
796 | + case RunState.Run: | |
797 | + CurrentState = cmdData.State; | |
798 | + AwakenCartographer(0.0f); | |
799 | + break; | |
747 | 800 | |
748 | - case RunState.Stop: | |
749 | - CurrentState = cmdData.State; | |
750 | - break; | |
801 | + case RunState.Stop: | |
802 | + CurrentState = cmdData.State; | |
803 | + break; | |
751 | 804 | |
752 | - case RunState.Snapshot: | |
753 | - CurrentState = RunState.Stop; | |
754 | - //Snapshot starts a second thread/process... | |
805 | + case RunState.Snapshot: | |
806 | + CurrentState = RunState.Stop; | |
807 | + //Snapshot starts a second thread/process... | |
755 | 808 | |
756 | - break; | |
809 | + break; | |
757 | 810 | |
758 | - case RunState.Notation: | |
759 | - //Add to POI list where player location | |
760 | - AddNote(cmdData.Notation); | |
761 | - break; | |
762 | - } | |
811 | + case RunState.Notation: | |
812 | + //Add to POI list where player location | |
813 | + AddNote(cmdData.Notation); | |
814 | + break; | |
815 | + } | |
763 | 816 | |
764 | - } | |
817 | + } | |
765 | 818 | |
766 | - if (CurrentState != cmdData.State) { | |
767 | - CurrentState = cmdData.State; | |
768 | - AwakenCartographer(0.0f); | |
769 | - } | |
819 | + if (CurrentState != cmdData.State) | |
820 | + { | |
821 | + CurrentState = cmdData.State; | |
822 | + AwakenCartographer(0.0f); | |
823 | + } | |
770 | 824 | |
771 | - #if DEBUG | |
772 | - ClientAPI.TriggerChatMessage($"Automap commanded to: {cmdData.State} "); | |
773 | - #endif | |
825 | +#if DEBUG | |
826 | + ClientAPI.TriggerChatMessage($"Automap commanded to: {cmdData.State} "); | |
827 | +#endif | |
774 | 828 | |
775 | 829 | } |
776 | 830 |