NOISSUE silly/simple implementation of mod metadata in OneSix version format
This commit is contained in:
parent
581460dcf9
commit
f3c46dbf11
@ -457,12 +457,12 @@ void MinecraftProfile::applyJarMods(const QList<LibraryPtr>& jarMods)
|
|||||||
this->m_jarMods.append(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;
|
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.
|
// only one is allowed.
|
||||||
if (retval != -1)
|
if (retval != -1)
|
||||||
@ -473,6 +473,31 @@ static int findLibraryByName(QList<LibraryPtr> haystack, const GradleSpecifier &
|
|||||||
return retval;
|
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)
|
void MinecraftProfile::applyLibrary(LibraryPtr library)
|
||||||
{
|
{
|
||||||
if(!library->isActive())
|
if(!library->isActive())
|
||||||
@ -489,7 +514,7 @@ void MinecraftProfile::applyLibrary(LibraryPtr library)
|
|||||||
auto libraryCopy = Library::limitedCopy(library);
|
auto libraryCopy = Library::limitedCopy(library);
|
||||||
|
|
||||||
// find the library by name.
|
// 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.
|
// library not found? just add it.
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
{
|
{
|
||||||
|
@ -99,6 +99,7 @@ public: /* application of profile variables from patches */
|
|||||||
void applyTraits(const QSet<QString> &traits);
|
void applyTraits(const QSet<QString> &traits);
|
||||||
void applyTweakers(const QStringList &tweakers);
|
void applyTweakers(const QStringList &tweakers);
|
||||||
void applyJarMods(const QList<LibraryPtr> &jarMods);
|
void applyJarMods(const QList<LibraryPtr> &jarMods);
|
||||||
|
void applyMods(const QList<LibraryPtr> &jarMods);
|
||||||
void applyLibrary(LibraryPtr library);
|
void applyLibrary(LibraryPtr library);
|
||||||
void applyMainJar(LibraryPtr jar);
|
void applyMainJar(LibraryPtr jar);
|
||||||
void applyProblemSeverity(ProblemSeverity severity);
|
void applyProblemSeverity(ProblemSeverity severity);
|
||||||
@ -179,6 +180,9 @@ private: /* data */
|
|||||||
/// A list of jar mods. version files can add those.
|
/// A list of jar mods. version files can add those.
|
||||||
QList<LibraryPtr> m_jarMods;
|
QList<LibraryPtr> m_jarMods;
|
||||||
|
|
||||||
|
/// the list of mods
|
||||||
|
QList<LibraryPtr> m_mods;
|
||||||
|
|
||||||
ProblemSeverity m_problemSeverity = ProblemSeverity::None;
|
ProblemSeverity m_problemSeverity = ProblemSeverity::None;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -35,6 +35,7 @@ void VersionFile::applyTo(MinecraftProfile *profile)
|
|||||||
profile->applyMinecraftArguments(minecraftArguments);
|
profile->applyMinecraftArguments(minecraftArguments);
|
||||||
profile->applyTweakers(addTweakers);
|
profile->applyTweakers(addTweakers);
|
||||||
profile->applyJarMods(jarMods);
|
profile->applyJarMods(jarMods);
|
||||||
|
profile->applyMods(mods);
|
||||||
profile->applyTraits(traits);
|
profile->applyTraits(traits);
|
||||||
|
|
||||||
for (auto library : libraries)
|
for (auto library : libraries)
|
||||||
|
@ -85,6 +85,9 @@ public: /* data */
|
|||||||
/// MultiMC: list of jar mods added to this version
|
/// MultiMC: list of jar mods added to this version
|
||||||
QList<LibraryPtr> jarMods;
|
QList<LibraryPtr> jarMods;
|
||||||
|
|
||||||
|
/// MultiMC: list of mods added to this version
|
||||||
|
QList<LibraryPtr> mods;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Mojang: DEPRECATED list of 'downloads' - client jar, server jar, windows server exe, maybe more.
|
// Mojang: DEPRECATED list of 'downloads' - client jar, server jar, windows server exe, maybe more.
|
||||||
QMap <QString, std::shared_ptr<MojangDownloadInfo>> mojangDownloads;
|
QMap <QString, std::shared_ptr<MojangDownloadInfo>> mojangDownloads;
|
||||||
|
@ -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)
|
auto readLibs = [&](const char * which)
|
||||||
{
|
{
|
||||||
for (auto libVal : requireArray(root.value(which)))
|
for (auto libVal : requireArray(root.value(which)))
|
||||||
@ -246,6 +258,15 @@ QJsonDocument OneSixVersionFormat::versionFileToJson(const VersionFilePtr &patch
|
|||||||
}
|
}
|
||||||
root.insert("jarMods", array);
|
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.
|
// write the contents to a json document.
|
||||||
{
|
{
|
||||||
QJsonDocument out;
|
QJsonDocument out;
|
||||||
@ -306,3 +327,13 @@ QJsonObject OneSixVersionFormat::jarModtoJson(Library *jarmod)
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LibraryPtr OneSixVersionFormat::modFromJson(const QJsonObject& libObj, const QString& filename)
|
||||||
|
{
|
||||||
|
return libraryFromJson(libObj, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject OneSixVersionFormat::modtoJson(Library *jarmod)
|
||||||
|
{
|
||||||
|
return libraryToJson(jarmod);
|
||||||
|
}
|
||||||
|
@ -22,4 +22,8 @@ public:
|
|||||||
// new jar mods derived from libraries
|
// new jar mods derived from libraries
|
||||||
static LibraryPtr jarModFromJson(const QJsonObject &libObj, const QString &filename);
|
static LibraryPtr jarModFromJson(const QJsonObject &libObj, const QString &filename);
|
||||||
static QJsonObject jarModtoJson(Library * jarmod);
|
static QJsonObject jarModtoJson(Library * jarmod);
|
||||||
|
|
||||||
|
// mods, also derived from libraries
|
||||||
|
static LibraryPtr modFromJson(const QJsonObject &libObj, const QString &filename);
|
||||||
|
static QJsonObject modtoJson(Library * jarmod);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user