Skip to content

Commit

Permalink
simplify DefaultSet.Name
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Jul 3, 2018
1 parent d895354 commit 090f54a
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions fCraft/World/DefaultSet.cs
Expand Up @@ -146,38 +146,22 @@ public static class DefaultSet {
} }




const string Names = "Air Stone Grass Dirt Cobblestone Wood Sapling Bedrock Water StillWater Lava" + const string RawNames = "Air_Stone_Grass_Dirt_Cobblestone_Wood_Sapling_Bedrock_Water_Still water_Lava" +
" StillLava Sand Gravel GoldOre IronOre CoalOre Log Leaves Sponge Glass Red Orange Yellow Lime Green" + "_Still lava_Sand_Gravel_Gold ore_Iron ore_Coal ore_Log_Leaves_Sponge_Glass_Red_Orange_Yellow_Lime_Green" +
" Teal Aqua Cyan Blue Indigo Violet Magenta Pink Black Gray White Dandelion Rose BrownMushroom RedMushroom" + "_Teal_Aqua_Cyan_Blue_Indigo_Violet_Magenta_Pink_Black_Gray_White_Dandelion_Rose_Brown mushroom_Red mushroom" +
" Gold Iron DoubleSlab Slab Brick TNT Bookshelf MossyRocks Obsidian CobblestoneSlab Rope Sandstone" + "_Gold_Iron_Double slab_Slab_Brick_TNT_Bookshelf_Mossy rocks_Obsidian_Cobblestone slab_Rope_Sandstone" +
" Snow Fire LightPink ForestGreen Brown DeepBlue Turquoise Ice CeramicTile Magma Pillar Crate StoneBrick"; "_Snow_Fire_Light pink_Forest green_Brown_Deep blue_Turquoise_Ice_Ceramic tile_Magma_Pillar_Crate_Stone brick";


static string Name(int block) { static string Name(int block) {
// Find start and end of this particular block name // Find start and end of this particular block name
int start = 0; int start = 0;
for (int i = 0; i < block; i++) for (int i = 0; i < block; i++)
start = Names.IndexOf(' ', start) + 1; start = RawNames.IndexOf('_', start) + 1;
int end = Names.IndexOf(' ', start);
if (end == -1) end = Names.Length;


StringBuilder buffer = new StringBuilder(); int end = RawNames.IndexOf('_', start);
SplitUppercase(buffer, start, end); if (end == -1) end = RawNames.Length;
return buffer.ToString();
} return RawNames.Substring(start, end - start);

static void SplitUppercase(StringBuilder buffer, int start, int end) {
for (int i = start; i < end; i++) {
char c = Names[i];
bool upper = Char.IsUpper(c) && i > start;
bool nextLower = i < end - 1 && !Char.IsUpper(Names[i + 1]);

if (upper && nextLower) {
buffer.Append(' ');
buffer.Append(Char.ToLower(c));
} else {
buffer.Append(c);
}
}
} }




Expand Down

0 comments on commit 090f54a

Please sign in to comment.