From f3c46dbf11ada91b0da8de506cb5308a7242bb33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 21 Apr 2017 22:23:00 +0200 Subject: NOISSUE silly/simple implementation of mod metadata in OneSix version format --- api/logic/minecraft/MinecraftProfile.cpp | 33 ++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'api/logic/minecraft/MinecraftProfile.cpp') diff --git a/api/logic/minecraft/MinecraftProfile.cpp b/api/logic/minecraft/MinecraftProfile.cpp index a82d892f..5f1a9f26 100644 --- a/api/logic/minecraft/MinecraftProfile.cpp +++ b/api/logic/minecraft/MinecraftProfile.cpp @@ -457,12 +457,12 @@ void MinecraftProfile::applyJarMods(const QList& jarMods) this->m_jarMods.append(jarMods); } -static int findLibraryByName(QList haystack, const GradleSpecifier &needle) +static int findLibraryByName(QList *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 haystack, const GradleSpecifier & return retval; } +void MinecraftProfile::applyMods(const QList& mods) +{ + QList * 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) { -- cgit v1.2.3