1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-08-09 15:49:52 +00:00

Fixes to scripted ingredients, now it actually works

This commit is contained in:
fgenesis 2013-06-21 03:33:35 +02:00
parent 46516eefc8
commit 2c99f010a4
3 changed files with 45 additions and 34 deletions

View file

@ -850,6 +850,7 @@ bool Continuity::applyIngredientEffects(IngredientData *data)
if(dsq->game->cookingScript) if(dsq->game->cookingScript)
dsq->game->cookingScript->call("useIngredient", data->name.c_str(), &eaten); dsq->game->cookingScript->call("useIngredient", data->name.c_str(), &eaten);
} }
break;
default: default:
{ {
char str[256]; char str[256];
@ -921,6 +922,43 @@ void Continuity::clearIngredientData()
ingredientData.clear(); ingredientData.clear();
} }
void Continuity::loadIngredientData()
{
if(ingredients.size())
{
debugLog("Can't reload ingredient data, inventory is not empty");
return; // ... because otherwise there would be dangling pointers and it would crash.
}
clearIngredientData();
ingredientDescriptions.clear();
ingredientDisplayNames.clear();
recipes.clear();
loadIngredientDisplayNames("data/ingredientnames.txt");
std::string fname = localisePath("data/ingredientnames.txt");
loadIngredientDisplayNames(fname);
if(dsq->mod.isActive())
{
fname = localisePath(dsq->mod.getPath() + "ingredientnames.txt", dsq->mod.getPath());
loadIngredientDisplayNames(fname);
}
if(dsq->mod.isActive())
{
//load mod ingredients
loadIngredientData(dsq->mod.getPath() + "ingredients.txt");
}
//load ingredients for the main game
if(ingredientData.empty() && recipes.empty())
{
loadIngredientData("data/ingredients.txt");
}
}
void Continuity::loadIngredientData(const std::string &file) void Continuity::loadIngredientData(const std::string &file)
{ {
std::string line, name, gfx, type, effects; std::string line, name, gfx, type, effects;
@ -961,7 +999,7 @@ void Continuity::loadIngredientData(const std::string &file)
if (p1 != std::string::npos && p2 != std::string::npos) if (p1 != std::string::npos && p2 != std::string::npos)
{ {
effects = effects.substr(p1+1, p2-(p1+1)); effects = effects.substr(p1+1, p2-(p1+1));
SimpleIStringStream fxLine(effects.c_str(), SimpleIStringStream::REUSE); std::istringstream fxLine(effects);
std::string bit; std::string bit;
while (fxLine >> bit) while (fxLine >> bit)
{ {
@ -1075,7 +1113,7 @@ void Continuity::loadIngredientData(const std::string &file)
if(extradata) if(extradata)
{ {
while (in >> line) while (std::getline(in, line))
{ {
SimpleIStringStream inLine(line.c_str(), SimpleIStringStream::REUSE); SimpleIStringStream inLine(line.c_str(), SimpleIStringStream::REUSE);
int maxAmount = MAX_INGREDIENT_AMOUNT; int maxAmount = MAX_INGREDIENT_AMOUNT;
@ -1084,7 +1122,7 @@ void Continuity::loadIngredientData(const std::string &file)
if (name == "==Recipes==") if (name == "==Recipes==")
{ {
recipes = true; recipes = true;
continue; break;
} }
IngredientData *data = getIngredientDataByName(name); IngredientData *data = getIngredientDataByName(name);
if(!data) if(!data)
@ -3343,40 +3381,11 @@ void Continuity::reset()
worldMap.load(); worldMap.load();
ingredients.clear();
naijaEats.clear(); naijaEats.clear();
foodSortType = 0; foodSortType = 0;
ingredients.clear();
//load ingredients loadIngredientData(); // must be after clearing ingredients
ingredientDisplayNames.clear();
loadIngredientDisplayNames("data/ingredientnames.txt");
std::string fname = localisePath("data/ingredientnames.txt");
loadIngredientDisplayNames(fname);
if(dsq->mod.isActive())
{
fname = localisePath(dsq->mod.getPath() + "ingredientnames.txt", dsq->mod.getPath());
loadIngredientDisplayNames(fname);
}
ingredientDescriptions.clear();
ingredientData.clear();
recipes.clear();
if(dsq->mod.isActive())
{
//load mod ingredients
loadIngredientData(dsq->mod.getPath() + "ingredients.txt");
}
//load ingredients for the main game
if(ingredientData.empty() && recipes.empty()) {
loadIngredientData("data/ingredients.txt");
}
loadPetData(); loadPetData();

View file

@ -614,6 +614,7 @@ void DSQ::debugMenu()
core->afterEffectManager->loadShaders(); core->afterEffectManager->loadShaders();
} }
dsq->user.load(); dsq->user.load();
dsq->continuity.loadIngredientData();
} }
else if (c == '2') else if (c == '2')
{ {

View file

@ -1065,6 +1065,7 @@ public:
bool applyIngredientEffects(IngredientData *data); bool applyIngredientEffects(IngredientData *data);
void loadIngredientData();
void loadIngredientData(const std::string &file); void loadIngredientData(const std::string &file);
void loadIngredientDisplayNames(const std::string& file); void loadIngredientDisplayNames(const std::string& file);
bool hasIngredients() const { return !ingredients.empty(); } bool hasIngredients() const { return !ingredients.empty(); }