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

Commit 88a694a

Browse files
committed
Fixed a bug
1 parent 8d5fd24 commit 88a694a

File tree

5 files changed

+561
-75
lines changed

5 files changed

+561
-75
lines changed

EXITCODE.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,18 @@ namespace BuildPlate_Editor
99
public enum EXITCODE : int
1010
{
1111
Normal = 0,
12+
1213
OpenGL_LowVersion = 1,
13-
World_Load_TextureArray = 4,
14-
World_ReLoad_TextureArray = 5,
14+
15+
TexturesFile_Existance = 2, // doesn't exist
16+
TexturesFile_Path = 3,
17+
18+
Failed_BuildPlate_Existance = 4, // doesn't exist
19+
Failed_BuildPlate_Extension = 5,
20+
Failed_BuildPlate_Parse = 6,
21+
22+
World_Load_TextureArray = 7,
23+
World_ReLoad_TextureArray = 8,
1524
World_Render_Block = 10,
1625
World_Unknown = 20,
1726
}

Program.cs

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@ class Program
1818
public static Window Window;
1919
public static string baseDir;
2020

21-
static void Main(string[] args)
21+
static int Main(string[] args)
2222
{
23-
// this will run on console close
24-
handler = new ConsoleEventDelegate(ConsoleEventCallback);
25-
SetConsoleCtrlHandler(handler, true);
26-
2723
// Get base path (.exe location)
2824
string myExecutable = Assembly.GetEntryAssembly().Location;
2925

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

4238
baseDir = Path.GetDirectoryName(myExecutable) + "\\";
@@ -72,7 +68,7 @@ static void Main(string[] args)
7268
}
7369
}
7470
else
75-
Console.WriteLine("Ok :(, I won't aks again");
71+
Console.WriteLine("Ok :(, I won't ask again");
7672

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

@@ -82,21 +78,21 @@ static void Main(string[] args)
8278
Console.WriteLine("texturesPath.txt doen't exist");
8379
Console.WriteLine($"Extract mce resource pack 2 times and set path to {{path}}/textures/blocks/");
8480
Console.ReadKey(true);
85-
return;
81+
return (int)EXITCODE.TexturesFile_Existance;
8682
}
8783
string texturesPath = File.ReadAllText(baseDir + "texturesPath.txt");
8884
if (texturesPath == string.Empty || !Directory.Exists(texturesPath)) {
8985
Console.WriteLine($"path inside texturesPath.txt ({texturesPath}) doesn't exist");
9086
Console.WriteLine($"Extract mce resource pack 2 times and set path to {{path}}/textures/blocks/");
9187
Console.ReadKey(true);
92-
return;
88+
return (int)EXITCODE.TexturesFile_Path;
9389
}
9490
char lastChar = texturesPath[texturesPath.Length - 1];
9591
if (lastChar != '\\' && lastChar != '/')
9692
texturesPath += '/';
9793
World.textureBasePath = texturesPath;
9894
#if DEBUG
99-
World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\buildplate (1).json";
95+
World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\c0eb3037-94c1-4a85-b0d7-7b8375c6f1b1.json";
10096
//World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\411398a6-5810-43a0-824c-27a9077a9ac3.json"; // fancy
10197
//World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\c0eb3037-94c1-4a85-b0d7-7b8375c6f1b1.json"; // redstone
10298
//World.targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\c0f771f0-a5d6-4acc-bd35-055e52548a20.json"; // igloo super fancy secret base
@@ -107,23 +103,24 @@ static void Main(string[] args)
107103
if (args != null && args.Length > 0 && File.Exists(string.Join(" ", args)) && string.Join(" ", args).Split('.').Length > 1) {
108104
string truePath = new FileInfo(string.Join(" ", args)).FullName;
109105
Console.WriteLine(truePath);
110-
string extension = truePath.Split('.').Last();
111-
if (extension == "json" || extension == "plate" || extension == "plate64") {
106+
string _extension = truePath.Split('.').Last();
107+
if (_extension == "json" || _extension == "plate" || _extension == "plate64") {
112108
World.targetFilePath = truePath;
113109
goto check;
114110
}
115111
}
116112

117113
string buildPlate = Console.ReadLine();
114+
string extension = Path.GetExtension(buildPlate);
118115
if (!File.Exists(buildPlate)) {
119116
Console.WriteLine($"build plate \"{buildPlate}\" doesn't exist");
120117
Console.ReadKey(true);
121-
return;
122-
} else if (Path.GetExtension(buildPlate) == ".json" || Path.GetExtension(buildPlate) == ".plate"
123-
|| Path.GetExtension(buildPlate) == ".plate64") {
118+
return (int)EXITCODE.Failed_BuildPlate_Existance;
119+
} else if (extension != ".json" && extension != ".plate"
120+
&& extension != ".plate64") {
124121
Console.WriteLine($"\"{Path.GetExtension(buildPlate)}\" isn't valid buildplate extension, valid: .json, .plate, .plate64");
125122
Console.ReadKey(true);
126-
return;
123+
return (int)EXITCODE.Failed_BuildPlate_Extension;
127124
}
128125
World.targetFilePath = buildPlate;
129126
#endif
@@ -135,7 +132,7 @@ static void Main(string[] args)
135132
Console.WriteLine($"Couldn't parse \"{World.targetFilePath}\", Make sure it's valid build plate file.");
136133
Console.WriteLine("Press any key to exit...");
137134
Console.ReadKey(true);
138-
return;
135+
return (int)EXITCODE.Failed_BuildPlate_Parse;
139136
}
140137

141138
Window = new Window();
@@ -148,6 +145,8 @@ static void Main(string[] args)
148145
else if (int.TryParse(version.Split(' ')[0].Split('.')[1], out int subVer) && mainVer == 4 && subVer < 5)
149146
LowVersion();
150147
Window.Run(60d);
148+
149+
return (int)EXITCODE.Normal;
151150
}
152151

153152
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
@@ -167,19 +166,5 @@ private static void LowVersion()
167166
if (Console.ReadKey(true).Key != ConsoleKey.Enter)
168167
Util.Exit(EXITCODE.OpenGL_LowVersion);
169168
}
170-
171-
// Handle on close event
172-
static bool ConsoleEventCallback(int eventType)
173-
{
174-
if (eventType == 2) { // on exit
175-
Util.Exit(EXITCODE.Normal);
176-
}
177-
return false;
178-
}
179-
static ConsoleEventDelegate handler; // Keeps it from getting garbage collected
180-
181-
private delegate bool ConsoleEventDelegate(int eventType);
182-
[DllImport("kernel32.dll", SetLastError = true)]
183-
private static extern bool SetConsoleCtrlHandler(ConsoleEventDelegate callback, bool add);
184169
}
185170
}

Util.cs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,91 @@ public static Vector2 PixelToGL(Vector2i pos)
252252

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

255+
public static void SetXLow(this Vector2[] array, float x)
256+
{
257+
for (int i = 0; i < array.Length; i++)
258+
if (array[i].X < 0.5f)
259+
array[i] = new Vector2(x, array[i].Y);
260+
}
261+
public static void SetXHigh(this Vector2[] array, float x)
262+
{
263+
for (int i = 0; i < array.Length; i++)
264+
if (array[i].X >= 0.5f)
265+
array[i] = new Vector2(x, array[i].Y);
266+
}
267+
public static void SetYLow(this Vector2[] array, float y)
268+
{
269+
for (int i = 0; i < array.Length; i++)
270+
if (array[i].Y < 0.5f)
271+
array[i] = new Vector2(array[i].X, y);
272+
}
273+
public static void SetYHigh(this Vector2[] array, float y)
274+
{
275+
for (int i = 0; i < array.Length; i++)
276+
if (array[i].Y >= 0.5f)
277+
array[i] = new Vector2(array[i].X, y);
278+
}
279+
280+
public static void SetXLow(this Vector3[] array, float x)
281+
{
282+
for (int i = 0; i < array.Length; i++)
283+
if (array[i].X < 0.5f)
284+
array[i] = new Vector3(x, array[i].Y, array[i].Z);
285+
}
286+
public static void SetXHigh(this Vector3[] array, float x)
287+
{
288+
for (int i = 0; i < array.Length; i++)
289+
if (array[i].X >= 0.5f)
290+
array[i] = new Vector3(x, array[i].Y, array[i].Z);
291+
}
292+
public static void SetZLow(this Vector3[] array, float z)
293+
{
294+
for (int i = 0; i < array.Length; i++)
295+
if (array[i].Z < 0.5f)
296+
array[i] = new Vector3(array[i].X, array[i].Y, z);
297+
}
298+
public static void SetZHigh(this Vector3[] array, float z)
299+
{
300+
for (int i = 0; i < array.Length; i++)
301+
if (array[i].Z >= 0.5f)
302+
array[i] = new Vector3(array[i].X, array[i].Y, z);
303+
}
304+
305+
public static void FlipX(this Vector2[] array)
306+
{
307+
float low = 0f;
308+
float high = 1f;
309+
310+
for (int i = 0; i < array.Length; i++)
311+
if (array[i].X < 0.5f)
312+
low = array[i].X;
313+
else
314+
high = array[i].X;
315+
316+
for (int i = 0; i < array.Length; i++)
317+
if (array[i].X < 0.5f)
318+
array[i] = new Vector2(high, array[i].Y);
319+
else
320+
array[i] = new Vector2(low, array[i].Y);
321+
}
322+
public static void FlipY(this Vector2[] array)
323+
{
324+
float low = 0f;
325+
float high = 1f;
326+
327+
for (int i = 0; i < array.Length; i++)
328+
if (array[i].Y < 0.5f)
329+
low = array[i].Y;
330+
else
331+
high = array[i].Y;
332+
333+
for (int i = 0; i < array.Length; i++)
334+
if (array[i].Y < 0.5f)
335+
array[i] = new Vector2(array[i].X, high);
336+
else
337+
array[i] = new Vector2(array[i].X, low);
338+
}
339+
255340
// Set Foregroun
256341
[DllImport("user32.dll")]
257342
[return: MarshalAs(UnmanagedType.Bool)]

VoxelData.cs

Lines changed: 111 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -412,30 +412,123 @@ public static class Rail
412412
}
413413
public static class Cobweb
414414
{
415-
public static readonly Vector3[] verts = new Vector3[8] {
416-
new Vector3(0.0f, 0.0f, 0.0f), // 0
417-
new Vector3(1.0f, 0.0f, 0.0f), // 1
418-
new Vector3(1.0f, 1.0f, 0.0f), // 2
419-
new Vector3(0.0f, 1.0f, 0.0f), // 3
420-
new Vector3(0.0f, 0.0f, 1.0f), // 4
421-
new Vector3(1.0f, 0.0f, 1.0f), // 5
422-
new Vector3(1.0f, 1.0f, 1.0f), // 6
423-
new Vector3(0.0f, 1.0f, 1.0f) // 7
424-
};
425415
public static readonly int[,] tris = new int[,] {
426416
{0, 3, 5, 6},
427417
{5, 6, 0, 3},
428418
{1, 2, 4, 7},
429419
{4, 7, 1, 2},
430420
};
431-
/*public static readonly int[,] voxelTris = new int[6, 4] {
432-
{0, 3, 1, 2}, // Back Face
433-
{5, 6, 4, 7}, // Front Face
434-
{3, 7, 2, 6}, // Top Face
435-
{1, 5, 0, 4}, // Bottom Face
436-
{4, 7, 0, 3}, // Left Face
437-
{1, 2, 5, 6} // Right Face
438-
};*/
421+
}
422+
public static class Redstone
423+
{
424+
public const float DefaultOffset = 0.01f;
425+
public const float toDot = 0.3125f;
426+
public const float toDot2 = 1f - toDot;
427+
public static readonly Vector3[] verts = new Vector3[]
428+
{
429+
new Vector3(0.0f, DefaultOffset, 0.0f), // 0
430+
new Vector3(1.0f, DefaultOffset, 0.0f), // 1
431+
new Vector3(0.0f, DefaultOffset, 1.0f), // 2
432+
new Vector3(1.0f, DefaultOffset, 1.0f), // 3
433+
};
434+
public static readonly Vector3[] vertsSide = new Vector3[]
435+
{
436+
new Vector3(DefaultOffset, 0.0f, 0.0f),
437+
new Vector3(DefaultOffset, 1.0f, 0.0f),
438+
new Vector3(DefaultOffset, 0.0f, 1.0f),
439+
new Vector3(DefaultOffset, 1.0f, 1.0f)
440+
};
441+
public static readonly int[,] tris = new int[2, 4] {
442+
{0, 2, 1, 3}, // Top Face
443+
{1, 3, 0, 2}, // Bottom Face
444+
};
445+
public static readonly int[,] trisSide = new int[2, 4] {
446+
{2, 3, 0, 1},
447+
{0, 1, 2, 3},
448+
};
449+
public static readonly Vector2[] uvsSide = new Vector2[4] {
450+
new Vector2(1.0f, 0.0f),
451+
new Vector2(0.0f, 0.0f),
452+
new Vector2(1.0f, 1.0f),
453+
new Vector2(0.0f, 1.0f)
454+
};
455+
}
456+
public static class Lever_Base
457+
{
458+
public const float X = 0.3125f;
459+
public const float X2 = 1f - X;
460+
public const float Y = 0f;
461+
public const float Y2 = 0.1875f;
462+
public const float Z = 0.25f;
463+
public const float Z2 = 1f - Z;
464+
public static readonly Vector3[] verts = new Vector3[8] {
465+
new Vector3(X, Y, Z), // 0
466+
new Vector3(X2, Y, Z), // 1
467+
new Vector3(X2, Y2, Z), // 2
468+
new Vector3(X, Y2, Z), // 3
469+
new Vector3(X, Y, Z2), // 4
470+
new Vector3(X2, Y, Z2), // 5
471+
new Vector3(X2, Y2, Z2), // 6
472+
new Vector3(X, Y2, Z2) // 7
473+
};
474+
public static readonly Vector2[,] uvs = new Vector2[3,4] { // Z Y X
475+
{
476+
new Vector2(X, Y),
477+
new Vector2(X, Y2),
478+
new Vector2(X2, Y),
479+
new Vector2(X2, Y2)
480+
},
481+
{
482+
new Vector2(X, Z),
483+
new Vector2(X, Z2),
484+
new Vector2(X2, Z),
485+
new Vector2(X2, Z2)
486+
},
487+
{
488+
new Vector2(Z, Y),
489+
new Vector2(Z, Y2),
490+
new Vector2(Z2, Y),
491+
new Vector2(Z2, Y2)
492+
},
493+
};
494+
}
495+
public static class Lever_Top
496+
{
497+
public const float X = 0.4375f;
498+
public const float X2 = 1f - X;
499+
public const float Y = 0f;
500+
public const float Y2 = 0.625f;
501+
public const float Y3 = Y2 - 0.125f;
502+
public static readonly Vector3[] verts = new Vector3[8] {
503+
new Vector3(X, Y, X), // 0
504+
new Vector3(X2, Y, X), // 1
505+
new Vector3(X2, Y2, X), // 2
506+
new Vector3(X, Y2, X), // 3
507+
new Vector3(X, Y, X2), // 4
508+
new Vector3(X2, Y, X2), // 5
509+
new Vector3(X2, Y2, X2), // 6
510+
new Vector3(X, Y2, X2) // 7
511+
};
512+
public static readonly Vector2[,] uvs = new Vector2[3, 4] { // Z Y X
513+
{
514+
new Vector2(X, Y),
515+
new Vector2(X, Y2),
516+
new Vector2(X2, Y),
517+
new Vector2(X2, Y2)
518+
},
519+
{
520+
new Vector2(X, Y3),
521+
new Vector2(X, Y2),
522+
new Vector2(X2, Y3),
523+
new Vector2(X2, Y2)
524+
},
525+
{
526+
new Vector2(X, Y),
527+
new Vector2(X, Y2),
528+
new Vector2(X2, Y),
529+
new Vector2(X2, Y2)
530+
},
531+
};
439532
}
440533
}
441534
}

0 commit comments

Comments
 (0)