Skip to content

Commit

Permalink
Merge pull request #7 from Sigma88/Development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Sigma88 authored Apr 11, 2018
2 parents 8db6dbc + 823b530 commit c403fc6
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
**v0.3.0**

- Added flipH
- Added flipV


**v0.2.0**

- Expanded printTile system
Expand Down
2 changes: 1 addition & 1 deletion GameData/Sigma/Cartographer/Sigma-Cartographer.version
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"VERSION":
{
"MAJOR": 0,
"MINOR": 2,
"MINOR": 3,
"PATCH": 0,
"BUILD": 0
},
Expand Down
Binary file modified GameData/Sigma/Cartographer/SigmaCartographer.dll
Binary file not shown.
Binary file modified [Source]/Distribution/SigmaCartographer.dll
Binary file not shown.
70 changes: 68 additions & 2 deletions [Source]/SigmaCartographer/MapExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ static bool exportAny
static int tile = 1024;
static string exportFolder = "";
static bool leaflet = false;
static bool flipV = false;
static bool flipH = false;

static bool oceanFloor = true;
static Color oceanColor = new Color(0.1f, 0.1f, 0.2f, 1f);
Expand Down Expand Up @@ -89,6 +91,10 @@ void Start()

bool.TryParse(planetInfo.GetValue("leaflet"), out leaflet);

bool.TryParse(planetInfo.GetValue("flipV"), out flipV);

bool.TryParse(planetInfo.GetValue("flipH"), out flipH);

if (!bool.TryParse(planetInfo.GetValue("oceanFloor"), out oceanFloor))
{
oceanFloor = true;
Expand Down Expand Up @@ -376,12 +382,17 @@ void GeneratePQSMaps()
biomeMap.SetPixels(biomeMapValues);

// Serialize them to disk
string folder = leaflet ? (current % (width / tile) + "/") : "";
string fileName = leaflet ? (current / (width / tile)) + ".png" : "Tile" + current.ToString("D4") + ".png";
int position = Flip(current);
string folder = leaflet ? (position % (width / tile) + "/") : "";
string fileName = leaflet ? (position / (width / tile)) + ".png" : "Tile" + position.ToString("D4") + ".png";

if (exportHeightMap)
{
Directory.CreateDirectory(exportFolder + "HeightMap/" + folder);

if (flipH) FlipH(ref heightMap);
if (flipV) FlipV(ref heightMap);

File.WriteAllBytes(exportFolder + "HeightMap/" + folder + fileName, heightMap.EncodeToPNG());
File.WriteAllLines
(
Expand All @@ -400,36 +411,60 @@ void GeneratePQSMaps()
if (exportNormalMap)
{
Directory.CreateDirectory(exportFolder + "NormalMap/" + folder);

if (flipH) FlipH(ref normalMap);
if (flipV) FlipV(ref normalMap);

File.WriteAllBytes(exportFolder + "NormalMap/" + folder + fileName, normalMap.EncodeToPNG());
}

if (exportSlopeMap)
{
Directory.CreateDirectory(exportFolder + "SlopeMap/" + folder);

if (flipH) FlipH(ref slopeMap);
if (flipV) FlipV(ref slopeMap);

File.WriteAllBytes(exportFolder + "SlopeMap/" + folder + fileName, slopeMap.EncodeToPNG());
}

if (exportColorMap)
{
Directory.CreateDirectory(exportFolder + "ColorMap/" + folder);

if (flipH) FlipH(ref colorMap);
if (flipV) FlipV(ref colorMap);

File.WriteAllBytes(exportFolder + "ColorMap/" + folder + fileName, colorMap.EncodeToPNG());
}

if (exportOceanMap)
{
Directory.CreateDirectory(exportFolder + "OceanMap/" + folder);

if (flipH) FlipH(ref oceanMap);
if (flipV) FlipV(ref oceanMap);

File.WriteAllBytes(exportFolder + "OceanMap/" + folder + fileName, oceanMap.EncodeToPNG());
}

if (exportSatelliteMap)
{
Directory.CreateDirectory(exportFolder + "SatelliteMap/" + folder);

if (flipH) FlipH(ref satelliteMap);
if (flipV) FlipV(ref satelliteMap);

File.WriteAllBytes(exportFolder + "SatelliteMap/" + folder + fileName, satelliteMap.EncodeToPNG());
}

if (exportBiomeMap)
{
Directory.CreateDirectory(exportFolder + "BiomeMap/" + folder);

if (flipH) FlipH(ref biomeMap);
if (flipV) FlipV(ref biomeMap);

File.WriteAllBytes(exportFolder + "BiomeMap/" + folder + fileName, biomeMap.EncodeToPNG());

List<string> attributes = new string[] { "BiomeMap info", "", "Body = " + body.transform.name }.ToList();
Expand Down Expand Up @@ -568,6 +603,37 @@ List<KeyValuePair<double, Color>> Parse(ConfigNode node, List<KeyValuePair<doubl

return defaultValue;
}

int Flip(int n)
{
if (flipV)
{
n = ((width / tile / 2) - 1 - (n * tile / width)) * width / tile + (n % (width / tile));
}

if (flipH)
{
n = (n * tile / width) * width / tile + width / tile - 1 - (n % (width / tile));
}

return n;
}

void FlipV(ref Texture2D texture)
{
for (int x = 0; x < texture?.width; x++)
{
texture.SetPixels(x, 0, 1, texture.height, texture.GetPixels(x, 0, 1, texture.height).Reverse().ToArray());
}
}

void FlipH(ref Texture2D texture)
{
for (int y = 0; y < texture?.height; y++)
{
texture.SetPixels(0, y, texture.width, 1, texture.GetPixels(0, y, texture.width, 1).Reverse().ToArray());
}
}
}

static class TryParse
Expand Down

0 comments on commit c403fc6

Please sign in to comment.