mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Simplify default block name code
This commit is contained in:
parent
39690ed7ca
commit
ed5a967989
@ -77,12 +77,6 @@ namespace ClassicalSharp {
|
||||
public const BlockRaw StoneBrick = 65;
|
||||
#pragma warning restore 1591
|
||||
|
||||
public const string RawNames = "Air Stone Grass Dirt Cobblestone Wood Sapling Bedrock Water StillWater Lava" +
|
||||
" StillLava Sand Gravel GoldOre IronOre CoalOre Log Leaves Sponge Glass Red Orange Yellow Lime Green" +
|
||||
" Teal Aqua Cyan Blue Indigo Violet Magenta Pink Black Gray White Dandelion Rose BrownMushroom RedMushroom" +
|
||||
" Gold Iron DoubleSlab Slab Brick TNT Bookshelf MossyRocks Obsidian CobblestoneSlab Rope Sandstone" +
|
||||
" Snow Fire LightPink ForestGreen Brown DeepBlue Turquoise Ice CeramicTile Magma Pillar Crate StoneBrick";
|
||||
|
||||
/// <summary> Max block ID used in original classic. </summary>
|
||||
public const BlockRaw MaxOriginalBlock = Block.Obsidian;
|
||||
|
||||
|
@ -228,6 +228,12 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
|
||||
const string RawNames = "Air_Stone_Grass_Dirt_Cobblestone_Wood_Sapling_Bedrock_Water_Still water_Lava" +
|
||||
"_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_Brown mushroom_Red mushroom" +
|
||||
"_Gold_Iron_Double slab_Slab_Brick_TNT_Bookshelf_Mossy rocks_Obsidian_Cobblestone slab_Rope_Sandstone" +
|
||||
"_Snow_Fire_Light pink_Forest green_Brown_Deep blue_Turquoise_Ice_Ceramic tile_Magma_Pillar_Crate_Stone brick";
|
||||
|
||||
static StringBuffer buffer = new StringBuffer(64);
|
||||
static string DefaultName(BlockID block) {
|
||||
if (block >= Block.CpeCount) return "Invalid";
|
||||
@ -235,28 +241,15 @@ namespace ClassicalSharp {
|
||||
// Find start and end of this particular block name
|
||||
int start = 0;
|
||||
for (int i = 0; i < block; i++)
|
||||
start = Block.RawNames.IndexOf(' ', start) + 1;
|
||||
int end = Block.RawNames.IndexOf(' ', start);
|
||||
if (end == -1) end = Block.RawNames.Length;
|
||||
start = RawNames.IndexOf('_', start) + 1;
|
||||
int end = RawNames.IndexOf('_', start);
|
||||
if (end == -1) end = RawNames.Length;
|
||||
|
||||
buffer.Clear();
|
||||
SplitUppercase(buffer, start, end);
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
||||
static void SplitUppercase(StringBuffer buffer, int start, int end) {
|
||||
for (int i = start; i < end; i++) {
|
||||
char c = Block.RawNames[i];
|
||||
bool upper = Char.IsUpper(c) && i > start;
|
||||
bool nextLower = i < end - 1 && !Char.IsUpper(Block.RawNames[i + 1]);
|
||||
|
||||
if (upper && nextLower) {
|
||||
buffer.Append(' ');
|
||||
buffer.Append(Char.ToLower(c));
|
||||
} else {
|
||||
buffer.Append(c);
|
||||
}
|
||||
buffer.Append(RawNames[i]);
|
||||
}
|
||||
return buffer.ToString();
|
||||
}
|
||||
|
||||
|
||||
|
@ -29,9 +29,8 @@ namespace ClassicalSharp {
|
||||
|
||||
static string Format(Exception ex) {
|
||||
try {
|
||||
return ex.GetType().FullName + ": " + ex.Message
|
||||
+ Environment.NewLine + ex.StackTrace;
|
||||
} catch {
|
||||
return ex.GetType().FullName + ": " + ex.Message + Environment.NewLine + ex.StackTrace;
|
||||
} catch (Exception) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@ -84,17 +83,13 @@ namespace ClassicalSharp {
|
||||
|
||||
/// <summary> Logs a handled exception that occured at the specified location to the log file. </summary>
|
||||
public static bool LogError(string location, Exception ex) {
|
||||
string error = DescribeException(ex);
|
||||
string error = Format(ex);
|
||||
if (ex.InnerException != null) {
|
||||
error += Environment.NewLine + DescribeException(ex.InnerException);
|
||||
error += Environment.NewLine + Format(ex.InnerException);
|
||||
}
|
||||
return LogError(location, error);
|
||||
}
|
||||
|
||||
static string DescribeException(Exception ex) {
|
||||
return ex.GetType().FullName + ": " + ex.Message + Environment.NewLine + ex.StackTrace;
|
||||
}
|
||||
|
||||
/// <summary> Logs an error that occured at the specified location to the log file. </summary>
|
||||
public static bool LogError(string location, string text) {
|
||||
try {
|
||||
|
@ -106,22 +106,11 @@ void Block_SetDrawType(BlockID block, UInt8 draw) {
|
||||
}
|
||||
|
||||
|
||||
bool Char_IsUpper(UInt8 c) { return c >= 'A' && c <= 'Z'; }
|
||||
void Block_SplitUppercase(STRING_TRANSIENT String* buffer, STRING_PURE String* blockNames, Int32 start, Int32 end) {
|
||||
Int32 i;
|
||||
for (i = start; i < end; i++) {
|
||||
UInt8 c = String_CharAt(blockNames, i);
|
||||
bool upper = Char_IsUpper(c) && i > start;
|
||||
bool nextLower = i < end - 1 && !Char_IsUpper(String_CharAt(blockNames, i + 1));
|
||||
|
||||
if (upper && nextLower) {
|
||||
String_Append(buffer, ' ');
|
||||
String_Append(buffer, Char_ToLower(c));
|
||||
} else {
|
||||
String_Append(buffer, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
#define BLOCK_RAW_NAMES "Air_Stone_Grass_Dirt_Cobblestone_Wood_Sapling_Bedrock_Water_Still water_Lava"\
|
||||
"_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_Brown mushroom_Red mushroom_Gold"\
|
||||
"_Iron_Double slab_Slab_Brick_TNT_Bookshelf_Mossy rocks_Obsidian_Cobblestone slab_Rope_Sandstone_Snow_Fire_Light pink"\
|
||||
"_Forest green_Brown_Deep blue_Turquoise_Ice_Ceramic tile_Magma_Pillar_Crate_Stone brick"
|
||||
|
||||
String Block_DefaultName(BlockID block) {
|
||||
#if USE16_BIT
|
||||
@ -136,13 +125,16 @@ String Block_DefaultName(BlockID block) {
|
||||
/* Find start and end of this particular block name. */
|
||||
Int32 start = 0, i;
|
||||
for (i = 0; i < block; i++) {
|
||||
start = String_IndexOf(&blockNames, ' ', start) + 1;
|
||||
start = String_IndexOf(&blockNames, '_', start) + 1;
|
||||
}
|
||||
Int32 end = String_IndexOf(&blockNames, ' ', start);
|
||||
Int32 end = String_IndexOf(&blockNames, '_', start);
|
||||
if (end == -1) end = blockNames.length;
|
||||
|
||||
String buffer = String_InitAndClear(Block_NamePtr(block), STRING_SIZE);
|
||||
Block_SplitUppercase(&buffer, &blockNames, start, end);
|
||||
Int32 i;
|
||||
for (i = start; i < end; i++) {
|
||||
String_Append(&buffer, blockNames.buffer[i]);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -89,11 +89,5 @@
|
||||
#define BLOCK_MAX_DEFINED 0xFF
|
||||
#endif
|
||||
|
||||
#define BLOCK_RAW_NAMES "Air Stone Grass Dirt Cobblestone Wood Sapling Bedrock Water StillWater Lava"\
|
||||
" StillLava Sand Gravel GoldOre IronOre CoalOre Log Leaves Sponge Glass Red Orange Yellow Lime Green Teal"\
|
||||
" Aqua Cyan Blue Indigo Violet Magenta Pink Black Gray White Dandelion Rose BrownMushroom RedMushroom Gold"\
|
||||
" Iron DoubleSlab Slab Brick TNT Bookshelf MossyRocks Obsidian CobblestoneSlab Rope Sandstone Snow Fire LightPink"\
|
||||
" ForestGreen Brown DeepBlue Turquoise Ice CeramicTile Magma Pillar Crate StoneBrick"
|
||||
|
||||
#define BLOCK_COUNT (BLOCK_MAX_DEFINED + 1)
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user