2015-06-13 16:08:31 +00:00
|
|
|
#include "soundgencheck.hpp"
|
|
|
|
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <string>
|
|
|
|
|
2018-06-19 22:20:03 +00:00
|
|
|
#include "../prefs/state.hpp"
|
|
|
|
|
2015-06-13 16:08:31 +00:00
|
|
|
#include "../world/refiddata.hpp"
|
|
|
|
#include "../world/universalid.hpp"
|
|
|
|
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <apps/opencs/model/doc/messages.hpp>
|
|
|
|
#include <apps/opencs/model/prefs/category.hpp>
|
|
|
|
#include <apps/opencs/model/prefs/setting.hpp>
|
|
|
|
#include <apps/opencs/model/world/idcollection.hpp>
|
|
|
|
#include <apps/opencs/model/world/record.hpp>
|
|
|
|
#include <apps/opencs/model/world/refidcollection.hpp>
|
|
|
|
|
2022-08-19 17:19:42 +00:00
|
|
|
#include <components/esm3/loadsndg.hpp>
|
|
|
|
#include <components/esm3/loadsoun.hpp>
|
|
|
|
|
2015-06-13 16:08:31 +00:00
|
|
|
CSMTools::SoundGenCheckStage::SoundGenCheckStage(const CSMWorld::IdCollection<ESM::SoundGenerator>& soundGens,
|
|
|
|
const CSMWorld::IdCollection<ESM::Sound>& sounds, const CSMWorld::RefIdCollection& objects)
|
|
|
|
: mSoundGens(soundGens)
|
|
|
|
, mSounds(sounds)
|
2018-08-24 17:20:27 +00:00
|
|
|
, mObjects(objects)
|
2018-06-19 22:20:03 +00:00
|
|
|
{
|
2018-06-20 09:29:38 +00:00
|
|
|
mIgnoreBaseRecords = false;
|
2018-06-19 22:20:03 +00:00
|
|
|
}
|
2015-06-13 16:08:31 +00:00
|
|
|
|
|
|
|
int CSMTools::SoundGenCheckStage::setup()
|
|
|
|
{
|
2018-06-19 22:20:03 +00:00
|
|
|
mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue();
|
|
|
|
|
2015-06-13 16:08:31 +00:00
|
|
|
return mSoundGens.getSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSMTools::SoundGenCheckStage::perform(int stage, CSMDoc::Messages& messages)
|
|
|
|
{
|
|
|
|
const CSMWorld::Record<ESM::SoundGenerator>& record = mSoundGens.getRecord(stage);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2018-06-19 22:20:03 +00:00
|
|
|
// Skip "Base" records (setting!) and "Deleted" records
|
2018-06-20 09:29:38 +00:00
|
|
|
if ((mIgnoreBaseRecords && record.mState == CSMWorld::RecordBase::State_BaseOnly) || record.isDeleted())
|
2015-06-13 16:08:31 +00:00
|
|
|
return;
|
|
|
|
|
2016-01-03 17:20:34 +00:00
|
|
|
const ESM::SoundGenerator& soundGen = record.get();
|
2015-06-13 16:08:31 +00:00
|
|
|
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_SoundGen, soundGen.mId);
|
|
|
|
|
2015-06-13 16:47:39 +00:00
|
|
|
if (!soundGen.mCreature.empty())
|
2015-06-13 16:08:31 +00:00
|
|
|
{
|
2018-08-24 17:20:27 +00:00
|
|
|
CSMWorld::RefIdData::LocalIndex creatureIndex = mObjects.getDataSet().searchId(soundGen.mCreature);
|
2015-06-13 16:08:31 +00:00
|
|
|
if (creatureIndex.first == -1)
|
|
|
|
{
|
2022-10-18 07:26:55 +00:00
|
|
|
messages.add(id, "Creature '" + soundGen.mCreature.getRefIdString() + "' doesn't exist", "",
|
|
|
|
CSMDoc::Message::Severity_Error);
|
2015-06-13 16:08:31 +00:00
|
|
|
}
|
|
|
|
else if (creatureIndex.second != CSMWorld::UniversalId::Type_Creature)
|
|
|
|
{
|
2022-10-18 07:26:55 +00:00
|
|
|
messages.add(id, "'" + soundGen.mCreature.getRefIdString() + "' is not a creature", "",
|
|
|
|
CSMDoc::Message::Severity_Error);
|
2015-06-13 16:08:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-13 16:47:39 +00:00
|
|
|
if (soundGen.mSound.empty())
|
|
|
|
{
|
2018-08-25 02:04:49 +00:00
|
|
|
messages.add(id, "Sound is missing", "", CSMDoc::Message::Severity_Error);
|
2015-06-13 16:47:39 +00:00
|
|
|
}
|
|
|
|
else if (mSounds.searchId(soundGen.mSound) == -1)
|
2015-06-13 16:08:31 +00:00
|
|
|
{
|
2022-10-18 07:26:55 +00:00
|
|
|
messages.add(
|
|
|
|
id, "Sound '" + soundGen.mSound.getRefIdString() + "' doesn't exist", "", CSMDoc::Message::Severity_Error);
|
2015-06-13 16:08:31 +00:00
|
|
|
}
|
|
|
|
}
|