Browse Source

added sufficient debug to diagnose - problem is with lack of original data

Henning Koehler 8 năm trước cách đây
mục cha
commit
64e2db6a0f
5 tập tin đã thay đổi với 39 bổ sung8 xóa
  1. 5 1
      config/schemas/skill.json
  2. 8 2
      lib/CModHandler.cpp
  3. 20 1
      lib/CModHandler.h
  4. 6 2
      lib/CSkillHandler.cpp
  5. 0 2
      lib/IHandlerBase.h

+ 5 - 1
config/schemas/skill.json

@@ -19,6 +19,10 @@
         "required" : ["basic", "advanced", "expert"],
 
         "properties": {
+            "index":{
+                "type": "number",
+                "description": "numeric id of skill required only for original skills, prohibited for new skills"
+            },
             "basic":{
                 "$ref" : "#/definitions/skillBonus"
             },
@@ -27,7 +31,7 @@
             },
             "expert":{
                 "$ref" : "#/definitions/skillBonus"
-            },
+            }
         }
 	}
 }

+ 8 - 2
lib/CModHandler.cpp

@@ -204,7 +204,12 @@ void CIdentifierStorage::registerObject(std::string scope, std::string type, std
 	std::string fullID = type + '.' + name;
 	checkIdentifier(fullID);
 
-	registeredObjects.insert(std::make_pair(fullID, data));
+	auto mapping = std::make_pair(fullID, data);
+	if(!registeredObjects.contains(mapping))
+	{
+		CLogger::getLogger(CLoggerDomain("identifier"))->traceStream() << "registered " << fullID << " as " << scope << ":" << identifier;
+		registeredObjects.insert(mapping);
+	}
 }
 
 std::vector<CIdentifierStorage::ObjectData> CIdentifierStorage::getPossibleIdentifiers(const ObjectCallback & request)
@@ -393,8 +398,9 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali
 
 				continue;
 			}
+			logGlobal->debugStream() << "no original data in loadMod(" << name << "): " << data;
 		}
-		// normal new object or one with index bigger that data size
+		// normal new object or one with index bigger than data size
 		performValidate(data,name);
 		handler->loadObject(modName, name, data);
 	}

+ 20 - 1
lib/CModHandler.h

@@ -51,6 +51,10 @@ class CIdentifierStorage
 		si32 id;
 		std::string scope; /// scope in which this ID located
 
+		bool operator==(const ObjectData & other) const
+		{
+			return id == other.id && scope == other.scope;
+		}
 
 		template <typename Handler> void serialize(Handler &h, const int version)
 		{
@@ -59,7 +63,22 @@ class CIdentifierStorage
 		}
 	};
 
-	std::multimap<std::string, ObjectData > registeredObjects;
+	class ObjectMap: public std::multimap<std::string, ObjectData>
+	{
+	public:
+		bool contains(const value_type & value) const
+		{
+			auto range = equal_range(value.first);
+			for(auto contained = range.first; contained != range.second; contained++)
+			{
+				if(value.second == contained->second)
+					return true;
+			}
+			return false;
+		}
+	};
+
+	ObjectMap registeredObjects;
 	std::vector<ObjectCallback> scheduledRequests;
 
 	ELoadingState state;

+ 6 - 2
lib/CSkillHandler.cpp

@@ -83,7 +83,7 @@ std::vector<JsonNode> CSkillHandler::loadLegacyData(size_t dataSize)
 
 const std::string CSkillHandler::getTypeName() const
 {
-	return "secondarySkill";
+	return "skill";
 }
 
 CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string & identifier)
@@ -115,7 +115,7 @@ CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string &
             skill->addNewBonus(bonus, level);
         }
     }
-    CLogger * logger = CLogger::getLogger(CLoggerDomain("skills"));
+    CLogger * logger = CLogger::getLogger(CLoggerDomain(getTypeName()));
     logger->debugStream() << "loaded secondary skill " << identifier << "(" << (int)skill->id << ")";
     logger->traceStream() << *skill;
 
@@ -124,6 +124,10 @@ CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string &
 
 void CSkillHandler::afterLoadFinalization()
 {
+    CLogger * logger = CLogger::getLogger(CLoggerDomain(getTypeName()));
+    logger->traceStream() << "skill handler after load: ";
+    for(auto skill : objects)
+        logger->traceStream() << *skill;
 }
 
 void CSkillHandler::beforeValidate(JsonNode & object)

+ 0 - 2
lib/IHandlerBase.h

@@ -82,12 +82,10 @@ public:
 		auto object = loadFromJson(data, normalizeIdentifier(scope, "core", name));
 		object->id = _ObjectID(index);
 
-
 		assert(objects[index] == nullptr); // ensure that this id was not loaded before
 		objects[index] = object;
 
 		registerObject(scope,type_name, name, object->id);
-
 	}
 
 	ConstTransitivePtr<_Object> operator[] (const _ObjectID id) const