Skip to content

Commit

Permalink
Functional flatten & underground options
Browse files Browse the repository at this point in the history
  • Loading branch information
thepsycho committed Nov 27, 2018
1 parent 555243a commit 6ccece9
Show file tree
Hide file tree
Showing 7 changed files with 348 additions and 38 deletions.
109 changes: 107 additions & 2 deletions StationeersTools/StationeersTools/BinUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,114 @@ namespace StationeersTools
{
public static class BinUtils
{
public static void TrimWorld ()
public static List<Voxel> ActiveVoxels;
public static List<Voxel> FloorVoxels;

public static void CreateUndergroundSpace()
{
Menus.ShowVoxelSelectMenu(true);

VoxelUtils.ClearVoxelList(ActiveVoxels);
Console.Write("Cleared voxels: ");
PrintUtils.PrintLine(ActiveVoxels.Count.ToString(), ConsoleColor.DarkYellow);

VoxelUtils.SetVoxelList(FloorVoxels, 1, 255);

Console.WriteLine("Saving to file...");
Program.binfile.Save(Program.raw_binfile.FullName);
Console.Write("Saved! Press any key to continue.");
Console.Read();
}

public static void FlattenSurface()
{
Menus.ShowVoxelSelectMenu(false);

VoxelUtils.ClearVoxelList(ActiveVoxels);
Console.Write("Cleared voxels: ");
PrintUtils.PrintLine(ActiveVoxels.Count.ToString(), ConsoleColor.DarkYellow);

VoxelUtils.SetVoxelList(FloorVoxels, 1, 255);

Console.WriteLine("Saving to file...");
Program.binfile.Save(Program.raw_binfile.FullName);
Console.Write("Saved! Press any key to continue.");
Console.Read();
}

public static void StartSelect(int type, bool heightrequired)
{

if (type == 1)
{
Console.Clear();

Vector3 point = PrintUtils.RequestVector("Enter coördinates of the center point");
float radius = PrintUtils.RequestFloat("Enter radius (length of center to edge)");

Console.Clear();
Console.WriteLine("Reading voxels");

if (heightrequired)
{
float height = PrintUtils.RequestFloat("Please input height");
var res = VoxelUtils.SelectVoxels(Program.binfile, point, radius, point.y, point.y + height);
ActiveVoxels = res.Item1;
FloorVoxels = res.Item2;
}
else
{
var res = VoxelUtils.SelectVoxels(Program.binfile, point, radius);
ActiveVoxels = res.Item1;
FloorVoxels = res.Item2;
}
}
else if (type == 2)
{
Console.Clear();

Vector3 point = PrintUtils.RequestVector("Enter coördinates of the center point");
float range = PrintUtils.RequestFloat("Enter range (length of center to edges)");

Vector3 min = VectorUtils.GetMinVector(point, range);
Vector3 max = VectorUtils.GetMaxVector(point, range);
max.y = 150;

if (heightrequired)
{
float height = PrintUtils.RequestFloat("Please input height");
max.y = min.y + height;
var res = VoxelUtils.SelectVoxels(Program.binfile, min, max);
ActiveVoxels = res.Item1;
FloorVoxels = res.Item2;
}
else
{
var res = VoxelUtils.SelectVoxels(Program.binfile, min, max);
ActiveVoxels = res.Item1;
FloorVoxels = res.Item2;
}

Console.Clear();
Console.WriteLine("Reading voxels");
}
else if (type == 3)
{
Vector3 startpoint = PrintUtils.RequestVector("Enter coördinates of the start point");
Vector3 endpoint = PrintUtils.RequestVector("Enter coördinates of the end point");

Console.Clear();
Console.WriteLine("Reading voxels");
var res = VoxelUtils.SelectVoxels(Program.binfile, startpoint, endpoint);
ActiveVoxels = res.Item1;
FloorVoxels = res.Item2;
}
else
{
Menus.ShowMenus();
}

Console.SetCursorPosition(0, 4);
Console.WriteLine("All applicable voxels found!");
}
}
}
42 changes: 29 additions & 13 deletions StationeersTools/StationeersTools/Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,10 @@ public static class Menus
{
public static void ShowMenus()
{
var trimMenu = new ConsoleMenu()
.Add("Circle around player", () => Console.WriteLine("Sub_One"))
.Add("Circle around point", () => Console.WriteLine("Sub_One"))
.Add("Back to previous menu", ConsoleMenu.Close)
.Configure(config => {
config.WriteHeaderAction = () => Console.WriteLine("What do you want to do?");
config.SelectedItemBackgroundColor = ConsoleColor.DarkYellow;
});

var voxelMenu = new ConsoleMenu()
.Add("Trim world", () => trimMenu.Show())
.Add("Flatten surface", () => Console.WriteLine("Sub_Two"))
.Add("Create underground space", () => Console.WriteLine("Sub_Three"))
.Add("Check ore count", () => Console.WriteLine("Sub_Four"))
//.Add("Trim world", () => trimMenu.Show())
.Add("Flatten surface", () => BinUtils.FlattenSurface())
.Add("Create underground space", () => BinUtils.CreateUndergroundSpace())
.Add("Back to main menu", ConsoleMenu.Close)
.Configure(config => {
config.WriteHeaderAction = () => Console.WriteLine("What do you want to do?");
Expand Down Expand Up @@ -53,5 +43,31 @@ public static void ShowMenus()

mainMenu.Show();
}

public static void ShowVoxelSelectMenu(bool heightrequired)
{
Console.Clear();
Console.WriteLine("How would you like to pick the affected area?");

string[][] options =
{
PrintUtils.BuildRow("1", "Circle around point"),
PrintUtils.BuildRow("2", "Square around point"),
PrintUtils.BuildRow("3", "Point to point")
};

PrintUtils.PrintColumns(options, 1);
Console.WriteLine();

int selected = 100;

while (selected == 100)
{
string input = PrintUtils.RequestInputLine("Option");
int.TryParse(input, out selected);
}

BinUtils.StartSelect(selected, heightrequired);
}
}
}
75 changes: 75 additions & 0 deletions StationeersTools/StationeersTools/PrintUtils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using WorldUtils;

namespace StationeersTools
{
Expand Down Expand Up @@ -62,5 +63,79 @@ public static void PrintColumns (string[][] content, int fromtop)
fromtop++;
}
}

public static Vector3 RequestVector(string message)
{
PrintUtils.PrintLine(message, ConsoleColor.DarkYellow);

Vector3 point = new Vector3();
bool fx = false, fy = false, fz = false;

while (!fx)
{
string input = PrintUtils.RequestInputLine("X");
try
{
point.x = float.Parse(input);
fx = true;
}
catch (Exception ex)
{
PrintUtils.PrintLine("Incorrect input!", ConsoleColor.Red);
}
}
while (!fy)
{
string input = PrintUtils.RequestInputLine("Y");
try
{
point.y = float.Parse(input);
fy = true;
}
catch (Exception ex)
{
PrintUtils.PrintLine("Incorrect input!", ConsoleColor.Red);
}
}
while (!fz)
{
string input = PrintUtils.RequestInputLine("Z");
try
{
point.z = float.Parse(input);
fz = true;
}
catch (Exception ex)
{
PrintUtils.PrintLine("Incorrect input!", ConsoleColor.Red);
}
}

return point;
}

public static float RequestFloat(string message)
{
float value = 0;
bool fr = false;

PrintUtils.PrintLine(message, ConsoleColor.DarkYellow);

while (!fr)
{
string input = PrintUtils.RequestInputLine("Value");
try
{
value = float.Parse(input);
fr = true;
}
catch (Exception ex)
{
PrintUtils.PrintLine("Incorrect input!", ConsoleColor.Red);
}
}

return value;
}
}
}
11 changes: 6 additions & 5 deletions StationeersTools/StationeersTools/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class Program
{
private static bool keepRunning = true;

private static Saves binfile;
private static XmlDocument xmlfile;
private static FileInfo raw_binfile;
private static FileInfo raw_xmlfile;
public static Saves binfile;
public static XmlDocument xmlfile;
public static FileInfo raw_binfile;
public static FileInfo raw_xmlfile;

static void Main (string[] args)
{
Expand Down Expand Up @@ -60,7 +60,7 @@ static void Main (string[] args)
}
}

string datetime = DateTime.Now.ToString("yyyyMMddHmm");
string datetime = DateTime.Now.ToString("yyyyMMddHmmss");

raw_binfile.CopyTo(raw_binfile.FullName + "." + datetime + ".original");
raw_xmlfile.CopyTo(raw_xmlfile.FullName + "." + datetime + ".original");
Expand All @@ -83,6 +83,7 @@ public static void LoadFiles()
{
binfile = new Saves();
binfile.LoadSave(raw_binfile.FullName);
VoxelUtils.ChunkSize = binfile.ChunkSize;

xmlfile = new XmlDocument();
xmlfile.Load(raw_xmlfile.FullName);
Expand Down
20 changes: 20 additions & 0 deletions StationeersTools/StationeersTools/VectorUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using WorldUtils;
using System.Text;

namespace StationeersTools
{
public static class VectorUtils
{
public static Vector3 GetMinVector(Vector3 center, float range)
{
return new Vector3(center.x - range, center.y, center.z - range);
}

public static Vector3 GetMaxVector(Vector3 center, float range)
{
return new Vector3(center.x + range, center.y, center.z + range);
}
}
}
Loading

0 comments on commit 6ccece9

Please sign in to comment.