-
Notifications
You must be signed in to change notification settings - Fork 0
/
Info.cs
35 lines (31 loc) · 836 Bytes
/
Info.cs
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
using System;
using UnityEngine;
namespace KerbalGIS
{
public class Info
{
public static string getJSONInfo (CelestialBody body)
{
string ret = "{ \"biomes\": [ ";
foreach (CBAttributeMap.MapAttribute biome in body.BiomeMap.Attributes) {
ret += "{ \"name\": \"" + biome.name + "\", ";
ret += "\"color\": \"" + toHTMLColor (biome.mapColor) + "\" }, ";
}
ret += "] }";
return ret;
}
public static string getJSONInfo ()
{
string ret = "{ ";
foreach (CelestialBody body in FlightGlobals.Bodies) {
ret += "\"" + body.name + "\": " + Info.getJSONInfo (body) + ",";
}
ret += "}";
return ret;
}
public static string toHTMLColor (Color c)
{
return string.Format ("#{0,2:X}{1,2:X}{2,2:X}", (byte)(c.r * 0xff), (byte)(c.g * 0xff), (byte)(c.b * 0xff)).Replace (' ', '0');
}
}
}