Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Fixed a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
BitcoderCZ committed Apr 21, 2023
1 parent 8d5fd24 commit 88a694a
Show file tree
Hide file tree
Showing 5 changed files with 561 additions and 75 deletions.
13 changes: 11 additions & 2 deletions EXITCODE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ namespace BuildPlate_Editor
public enum EXITCODE : int
{
Normal = 0,

OpenGL_LowVersion = 1,
World_Load_TextureArray = 4,
World_ReLoad_TextureArray = 5,

TexturesFile_Existance = 2, // doesn't exist
TexturesFile_Path = 3,

Failed_BuildPlate_Existance = 4, // doesn't exist
Failed_BuildPlate_Extension = 5,
Failed_BuildPlate_Parse = 6,

World_Load_TextureArray = 7,
World_ReLoad_TextureArray = 8,
World_Render_Block = 10,
World_Unknown = 20,
}
Expand Down
47 changes: 16 additions & 31 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ class Program
public static Window Window;
public static string baseDir;

static void Main(string[] args)
static int Main(string[] args)
{
// this will run on console close
handler = new ConsoleEventDelegate(ConsoleEventCallback);
SetConsoleCtrlHandler(handler, true);

// Get base path (.exe location)
string myExecutable = Assembly.GetEntryAssembly().Location;

Expand All @@ -36,7 +32,7 @@ static void Main(string[] args)
Console.WriteLine("You can also do this for .plate and .plate64");
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
return;
return (int)EXITCODE.Normal;
}

baseDir = Path.GetDirectoryName(myExecutable) + "\\";
Expand Down Expand Up @@ -72,7 +68,7 @@ static void Main(string[] args)
}
}
else
Console.WriteLine("Ok :(, I won't aks again");
Console.WriteLine("Ok :(, I won't ask again");

File.WriteAllBytes(baseDir + "askedForDefault", new byte[0]);

Expand All @@ -82,21 +78,21 @@ static void Main(string[] args)
Console.WriteLine("texturesPath.txt doen't exist");
Console.WriteLine($"Extract mce resource pack 2 times and set path to {{path}}/textures/blocks/");
Console.ReadKey(true);
return;
return (int)EXITCODE.TexturesFile_Existance;
}
string texturesPath = File.ReadAllText(baseDir + "texturesPath.txt");
if (texturesPath == string.Empty || !Directory.Exists(texturesPath)) {
Console.WriteLine($"path inside texturesPath.txt ({texturesPath}) doesn't exist");
Console.WriteLine($"Extract mce resource pack 2 times and set path to {{path}}/textures/blocks/");
Console.ReadKey(true);
return;
return (int)EXITCODE.TexturesFile_Path;
}
char lastChar = texturesPath[texturesPath.Length - 1];
if (lastChar != '\\' && lastChar != '/')
texturesPath += '/';
World.textureBasePath = texturesPath;
#if DEBUG
World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\buildplate (1).json";
World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\c0eb3037-94c1-4a85-b0d7-7b8375c6f1b1.json";
//World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\411398a6-5810-43a0-824c-27a9077a9ac3.json"; // fancy
//World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\c0eb3037-94c1-4a85-b0d7-7b8375c6f1b1.json"; // redstone
//World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\c0f771f0-a5d6-4acc-bd35-055e52548a20.json"; // igloo super fancy secret base
Expand All @@ -107,23 +103,24 @@ static void Main(string[] args)
if (args != null && args.Length > 0 && File.Exists(string.Join(" ", args)) && string.Join(" ", args).Split('.').Length > 1) {
string truePath = new FileInfo(string.Join(" ", args)).FullName;
Console.WriteLine(truePath);
string extension = truePath.Split('.').Last();
if (extension == "json" || extension == "plate" || extension == "plate64") {
string _extension = truePath.Split('.').Last();
if (_extension == "json" || _extension == "plate" || _extension == "plate64") {
World.targetFilePath = truePath;
goto check;
}
}

string buildPlate = Console.ReadLine();
string extension = Path.GetExtension(buildPlate);
if (!File.Exists(buildPlate)) {
Console.WriteLine($"build plate \"{buildPlate}\" doesn't exist");
Console.ReadKey(true);
return;
} else if (Path.GetExtension(buildPlate) == ".json" || Path.GetExtension(buildPlate) == ".plate"
|| Path.GetExtension(buildPlate) == ".plate64") {
return (int)EXITCODE.Failed_BuildPlate_Existance;
} else if (extension != ".json" && extension != ".plate"
&& extension != ".plate64") {
Console.WriteLine($"\"{Path.GetExtension(buildPlate)}\" isn't valid buildplate extension, valid: .json, .plate, .plate64");
Console.ReadKey(true);
return;
return (int)EXITCODE.Failed_BuildPlate_Extension;
}
World.targetFilePath = buildPlate;
#endif
Expand All @@ -135,7 +132,7 @@ static void Main(string[] args)
Console.WriteLine($"Couldn't parse \"{World.targetFilePath}\", Make sure it's valid build plate file.");
Console.WriteLine("Press any key to exit...");
Console.ReadKey(true);
return;
return (int)EXITCODE.Failed_BuildPlate_Parse;
}

Window = new Window();
Expand All @@ -148,6 +145,8 @@ static void Main(string[] args)
else if (int.TryParse(version.Split(' ')[0].Split('.')[1], out int subVer) && mainVer == 4 && subVer < 5)
LowVersion();
Window.Run(60d);

return (int)EXITCODE.Normal;
}

private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
Expand All @@ -167,19 +166,5 @@ private static void LowVersion()
if (Console.ReadKey(true).Key != ConsoleKey.Enter)
Util.Exit(EXITCODE.OpenGL_LowVersion);
}

// Handle on close event
static bool ConsoleEventCallback(int eventType)
{
if (eventType == 2) { // on exit
Util.Exit(EXITCODE.Normal);
}
return false;
}
static ConsoleEventDelegate handler; // Keeps it from getting garbage collected

private delegate bool ConsoleEventDelegate(int eventType);
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool SetConsoleCtrlHandler(ConsoleEventDelegate callback, bool add);
}
}
85 changes: 85 additions & 0 deletions Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,91 @@ public static Vector2 PixelToGL(Vector2i pos)

public static char ToLower(this char c) => c.ToString().ToLower()[0];

public static void SetXLow(this Vector2[] array, float x)
{
for (int i = 0; i < array.Length; i++)
if (array[i].X < 0.5f)
array[i] = new Vector2(x, array[i].Y);
}
public static void SetXHigh(this Vector2[] array, float x)
{
for (int i = 0; i < array.Length; i++)
if (array[i].X >= 0.5f)
array[i] = new Vector2(x, array[i].Y);
}
public static void SetYLow(this Vector2[] array, float y)
{
for (int i = 0; i < array.Length; i++)
if (array[i].Y < 0.5f)
array[i] = new Vector2(array[i].X, y);
}
public static void SetYHigh(this Vector2[] array, float y)
{
for (int i = 0; i < array.Length; i++)
if (array[i].Y >= 0.5f)
array[i] = new Vector2(array[i].X, y);
}

public static void SetXLow(this Vector3[] array, float x)
{
for (int i = 0; i < array.Length; i++)
if (array[i].X < 0.5f)
array[i] = new Vector3(x, array[i].Y, array[i].Z);
}
public static void SetXHigh(this Vector3[] array, float x)
{
for (int i = 0; i < array.Length; i++)
if (array[i].X >= 0.5f)
array[i] = new Vector3(x, array[i].Y, array[i].Z);
}
public static void SetZLow(this Vector3[] array, float z)
{
for (int i = 0; i < array.Length; i++)
if (array[i].Z < 0.5f)
array[i] = new Vector3(array[i].X, array[i].Y, z);
}
public static void SetZHigh(this Vector3[] array, float z)
{
for (int i = 0; i < array.Length; i++)
if (array[i].Z >= 0.5f)
array[i] = new Vector3(array[i].X, array[i].Y, z);
}

public static void FlipX(this Vector2[] array)
{
float low = 0f;
float high = 1f;

for (int i = 0; i < array.Length; i++)
if (array[i].X < 0.5f)
low = array[i].X;
else
high = array[i].X;

for (int i = 0; i < array.Length; i++)
if (array[i].X < 0.5f)
array[i] = new Vector2(high, array[i].Y);
else
array[i] = new Vector2(low, array[i].Y);
}
public static void FlipY(this Vector2[] array)
{
float low = 0f;
float high = 1f;

for (int i = 0; i < array.Length; i++)
if (array[i].Y < 0.5f)
low = array[i].Y;
else
high = array[i].Y;

for (int i = 0; i < array.Length; i++)
if (array[i].Y < 0.5f)
array[i] = new Vector2(array[i].X, high);
else
array[i] = new Vector2(array[i].X, low);
}

// Set Foregroun
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
Expand Down
129 changes: 111 additions & 18 deletions VoxelData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,30 +412,123 @@ public static class Rail
}
public static class Cobweb
{
public static readonly Vector3[] verts = new Vector3[8] {
new Vector3(0.0f, 0.0f, 0.0f), // 0
new Vector3(1.0f, 0.0f, 0.0f), // 1
new Vector3(1.0f, 1.0f, 0.0f), // 2
new Vector3(0.0f, 1.0f, 0.0f), // 3
new Vector3(0.0f, 0.0f, 1.0f), // 4
new Vector3(1.0f, 0.0f, 1.0f), // 5
new Vector3(1.0f, 1.0f, 1.0f), // 6
new Vector3(0.0f, 1.0f, 1.0f) // 7
};
public static readonly int[,] tris = new int[,] {
{0, 3, 5, 6},
{5, 6, 0, 3},
{1, 2, 4, 7},
{4, 7, 1, 2},
};
/*public static readonly int[,] voxelTris = new int[6, 4] {
{0, 3, 1, 2}, // Back Face
{5, 6, 4, 7}, // Front Face
{3, 7, 2, 6}, // Top Face
{1, 5, 0, 4}, // Bottom Face
{4, 7, 0, 3}, // Left Face
{1, 2, 5, 6} // Right Face
};*/
}
public static class Redstone
{
public const float DefaultOffset = 0.01f;
public const float toDot = 0.3125f;
public const float toDot2 = 1f - toDot;
public static readonly Vector3[] verts = new Vector3[]
{
new Vector3(0.0f, DefaultOffset, 0.0f), // 0
new Vector3(1.0f, DefaultOffset, 0.0f), // 1
new Vector3(0.0f, DefaultOffset, 1.0f), // 2
new Vector3(1.0f, DefaultOffset, 1.0f), // 3
};
public static readonly Vector3[] vertsSide = new Vector3[]
{
new Vector3(DefaultOffset, 0.0f, 0.0f),
new Vector3(DefaultOffset, 1.0f, 0.0f),
new Vector3(DefaultOffset, 0.0f, 1.0f),
new Vector3(DefaultOffset, 1.0f, 1.0f)
};
public static readonly int[,] tris = new int[2, 4] {
{0, 2, 1, 3}, // Top Face
{1, 3, 0, 2}, // Bottom Face
};
public static readonly int[,] trisSide = new int[2, 4] {
{2, 3, 0, 1},
{0, 1, 2, 3},
};
public static readonly Vector2[] uvsSide = new Vector2[4] {
new Vector2(1.0f, 0.0f),
new Vector2(0.0f, 0.0f),
new Vector2(1.0f, 1.0f),
new Vector2(0.0f, 1.0f)
};
}
public static class Lever_Base
{
public const float X = 0.3125f;
public const float X2 = 1f - X;
public const float Y = 0f;
public const float Y2 = 0.1875f;
public const float Z = 0.25f;
public const float Z2 = 1f - Z;
public static readonly Vector3[] verts = new Vector3[8] {
new Vector3(X, Y, Z), // 0
new Vector3(X2, Y, Z), // 1
new Vector3(X2, Y2, Z), // 2
new Vector3(X, Y2, Z), // 3
new Vector3(X, Y, Z2), // 4
new Vector3(X2, Y, Z2), // 5
new Vector3(X2, Y2, Z2), // 6
new Vector3(X, Y2, Z2) // 7
};
public static readonly Vector2[,] uvs = new Vector2[3,4] { // Z Y X
{
new Vector2(X, Y),
new Vector2(X, Y2),
new Vector2(X2, Y),
new Vector2(X2, Y2)
},
{
new Vector2(X, Z),
new Vector2(X, Z2),
new Vector2(X2, Z),
new Vector2(X2, Z2)
},
{
new Vector2(Z, Y),
new Vector2(Z, Y2),
new Vector2(Z2, Y),
new Vector2(Z2, Y2)
},
};
}
public static class Lever_Top
{
public const float X = 0.4375f;
public const float X2 = 1f - X;
public const float Y = 0f;
public const float Y2 = 0.625f;
public const float Y3 = Y2 - 0.125f;
public static readonly Vector3[] verts = new Vector3[8] {
new Vector3(X, Y, X), // 0
new Vector3(X2, Y, X), // 1
new Vector3(X2, Y2, X), // 2
new Vector3(X, Y2, X), // 3
new Vector3(X, Y, X2), // 4
new Vector3(X2, Y, X2), // 5
new Vector3(X2, Y2, X2), // 6
new Vector3(X, Y2, X2) // 7
};
public static readonly Vector2[,] uvs = new Vector2[3, 4] { // Z Y X
{
new Vector2(X, Y),
new Vector2(X, Y2),
new Vector2(X2, Y),
new Vector2(X2, Y2)
},
{
new Vector2(X, Y3),
new Vector2(X, Y2),
new Vector2(X2, Y3),
new Vector2(X2, Y2)
},
{
new Vector2(X, Y),
new Vector2(X, Y2),
new Vector2(X2, Y),
new Vector2(X2, Y2)
},
};
}
}
}
Loading

0 comments on commit 88a694a

Please sign in to comment.