2021-08-19 09:30:01 +00:00
|
|
|
#include "idcollection.hpp"
|
|
|
|
|
2022-10-19 17:02:00 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include <apps/opencs/model/world/collection.hpp>
|
|
|
|
#include <apps/opencs/model/world/pathgrid.hpp>
|
|
|
|
#include <apps/opencs/model/world/record.hpp>
|
|
|
|
|
|
|
|
#include <components/esm3/loadpgrd.hpp>
|
|
|
|
|
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
class ESMReader;
|
|
|
|
}
|
|
|
|
|
2021-08-19 09:30:01 +00:00
|
|
|
namespace CSMWorld
|
|
|
|
{
|
2022-09-22 18:26:05 +00:00
|
|
|
template <>
|
|
|
|
int IdCollection<Pathgrid, IdAccessor<Pathgrid>>::load(ESM::ESMReader& reader, bool base)
|
2021-08-19 09:30:01 +00:00
|
|
|
{
|
|
|
|
Pathgrid record;
|
|
|
|
bool isDeleted = false;
|
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
loadRecord(record, reader, isDeleted);
|
2021-08-19 09:30:01 +00:00
|
|
|
|
2022-10-06 17:39:46 +00:00
|
|
|
auto id = IdAccessor<Pathgrid>().getId(record);
|
2022-09-22 18:26:05 +00:00
|
|
|
int index = this->searchId(id);
|
2021-08-19 09:30:01 +00:00
|
|
|
|
|
|
|
if (record.mPoints.empty() || record.mEdges.empty())
|
|
|
|
isDeleted = true;
|
|
|
|
|
|
|
|
if (isDeleted)
|
|
|
|
{
|
2022-09-22 18:26:05 +00:00
|
|
|
if (index == -1)
|
2021-08-19 09:30:01 +00:00
|
|
|
{
|
|
|
|
// deleting a record that does not exist
|
|
|
|
// ignore it for now
|
|
|
|
/// \todo report the problem to the user
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (base)
|
|
|
|
{
|
2022-09-22 18:26:05 +00:00
|
|
|
this->removeRows(index, 1);
|
2021-08-19 09:30:01 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-05-29 11:25:17 +00:00
|
|
|
auto baseRecord = std::make_unique<Record<Pathgrid>>(this->getRecord(index));
|
2021-08-19 09:30:01 +00:00
|
|
|
baseRecord->mState = RecordBase::State_Deleted;
|
|
|
|
this->setRecord(index, std::move(baseRecord));
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
return load(record, base, index);
|
2021-08-19 09:30:01 +00:00
|
|
|
}
|
|
|
|
}
|