Bladeren bron

Fix string ID's road/river/terrains

Ivan Savenko 2 jaren geleden
bovenliggende
commit
190368e419
6 gewijzigde bestanden met toevoegingen van 36 en 23 verwijderingen
  1. 10 7
      lib/RiverHandler.cpp
  2. 3 1
      lib/RiverHandler.h
  3. 9 6
      lib/RoadHandler.cpp
  4. 3 1
      lib/RoadHandler.h
  5. 8 7
      lib/TerrainHandler.cpp
  6. 3 1
      lib/TerrainHandler.h

+ 10 - 7
lib/RiverHandler.cpp

@@ -33,11 +33,8 @@ RiverType * RiverTypeHandler::loadFromJson(
 	RiverType * info = new RiverType;
 
 	info->id              = RiverId(index);
-	if (identifier.find(':') == std::string::npos)
-		info->identifier = scope + ":" + identifier;
-	else
-		info->identifier = identifier;
-
+	info->identifier      = identifier;
+	info->modScope        = scope;
 	info->tilesFilename   = json["tilesFilename"].String();
 	info->shortIdentifier = json["shortIdentifier"].String();
 	info->deltaName       = json["delta"].String();
@@ -64,9 +61,14 @@ std::vector<bool> RiverTypeHandler::getDefaultAllowed() const
 	return {};
 }
 
+std::string RiverType::getJsonKey() const
+{
+	return modScope + ":" + identifier;
+}
+
 std::string RiverType::getNameTextID() const
 {
-	return TextIdentifier( "river", identifier,  "name" ).get();
+	return TextIdentifier( "river", modScope, identifier, "name" ).get();
 }
 
 std::string RiverType::getNameTranslated() const
@@ -76,7 +78,8 @@ std::string RiverType::getNameTranslated() const
 
 RiverType::RiverType():
 	id(River::NO_RIVER),
-	identifier("empty")
+	identifier("empty"),
+	modScope("core")
 {}
 
 VCMI_LIB_NAMESPACE_END

+ 3 - 1
lib/RiverHandler.h

@@ -21,12 +21,13 @@ class DLL_LINKAGE RiverType : public EntityT<RiverId>
 {
 	friend class RiverTypeHandler;
 	std::string identifier;
+	std::string modScope;
 	RiverId id;
 
 public:
 	int32_t getIndex() const override { return id.getNum(); }
 	int32_t getIconIndex() const override { return 0; }
-	std::string getJsonKey() const override { return identifier;}
+	std::string getJsonKey() const override;
 	void registerIcons(const IconRegistar & cb) const override {}
 	RiverId getId() const override { return id;}
 	void updateFrom(const JsonNode & data) {};
@@ -44,6 +45,7 @@ public:
 	{
 		h & tilesFilename;
 		h & identifier;
+		h & modScope;
 		h & deltaName;
 		h & id;
 	}

+ 9 - 6
lib/RoadHandler.cpp

@@ -33,11 +33,8 @@ RoadType * RoadTypeHandler::loadFromJson(
 	RoadType * info = new RoadType;
 
 	info->id              = RoadId(index);
-	if (identifier.find(':') == std::string::npos)
-		info->identifier = scope + ":" + identifier;
-	else
-		info->identifier = identifier;
-
+	info->identifier      = identifier;
+	info->modScope        = scope;
 	info->tilesFilename   = json["tilesFilename"].String();
 	info->shortIdentifier = json["shortIdentifier"].String();
 	info->movementCost    = json["moveCost"].Integer();
@@ -64,9 +61,14 @@ std::vector<bool> RoadTypeHandler::getDefaultAllowed() const
 	return {};
 }
 
+std::string RoadType::getJsonKey() const
+{
+	return modScope + ":" + identifier;
+}
+
 std::string RoadType::getNameTextID() const
 {
-	return TextIdentifier( "road", identifier,  "name" ).get();
+	return TextIdentifier( "road", modScope, identifier, "name" ).get();
 }
 
 std::string RoadType::getNameTranslated() const
@@ -77,6 +79,7 @@ std::string RoadType::getNameTranslated() const
 RoadType::RoadType():
 	id(Road::NO_ROAD),
 	identifier("empty"),
+	modScope("core"),
 	movementCost(GameConstants::BASE_MOVEMENT_COST)
 {}
 VCMI_LIB_NAMESPACE_END

+ 3 - 1
lib/RoadHandler.h

@@ -21,12 +21,13 @@ class DLL_LINKAGE RoadType : public EntityT<RoadId>
 {
 	friend class RoadTypeHandler;
 	std::string identifier;
+	std::string modScope;
 	RoadId id;
 
 public:
 	int32_t getIndex() const override { return id.getNum(); }
 	int32_t getIconIndex() const override { return 0; }
-	std::string getJsonKey() const override { return identifier;}
+	std::string getJsonKey() const override;
 	void registerIcons(const IconRegistar & cb) const override {}
 	RoadId getId() const override { return id;}
 	void updateFrom(const JsonNode & data) {};
@@ -44,6 +45,7 @@ public:
 	{
 		h & tilesFilename;
 		h & identifier;
+		h & modScope;
 		h & id;
 		h & movementCost;
 	}

+ 8 - 7
lib/TerrainHandler.cpp

@@ -22,12 +22,8 @@ TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const
 	TerrainType * info = new TerrainType;
 
 	info->id = TerrainId(index);
-
-	if (identifier.find(':') == std::string::npos)
-		info->identifier = scope + ":" + identifier;
-	else
-		info->identifier = identifier;
-
+	info->identifier = identifier;
+	info->modScope = scope;
 	info->moveCost = static_cast<int>(json["moveCost"].Integer());
 	info->musicFilename = json["music"].String();
 	info->tilesFilename = json["tiles"].String();
@@ -177,9 +173,14 @@ bool TerrainType::isTransitionRequired() const
 	return transitionRequired;
 }
 
+std::string TerrainType::getJsonKey() const
+{
+	return modScope + ":" + identifier;
+}
+
 std::string TerrainType::getNameTextID() const
 {
-	return TextIdentifier( "terrain", identifier,  "name" ).get();
+	return TextIdentifier( "terrain", modScope, identifier, "name" ).get();
 }
 
 std::string TerrainType::getNameTranslated() const

+ 3 - 1
lib/TerrainHandler.h

@@ -22,13 +22,14 @@ class DLL_LINKAGE TerrainType : public EntityT<TerrainId>
 {
 	friend class TerrainTypeHandler;
 	std::string identifier;
+	std::string modScope;
 	TerrainId id;
 	ui8 passabilityType;
 
 public:
 	int32_t getIndex() const override { return id.getNum(); }
 	int32_t getIconIndex() const override { return 0; }
-	std::string getJsonKey() const override { return identifier;}
+	std::string getJsonKey() const override;
 	void registerIcons(const IconRegistar & cb) const override {}
 	TerrainId getId() const override { return id;}
 	void updateFrom(const JsonNode & data) {};
@@ -78,6 +79,7 @@ public:
 		h & prohibitTransitions;
 		h & minimapBlocked;
 		h & minimapUnblocked;
+		h & modScope;
 		h & identifier;
 		h & musicFilename;
 		h & tilesFilename;