1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

- better logging of some config files errors

- restored lvl 10 for some dragons
This commit is contained in:
Ivan Savenko 2013-03-09 13:16:35 +00:00
parent 044b19269e
commit b413d80ccc
4 changed files with 36 additions and 27 deletions

View File

@ -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

View File

@ -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());
}

View File

@ -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("<unknown>");
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<char*>(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 &copy):
@ -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<<errors;
if (!errors.empty())
{
tlog3<<"File " << fileName << " is not a valid JSON file!\n";
tlog3<<errors;
}
return root;
}
bool JsonParser::extractSeparator()

View File

@ -339,7 +339,10 @@ namespace JsonDetail
bool error(const std::string &message, bool warning=false);
public:
JsonParser(const char * inputString, size_t stringSize, JsonNode &root);
JsonParser(const char * inputString, size_t stringSize);
/// do actual parsing. filename is name of file that will printed to console if any errors were found
JsonNode parse(std::string fileName);
};
//Internal class for Json validation, used automaticaly in JsonNode constructor. Behaviour: