This commit is contained in:
Ian Brown 2021-03-17 18:19:20 +00:00
parent 58e9c2920e
commit 3bbe3612fe
5 changed files with 71 additions and 9 deletions

View file

@ -62,6 +62,7 @@ set(SNOWLIB_SRC_FILES
snowlib/AnimData.cpp
snowlib/AnimDecoder.cpp
snowlib/FntDecoder.cpp
snowlib/GameRegion.h
snowlib/GameType.h
snowlib/GIFTag.cpp
snowlib/GobFile.cpp

View file

@ -1,6 +1,7 @@
#include "gameData.h"
#include <QDir>
#include <QDebug>
#include "LmpRepository.h"
#include "GobFile.h"
@ -13,15 +14,19 @@
#include "WorldReader.h"
#include "World.h"
void GameData::read(QString rootDir, QString worldName)
void GameData::read(QString rootDir, QString worldName)
{
this->rootDir = rootDir;
gameType = GameType::UNKNOWN;
findGame(rootDir);
/*
LmpRepository* lmpRepository = new LmpRepositoryImpl(dataPath, GameType::DARK_ALLIANCE);
if (gameType != GameType::UNKNOWN) {
QString lmpDir = rootDir + dataRelPath;
LmpRepository* lmpRepository = new LmpRepositoryImpl(lmpDir.toStdString(), gameType);
GobFile cuttownGob = GobFile(dataPath + "CUTTOWN.GOB", GameType::DARK_ALLIANCE);
World* world = WorldReader().readWorld(&cuttownGob, "cuttown");
*/
QString gobFile = lmpDir + "CUTTOWN.GOB";
GobFile cuttownGob = GobFile(gobFile.toStdString(), gameType);
World* world = WorldReader().readWorld(&cuttownGob, "cuttown");
}
}
void GameData::findGame(QString rootDir)
@ -29,6 +34,35 @@ void GameData::findGame(QString rootDir)
QDir rootDirectory(rootDir);
if (rootDirectory.exists()) {
auto entries = rootDirectory.entryList(QStringList() << "SL*.*");
if (entries.length() == 1) {
auto slFile = entries.first();
findGameFromElf(slFile);
}
else {
qWarning() << "Cannot find SL*.* file in " << rootDir;
}
}
}
void GameData::findGameFromElf(QString elfname)
{
qDebug() << "found elf " << elfname;
if (elfname == "SLES_506.72") {
gameType = GameType::DARK_ALLIANCE;
gameRegion = GameRegion::PAL;
dataRelPath = "BG/DATA";
}
else if (elfname == "SLES_530.39") {
gameType = GameType::CHAMPIONS_RTA;
gameRegion = GameRegion::PAL;
dataRelPath = "BG/DATA";
}
else if (elfname == "SLES_544.23") {
gameType = GameType::JL_HEROES;
gameRegion = GameRegion::PAL;
dataRelPath = "GAME/DATA";
}
else {
qWarning() << "Unknown game: " << elfname;
}
}

View file

@ -2,11 +2,27 @@
#include <QString>
#include "GameType.h"
#include "GameRegion.h"
class GameData
{
public:
GameData() : gameRegion(GameRegion::UNKNOWN), gameType(GameType::UNKNOWN) {}
void read(QString rootDir, QString worldName);
private:
GameRegion gameRegion;
GameType gameType;
/* The directory to the root of the disc, where the elf is located. */
QString rootDir;
/* Relative path from the root where the data files live. */
QString dataRelPath;
private:
void findGame(QString rootDir);
void findGameFromElf(QString elfname);
};

9
snowlib/GameRegion.h Normal file
View file

@ -0,0 +1,9 @@
#pragma once
enum class GameRegion
{
UNKNOWN,
PAL,
NTSC
};

View file

@ -1,10 +1,12 @@
#ifndef GAMETYPE_H_
#define GAMETYPE_H_
enum GameType
enum class GameType
{
UNKNOWN,
DARK_ALLIANCE,
CHAMPIONS_RTA
CHAMPIONS_RTA,
JL_HEROES
};
#endif // GAMETYPE_H_