-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathInstanceDataDumper.cs
More file actions
101 lines (88 loc) · 3 KB
/
InstanceDataDumper.cs
File metadata and controls
101 lines (88 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Radar;
public class TilePosition
{
public int X { get; set; }
public int Y { get; set; }
public int W { get; set; }
public int H { get; set; }
public List<string> Tiles { get; set; }
}
public class OptimizedInstanceData
{
public string Name { get; set; }
public int W { get; set; }
public int H { get; set; }
public float[] Heights { get; set; }
public int[] Walk { get; set; }
public int[] Target { get; set; }
public List<TilePosition> Tiles { get; set; }
}
public partial class Radar
{
public void DumpInstanceData(string outputPath)
{
if (_heightData == null || _processedTerrainData == null || _processedTerrainTargetingData == null || _areaDimensions == null)
{
return;
}
try
{
var dimensions = _areaDimensions.Value;
// Create flattened arrays
var heights = new float[dimensions.X * dimensions.Y];
var walk = new int[dimensions.X * dimensions.Y];
var target = new int[dimensions.X * dimensions.Y];
// Fill the arrays
for (var y = 0; y < dimensions.Y && y < _heightData.Length; y++)
{
for (var x = 0; x < dimensions.X && x < _heightData[y].Length; x++)
{
var index = y * dimensions.X + x;
heights[index] = _heightData[y][x];
walk[index] = _processedTerrainData[y][x];
target[index] = _processedTerrainTargetingData[y][x];
}
}
// Convert to list of TilePositions
var tilePositions = _locationsByPosition.Select(kvp => new TilePosition
{
X = kvp.Key.X,
Y = kvp.Key.Y,
W = TileToGridConversion,
H = TileToGridConversion,
Tiles = kvp.Value
}).ToList();
var instanceData = new OptimizedInstanceData
{
Name = GameController.Area.CurrentArea.Area.RawName,
W = dimensions.X,
H = dimensions.Y,
Heights = heights,
Walk = walk,
Target = target,
Tiles = tilePositions
};
// Create directory if it doesn't exist
var fullPath = Path.GetFullPath(outputPath);
var directory = Path.GetDirectoryName(fullPath);
if (!string.IsNullOrEmpty(directory))
{
Directory.CreateDirectory(directory);
}
// Serialize and write with indentation for readability
var json = JsonConvert.SerializeObject(instanceData, new JsonSerializerSettings
{
Formatting = Formatting.None
});
File.WriteAllText(outputPath, json);
}
catch (Exception ex)
{
}
}
}