Jelajahi Sumber

Dwellings & Banks will register custom names for their objects

Ivan Savenko 2 tahun lalu
induk
melakukan
7b82387a49

+ 21 - 1
lib/mapObjects/CommonConstructors.cpp

@@ -16,6 +16,7 @@
 #include "../TerrainHandler.h"
 #include "../mapping/CMap.h"
 #include "../CHeroHandler.h"
+#include "../CGeneralTextHandler.h"
 #include "../CCreatureHandler.h"
 #include "JsonRandom.h"
 #include "../CModHandler.h"
@@ -150,8 +151,18 @@ CDwellingInstanceConstructor::CDwellingInstanceConstructor()
 
 }
 
+bool CDwellingInstanceConstructor::hasNameTextID() const
+{
+	return true;
+}
+
 void CDwellingInstanceConstructor::initTypeData(const JsonNode & input)
 {
+	if (input.Struct().count("name") == 0)
+		logMod->warn("Dwelling %s missing name!", getJsonKey());
+
+	VLC->generaltexth->registerString(getNameTextID(), input["name"].String());
+
 	const JsonVector & levels = input["creatures"].Vector();
 	const auto totalLevels = levels.size();
 
@@ -272,9 +283,18 @@ CBankInstanceConstructor::CBankInstanceConstructor()
 
 }
 
+bool CBankInstanceConstructor::hasNameTextID() const
+{
+	return true;
+}
+
 void CBankInstanceConstructor::initTypeData(const JsonNode & input)
 {
-	//TODO: name = input["name"].String();
+	if (input.Struct().count("name") == 0)
+		logMod->warn("Bank %s missing name!", getJsonKey());
+
+	VLC->generaltexth->registerString(getNameTextID(), input["name"].String());
+
 	levels = input["levels"].Vector();
 	bankResetDuration = static_cast<si32>(input["resetDuration"].Float());
 }

+ 3 - 0
lib/mapObjects/CommonConstructors.h

@@ -127,6 +127,7 @@ protected:
 	void initTypeData(const JsonNode & input) override;
 
 public:
+	bool hasNameTextID() const override;
 
 	CDwellingInstanceConstructor();
 	CGObjectInstance * create(std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override;
@@ -218,6 +219,8 @@ public:
 	CGObjectInstance * create(std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override;
 	void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
 
+	bool hasNameTextID() const override;
+
 	std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const override;
 
 	template <typename Handler> void serialize(Handler &h, const int version)