Skip to content

Commit a5bc9ba

Browse files
authored
Merge pull request #29
Implemented Modlist Importing
2 parents ba5a805 + 34ea4a8 commit a5bc9ba

12 files changed

Lines changed: 84 additions & 61 deletions

File tree

.github/workflows/development-build-win.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ jobs:
5959
directory: Space Engineers Mod Manager-v${{ env.VERSION_INFORMATION }}
6060
filename: "SEMM-v${{ env.VERSION_INFORMATION }}-win.zip"
6161

62-
- name: Upload release
62+
- name: Upload Release
6363
uses: softprops/action-gh-release@v2
6464
with:
6565
prerelease: true
66+
name: ${{ github.ref }}
6667
tag_name: ${{ env.VERSION_INFORMATION }}
6768
files: |
6869
Space Engineers Mod Manager-v${{ env.VERSION_INFORMATION }}/SEMM-v${{ env.VERSION_INFORMATION }}-win.zip

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies {
5656
}
5757

5858
group = 'com.gearshiftgaming.se_mod_manager'
59-
version = '0.2.2'
59+
version = '0.2.3'
6060
description = 'Space-Engineers-Mod-Manager'
6161
java.sourceCompatibility = JavaVersion.VERSION_21
6262

src/main/java/com/gearshiftgaming/se_mod_manager/backend/data/UserDataFileRepository.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,8 @@ public Result<Void> exportModlist(ModlistProfile modlistProfile, File modlistLoc
5959

6060
Result<Void> result = new Result<>();
6161

62-
//We don't want to copy the description.
63-
for(Mod m : copiedProfile.getModList()) {
64-
m.setDescription(null);
65-
}
66-
6762
try(BufferedWriter bw = new BufferedWriter(new FileWriter(modlistLocation))) {
68-
JAXBContext context = JAXBContext.newInstance(UserConfiguration.class);
63+
JAXBContext context = JAXBContext.newInstance(ModlistProfile.class);
6964
Marshaller marshaller = context.createMarshaller();
7065
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
7166
StringWriter sw = new StringWriter();
@@ -81,7 +76,16 @@ public Result<Void> exportModlist(ModlistProfile modlistProfile, File modlistLoc
8176

8277
@Override
8378
public Result<ModlistProfile> importModlist(File modlistLocation) {
84-
//TODO: Implement
85-
return null;
79+
Result<ModlistProfile> modlistProfileResult = new Result<>();
80+
try {
81+
JAXBContext context = JAXBContext.newInstance(ModlistProfile.class);
82+
Unmarshaller unmarshaller = context.createUnmarshaller();
83+
ModlistProfile modlistProfile = (ModlistProfile) unmarshaller.unmarshal(modlistLocation);
84+
modlistProfileResult.addMessage("Successfully loaded mod profile.", ResultType.SUCCESS);
85+
modlistProfileResult.setPayload(modlistProfile);
86+
} catch (JAXBException e) {
87+
modlistProfileResult.addMessage("Failed to load mod profile. Error Details: " + e, ResultType.FAILED);
88+
}
89+
return modlistProfileResult;
8690
}
8791
}

src/main/java/com/gearshiftgaming/se_mod_manager/backend/domain/UserDataService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,4 @@ public Result<Void> exportModlist(ModlistProfile modlistProfile, File saveLocati
4848
public Result<ModlistProfile> importModlist(File saveLocation) {
4949
return userDataFileRepository.importModlist(saveLocation);
5050
}
51-
5251
}

src/main/java/com/gearshiftgaming/se_mod_manager/frontend/domain/UiService.java

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class UiService {
5757
private final ObservableList<LogMessage> USER_LOG;
5858

5959
@Getter
60-
private final ObservableList<ModlistProfile> MOD_PROFILES;
60+
private final ObservableList<ModlistProfile> MODLIST_PROFILES;
6161

6262
@Getter
6363
private final ObservableList<SaveProfile> SAVE_PROFILES;
@@ -93,13 +93,13 @@ public class UiService {
9393
private final String MOD_DATE_FORMAT;
9494

9595
public UiService(Logger LOGGER, @NotNull ObservableList<LogMessage> USER_LOG,
96-
@NotNull ObservableList<ModlistProfile> MOD_PROFILES, @NotNull ObservableList<SaveProfile> SAVE_PROFILES,
96+
@NotNull ObservableList<ModlistProfile> MODLIST_PROFILES, @NotNull ObservableList<SaveProfile> SAVE_PROFILES,
9797
StorageController storageController, ModInfoController modInfoController, UserConfiguration USER_CONFIGURATION, @NotNull Properties properties) {
9898

9999
this.LOGGER = LOGGER;
100100
this.MOD_INFO_CONTROLLER = modInfoController;
101101
this.USER_LOG = USER_LOG;
102-
this.MOD_PROFILES = MOD_PROFILES;
102+
this.MODLIST_PROFILES = MODLIST_PROFILES;
103103
this.SAVE_PROFILES = SAVE_PROFILES;
104104
this.STORAGE_CONTROLLER = storageController;
105105
this.USER_CONFIGURATION = USER_CONFIGURATION;
@@ -112,14 +112,14 @@ public UiService(Logger LOGGER, @NotNull ObservableList<LogMessage> USER_LOG,
112112
.findFirst();
113113
if (lastUsedSaveProfile.isPresent()) {
114114
currentSaveProfile = lastUsedSaveProfile.get();
115-
Optional<ModlistProfile> lastUsedModProfile = MOD_PROFILES.stream()
115+
Optional<ModlistProfile> lastUsedModProfile = MODLIST_PROFILES.stream()
116116
.filter(modProfile -> modProfile.getID().equals(currentSaveProfile.getLastUsedModProfile()))
117117
.findFirst();
118-
currentModlistProfile = lastUsedModProfile.orElseGet(MOD_PROFILES::getFirst);
118+
currentModlistProfile = lastUsedModProfile.orElseGet(MODLIST_PROFILES::getFirst);
119119
} else {
120120
log("No previously applied save profile detected.", MessageType.INFO);
121121
currentSaveProfile = SAVE_PROFILES.getFirst();
122-
currentModlistProfile = MOD_PROFILES.getFirst();
122+
currentModlistProfile = MODLIST_PROFILES.getFirst();
123123
}
124124

125125
//A little bit of duplication, but the order of construction is a big different from setCurrentModProfile
@@ -459,9 +459,9 @@ protected List<Result<String>> call() throws ExecutionException, InterruptedExce
459459
} else {
460460
idResult = getModIoModIdFromUrlName(modUrl);
461461
}
462-
if(idResult.isSuccess()) {
462+
if (idResult.isSuccess()) {
463463
Result<Void> duplicateIdResult = ModlistManagerHelper.checkForDuplicateModIoMod(idResult.getPayload(), UiService.this);
464-
if(!duplicateIdResult.isSuccess()) {
464+
if (!duplicateIdResult.isSuccess()) {
465465
idResult.addMessage(duplicateIdResult.getCurrentMessage(), duplicateIdResult.getType());
466466
}
467467
}
@@ -496,7 +496,7 @@ public Task<Result<String>> convertModIoUrlToId(String modUrl) {
496496
@Override
497497
protected Result<String> call() {
498498
Result<String> urltoIdConversionResult = getModIoModIdFromUrlName(modUrl);
499-
if(urltoIdConversionResult.isSuccess()) {
499+
if (urltoIdConversionResult.isSuccess()) {
500500
Result<Void> duplicateIdResult = ModlistManagerHelper.checkForDuplicateModIoMod(modUrl, UiService.this);
501501
if (!duplicateIdResult.isSuccess()) {
502502
urltoIdConversionResult.addMessage(duplicateIdResult.getCurrentMessage(), duplicateIdResult.getType());
@@ -537,6 +537,20 @@ public Result<Void> exportModlist(ModlistProfile modlistProfile, File exportLoca
537537
}
538538

539539
public Result<ModlistProfile> importModlist(File saveLocation) {
540-
return STORAGE_CONTROLLER.importModlist(saveLocation);
540+
Result<ModlistProfile> modlistProfileResult = STORAGE_CONTROLLER.importModlist(saveLocation);
541+
if (modlistProfileResult.isSuccess()) {
542+
ModlistProfile importModlistProfile = modlistProfileResult.getPayload();
543+
boolean duplicateProfileExists = MODLIST_PROFILES
544+
.stream()
545+
.anyMatch(modlistProfile -> modlistProfile.getProfileName().toLowerCase().trim().equals(importModlistProfile.getProfileName().toLowerCase().trim()));
546+
if (!duplicateProfileExists) {
547+
for(int i = 0; i < importModlistProfile.getModList().size(); i++) {
548+
importModlistProfile.getModList().get(i).setLoadPriority(i + 1);
549+
}
550+
MODLIST_PROFILES.add(modlistProfileResult.getPayload());
551+
} else
552+
modlistProfileResult.addMessage(String.format("Mod profile \"%s\" already exists!", modlistProfileResult.getPayload().getProfileName()), ResultType.INVALID);
553+
}
554+
return modlistProfileResult;
541555
}
542556
}

src/main/java/com/gearshiftgaming/se_mod_manager/frontend/models/utility/ModImportUtility.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static String createNewModProfile(final UiService UI_SERVICE, final Stage
9797
if (duplicateProfileName) {
9898
Popup.displaySimpleAlert("Profile name already exists!", STAGE, MessageType.WARN);
9999
} else if (!PROFILE_INPUT_VIEW.getInput().getText().isBlank()) {
100-
UI_SERVICE.getMOD_PROFILES().add(newModlistProfile);
100+
UI_SERVICE.getMODLIST_PROFILES().add(newModlistProfile);
101101
UI_SERVICE.setCurrentModlistProfile(newModlistProfile);
102102
UI_SERVICE.log("Successfully created profile " + PROFILE_INPUT_VIEW.getInput().getText(), MessageType.INFO);
103103
newProfileName = PROFILE_INPUT_VIEW.getInput().getText();
@@ -110,7 +110,7 @@ public static String createNewModProfile(final UiService UI_SERVICE, final Stage
110110
}
111111

112112
private static boolean profileNameExists(String profileName, final UiService UI_SERVICE) {
113-
return UI_SERVICE.getMOD_PROFILES().stream()
113+
return UI_SERVICE.getMODLIST_PROFILES().stream()
114114
.anyMatch(modProfile -> modProfile.getProfileName().equals(profileName));
115115
}
116116
}

src/main/java/com/gearshiftgaming/se_mod_manager/frontend/view/ModProfileManagerView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class ModProfileManagerView {
6464

6565
public ModProfileManagerView(UiService UI_SERVICE, SimpleInputView PROFILE_INPUT_VIEW) {
6666
this.UI_SERVICE = UI_SERVICE;
67-
MOD_PROFILES = UI_SERVICE.getMOD_PROFILES();
67+
MOD_PROFILES = UI_SERVICE.getMODLIST_PROFILES();
6868
this.PROFILE_INPUT_VIEW = PROFILE_INPUT_VIEW;
6969
}
7070

src/main/java/com/gearshiftgaming/se_mod_manager/frontend/view/ModTableContextBarView.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import com.gearshiftgaming.se_mod_manager.frontend.models.ModProfileDropdownItemCell;
88
import com.gearshiftgaming.se_mod_manager.frontend.models.SaveProfileDropdownButtonCell;
99
import com.gearshiftgaming.se_mod_manager.frontend.models.SaveProfileDropdownItemCell;
10-
import com.gearshiftgaming.se_mod_manager.frontend.models.utility.ModImportUtility;
1110
import com.gearshiftgaming.se_mod_manager.frontend.view.utility.NativeWindowUtility;
12-
import com.gearshiftgaming.se_mod_manager.frontend.view.utility.Popup;
13-
import javafx.animation.FadeTransition;
1411
import javafx.application.Application;
1512
import javafx.application.Platform;
1613
import javafx.concurrent.Task;
@@ -21,11 +18,9 @@
2118
import javafx.scene.paint.Color;
2219
import javafx.scene.shape.Rectangle;
2320
import javafx.stage.Stage;
24-
import javafx.util.Duration;
2521
import javafx.util.StringConverter;
2622
import lombok.Getter;
2723
import org.apache.commons.lang3.StringUtils;
28-
import org.checkerframework.checker.guieffect.qual.UI;
2924

3025
import java.lang.reflect.InvocationTargetException;
3126
import java.util.ArrayList;
@@ -156,7 +151,7 @@ public void initView() throws ClassNotFoundException, InvocationTargetException,
156151
saveProfileDropdown.setButtonCell(new SaveProfileDropdownButtonCell(themeName));
157152
saveProfileDropdown.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> saveProfileDropdown.setButtonCell(new SaveProfileDropdownButtonCell(themeName)));
158153

159-
modProfileDropdown.setItems(UI_SERVICE.getMOD_PROFILES());
154+
modProfileDropdown.setItems(UI_SERVICE.getMODLIST_PROFILES());
160155
modProfileDropdown.getSelectionModel().selectFirst();
161156

162157
modProfileDropdown.setCellFactory(param -> new ModProfileDropdownItemCell(themeName));

src/main/java/com/gearshiftgaming/se_mod_manager/frontend/view/ModlistManagerView.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -814,23 +814,35 @@ private void manageSaveProfiles() {
814814

815815
@FXML
816816
private void importModlist() {
817-
//TODO: Implement. Allow importing modlists from either sandbox file or exported list.
818-
// For our own applications lists, aka exported ones, create a custom file extension. Like, .SEMM. Then just marshall the modlist only.
817+
FileChooser importChooser = new FileChooser();
818+
importChooser.setTitle("Import Modlist");
819+
importChooser.setInitialDirectory(new File(System.getProperty("user.home")));
820+
importChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("SEMM Modlists", "*.semm"));
821+
822+
File savePath = importChooser.showOpenDialog(STAGE);
823+
824+
if(savePath != null) {
825+
Result<ModlistProfile> modlistProfileResult = UI_SERVICE.importModlist(savePath);
826+
if(modlistProfileResult.isSuccess()) {
827+
modProfileDropdown.getSelectionModel().select(modlistProfileResult.getPayload());
828+
}
829+
Popup.displaySimpleAlert(modlistProfileResult, STAGE);
830+
}
819831
}
820832

821833

822834
@FXML
823835
private void exportModlist() {
824-
FileChooser saveChooser = new FileChooser();
825-
saveChooser.setTitle("Export Modlist");
826-
saveChooser.setInitialDirectory(new File(System.getProperty("user.home")));
827-
saveChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("SEMM Modlists", "*.semm"));
836+
FileChooser exportChooser = new FileChooser();
837+
exportChooser.setTitle("Export Modlist");
838+
exportChooser.setInitialDirectory(new File(System.getProperty("user.home")));
839+
exportChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("SEMM Modlists", "*.semm"));
828840

829-
File savePath = saveChooser.showSaveDialog(STAGE);
841+
File savePath = exportChooser.showSaveDialog(STAGE);
830842
if (savePath != null) {
831843
Result<Void> exportModlistResult = UI_SERVICE.exportModlist(UI_SERVICE.getCurrentModlistProfile(), savePath);
832844
if (!exportModlistResult.isSuccess()) UI_SERVICE.log(exportModlistResult);
833-
Popup.displaySimpleAlert(exportModlistResult);
845+
Popup.displaySimpleAlert(exportModlistResult, STAGE);
834846
}
835847
}
836848

src/main/java/com/gearshiftgaming/se_mod_manager/frontend/view/SaveManagerView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private void addSave() throws IOException {
188188
if (addExistingModsLocationChoice == 1) { //Create a new modlist and switch to it before we add mods
189189
String newProfileName = ModImportUtility.createNewModProfile(UI_SERVICE, stage, PROFILE_INPUT_VIEW);
190190
if (!newProfileName.isEmpty()) {
191-
Optional<ModlistProfile> modlistProfile = UI_SERVICE.getMOD_PROFILES().stream()
191+
Optional<ModlistProfile> modlistProfile = UI_SERVICE.getMODLIST_PROFILES().stream()
192192
.filter(modlistProfile1 -> modlistProfile1.getProfileName().equals(newProfileName))
193193
.findFirst();
194194
modlistProfile.ifPresent(profile -> modTableContextBarView.getModProfileDropdown().getSelectionModel().select(profile));

0 commit comments

Comments
 (0)