refactor(mod): ModInfo -> LocalMod

This commit is contained in:
huanghongxun
2021-10-04 16:48:50 +08:00
parent bb6bd86e71
commit 31327d685b
21 changed files with 343 additions and 285 deletions

View File

@@ -24,7 +24,7 @@ import javafx.scene.Node;
import javafx.scene.layout.BorderPane;
import org.jackhuang.hmcl.download.*;
import org.jackhuang.hmcl.download.game.GameRemoteVersion;
import org.jackhuang.hmcl.mod.RemoteModRepository;
import org.jackhuang.hmcl.mod.RemoteMod;
import org.jackhuang.hmcl.mod.curse.CurseForgeRemoteModRepository;
import org.jackhuang.hmcl.setting.DownloadProviders;
import org.jackhuang.hmcl.setting.Profile;
@@ -154,7 +154,7 @@ public class DownloadPage extends BorderPane implements DecoratorPage {
setCenter(transitionPane);
}
private void download(Profile profile, @Nullable String version, RemoteModRepository.Version file, String subdirectoryName) {
private void download(Profile profile, @Nullable String version, RemoteMod.Version file, String subdirectoryName) {
if (version == null) version = profile.getSelectedVersion();
Path runDirectory = profile.getRepository().hasVersion(version) ? profile.getRepository().getRunDirectory(version).toPath() : profile.getRepository().getBaseDirectory().toPath();

View File

@@ -40,6 +40,7 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import org.jackhuang.hmcl.game.GameVersion;
import org.jackhuang.hmcl.game.Version;
import org.jackhuang.hmcl.mod.RemoteMod;
import org.jackhuang.hmcl.mod.RemoteModRepository;
import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.task.Schedulers;
@@ -74,7 +75,7 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP
private final BooleanProperty failed = new SimpleBooleanProperty(false);
private final boolean versionSelection;
private final ObjectProperty<Profile.ProfileVersion> version = new SimpleObjectProperty<>();
private final ListProperty<RemoteModRepository.Mod> items = new SimpleListProperty<>(this, "items", FXCollections.observableArrayList());
private final ListProperty<RemoteMod> items = new SimpleListProperty<>(this, "items", FXCollections.observableArrayList());
private final ObservableList<String> versions = FXCollections.observableArrayList();
private final StringProperty selectedVersion = new SimpleStringProperty();
private final DownloadPage.DownloadCallback callback;
@@ -351,16 +352,16 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP
}
}, getSkinnable().failedProperty()));
JFXListView<RemoteModRepository.Mod> listView = new JFXListView<>();
JFXListView<RemoteMod> listView = new JFXListView<>();
spinnerPane.setContent(listView);
Bindings.bindContent(listView.getItems(), getSkinnable().items);
listView.setOnMouseClicked(e -> {
if (listView.getSelectionModel().getSelectedIndex() < 0)
return;
RemoteModRepository.Mod selectedItem = listView.getSelectionModel().getSelectedItem();
RemoteMod selectedItem = listView.getSelectionModel().getSelectedItem();
Controllers.navigate(new DownloadPage(getSkinnable(), selectedItem, getSkinnable().getProfileVersion(), getSkinnable().callback));
});
listView.setCellFactory(x -> new FloatListCell<RemoteModRepository.Mod>(listView) {
listView.setCellFactory(x -> new FloatListCell<RemoteMod>(listView) {
TwoLineListItem content = new TwoLineListItem();
ImageView imageView = new ImageView();
@@ -373,7 +374,7 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP
}
@Override
protected void updateControl(RemoteModRepository.Mod dataItem, boolean empty) {
protected void updateControl(RemoteMod dataItem, boolean empty) {
if (empty) return;
ModTranslations.Mod mod = ModTranslations.getModByCurseForgeId(dataItem.getSlug());
content.setTitle(mod != null ? mod.getDisplayName() : dataItem.getTitle());

View File

@@ -37,7 +37,7 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.stage.FileChooser;
import org.jackhuang.hmcl.mod.ModManager;
import org.jackhuang.hmcl.mod.RemoteModRepository;
import org.jackhuang.hmcl.mod.RemoteMod;
import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.task.FileDownloadTask;
@@ -69,16 +69,16 @@ public class DownloadPage extends Control implements DecoratorPage {
private final BooleanProperty loaded = new SimpleBooleanProperty(false);
private final BooleanProperty loading = new SimpleBooleanProperty(false);
private final BooleanProperty failed = new SimpleBooleanProperty(false);
private final RemoteModRepository.Mod addon;
private final RemoteMod addon;
private final ModTranslations.Mod mod;
private final Profile.ProfileVersion version;
private final DownloadCallback callback;
private final DownloadListPage page;
private List<RemoteModRepository.Mod> dependencies;
private SimpleMultimap<String, RemoteModRepository.Version> versions;
private List<RemoteMod> dependencies;
private SimpleMultimap<String, RemoteMod.Version> versions;
public DownloadPage(DownloadListPage page, RemoteModRepository.Mod addon, Profile.ProfileVersion version, @Nullable DownloadCallback callback) {
public DownloadPage(DownloadListPage page, RemoteMod addon, Profile.ProfileVersion version, @Nullable DownloadCallback callback) {
this.page = page;
this.addon = addon;
this.mod = ModTranslations.getModByCurseForgeId(addon.getSlug());
@@ -95,7 +95,7 @@ public class DownloadPage extends Control implements DecoratorPage {
Task.allOf(
Task.supplyAsync(() -> addon.getData().loadDependencies()),
Task.supplyAsync(() -> {
Stream<RemoteModRepository.Version> versions = addon.getData().loadVersions();
Stream<RemoteMod.Version> versions = addon.getData().loadVersions();
// if (StringUtils.isNotBlank(version.getVersion())) {
// Optional<String> gameVersion = GameVersion.minecraftVersion(versionJar);
// if (gameVersion.isPresent()) {
@@ -108,9 +108,9 @@ public class DownloadPage extends Control implements DecoratorPage {
.whenComplete(Schedulers.javafx(), (result, exception) -> {
if (exception == null) {
@SuppressWarnings("unchecked")
List<RemoteModRepository.Mod> dependencies = (List<RemoteModRepository.Mod>) result.get(0);
List<RemoteMod> dependencies = (List<RemoteMod>) result.get(0);
@SuppressWarnings("unchecked")
SimpleMultimap<String, RemoteModRepository.Version> versions = (SimpleMultimap<String, RemoteModRepository.Version>) result.get(1);
SimpleMultimap<String, RemoteMod.Version> versions = (SimpleMultimap<String, RemoteMod.Version>) result.get(1);
this.dependencies = dependencies;
this.versions = versions;
@@ -126,9 +126,9 @@ public class DownloadPage extends Control implements DecoratorPage {
this.state.set(State.fromTitle(addon.getTitle()));
}
private SimpleMultimap<String, RemoteModRepository.Version> sortVersions(Stream<RemoteModRepository.Version> versions) {
SimpleMultimap<String, RemoteModRepository.Version> classifiedVersions
= new SimpleMultimap<String, RemoteModRepository.Version>(HashMap::new, ArrayList::new);
private SimpleMultimap<String, RemoteMod.Version> sortVersions(Stream<RemoteMod.Version> versions) {
SimpleMultimap<String, RemoteMod.Version> classifiedVersions
= new SimpleMultimap<String, RemoteMod.Version>(HashMap::new, ArrayList::new);
versions.forEach(version -> {
for (String gameVersion : version.getGameVersions()) {
classifiedVersions.put(gameVersion, version);
@@ -136,13 +136,13 @@ public class DownloadPage extends Control implements DecoratorPage {
});
for (String gameVersion : classifiedVersions.keys()) {
List<RemoteModRepository.Version> versionList = (List<RemoteModRepository.Version>) classifiedVersions.get(gameVersion);
versionList.sort(Comparator.comparing(RemoteModRepository.Version::getDatePublished).reversed());
List<RemoteMod.Version> versionList = (List<RemoteMod.Version>) classifiedVersions.get(gameVersion);
versionList.sort(Comparator.comparing(RemoteMod.Version::getDatePublished).reversed());
}
return classifiedVersions;
}
public RemoteModRepository.Mod getAddon() {
public RemoteMod getAddon() {
return addon;
}
@@ -174,7 +174,7 @@ public class DownloadPage extends Control implements DecoratorPage {
this.failed.set(failed);
}
public void download(RemoteModRepository.Version file) {
public void download(RemoteMod.Version file) {
if (this.callback == null) {
saveAs(file);
} else {
@@ -182,7 +182,7 @@ public class DownloadPage extends Control implements DecoratorPage {
}
}
public void saveAs(RemoteModRepository.Version file) {
public void saveAs(RemoteMod.Version file) {
String extension = StringUtils.substringAfterLast(file.getFile().getFilename(), '.');
FileChooser fileChooser = new FileChooser();
@@ -328,7 +328,7 @@ public class DownloadPage extends Control implements DecoratorPage {
private static final class DependencyModItem extends StackPane {
DependencyModItem(DownloadListPage page, RemoteModRepository.Mod addon, Profile.ProfileVersion version, DownloadCallback callback) {
DependencyModItem(DownloadListPage page, RemoteMod addon, Profile.ProfileVersion version, DownloadCallback callback) {
HBox pane = new HBox(8);
pane.setPadding(new Insets(8));
pane.setAlignment(Pos.CENTER_LEFT);
@@ -355,7 +355,7 @@ public class DownloadPage extends Control implements DecoratorPage {
}
private static final class ModItem extends StackPane {
ModItem(RemoteModRepository.Version dataItem, DownloadPage selfPage) {
ModItem(RemoteMod.Version dataItem, DownloadPage selfPage) {
HBox pane = new HBox(8);
pane.setPadding(new Insets(8));
pane.setAlignment(Pos.CENTER_LEFT);
@@ -399,6 +399,6 @@ public class DownloadPage extends Control implements DecoratorPage {
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).withLocale(Locale.getDefault()).withZone(ZoneId.systemDefault());
public interface DownloadCallback {
void download(Profile profile, @Nullable String version, RemoteModRepository.Version file);
void download(Profile profile, @Nullable String version, RemoteMod.Version file);
}
}

View File

@@ -17,6 +17,7 @@
*/
package org.jackhuang.hmcl.ui.versions;
import org.jackhuang.hmcl.mod.RemoteMod;
import org.jackhuang.hmcl.mod.RemoteModRepository;
import org.jackhuang.hmcl.mod.curse.CurseForgeRemoteModRepository;
import org.jackhuang.hmcl.mod.modrinth.ModrinthRemoteModRepository;
@@ -46,7 +47,7 @@ public class ModDownloadListPage extends DownloadListPage {
private class Repository implements RemoteModRepository {
@Override
public Stream<Mod> search(String gameVersion, Category category, int pageOffset, int pageSize, String searchFilter, int sort) throws IOException {
public Stream<RemoteMod> search(String gameVersion, Category category, int pageOffset, int pageSize, String searchFilter, int sort) throws IOException {
String newSearchFilter;
if (StringUtils.CHINESE_PATTERN.matcher(searchFilter).find()) {
List<ModTranslations.Mod> mods = ModTranslations.searchMod(searchFilter);
@@ -76,7 +77,7 @@ public class ModDownloadListPage extends DownloadListPage {
}
@Override
public Optional<Version> getRemoteVersionByLocalFile(Path file) {
public Optional<RemoteMod.Version> getRemoteVersionByLocalFile(Path file) {
throw new UnsupportedOperationException();
}

View File

@@ -24,7 +24,7 @@ import javafx.collections.ObservableList;
import javafx.scene.control.Skin;
import javafx.stage.FileChooser;
import org.jackhuang.hmcl.download.LibraryAnalyzer;
import org.jackhuang.hmcl.mod.ModInfo;
import org.jackhuang.hmcl.mod.LocalMod;
import org.jackhuang.hmcl.mod.ModManager;
import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.task.Schedulers;
@@ -151,7 +151,7 @@ public final class ModListPage extends ListPageBase<ModListPageSkin.ModInfoObjec
modManager.removeMods(selectedItems.stream()
.filter(Objects::nonNull)
.map(ModListPageSkin.ModInfoObject::getModInfo)
.toArray(ModInfo[]::new));
.toArray(LocalMod[]::new));
loadMods(modManager);
} catch (IOException ignore) {
// Fail to remove mods if the game is running or the mod is absent.

View File

@@ -34,7 +34,7 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import org.jackhuang.hmcl.mod.ModInfo;
import org.jackhuang.hmcl.mod.LocalMod;
import org.jackhuang.hmcl.mod.ModManager;
import org.jackhuang.hmcl.setting.Theme;
import org.jackhuang.hmcl.task.Schedulers;
@@ -124,34 +124,34 @@ class ModListPageSkin extends SkinBase<ModListPage> {
static class ModInfoObject extends RecursiveTreeObject<ModInfoObject> implements Comparable<ModInfoObject> {
private final BooleanProperty active;
private final ModInfo modInfo;
private final LocalMod localMod;
private final String message;
private final ModTranslations.Mod mod;
ModInfoObject(ModInfo modInfo) {
this.modInfo = modInfo;
this.active = modInfo.activeProperty();
StringBuilder message = new StringBuilder(modInfo.getName());
if (isNotBlank(modInfo.getVersion()))
message.append(", ").append(i18n("archive.version")).append(": ").append(modInfo.getVersion());
if (isNotBlank(modInfo.getGameVersion()))
message.append(", ").append(i18n("archive.game_version")).append(": ").append(modInfo.getGameVersion());
if (isNotBlank(modInfo.getAuthors()))
message.append(", ").append(i18n("archive.author")).append(": ").append(modInfo.getAuthors());
ModInfoObject(LocalMod localMod) {
this.localMod = localMod;
this.active = localMod.activeProperty();
StringBuilder message = new StringBuilder(localMod.getName());
if (isNotBlank(localMod.getVersion()))
message.append(", ").append(i18n("archive.version")).append(": ").append(localMod.getVersion());
if (isNotBlank(localMod.getGameVersion()))
message.append(", ").append(i18n("archive.game_version")).append(": ").append(localMod.getGameVersion());
if (isNotBlank(localMod.getAuthors()))
message.append(", ").append(i18n("archive.author")).append(": ").append(localMod.getAuthors());
this.message = message.toString();
this.mod = ModTranslations.getModById(modInfo.getId());
this.mod = ModTranslations.getModById(localMod.getId());
}
String getTitle() {
return modInfo.getFileName();
return localMod.getFileName();
}
String getSubtitle() {
return message;
}
ModInfo getModInfo() {
return modInfo;
LocalMod getModInfo() {
return localMod;
}
public ModTranslations.Mod getMod() {
@@ -160,7 +160,7 @@ class ModListPageSkin extends SkinBase<ModListPage> {
@Override
public int compareTo(@NotNull ModListPageSkin.ModInfoObject o) {
return modInfo.getFileName().toLowerCase().compareTo(o.modInfo.getFileName().toLowerCase());
return localMod.getFileName().toLowerCase().compareTo(o.localMod.getFileName().toLowerCase());
}
}

View File

@@ -25,7 +25,7 @@ import org.jackhuang.hmcl.download.game.GameAssetDownloadTask;
import org.jackhuang.hmcl.game.GameDirectoryType;
import org.jackhuang.hmcl.game.GameRepository;
import org.jackhuang.hmcl.game.LauncherHelper;
import org.jackhuang.hmcl.mod.RemoteModRepository;
import org.jackhuang.hmcl.mod.RemoteMod;
import org.jackhuang.hmcl.setting.Accounts;
import org.jackhuang.hmcl.setting.Profile;
import org.jackhuang.hmcl.setting.Profiles;
@@ -77,7 +77,7 @@ public final class Versions {
}
}
public static void downloadModpackImpl(Profile profile, String version, RemoteModRepository.Version file) {
public static void downloadModpackImpl(Profile profile, String version, RemoteMod.Version file) {
Path modpack;
URL downloadURL;
try {