From b413d80ccc942ad072995d58e588677b8103d971 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 9 Mar 2013 13:16:35 +0000 Subject: [PATCH] - better logging of some config files errors - restored lvl 10 for some dragons --- config/creatures/neutral.json | 6 +++--- lib/CModHandler.cpp | 12 +++++++++-- lib/JsonNode.cpp | 40 +++++++++++++++++------------------ lib/JsonNode.h | 5 ++++- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/config/creatures/neutral.json b/config/creatures/neutral.json index 62168f948..fa22446b4 100644 --- a/config/creatures/neutral.json +++ b/config/creatures/neutral.json @@ -68,7 +68,7 @@ { "special" : true, "id": 133, - "level": 9, + "level": 10, "faction": "neutral", "abilities": [ [ "DRAGON_NATURE", 0, 0, 0 ] ], //crystal dragon is a dragon "ability_remove": [ "FLYING" ], //Crystal Dragons do not fly @@ -92,7 +92,7 @@ "level": 8, "faction": "neutral", "abilities": [ [ "DRAGON_NATURE", 0, 0, 0 ], //faerie dragon is a dragon - [ "MAGIC_MIRROR", 30, 0, 0 ] + [ "MAGIC_MIRROR", 30, 0, 0 ], [ "CASTS", 5, 0, 0 ], [ "CREATURE_SPELL_POWER", 500, 0, 0], //5 spell power per dragon [ "SPELLCASTER", 2, "spell.magicArrow", 10 ], @@ -121,7 +121,7 @@ { "special" : true, "id": 135, - "level": 9, + "level": 10, "faction": "neutral", "abilities": [ [ "SPELL_AFTER_ATTACK", 100, 80, 0 ], //always reduce defense [ "ACID_BREATH", 25, 0, 20 ], //20% chance to do 25 damage diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index 0701fab5a..ead464866 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -84,9 +84,17 @@ void CIdentifierStorage::finalize() const { // print list of missing objects and crash // in future should try to do some cleanup (like returning all id's as 0) - BOOST_FOREACH(auto object, missingObjects) + if (!missingObjects.empty()) { - tlog1 << "Error: object " << object.first << " was not found!\n"; + BOOST_FOREACH(auto object, missingObjects) + { + tlog1 << "Error: object " << object.first << " was not found!\n"; + } + BOOST_FOREACH(auto object, registeredObjects) + { + tlog5 << object.first << " -> " << object.second << "\n"; + } + tlog1 << "All known identifiers were dumped into log file\n"; } assert(missingObjects.empty()); } diff --git a/lib/JsonNode.cpp b/lib/JsonNode.cpp index dcd2ec8dd..d7aa70d1f 100644 --- a/lib/JsonNode.cpp +++ b/lib/JsonNode.cpp @@ -32,33 +32,21 @@ JsonNode::JsonNode(JsonType Type): JsonNode::JsonNode(const char *data, size_t datasize): type(DATA_NULL) { - JsonParser parser(data, datasize, *this); + JsonParser parser(data, datasize); + *this = parser.parse(""); + JsonValidator validator(*this); } JsonNode::JsonNode(ResourceID && fileURI): type(DATA_NULL) { - std::string filename = CResourceHandler::get()->getResourceName(fileURI); - FILE * file = fopen(filename.c_str(), "rb"); - if (!file) - { - tlog1 << "Failed to open file " << filename << "\n"; - perror("Last system error was "); - return; - } + auto file = CResourceHandler::get()->loadData(fileURI); - fseek(file, 0, SEEK_END); - size_t datasize = ftell(file); - fseek(file, 0, SEEK_SET); + JsonParser parser(reinterpret_cast(file.first.get()), file.second); + *this = parser.parse(fileURI.getName()); - char *input = new char[datasize]; - datasize = fread((void*)input, 1, datasize, file); - fclose(file); - - JsonParser parser(input, datasize, *this); JsonValidator validator(*this); - delete [] input; } JsonNode::JsonNode(const JsonNode ©): @@ -345,12 +333,18 @@ std::ostream & operator<<(std::ostream &out, const JsonNode &node) //////////////////////////////////////////////////////////////////////////////// -JsonParser::JsonParser(const char * inputString, size_t stringSize, JsonNode &root): +JsonParser::JsonParser(const char * inputString, size_t stringSize): input(inputString, stringSize), lineCount(1), lineStart(0), pos(0) { +} + +JsonNode JsonParser::parse(std::string fileName) +{ + JsonNode root; + extractValue(root); extractWhitespace(false); @@ -358,8 +352,12 @@ JsonParser::JsonParser(const char * inputString, size_t stringSize, JsonNode &ro if (pos < input.size()) error("Not all file was parsed!", true); - //TODO: better way to show errors (like printing file name as well) - tlog3<