1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-15 13:33:36 +02:00

Merge pull request #4415 from godric3/map-editor-validate-spells

map editor: check hero and town spells during mod assessment
This commit is contained in:
Ivan Savenko 2024-08-12 17:20:01 +03:00 committed by GitHub
commit 170330109f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 131 additions and 8 deletions

View File

@ -40,6 +40,7 @@ public:
virtual int32_t getIndex() const = 0;
virtual int32_t getIconIndex() const = 0;
virtual std::string getJsonKey() const = 0;
virtual std::string getModScope() const = 0;
virtual std::string getNameTranslated() const = 0;
virtual std::string getNameTextID() const = 0;

View File

@ -73,6 +73,11 @@ std::string BattleFieldInfo::getJsonKey() const
return modScope + ':' + identifier;
}
std::string BattleFieldInfo::getModScope() const
{
return modScope;
}
std::string BattleFieldInfo::getNameTextID() const
{
return name;

View File

@ -52,6 +52,7 @@ public:
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
std::string getNameTextID() const override;
std::string getNameTranslated() const override;
void registerIcons(const IconRegistar & cb) const override;

View File

@ -106,6 +106,11 @@ std::string CArtifact::getJsonKey() const
return modScope + ':' + identifier;
}
std::string CArtifact::getModScope() const
{
return modScope;
}
void CArtifact::registerIcons(const IconRegistar & cb) const
{
cb(getIconIndex(), 0, "ARTIFACT", image);

View File

@ -106,6 +106,7 @@ public:
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
void registerIcons(const IconRegistar & cb) const override;
ArtifactID getId() const override;
const IBonusBearer * getBonusBearer() const override;

View File

@ -61,6 +61,11 @@ std::string CCreature::getJsonKey() const
return modScope + ':' + identifier;
}
std::string CCreature::getModScope() const
{
return modScope;
}
void CCreature::registerIcons(const IconRegistar & cb) const
{
cb(getIconIndex(), 0, "CPRSMALL", smallIconName);

View File

@ -131,6 +131,7 @@ public:
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
void registerIcons(const IconRegistar & cb) const override;
CreatureID getId() const override;
const IBonusBearer * getBonusBearer() const override;

View File

@ -53,6 +53,11 @@ std::string CHero::getJsonKey() const
return modScope + ':' + identifier;
}
std::string CHero::getModScope() const
{
return modScope;
}
HeroTypeID CHero::getId() const
{
return ID;
@ -189,6 +194,11 @@ std::string CHeroClass::getJsonKey() const
return modScope + ':' + identifier;
}
std::string CHeroClass::getModScope() const
{
return modScope;
}
HeroClassID CHeroClass::getId() const
{
return id;

View File

@ -84,6 +84,7 @@ public:
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
HeroTypeID getId() const override;
void registerIcons(const IconRegistar & cb) const override;
@ -145,6 +146,7 @@ public:
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
HeroClassID getId() const override;
void registerIcons(const IconRegistar & cb) const override;

View File

@ -50,6 +50,11 @@ std::string PlayerState::getJsonKey() const
return color.toString();
}
std::string PlayerState::getModScope() const
{
return "core";
}
std::string PlayerState::getNameTranslated() const
{
return VLC->generaltexth->translate(getNameTextID());

View File

@ -85,6 +85,7 @@ public:
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
std::string getNameTranslated() const override;
std::string getNameTextID() const override;
void registerIcons(const IconRegistar & cb) const override;

View File

@ -64,6 +64,11 @@ std::string CSkill::getJsonKey() const
return modScope + ':' + identifier;
}
std::string CSkill::getModScope() const
{
return modScope;
}
std::string CSkill::getDescriptionTextID(int level) const
{
TextIdentifier id("skill", modScope, identifier, "description", NSecondarySkill::levels[level]);

View File

@ -52,6 +52,7 @@ public:
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
void registerIcons(const IconRegistar & cb) const override;
SecondarySkill getId() const override;

View File

@ -28,7 +28,12 @@ int32_t ObstacleInfo::getIconIndex() const
std::string ObstacleInfo::getJsonKey() const
{
return identifier;
return modScope + ':' + identifier;
}
std::string ObstacleInfo::getModScope() const
{
return modScope;
}
std::string ObstacleInfo::getNameTranslated() const
@ -91,6 +96,7 @@ std::shared_ptr<ObstacleInfo> ObstacleHandler::loadFromJson(const std::string &
auto info = std::make_shared<ObstacleInfo>(Obstacle(index), identifier);
info->modScope = scope;
info->animation = AnimationPath::fromJson(json["animation"]);
info->width = json["width"].Integer();
info->height = json["height"].Integer();

View File

@ -31,6 +31,7 @@ public:
Obstacle obstacle;
si32 iconIndex;
std::string modScope;
std::string identifier;
AudioPath appearSound;
AnimationPath appearAnimation;
@ -47,6 +48,7 @@ public:
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
std::string getNameTranslated() const override;
std::string getNameTextID() const override;
void registerIcons(const IconRegistar & cb) const override;

View File

@ -74,6 +74,11 @@ std::string RiverType::getJsonKey() const
return modScope + ":" + identifier;
}
std::string RiverType::getModScope() const
{
return modScope;
}
std::string RiverType::getNameTextID() const
{
return TextIdentifier( "river", modScope, identifier, "name" ).get();

View File

@ -37,6 +37,7 @@ public:
int32_t getIndex() const override { return id.getNum(); }
int32_t getIconIndex() const override { return 0; }
std::string getJsonKey() const override;
std::string getModScope() const override;
void registerIcons(const IconRegistar & cb) const override {}
RiverId getId() const override { return id;}
void updateFrom(const JsonNode & data) {};

View File

@ -65,6 +65,11 @@ std::string RoadType::getJsonKey() const
return modScope + ":" + identifier;
}
std::string RoadType::getModScope() const
{
return modScope;
}
std::string RoadType::getNameTextID() const
{
return TextIdentifier( "road", modScope, identifier, "name" ).get();

View File

@ -29,6 +29,7 @@ public:
int32_t getIndex() const override { return id.getNum(); }
int32_t getIconIndex() const override { return 0; }
std::string getJsonKey() const override;
std::string getModScope() const override;
void registerIcons(const IconRegistar & cb) const override {}
RoadId getId() const override { return id;}
void updateFrom(const JsonNode & data) {};

View File

@ -191,6 +191,11 @@ std::string TerrainType::getJsonKey() const
return modScope + ":" + identifier;
}
std::string TerrainType::getModScope() const
{
return modScope;
}
std::string TerrainType::getNameTextID() const
{
return TextIdentifier( "terrain", modScope, identifier, "name" ).get();

View File

@ -55,6 +55,7 @@ public:
int32_t getIndex() const override { return id.getNum(); }
int32_t getIconIndex() const override { return 0; }
std::string getJsonKey() const override;
std::string getModScope() const override;
void registerIcons(const IconRegistar & cb) const override {}
TerrainId getId() const override { return id;}
void updateFrom(const JsonNode & data) {};

View File

@ -41,6 +41,11 @@ std::string CFaction::getJsonKey() const
return modScope + ':' + identifier;
}
std::string CFaction::getModScope() const
{
return modScope;
}
void CFaction::registerIcons(const IconRegistar & cb) const
{
if(town)

View File

@ -63,6 +63,7 @@ public:
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
void registerIcons(const IconRegistar & cb) const override;
FactionID getId() const override;

View File

@ -29,6 +29,11 @@ std::string AObjectTypeHandler::getJsonKey() const
return modScope + ':' + subTypeName;
}
std::string AObjectTypeHandler::getModScope() const
{
return modScope;
}
si32 AObjectTypeHandler::getIndex() const
{
return type;

View File

@ -74,6 +74,8 @@ public:
/// returns full form of identifier of this object in form of modName:objectName
std::string getJsonKey() const;
std::string getModScope() const;
/// Returns object-specific name, if set
SObjectSounds getSounds() const;

View File

@ -200,6 +200,11 @@ std::string CSpell::getJsonKey() const
return modScope + ':' + identifier;
}
std::string CSpell::getModScope() const
{
return modScope;
}
int32_t CSpell::getIndex() const
{
return id.toEnum();

View File

@ -228,6 +228,7 @@ public:
int32_t getIndex() const override;
int32_t getIconIndex() const override;
std::string getJsonKey() const override;
std::string getModScope() const override;
SpellID getId() const override;
std::string getNameTextID() const override;

View File

@ -613,16 +613,49 @@ ModCompatibilityInfo MapController::modAssessmentAll()
ModCompatibilityInfo MapController::modAssessmentMap(const CMap & map)
{
ModCompatibilityInfo result;
auto extractEntityMod = [&result](const auto & entity)
{
auto modScope = entity->getModScope();
if(modScope != "core")
result[modScope] = VLC->modh->getModInfo(modScope).getVerificationInfo();
};
for(auto obj : map.objects)
{
if(obj->ID == Obj::HERO)
continue; //stub!
auto handler = obj->getObjectHandler();
auto modName = QString::fromStdString(handler->getJsonKey()).split(":").at(0).toStdString();
if(modName != "core")
result[modName] = VLC->modh->getModInfo(modName).getVerificationInfo();
auto modScope = handler->getModScope();
if(modScope != "core")
result[modScope] = VLC->modh->getModInfo(modScope).getVerificationInfo();
if(obj->ID == Obj::TOWN || obj->ID == Obj::RANDOM_TOWN)
{
auto town = dynamic_cast<CGTownInstance *>(obj.get());
for(const auto & spellID : town->possibleSpells)
{
if(spellID == SpellID::PRESET)
continue;
extractEntityMod(spellID.toEntity(VLC));
}
for(const auto & spellID : town->obligatorySpells)
{
extractEntityMod(spellID.toEntity(VLC));
}
}
if(obj->ID == Obj::HERO || obj->ID == Obj::RANDOM_HERO)
{
auto hero = dynamic_cast<CGHeroInstance *>(obj.get());
for(const auto & spellID : hero->getSpellsInSpellbook())
{
if(spellID == SpellID::PRESET || spellID == SpellID::SPELLBOOK_PRESET)
continue;
extractEntityMod(spellID.toEntity(VLC));
}
}
}
//TODO: terrains?
//TODO: terrains, artifacts?
return result;
}

View File

@ -27,6 +27,7 @@ public:
MOCK_CONST_METHOD0(getIndex, int32_t());
MOCK_CONST_METHOD0(getIconIndex, int32_t());
MOCK_CONST_METHOD0(getJsonKey, std::string ());
MOCK_CONST_METHOD0(getModScope, std::string ());
MOCK_CONST_METHOD0(getName, const std::string &());
MOCK_CONST_METHOD0(getId, CreatureID());
MOCK_CONST_METHOD0(getBonusBearer, const IBonusBearer *());

View File

@ -27,6 +27,7 @@ public:
MOCK_CONST_METHOD0(getIndex, int32_t());
MOCK_CONST_METHOD0(getIconIndex, int32_t());
MOCK_CONST_METHOD0(getJsonKey, std::string ());
MOCK_CONST_METHOD0(getModScope, std::string ());
MOCK_CONST_METHOD0(getName, const std::string &());
MOCK_CONST_METHOD0(getId, SpellID());
MOCK_CONST_METHOD0(getLevel, int32_t());