Skip to content

Commit 090f54a

Browse files
simplify DefaultSet.Name
1 parent d895354 commit 090f54a

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

fCraft/World/DefaultSet.cs

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -146,38 +146,22 @@ public static DrawType Draw(Block b) {
146146
}
147147

148148

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

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

163-
StringBuilder buffer = new StringBuilder();
164-
SplitUppercase(buffer, start, end);
165-
return buffer.ToString();
166-
}
167-
168-
static void SplitUppercase(StringBuilder buffer, int start, int end) {
169-
for (int i = start; i < end; i++) {
170-
char c = Names[i];
171-
bool upper = Char.IsUpper(c) && i > start;
172-
bool nextLower = i < end - 1 && !Char.IsUpper(Names[i + 1]);
173-
174-
if (upper && nextLower) {
175-
buffer.Append(' ');
176-
buffer.Append(Char.ToLower(c));
177-
} else {
178-
buffer.Append(c);
179-
}
180-
}
161+
int end = RawNames.IndexOf('_', start);
162+
if (end == -1) end = RawNames.Length;
163+
164+
return RawNames.Substring(start, end - start);
181165
}
182166

183167

0 commit comments

Comments
 (0)