Merge pull request #597 from manongjohn/fix_reading_filenames_from_file

Fix loading scenes from Story Planner
This commit is contained in:
manongjohn 2022-04-05 15:54:46 -04:00 committed by GitHub
commit 80e2b1794e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View file

@ -35,7 +35,8 @@ TLevelReader::TLevelReader(const TFilePath &path)
, m_info(0) , m_info(0)
, m_path(path) , m_path(path)
, m_contentHistory(0) , m_contentHistory(0)
, m_frameFormat(TFrameId::FOUR_ZEROS) {} , m_frameFormat(TFrameId::FOUR_ZEROS)
, m_useExactPath(false) {}
//----------------------------------------------------------- //-----------------------------------------------------------
@ -102,6 +103,9 @@ const TImageInfo *TLevelReader::getImageInfo() {
TLevelP TLevelReader::loadInfo() { TLevelP TLevelReader::loadInfo() {
TFilePath parentDir = m_path.getParentDir(); TFilePath parentDir = m_path.getParentDir();
TFilePath levelName(m_path.getLevelName()); TFilePath levelName(m_path.getLevelName());
// For scene loading, use what was stored in the file instead
// of auto converting to a level name.
if (useExactPath()) levelName = m_path.withoutParentDir();
// cout << "Parent dir = '" << parentDir << "'" << endl; // cout << "Parent dir = '" << parentDir << "'" << endl;
// cout << "Level name = '" << levelName << "'" << endl; // cout << "Level name = '" << levelName << "'" << endl;
TFilePathSet files; TFilePathSet files;
@ -115,9 +119,13 @@ TLevelP TLevelReader::loadInfo() {
for (TFilePathSet::iterator it = files.begin(); it != files.end(); it++) { for (TFilePathSet::iterator it = files.begin(); it != files.end(); it++) {
TFilePath ln(it->getLevelName()); TFilePath ln(it->getLevelName());
// cout << "try " << *it << " " << it->getLevelName() << endl; // cout << "try " << *it << " " << it->getLevelName() << endl;
if (levelName == TFilePath(it->getLevelName())) { if (levelName == TFilePath(it->getLevelName()) ||
levelName == it->withoutParentDir()) {
try { try {
level->setFrame(it->getFrame(), TImageP()); if (levelName == it->withoutParentDir())
level->setFrame(TFrameId::NO_FRAME, TImageP());
else
level->setFrame(it->getFrame(), TImageP());
data.push_back(*it); data.push_back(*it);
} catch (TMalformedFrameException tmfe) { } catch (TMalformedFrameException tmfe) {
// skip frame named incorrectly warning to the user in the message // skip frame named incorrectly warning to the user in the message
@ -163,6 +171,7 @@ TLevelP TLevelReader::loadInfo() {
//----------------------------------------------------------- //-----------------------------------------------------------
TImageReaderP TLevelReader::getFrameReader(TFrameId fid) { TImageReaderP TLevelReader::getFrameReader(TFrameId fid) {
if (fid.isNoFrame()) return TImageReaderP(m_path);
return TImageReaderP(m_path.withFrame(fid, m_frameFormat)); return TImageReaderP(m_path.withFrame(fid, m_frameFormat));
} }

View file

@ -49,6 +49,8 @@ protected:
TFilePath m_path; TFilePath m_path;
TContentHistory *m_contentHistory; TContentHistory *m_contentHistory;
bool m_useExactPath;
public: public:
TLevelReader(const TFilePath &path); TLevelReader(const TFilePath &path);
virtual ~TLevelReader(); virtual ~TLevelReader();
@ -95,6 +97,9 @@ public:
//! TLevelReader keeps the ownership of TContentHistory. Don't delete it //! TLevelReader keeps the ownership of TContentHistory. Don't delete it
const TContentHistory *getContentHistory() const { return m_contentHistory; } const TContentHistory *getContentHistory() const { return m_contentHistory; }
void setUseExactPath(bool useExactPath) { m_useExactPath = useExactPath; }
bool useExactPath() { return m_useExactPath; }
private: private:
TFrameId::FrameFormat m_frameFormat; TFrameId::FrameFormat m_frameFormat;
}; };

View file

@ -1220,6 +1220,8 @@ void TXshSimpleLevel::load() {
TLevelReaderP lr(path); // May throw TLevelReaderP lr(path); // May throw
assert(lr); assert(lr);
lr->setUseExactPath(getScene()->isLoading());
TLevelP level = lr->loadInfo(); TLevelP level = lr->loadInfo();
if (level->getFrameCount() > 0) { if (level->getFrameCount() > 0) {
const TImageInfo *info = lr->getImageInfo(level->begin()->first); const TImageInfo *info = lr->getImageInfo(level->begin()->first);