FurnaceRecipe parser: Added an else branch, changed to a switch.
This commit is contained in:
parent
3216fbabfd
commit
b90b0a1dff
@ -68,20 +68,23 @@ void cFurnaceRecipe::ReloadRecipes(void)
|
|||||||
while (std::getline(f, ParsingLine))
|
while (std::getline(f, ParsingLine))
|
||||||
{
|
{
|
||||||
Line++;
|
Line++;
|
||||||
ParsingLine.erase(std::remove_if(ParsingLine.begin(), ParsingLine.end(), isspace), ParsingLine.end()); // Remove whitespace
|
TrimString(ParsingLine);
|
||||||
if (ParsingLine.empty())
|
if (ParsingLine.empty())
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comments
|
switch (ParsingLine[0])
|
||||||
if (ParsingLine[0] == '#')
|
|
||||||
{
|
{
|
||||||
continue;
|
case '#':
|
||||||
|
{
|
||||||
|
// Comment
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ParsingLine[0] == '!') // Fuels start with a bang :)
|
case '!':
|
||||||
{
|
{
|
||||||
|
// Fuel
|
||||||
int IItemID = 0, IItemCount = 0, IItemHealth = 0, IBurnTime = 0;
|
int IItemID = 0, IItemCount = 0, IItemHealth = 0, IBurnTime = 0;
|
||||||
AString::size_type BeginPos = 1; // Begin at one after exclamation mark (bang)
|
AString::size_type BeginPos = 1; // Begin at one after exclamation mark (bang)
|
||||||
|
|
||||||
@ -94,15 +97,26 @@ void cFurnaceRecipe::ReloadRecipes(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add to fuel list
|
// Add to fuel list:
|
||||||
Fuel F;
|
Fuel F;
|
||||||
F.In = new cItem((ENUM_ITEM_ID)IItemID, (char)IItemCount, (short)IItemHealth);
|
F.In = new cItem((ENUM_ITEM_ID)IItemID, (char)IItemCount, (short)IItemHealth);
|
||||||
F.BurnTime = IBurnTime;
|
F.BurnTime = IBurnTime;
|
||||||
m_pState->Fuel.push_back(F);
|
m_pState->Fuel.push_back(F);
|
||||||
continue;
|
break;
|
||||||
}
|
}
|
||||||
else if (isdigit(ParsingLine[0])) // Recipes start with a numeral :)
|
|
||||||
|
case '0':
|
||||||
|
case '1':
|
||||||
|
case '2':
|
||||||
|
case '3':
|
||||||
|
case '4':
|
||||||
|
case '5':
|
||||||
|
case '6':
|
||||||
|
case '7':
|
||||||
|
case '8':
|
||||||
|
case '9':
|
||||||
{
|
{
|
||||||
|
// Recipe
|
||||||
int IItemID = 0, IItemCount = 0, IItemHealth = 0, IBurnTime = 0;
|
int IItemID = 0, IItemCount = 0, IItemHealth = 0, IBurnTime = 0;
|
||||||
int OItemID = 0, OItemCount = 0, OItemHealth = 0;
|
int OItemID = 0, OItemCount = 0, OItemHealth = 0;
|
||||||
AString::size_type BeginPos = 0; // Begin at start of line
|
AString::size_type BeginPos = 0; // Begin at start of line
|
||||||
@ -124,8 +138,18 @@ void cFurnaceRecipe::ReloadRecipes(void)
|
|||||||
R.Out = new cItem((ENUM_ITEM_ID)OItemID, (char)OItemCount, (short)OItemHealth);
|
R.Out = new cItem((ENUM_ITEM_ID)OItemID, (char)OItemCount, (short)OItemHealth);
|
||||||
R.CookTime = IBurnTime;
|
R.CookTime = IBurnTime;
|
||||||
m_pState->Recipes.push_back(R);
|
m_pState->Recipes.push_back(R);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
LOGWARNING("Error in furnace recipes at line %d: Unexpected text: \"%s\". Ignoring line.",
|
||||||
|
Line, ParsingLine.c_str()
|
||||||
|
);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
} // switch (ParsingLine[0])
|
||||||
|
} // while (getline(ParsingLine))
|
||||||
|
|
||||||
LOG("Loaded " SIZE_T_FMT " furnace recipes and " SIZE_T_FMT " fuels", m_pState->Recipes.size(), m_pState->Fuel.size());
|
LOG("Loaded " SIZE_T_FMT " furnace recipes and " SIZE_T_FMT " fuels", m_pState->Recipes.size(), m_pState->Fuel.size());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user