-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpMapGen.cs
More file actions
79 lines (70 loc) · 1.9 KB
/
ExpMapGen.cs
File metadata and controls
79 lines (70 loc) · 1.9 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
using System;
using System.Collections.Generic;
using System.IO;
using Pluton;
using UnityEngine;
namespace ExpMapGen
{
public class ExpMapGen : CSharpPlugin
{
public void On_PluginInit()
{
ServerConsoleCommands.Register("genmap")
.setCallback(Generate)
.setDescription("Generates a map and saves to a .png file!")
.setUsage("");
}
public void Generate(string[] args)
{
string cmd = "";
List<string> arg = new List<string>();
MapSettings settings = new MapSettings();
for (int i = 0; i < args.Length; i++) {
string current = args[i];
bool last = i == (args.Length - 1);
if (current.StartsWith("-")) {
if (cmd != "") {
MapGenCommand command = new MapGenCommand(cmd, arg);
settings.ParseCommand(command);
arg = new List<string>();
}
cmd = current.Remove(0, 1);
} else {
if (cmd == "") {
continue;
}
arg.Add(current);
}
if (last) {
MapGenCommand command = new MapGenCommand(cmd, arg);
settings.ParseCommand(command);
}
}
GenerateMap(settings);
}
public void GenerateMap(MapSettings settings)
{
float[,] heightmap = TerrainMeta.HeightMap.GetFieldValue("src") as float[,];
byte[,,] splatmap = TerrainMeta.SplatMap.GetFieldValue("src") as byte[,,];
if (heightmap == null || splatmap == null) {
Logger.LogWarning ("null map?");
return;
}
Map map = new Map(heightmap, splatmap, settings);
SaveImage(map.mapSettings.FileName.Replace("%res", map.mapSettings.FinalResolution.ToString()), map.ToPNG(map.GenerateTexture()));
map.HeightMap = null;
map.SplatMap = null;
map = null;
Map.map = null;
}
void SaveImage(string name, byte[] image)
{
if (image != null) {
File.WriteAllBytes (Path.Combine (Plugin.RootDir.FullName, name), image);
Debug.Log("Saved map: " + name);
} else {
Logger.LogWarning (name + " is a null texture");
}
}
}
}