Skip to content

Commit

Permalink
Opt: Cache RemoteMod.Version
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirosakiMio committed Dec 24, 2024
1 parent 6b42877 commit 46cba9b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

import com.tungsten.fcl.R;
import com.tungsten.fcl.game.LocalizedRemoteModRepository;
import com.tungsten.fcl.setting.Profile;
import com.tungsten.fcl.setting.Profiles;
import com.tungsten.fcl.util.AndroidUtils;
import com.tungsten.fcl.util.RuntimeUtils;
import com.tungsten.fclcore.mod.ModManager;
import com.tungsten.fclcore.mod.RemoteModRepository;
import com.tungsten.fclcore.mod.curse.CurseForgeRemoteModRepository;
import com.tungsten.fclcore.mod.modrinth.ModrinthRemoteModRepository;
Expand All @@ -20,6 +23,7 @@
import java.io.IOException;

public class ModDownloadPage extends DownloadPage {
private ModManager modManager;

public ModDownloadPage(Context context, int id, FCLUILayout parent, int resId) {
super(context, id, parent, resId, null);
Expand Down Expand Up @@ -48,6 +52,16 @@ public ModDownloadPage(Context context, int id, FCLUILayout parent, int resId) {
});
}

@Override
public void loadVersion(Profile profile, String version) {
super.loadVersion(profile, version);
modManager = Profiles.getSelectedProfile().getRepository().getModManager(Profiles.getSelectedVersion());
}

public ModManager getModManager() {
return modManager;
}

private class Repository extends LocalizedRemoteModRepository {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.tungsten.fcl.setting.Profiles;
import com.tungsten.fcl.util.ModTranslations;
import com.tungsten.fclcore.mod.LocalModFile;
import com.tungsten.fclcore.mod.ModManager;
import com.tungsten.fclcore.mod.RemoteMod;
import com.tungsten.fclcore.task.Schedulers;
import com.tungsten.fclcore.task.Task;
Expand Down Expand Up @@ -96,16 +97,21 @@ public View getView(int i, View view, ViewGroup viewGroup) {
if (downloadPage instanceof ModDownloadPage) {
Task.supplyAsync(() -> {
String remoteName = remoteMod.getTitle().replace(" ", "").toLowerCase();
List<LocalModFile> modFiles = Profiles.getSelectedProfile().getRepository().getModManager(Profiles.getSelectedVersion()).getMods().parallelStream().filter(localModFile -> {
ModManager modManager = ((ModDownloadPage) downloadPage).getModManager();
List<LocalModFile> modFiles = modManager.getMods().parallelStream().filter(localModFile -> {
String localName = localModFile.getName().replace(" ", "").toLowerCase();
return remoteName.contains(localName);
}).collect(Collectors.toList());
for (LocalModFile localModFile : modFiles) {
Optional<RemoteMod.Version> remoteVersion = downloadPage.getRepository().getRemoteVersionByLocalFile(localModFile, localModFile.getFile());
if (remoteVersion.isPresent()) {
String modId = remoteVersion.get().getModid();
if (localModFile.getRemoteVersion() == null) {
Optional<RemoteMod.Version> remoteVersionOptional = downloadPage.getRepository().getRemoteVersionByLocalFile(localModFile, localModFile.getFile());
remoteVersionOptional.ifPresent(localModFile::setRemoteVersion);
}
RemoteMod.Version remoteVersion = localModFile.getRemoteVersion();
if (remoteVersion != null) {
String modId = remoteVersion.getModid();
if (remoteMod.getModID().equals(modId)) {
return remoteVersion.get();
return remoteVersion;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public final class LocalModFile implements Comparable<LocalModFile> {
private final String fileName;
private final String logoPath;
private final BooleanProperty activeProperty;
private RemoteMod.Version remoteVersion;

public LocalModFile(ModManager modManager, LocalMod mod, Path file, String name, Description description) {
this(modManager, mod, file, name, description, "", "", "", "", "");
Expand Down Expand Up @@ -198,6 +199,14 @@ public int hashCode() {
return Objects.hash(getFileName());
}

public RemoteMod.Version getRemoteVersion() {
return remoteVersion;
}

public void setRemoteVersion(RemoteMod.Version remoteVersion) {
this.remoteVersion = remoteVersion;
}

public static class ModUpdate {
private final LocalModFile localModFile;
private final RemoteMod.Version currentVersion;
Expand Down

0 comments on commit 46cba9b

Please sign in to comment.