Auto-detect more version names
This commit is contained in:
parent
db598a43db
commit
29ed696d9e
4 changed files with 41 additions and 23 deletions
|
@ -158,6 +158,7 @@ private:
|
|||
extern PorymapConfig porymapConfig;
|
||||
|
||||
enum BaseGameVersion {
|
||||
none,
|
||||
pokeruby,
|
||||
pokefirered,
|
||||
pokeemerald,
|
||||
|
@ -303,7 +304,7 @@ public:
|
|||
static const QMap<ProjectIdentifier, QPair<QString, QString>> defaultIdentifiers;
|
||||
static const QMap<ProjectFilePath, QPair<QString, QString>> defaultPaths;
|
||||
static const QStringList versionStrings;
|
||||
static BaseGameVersion stringToBaseGameVersion(QString string, bool * ok = nullptr);
|
||||
static BaseGameVersion stringToBaseGameVersion(const QString &string);
|
||||
|
||||
void reset(BaseGameVersion baseGameVersion);
|
||||
void setFilePath(ProjectFilePath pathId, const QString &path);
|
||||
|
|
|
@ -608,20 +608,32 @@ const QMap<BaseGameVersion, QString> baseGameVersionMap = {
|
|||
{BaseGameVersion::pokeemerald, ProjectConfig::versionStrings[2]},
|
||||
};
|
||||
|
||||
const QMap<QString, BaseGameVersion> baseGameVersionReverseMap = {
|
||||
{ProjectConfig::versionStrings[0], BaseGameVersion::pokeruby},
|
||||
{ProjectConfig::versionStrings[1], BaseGameVersion::pokefirered},
|
||||
{ProjectConfig::versionStrings[2], BaseGameVersion::pokeemerald},
|
||||
const QMap<BaseGameVersion, QStringList> versionDetectNames = {
|
||||
{BaseGameVersion::pokeruby, {"ruby", "sapphire"}},
|
||||
{BaseGameVersion::pokefirered, {"firered", "leafgreen"}},
|
||||
{BaseGameVersion::pokeemerald, {"emerald"}},
|
||||
};
|
||||
|
||||
BaseGameVersion ProjectConfig::stringToBaseGameVersion(QString string, bool * ok) {
|
||||
if (baseGameVersionReverseMap.contains(string)) {
|
||||
if (ok) *ok = true;
|
||||
return baseGameVersionReverseMap.value(string);
|
||||
} else {
|
||||
if (ok) *ok = false;
|
||||
return BaseGameVersion::pokeemerald;
|
||||
// If a string exclusively contains one version name we assume its identity,
|
||||
// otherwise we leave it unknown and we'll need the user to tell us the version.
|
||||
BaseGameVersion ProjectConfig::stringToBaseGameVersion(const QString &string) {
|
||||
BaseGameVersion version = BaseGameVersion::none;
|
||||
for (auto i = versionDetectNames.cbegin(), end = versionDetectNames.cend(); i != end; i++) {
|
||||
// Compare the given string to all the possible names for this game version
|
||||
const QStringList names = i.value();
|
||||
for (auto name : names) {
|
||||
if (string.contains(name)) {
|
||||
if (version != BaseGameVersion::none) {
|
||||
// The given string matches multiple versions, so we can't be sure which it is.
|
||||
return BaseGameVersion::none;
|
||||
}
|
||||
version = i.key();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// We finished checking the names for each version; the name either matched 1 version or none.
|
||||
return version;
|
||||
}
|
||||
|
||||
ProjectConfig projectConfig;
|
||||
|
@ -633,10 +645,11 @@ QString ProjectConfig::getConfigFilepath() {
|
|||
|
||||
void ProjectConfig::parseConfigKeyValue(QString key, QString value) {
|
||||
if (key == "base_game_version") {
|
||||
bool ok;
|
||||
this->baseGameVersion = this->stringToBaseGameVersion(value.toLower(), &ok);
|
||||
if (!ok)
|
||||
this->baseGameVersion = this->stringToBaseGameVersion(value.toLower());
|
||||
if (this->baseGameVersion == BaseGameVersion::none) {
|
||||
logWarn(QString("Invalid config value for base_game_version: '%1'. Must be 'pokeruby', 'pokefirered' or 'pokeemerald'.").arg(value));
|
||||
this->baseGameVersion = BaseGameVersion::pokeemerald;
|
||||
}
|
||||
} else if (key == "use_poryscript") {
|
||||
this->usePoryScript = getConfigBool(key, value);
|
||||
} else if (key == "use_custom_border_size") {
|
||||
|
@ -851,10 +864,11 @@ QMap<QString, QString> ProjectConfig::getKeyValueMap() {
|
|||
|
||||
void ProjectConfig::init() {
|
||||
QString dirName = QDir(this->projectDir).dirName().toLower();
|
||||
if (baseGameVersionReverseMap.contains(dirName)) {
|
||||
// TODO: Improve detection (ex: emerald or pokeemerald-2 aren't currently auto-detected)
|
||||
this->baseGameVersion = baseGameVersionReverseMap.value(dirName);
|
||||
logInfo(QString("Auto-detected base_game_version as '%1'").arg(dirName));
|
||||
|
||||
BaseGameVersion version = stringToBaseGameVersion(dirName);
|
||||
if (version != BaseGameVersion::none) {
|
||||
this->baseGameVersion = version;
|
||||
logInfo(QString("Auto-detected base_game_version as '%1'").arg(getBaseGameVersionString(version)));
|
||||
} else {
|
||||
QDialog dialog(nullptr, Qt::WindowTitleHint);
|
||||
dialog.setWindowTitle("Project Configuration");
|
||||
|
|
|
@ -338,6 +338,9 @@ bool Prefab::tryImportDefaultPrefabs(QWidget * parent, BaseGameVersion version,
|
|||
case BaseGameVersion::pokeemerald:
|
||||
content = parser.readTextFile(":/text/prefabs_default_emerald.json");
|
||||
break;
|
||||
default:
|
||||
content = QString();
|
||||
break;
|
||||
}
|
||||
|
||||
prefabsFile.write(content.toUtf8());
|
||||
|
|
|
@ -206,14 +206,14 @@ poryjson::Json RegionMapEditor::buildDefaultJson() {
|
|||
case BaseGameVersion::pokeemerald:
|
||||
buildEmeraldDefaults(defaultJson);
|
||||
break;
|
||||
|
||||
case BaseGameVersion::pokeruby:
|
||||
buildRubyDefaults(defaultJson);
|
||||
break;
|
||||
|
||||
case BaseGameVersion::pokefirered:
|
||||
buildFireredDefaults(defaultJson);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return defaultJson;
|
||||
|
@ -315,7 +315,7 @@ bool RegionMapEditor::buildConfigDialog() {
|
|||
QPushButton *delMapButton = new QPushButton("Delete Selected Region Map");
|
||||
form.addRow(delMapButton);
|
||||
|
||||
connect(delMapButton, &QPushButton::clicked, [this, regionMapList, &updateJsonFromList] {
|
||||
connect(delMapButton, &QPushButton::clicked, [regionMapList, &updateJsonFromList] {
|
||||
QListWidgetItem *item = regionMapList->currentItem();
|
||||
if (item) {
|
||||
regionMapList->removeItemWidget(item);
|
||||
|
@ -344,7 +344,7 @@ bool RegionMapEditor::buildConfigDialog() {
|
|||
|
||||
|
||||
// for sake of convenience, option to just use defaults for each basegame version
|
||||
QPushButton *config_useProjectDefault;
|
||||
QPushButton *config_useProjectDefault = nullptr;
|
||||
switch (projectConfig.baseGameVersion) {
|
||||
case BaseGameVersion::pokefirered:
|
||||
config_useProjectDefault = new QPushButton("\nUse pokefirered defaults\n");
|
||||
|
|
Loading…
Reference in a new issue