mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-13 05:46:59 -04:00
Move specialize and globalize VersionSetting to HMCLGameRepository
This commit is contained in:
parent
a5997be9c4
commit
25d79a94f8
@ -164,6 +164,27 @@ public class HMCLGameRepository extends DefaultGameRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make version use self version settings instead of the global one.
|
||||||
|
* @param id the version id.
|
||||||
|
* @return specialized version setting, null if given version does not exist.
|
||||||
|
*/
|
||||||
|
public VersionSetting specializeVersionSetting(String id) {
|
||||||
|
VersionSetting vs = getVersionSetting(id);
|
||||||
|
if (vs == null)
|
||||||
|
vs = createVersionSetting(id);
|
||||||
|
if (vs == null)
|
||||||
|
return null;
|
||||||
|
vs.setUsesGlobal(false);
|
||||||
|
return vs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void globalizeVersionSetting(String id) {
|
||||||
|
VersionSetting vs = getVersionSetting(id);
|
||||||
|
if (vs != null)
|
||||||
|
vs.setUsesGlobal(true);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean forbidsVersion(String id) {
|
public boolean forbidsVersion(String id) {
|
||||||
return FORBIDDEN.contains(id);
|
return FORBIDDEN.contains(id);
|
||||||
}
|
}
|
||||||
|
@ -87,9 +87,10 @@ public final class ModpackHelper {
|
|||||||
|
|
||||||
FinalizedCallback finalizeTask = (variables, isDependentsSucceeded) -> {
|
FinalizedCallback finalizeTask = (variables, isDependentsSucceeded) -> {
|
||||||
if (isDependentsSucceeded) {
|
if (isDependentsSucceeded) {
|
||||||
profile.getRepository().refreshVersions();
|
HMCLGameRepository repository = profile.getRepository();
|
||||||
VersionSetting vs = profile.specializeVersionSetting(name);
|
repository.refreshVersions();
|
||||||
profile.getRepository().undoMark(name);
|
VersionSetting vs = repository.specializeVersionSetting(name);
|
||||||
|
repository.undoMark(name);
|
||||||
if (vs != null)
|
if (vs != null)
|
||||||
vs.setGameDirType(EnumGameDirectory.VERSION_FOLDER);
|
vs.setGameDirType(EnumGameDirectory.VERSION_FOLDER);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public final class MultiMCInstallVersionSettingTask extends Task {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
VersionSetting vs = Objects.requireNonNull(profile.specializeVersionSetting(version));
|
VersionSetting vs = Objects.requireNonNull(profile.getRepository().specializeVersionSetting(version));
|
||||||
ModpackHelper.toVersionSetting(manifest, vs);
|
ModpackHelper.toVersionSetting(manifest, vs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ import org.jackhuang.hmcl.game.HMCLCacheRepository;
|
|||||||
import org.jackhuang.hmcl.game.HMCLGameRepository;
|
import org.jackhuang.hmcl.game.HMCLGameRepository;
|
||||||
import org.jackhuang.hmcl.game.Version;
|
import org.jackhuang.hmcl.game.Version;
|
||||||
import org.jackhuang.hmcl.mod.ModManager;
|
import org.jackhuang.hmcl.mod.ModManager;
|
||||||
|
import org.jackhuang.hmcl.task.Schedulers;
|
||||||
|
import org.jackhuang.hmcl.ui.FXUtils;
|
||||||
import org.jackhuang.hmcl.ui.WeakListenerHelper;
|
import org.jackhuang.hmcl.ui.WeakListenerHelper;
|
||||||
import org.jackhuang.hmcl.util.*;
|
import org.jackhuang.hmcl.util.*;
|
||||||
|
|
||||||
@ -174,32 +176,6 @@ public final class Profile implements Observable {
|
|||||||
return vs;
|
return vs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVersionGlobal(String id) {
|
|
||||||
VersionSetting vs = repository.getVersionSetting(id);
|
|
||||||
return vs == null || vs.isUsesGlobal();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make version use self version settings instead of the global one.
|
|
||||||
* @param id the version id.
|
|
||||||
* @return specialized version setting, null if given version does not exist.
|
|
||||||
*/
|
|
||||||
public VersionSetting specializeVersionSetting(String id) {
|
|
||||||
VersionSetting vs = repository.getVersionSetting(id);
|
|
||||||
if (vs == null)
|
|
||||||
vs = repository.createVersionSetting(id);
|
|
||||||
if (vs == null)
|
|
||||||
return null;
|
|
||||||
vs.setUsesGlobal(false);
|
|
||||||
return vs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void globalizeVersionSetting(String id) {
|
|
||||||
VersionSetting vs = repository.getVersionSetting(id);
|
|
||||||
if (vs != null)
|
|
||||||
vs.setUsesGlobal(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this)
|
return new ToStringBuilder(this)
|
||||||
@ -231,7 +207,7 @@ public final class Profile implements Observable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void invalidate() {
|
protected void invalidate() {
|
||||||
observableHelper.invalidate();
|
Schedulers.computation().schedule(observableHelper::invalidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Serializer implements JsonSerializer<Profile>, JsonDeserializer<Profile> {
|
public static final class Serializer implements JsonSerializer<Profile>, JsonDeserializer<Profile> {
|
||||||
|
@ -134,9 +134,9 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
|
|||||||
// because versionSettings can be the global one.
|
// because versionSettings can be the global one.
|
||||||
// global versionSettings.usesGlobal is always true.
|
// global versionSettings.usesGlobal is always true.
|
||||||
if (newValue)
|
if (newValue)
|
||||||
profile.specializeVersionSetting(versionId);
|
profile.getRepository().specializeVersionSetting(versionId);
|
||||||
else
|
else
|
||||||
profile.globalizeVersionSetting(versionId);
|
profile.getRepository().globalizeVersionSetting(versionId);
|
||||||
|
|
||||||
Platform.runLater(() -> loadVersionSetting(profile, versionId));
|
Platform.runLater(() -> loadVersionSetting(profile, versionId));
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user