|
|
@@ -13,25 +13,64 @@ using namespace Framework::JSON;
|
|
|
using namespace Framework::Validator;
|
|
|
|
|
|
RecipieLoader::RecipieLoader()
|
|
|
- : Framework::ReferenceCounter(),
|
|
|
- validator(0)
|
|
|
+ : Framework::ReferenceCounter()
|
|
|
{}
|
|
|
|
|
|
-RecipieLoader::~RecipieLoader()
|
|
|
-{
|
|
|
- if (validator) validator->release();
|
|
|
-}
|
|
|
+RecipieLoader::~RecipieLoader() {}
|
|
|
|
|
|
void RecipieLoader::loadRecipies(const char* path)
|
|
|
{
|
|
|
DataValidator* validator
|
|
|
+ = Framework::Validator::DataValidator::buildForArray()
|
|
|
+ ->addAcceptedTypeInArray(Game::INSTANCE->zTypeRegistry()
|
|
|
+ ->getValidator<RecipieGroupConfig>())
|
|
|
+ ->removeInvalidEntries()
|
|
|
+ ->finishArray();
|
|
|
+ loadAllJsonsFromDirectory(Framework::Text(path) + "/recipieGroups",
|
|
|
+ [this, &validator](JSONValue* zJson, Framework::Text path) {
|
|
|
+ Framework::Logging::info()
|
|
|
+ << "loading recipie groups from '" << path << "'";
|
|
|
+ Framework::RCArray<ValidationResult> invalidParts;
|
|
|
+ JSONValue* valid = validator->getValidParts(zJson, &invalidParts);
|
|
|
+ for (ValidationResult* invalidPart : invalidParts)
|
|
|
+ {
|
|
|
+ Framework::Logging::error() << invalidPart->getInvalidInfo();
|
|
|
+ }
|
|
|
+ int count = 0;
|
|
|
+ if (valid)
|
|
|
+ {
|
|
|
+ for (JSONValue* value : *valid->asArray())
|
|
|
+ {
|
|
|
+ RecipieGroupConfig* recipieGroup
|
|
|
+ = Game::INSTANCE->zTypeRegistry()
|
|
|
+ ->fromJson<RecipieGroupConfig>(value);
|
|
|
+ if (recipieGroup)
|
|
|
+ {
|
|
|
+ groupConfigs.add(recipieGroup);
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Framework::Logging::info()
|
|
|
+ << count << " recipie groups were loaded.";
|
|
|
+ });
|
|
|
+ Framework::JSON::JSONObject* schema = validator->getJsonSchema();
|
|
|
+ Framework::Datei syntaxFile;
|
|
|
+ syntaxFile.setDatei("data/syntax/schema/recipieGroups.json");
|
|
|
+ syntaxFile.erstellen();
|
|
|
+ syntaxFile.open(Framework::Datei::Style::schreiben);
|
|
|
+ syntaxFile.schreibe(schema->toString(), schema->toString().getLength());
|
|
|
+ syntaxFile.close();
|
|
|
+ schema->release();
|
|
|
+ validator->release();
|
|
|
+ validator
|
|
|
= Framework::Validator::DataValidator::buildForArray()
|
|
|
->addAcceptedTypeInArray(
|
|
|
Game::INSTANCE->zTypeRegistry()->getValidator<Recipie>())
|
|
|
->removeInvalidEntries()
|
|
|
->finishArray();
|
|
|
- loadAllJsonsFromDirectory(
|
|
|
- path, [this, &validator](JSONValue* zJson, Framework::Text path) {
|
|
|
+ loadAllJsonsFromDirectory(Framework::Text(path) + "/recipies",
|
|
|
+ [this, &validator](JSONValue* zJson, Framework::Text path) {
|
|
|
Framework::Logging::info()
|
|
|
<< "loading recipies from '" << path << "'";
|
|
|
Framework::RCArray<ValidationResult> invalidParts;
|
|
|
@@ -64,8 +103,7 @@ void RecipieLoader::loadRecipies(const char* path)
|
|
|
}
|
|
|
Framework::Logging::info() << count << " recipies were loaded.";
|
|
|
});
|
|
|
- Framework::JSON::JSONObject* schema = validator->getJsonSchema();
|
|
|
- Framework::Datei syntaxFile;
|
|
|
+ schema = validator->getJsonSchema();
|
|
|
syntaxFile.setDatei("data/syntax/schema/recipies.json");
|
|
|
syntaxFile.erstellen();
|
|
|
syntaxFile.open(Framework::Datei::Style::schreiben);
|
|
|
@@ -73,6 +111,25 @@ void RecipieLoader::loadRecipies(const char* path)
|
|
|
syntaxFile.close();
|
|
|
schema->release();
|
|
|
validator->release();
|
|
|
+ for (RecipieList* list : lists)
|
|
|
+ {
|
|
|
+ bool found = 0;
|
|
|
+ for (RecipieGroupConfig* groupConfig : groupConfigs)
|
|
|
+ {
|
|
|
+ if (list->getName().istGleich(groupConfig->getGroupName()))
|
|
|
+ {
|
|
|
+ found = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!found)
|
|
|
+ {
|
|
|
+ Framework::Logging::warning()
|
|
|
+ << "Recipie list '" << list->getName()
|
|
|
+ << "' has no group config. The recipies can not be viewed by "
|
|
|
+ "the client.";
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
RecipieList* RecipieLoader::zRecipieList(const char* name) const
|
|
|
@@ -101,20 +158,21 @@ Framework::Text RecipieLoader::getCrafingUIML(int itemTypeId)
|
|
|
list->findRecipies(itemTypeId, recipies);
|
|
|
if (recipies.getEintragAnzahl() > 0)
|
|
|
{
|
|
|
- result.append()
|
|
|
- << "<craftingRecipieGroup name=\"" << list->getName();
|
|
|
- if (list->getName().istGleich("inventory"))
|
|
|
+ for (RecipieGroupConfig* groupConfig : groupConfigs)
|
|
|
{
|
|
|
- result.append()
|
|
|
- << "\" itemIcon=\""
|
|
|
- << Game::INSTANCE->getItemTypeId("Crafting Table");
|
|
|
- }
|
|
|
- result += "\">";
|
|
|
- for (Recipie* recipie : recipies)
|
|
|
- {
|
|
|
- result += recipie->getRecipieUIML();
|
|
|
+ if (list->getName().istGleich(groupConfig->getGroupName()))
|
|
|
+ {
|
|
|
+ result.append() << "<craftingRecipieGroup name=\""
|
|
|
+ << list->getName() << "\" itemIcon=\""
|
|
|
+ << groupConfig->getIconItemType() << "\">";
|
|
|
+ for (Recipie* recipie : recipies)
|
|
|
+ {
|
|
|
+ result += recipie->getRecipieUIML();
|
|
|
+ }
|
|
|
+ result += "</craftingRecipieGroup>";
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- result += "</craftingRecipieGroup>";
|
|
|
}
|
|
|
}
|
|
|
result += "</craftingRecipies></dialog>";
|