2023-06-02 20:47:37 +02:00
|
|
|
/*
|
|
|
|
* CObjectClassesHandler.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2024-09-14 08:55:28 +02:00
|
|
|
#include "../mapObjects/CompoundMapObjectID.h"
|
2023-06-02 20:47:37 +02:00
|
|
|
#include "../IHandlerBase.h"
|
2024-02-11 23:09:01 +02:00
|
|
|
#include "../json/JsonNode.h"
|
2023-06-02 20:47:37 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class AObjectTypeHandler;
|
|
|
|
class ObjectTemplate;
|
|
|
|
struct SObjectSounds;
|
|
|
|
|
|
|
|
class CGObjectInstance;
|
|
|
|
|
|
|
|
using TObjectTypeHandler = std::shared_ptr<AObjectTypeHandler>;
|
|
|
|
|
|
|
|
/// Class responsible for creation of adventure map objects of specific type
|
2023-12-16 14:13:47 +02:00
|
|
|
class DLL_LINKAGE ObjectClass : boost::noncopyable
|
2023-06-02 20:47:37 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string modScope;
|
|
|
|
std::string identifier;
|
|
|
|
|
|
|
|
si32 id;
|
|
|
|
std::string handlerName; // ID of handler that controls this object, should be determined using handlerConstructor map
|
|
|
|
|
|
|
|
JsonNode base;
|
2024-08-17 01:19:42 +02:00
|
|
|
std::vector<TObjectTypeHandler> objectTypeHandlers;
|
2023-06-02 20:47:37 +02:00
|
|
|
|
2023-12-16 14:13:47 +02:00
|
|
|
ObjectClass();
|
|
|
|
~ObjectClass();
|
2023-06-02 20:47:37 +02:00
|
|
|
|
|
|
|
std::string getJsonKey() const;
|
|
|
|
std::string getNameTextID() const;
|
|
|
|
std::string getNameTranslated() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Main class responsible for creation of all adventure map objects
|
2023-12-16 14:13:47 +02:00
|
|
|
class DLL_LINKAGE CObjectClassesHandler : public IHandlerBase, boost::noncopyable
|
2023-06-02 20:47:37 +02:00
|
|
|
{
|
|
|
|
/// list of object handlers, each of them handles only one type
|
2024-08-17 01:19:42 +02:00
|
|
|
std::vector< std::unique_ptr<ObjectClass> > mapObjectTypes;
|
2023-06-02 20:47:37 +02:00
|
|
|
|
2024-06-24 03:23:26 +02:00
|
|
|
/// map that is filled during construction with all known handlers. Not serializeable due to usage of std::function
|
2023-06-02 20:47:37 +02:00
|
|
|
std::map<std::string, std::function<TObjectTypeHandler()> > handlerConstructors;
|
|
|
|
|
2024-08-21 20:16:41 +02:00
|
|
|
std::vector<std::pair<CompoundMapObjectID, std::function<void(CompoundMapObjectID)>>> objectIdHandlers;
|
|
|
|
|
2023-06-02 20:47:37 +02:00
|
|
|
/// container with H3 templates, used only during loading, no need to serialize it
|
2023-11-05 19:13:18 +02:00
|
|
|
using TTemplatesContainer = std::multimap<std::pair<MapObjectID, MapObjectSubID>, std::shared_ptr<const ObjectTemplate>>;
|
2023-06-02 20:47:37 +02:00
|
|
|
TTemplatesContainer legacyTemplates;
|
|
|
|
|
|
|
|
TObjectTypeHandler loadSubObjectFromJson(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj, size_t index);
|
|
|
|
|
|
|
|
void loadSubObject(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj);
|
|
|
|
void loadSubObject(const std::string & scope, const std::string & identifier, const JsonNode & entry, ObjectClass * obj, size_t index);
|
|
|
|
|
2023-12-16 13:42:12 +02:00
|
|
|
std::unique_ptr<ObjectClass> loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name, size_t index);
|
2023-06-02 20:47:37 +02:00
|
|
|
|
2023-11-21 18:32:07 +02:00
|
|
|
void generateExtraMonolithsForRMG(ObjectClass * container);
|
2023-06-02 20:47:37 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
CObjectClassesHandler();
|
|
|
|
~CObjectClassesHandler();
|
|
|
|
|
|
|
|
std::vector<JsonNode> loadLegacyData() override;
|
|
|
|
|
|
|
|
void loadObject(std::string scope, std::string name, const JsonNode & data) override;
|
|
|
|
void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
|
|
|
|
|
2023-11-02 18:45:46 +02:00
|
|
|
void loadSubObject(const std::string & identifier, JsonNode config, MapObjectID ID, MapObjectSubID subID);
|
|
|
|
void removeSubObject(MapObjectID ID, MapObjectSubID subID);
|
2023-06-02 20:47:37 +02:00
|
|
|
|
|
|
|
void beforeValidate(JsonNode & object) override;
|
|
|
|
void afterLoadFinalization() override;
|
|
|
|
|
|
|
|
/// Queries to detect loaded objects
|
2023-11-02 18:45:46 +02:00
|
|
|
std::set<MapObjectID> knownObjects() const;
|
|
|
|
std::set<MapObjectSubID> knownSubObjects(MapObjectID primaryID) const;
|
2023-06-02 20:47:37 +02:00
|
|
|
|
|
|
|
/// returns handler for specified object (ID-based). ObjectHandler keeps ownership
|
2023-11-02 18:45:46 +02:00
|
|
|
TObjectTypeHandler getHandlerFor(MapObjectID type, MapObjectSubID subtype) const;
|
2023-06-02 20:47:37 +02:00
|
|
|
TObjectTypeHandler getHandlerFor(const std::string & scope, const std::string & type, const std::string & subtype) const;
|
|
|
|
TObjectTypeHandler getHandlerFor(CompoundMapObjectID compoundIdentifier) const;
|
2024-08-21 20:16:41 +02:00
|
|
|
CompoundMapObjectID getCompoundIdentifier(const std::string & scope, const std::string & type, const std::string & subtype) const;
|
|
|
|
CompoundMapObjectID getCompoundIdentifier(const std::string & objectName) const;
|
2023-06-02 20:47:37 +02:00
|
|
|
|
2023-11-02 18:45:46 +02:00
|
|
|
std::string getObjectName(MapObjectID type, MapObjectSubID subtype) const;
|
2023-06-02 20:47:37 +02:00
|
|
|
|
2023-11-02 18:45:46 +02:00
|
|
|
SObjectSounds getObjectSounds(MapObjectID type, MapObjectSubID subtype) const;
|
2023-06-02 20:47:37 +02:00
|
|
|
|
2024-08-21 20:16:41 +02:00
|
|
|
void resolveObjectCompoundId(const std::string & id, std::function<void(CompoundMapObjectID)> callback);
|
|
|
|
|
2023-06-02 20:47:37 +02:00
|
|
|
/// Returns handler string describing the handler (for use in client)
|
2023-11-02 18:45:46 +02:00
|
|
|
std::string getObjectHandlerName(MapObjectID type) const;
|
2023-06-02 20:47:37 +02:00
|
|
|
|
2023-11-02 18:45:46 +02:00
|
|
|
std::string getJsonKey(MapObjectID type) const;
|
2023-06-02 20:47:37 +02:00
|
|
|
};
|
|
|
|
|
2024-08-21 20:16:41 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|