NOISSUE silly/simple implementation of mod metadata in OneSix version format

This commit is contained in:
Petr Mrázek 2017-04-21 22:23:00 +02:00
parent 581460dcf9
commit f3c46dbf11
6 changed files with 72 additions and 4 deletions

View File

@ -457,12 +457,12 @@ void MinecraftProfile::applyJarMods(const QList<LibraryPtr>& jarMods)
this->m_jarMods.append(jarMods);
}
static int findLibraryByName(QList<LibraryPtr> haystack, const GradleSpecifier &needle)
static int findLibraryByName(QList<LibraryPtr> *haystack, const GradleSpecifier &needle)
{
int retval = -1;
for (int i = 0; i < haystack.size(); ++i)
for (int i = 0; i < haystack->size(); ++i)
{
if (haystack.at(i)->rawName().matchName(needle))
if (haystack->at(i)->rawName().matchName(needle))
{
// only one is allowed.
if (retval != -1)
@ -473,6 +473,31 @@ static int findLibraryByName(QList<LibraryPtr> haystack, const GradleSpecifier &
return retval;
}
void MinecraftProfile::applyMods(const QList<LibraryPtr>& mods)
{
QList<LibraryPtr> * list = &m_mods;
for(auto & mod: mods)
{
auto modCopy = Library::limitedCopy(mod);
// find the mod by name.
const int index = findLibraryByName(list, mod->rawName());
// mod not found? just add it.
if (index < 0)
{
list->append(modCopy);
return;
}
auto existingLibrary = list->at(index);
// if we are higher it means we should update
if (Version(mod->version()) > Version(existingLibrary->version()))
{
list->replace(index, modCopy);
}
}
}
void MinecraftProfile::applyLibrary(LibraryPtr library)
{
if(!library->isActive())
@ -489,7 +514,7 @@ void MinecraftProfile::applyLibrary(LibraryPtr library)
auto libraryCopy = Library::limitedCopy(library);
// find the library by name.
const int index = findLibraryByName(*list, library->rawName());
const int index = findLibraryByName(list, library->rawName());
// library not found? just add it.
if (index < 0)
{

View File

@ -99,6 +99,7 @@ public: /* application of profile variables from patches */
void applyTraits(const QSet<QString> &traits);
void applyTweakers(const QStringList &tweakers);
void applyJarMods(const QList<LibraryPtr> &jarMods);
void applyMods(const QList<LibraryPtr> &jarMods);
void applyLibrary(LibraryPtr library);
void applyMainJar(LibraryPtr jar);
void applyProblemSeverity(ProblemSeverity severity);
@ -179,6 +180,9 @@ private: /* data */
/// A list of jar mods. version files can add those.
QList<LibraryPtr> m_jarMods;
/// the list of mods
QList<LibraryPtr> m_mods;
ProblemSeverity m_problemSeverity = ProblemSeverity::None;
/*

View File

@ -35,6 +35,7 @@ void VersionFile::applyTo(MinecraftProfile *profile)
profile->applyMinecraftArguments(minecraftArguments);
profile->applyTweakers(addTweakers);
profile->applyJarMods(jarMods);
profile->applyMods(mods);
profile->applyTraits(traits);
for (auto library : libraries)

View File

@ -85,6 +85,9 @@ public: /* data */
/// MultiMC: list of jar mods added to this version
QList<LibraryPtr> jarMods;
/// MultiMC: list of mods added to this version
QList<LibraryPtr> mods;
public:
// Mojang: DEPRECATED list of 'downloads' - client jar, server jar, windows server exe, maybe more.
QMap <QString, std::shared_ptr<MojangDownloadInfo>> mojangDownloads;

View File

@ -126,6 +126,18 @@ VersionFilePtr OneSixVersionFormat::versionFileFromJson(const QJsonDocument &doc
}
}
if (root.contains("mods"))
{
for (auto libVal : requireArray(root.value("mods")))
{
QJsonObject libObj = requireObject(libVal);
// parse the jarmod
auto lib = OneSixVersionFormat::modFromJson(libObj, filename);
// and add to jar mods
out->mods.append(lib);
}
}
auto readLibs = [&](const char * which)
{
for (auto libVal : requireArray(root.value(which)))
@ -246,6 +258,15 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch
}
root.insert("jarMods", array);
}
if (!patch->mods.isEmpty())
{
QJsonArray array;
for (auto value: patch->jarMods)
{
array.append(OneSixVersionFormat::modtoJson(value.get()));
}
root.insert("mods", array);
}
// write the contents to a json document.
{
QJsonDocument out;
@ -306,3 +327,13 @@ QJsonObject OneSixVersionFormat::jarModtoJson(Library *jarmod)
}
return out;
}
LibraryPtr OneSixVersionFormat::modFromJson(const QJsonObject& libObj, const QString& filename)
{
return libraryFromJson(libObj, filename);
}
QJsonObject OneSixVersionFormat::modtoJson(Library *jarmod)
{
return libraryToJson(jarmod);
}

View File

@ -22,4 +22,8 @@ public:
// new jar mods derived from libraries
static LibraryPtr jarModFromJson(const QJsonObject &libObj, const QString &filename);
static QJsonObject jarModtoJson(Library * jarmod);
// mods, also derived from libraries
static LibraryPtr modFromJson(const QJsonObject &libObj, const QString &filename);
static QJsonObject modtoJson(Library * jarmod);
};