Skip to content

Commit 9065e9f

Browse files
committed
save selected groups properly
1 parent 1ca4085 commit 9065e9f

4 files changed

Lines changed: 25 additions & 11 deletions

File tree

core/src/main/java/pl/skidam/automodpack_core/config/Jsons.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,11 @@ public Modpack(ModpackAddresses modpackAddresses) {
368368
this.modpackAddresses = modpackAddresses;
369369
this.selectedGroups = new ArrayList<>();
370370
}
371+
372+
public Modpack(ModpackAddresses modpackAddresses, List<Group> selectedGroups) {
373+
this.modpackAddresses = modpackAddresses;
374+
this.selectedGroups = selectedGroups;
375+
}
371376
}
372377

373378
public static class Group {

core/src/main/java/pl/skidam/automodpack_core/modpack/ClientSelectionManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public List<ClientSelectionManagerFields.Group> getSelectedGroups() {
5151
return getSelectedGroups(getSelectedPackId());
5252
}
5353

54+
// TODO make packids somehow unique and independet from modpackNames or server addresses
5455
public boolean packExists(String packId) {
5556
return selections.modpacks.containsKey(packId);
5657
}
@@ -61,6 +62,9 @@ public void removePack(String packId) {
6162
}
6263

6364
public void addPack(String packId, ClientSelectionManagerFields.Modpack pack) {
65+
if (selections.modpacks.containsKey(packId)) {
66+
LOGGER.debug("Overwritting pack {}", packId);
67+
}
6468
selections.modpacks.put(packId, pack);
6569
save();
6670
}

loader/core/src/main/java/pl/skidam/automodpack_loader_core/client/ModpackUtils.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,13 @@ public static void addModpackToList(String packId, Jsons.ModpackAddresses modpac
625625

626626
ClientSelectionManager clientSelectionManager = ClientSelectionManager.getMgr();
627627

628-
clientSelectionManager.addPack(packId, new Jsons.ClientSelectionManagerFields.Modpack(modpackAddresses));
628+
var pack = new Jsons.ClientSelectionManagerFields.Modpack(modpackAddresses);
629+
630+
if (clientSelectionManager.packExists(packId)) {
631+
pack.selectedGroups = clientSelectionManager.getSelectedGroups(packId);
632+
}
633+
634+
clientSelectionManager.addPack(packId, pack);
629635
}
630636

631637
// Returns modpack name formatted for path or url if server doesn't provide modpack name

src/main/java/pl/skidam/automodpack/client/ui/ModpackSelectionScreen.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import net.minecraft.client.gui.screens.Screen;
66
import net.minecraft.network.chat.Component;
77
import net.minecraft.util.Util;
8-
import pl.skidam.automodpack_core.Constants;
98
import pl.skidam.automodpack_loader_core.client.ModpackUpdater;
109
import pl.skidam.automodpack_core.config.Jsons;
1110
import pl.skidam.automodpack_core.modpack.ClientSelectionManager;
@@ -209,29 +208,29 @@ private void install() {
209208
mgr.addPack(content.modpackName, new Jsons.ClientSelectionManagerFields.Modpack(new Jsons.ModpackAddresses()));
210209
}
211210

212-
Constants.LOGGER.info("Selected {} pack", content.modpackName);
213-
Constants.LOGGER.info("Selected {} groups", selectedGroups);
214-
215-
mgr.setSelectedPack(content.modpackName);
216-
217211
// Assemble Groups map
218212
List<Jsons.ClientSelectionManagerFields.Group> finalGroupsToSave = new ArrayList<>();
219213
for (String id : selectedGroups) {
220214
List<String> filesForGroup = new ArrayList<>();
221215
Jsons.ModpackGroupFields group = content.groups.get(id);
222-
// add all groups even if the group is not selective because it might become one someday, so yeah save all files which we download currently
223-
if (group != null && selectedSelectiveFiles.containsKey(id)) {
224-
filesForGroup.addAll(selectedSelectiveFiles.get(id));
216+
// add all groups even if the group is not selective because it might become one someday, so save all files which we download currently
217+
if (group != null) {
218+
if (group.selective && selectedSelectiveFiles.containsKey(id)) {
219+
filesForGroup.addAll(selectedSelectiveFiles.get(id));
220+
} else if (!group.selective) {
221+
filesForGroup.addAll(group.files.stream().map(modpackContentItem -> modpackContentItem.file).toList());
222+
}
225223
}
226224
finalGroupsToSave.add(new Jsons.ClientSelectionManagerFields.Group(id, filesForGroup));
227225
}
228226

229227
mgr.setSelectedGroups(content.modpackName, finalGroupsToSave);
228+
mgr.setSelectedPack(content.modpackName);
230229

231230
Set<Jsons.ModpackContentItem> finalFiles = new HashSet<>();
232231
for (String id : selectedGroups) {
233232
Jsons.ModpackGroupFields group = content.groups.get(id);
234-
if (group == null || !isOsCompatible(group.compatibleOS) || group.files == null) continue;
233+
if (group == null || group.files == null) continue;
235234

236235
if (group.selective) {
237236
Set<String> selectedFiles = selectedSelectiveFiles.get(id);

0 commit comments

Comments
 (0)