Skip to content

Commit 0712f1e

Browse files
committed
Exclude unsupported file formats
Exclude unsupported file formats from Texture Set creation process
1 parent fb20481 commit 0712f1e

1 file changed

Lines changed: 37 additions & 17 deletions

File tree

Program.cs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
using System.IO;
44
using System.Media;
55
using static System.Console;
6-
6+
using Newtonsoft.Json.Linq;
7+
using System.Runtime.CompilerServices;
78

89
internal class TSMaker
910
{
@@ -12,7 +13,7 @@ private static void Main(string[] args)
1213
ForegroundColor = ConsoleColor.Yellow;
1314
BackgroundColor = ConsoleColor.Black;
1415

15-
16+
// User controls heightmap/normal json creation
1617
Write("Input 0 or 1\n0 = Normals\n1 = Heightmaps\nType here: ");
1718

1819
string heightmap_NormalMap_Switch = ReadLine();
@@ -32,42 +33,61 @@ private static void Main(string[] args)
3233
{
3334
ForegroundColor = ConsoleColor.DarkRed;
3435
WriteLine("Input a number (0 or 1 only) now close the application");
35-
3636
}
3737

3838

39+
// Store all full file directories
3940
string _ = ReadLine();
40-
string folderPath = _ + @"\JSONS\";
41+
string[] image_Directories_Full = Directory.GetFiles(_);
42+
43+
List<string> image_Directories_Full_List = new List<string>();
44+
image_Directories_Full_List = image_Directories_Full.ToList();
4145

42-
if (folderPath.EndsWith(@"\\")) { folderPath.Replace(@"\\", @"\"); }
4346

47+
// Define the folder path
48+
string folderPath = _ + @"\JSONS\";
49+
if (folderPath.EndsWith(@"\\"))
50+
folderPath.Replace(@"\\", @"\");
4451
Directory.CreateDirectory(folderPath);
4552

46-
string[] image_Directories_Full = Directory.GetFiles(_);
53+
54+
// Get rid of unsupported formats
55+
for (int i = image_Directories_Full_List.Count() - 1; i >= 0; i--)
56+
{
57+
58+
if (!(image_Directories_Full_List[i].EndsWith(".png") || image_Directories_Full_List[i].EndsWith(".jpg") || image_Directories_Full_List[i].EndsWith(".tga") || image_Directories_Full_List[i].EndsWith(".jpeg")))
59+
{
60+
image_Directories_Full_List.RemoveAt(i);
61+
}
62+
63+
}
4764

4865

49-
foreach (string listed_image_Directories_Full in image_Directories_Full)
66+
67+
// Factory
68+
foreach (string listed_image_Directories_Full in image_Directories_Full_List)
5069

5170
{
52-
string image_Name_Without_Extension = Path.GetFileNameWithoutExtension(listed_image_Directories_Full);
5371

72+
string image_Name_Without_Extension = Path.GetFileNameWithoutExtension(listed_image_Directories_Full);
5473

74+
// Discard unneeded files
5575
if (image_Name_Without_Extension.EndsWith("mer")) continue;
5676
else if (image_Name_Without_Extension.EndsWith("heightmap")) continue;
5777
else if (image_Name_Without_Extension.EndsWith("texture_set")) continue;
5878
else if (image_Name_Without_Extension.EndsWith("normal") && !(image_Name_Without_Extension.StartsWith("sandstone") || image_Name_Without_Extension.StartsWith("red_sandstone") || image_Name_Without_Extension.StartsWith("rail")) ) continue;
5979

6080
string json_Fullpath = folderPath + image_Name_Without_Extension + ".texture_set.json";
6181
WriteLine(json_Fullpath);
62-
63-
//------------
82+
83+
//------------------------------------------- Base information which we use to create the json's content
6484
string json_File_Content = "{\"format_version\":\"1.16.100\",\"minecraft:texture_set\":{\"color\":\"X\",\"metalness_emissive_roughness\":\"Y\",\"W\":\"Z\"}}";
6585

6686
string[] NH = { "normal", "heightmap" };
6787
string MER = image_Name_Without_Extension + "_mer";
6888
string normal = image_Name_Without_Extension + "_normal";
6989
string heightmap = image_Name_Without_Extension + "_heightmap";
70-
//-------------
90+
//------------------------------------ Customize this if you have named your textures in a different way
7191

7292
json_File_Content = json_File_Content.Replace("X", image_Name_Without_Extension);
7393
json_File_Content = json_File_Content.Replace("Y", MER);
@@ -84,11 +104,12 @@ private static void Main(string[] args)
84104
}
85105
else Environment.Exit(1);
86106

87-
107+
88108
File.WriteAllText(json_Fullpath, json_File_Content);
89109
}
90110

91-
111+
112+
// Finish
92113
if (answer == 0 || answer == 1)
93114
{
94115
WriteLine($"\nSUCCESSFUL! Find JSONS folder at:\n{folderPath}");
@@ -97,20 +118,19 @@ private static void Main(string[] args)
97118
finishSound.Play();
98119
}
99120
ReadLine();
100-
}
121+
}
101122
}
102123

103124
// ideas/plans:
104-
105-
// This app should not do anything with the files that aren't PNG, JPG, JPEG, TGA etc.. all other supported formats.
106125
// Re-Run the app whenever user types anything wrong, could be a few cases
107126
// Reading subdirectories and placing the jsons in the directories with the same folder name inside of JSONS folder.
108127
// e.g get files in /blocks/candles, and places candles jsons in JSONS/candles folders.
109-
// Get files and create copies of the them with the same name + _mer/normal/heightmap in the same directory (Optional Feature, answer 0 0 == normal map, without file copy, 0 1 == normal map with file copy)|
128+
// Get files and create copies of the them with the same name + _mer/normal/heightmap in the same directory (Optional Feature)
110129
// Move it all to an actual Ui
111130

112131

113132
// v2 so far:
133+
// This app should not do anything with the files that aren't PNG, JPG, JPEG, TGA etc.. all other supported formats.
114134
// General improvements e.g., cleaner text, better exception handling, etc...
115135
// Exclude textures if the file name ends with _mer, _normal, _heightmap, this could be a bit tricky because of some special cases/exceptions
116136
// Update readme.md with a more accurate description of the app, maybe a little "How To" too in case anyone has any problems

0 commit comments

Comments
 (0)