Move specialize and globalize VersionSetting to HMCLGameRepository

This commit is contained in:
huangyuhui 2018-09-09 18:55:01 +08:00
parent a5997be9c4
commit 25d79a94f8
5 changed files with 31 additions and 33 deletions

View File

@ -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) {
return FORBIDDEN.contains(id);
}

View File

@ -87,9 +87,10 @@ public final class ModpackHelper {
FinalizedCallback finalizeTask = (variables, isDependentsSucceeded) -> {
if (isDependentsSucceeded) {
profile.getRepository().refreshVersions();
VersionSetting vs = profile.specializeVersionSetting(name);
profile.getRepository().undoMark(name);
HMCLGameRepository repository = profile.getRepository();
repository.refreshVersions();
VersionSetting vs = repository.specializeVersionSetting(name);
repository.undoMark(name);
if (vs != null)
vs.setGameDirType(EnumGameDirectory.VERSION_FOLDER);
}

View File

@ -44,7 +44,7 @@ public final class MultiMCInstallVersionSettingTask extends Task {
@Override
public void execute() {
VersionSetting vs = Objects.requireNonNull(profile.specializeVersionSetting(version));
VersionSetting vs = Objects.requireNonNull(profile.getRepository().specializeVersionSetting(version));
ModpackHelper.toVersionSetting(manifest, vs);
}
}

View File

@ -28,6 +28,8 @@ import org.jackhuang.hmcl.game.HMCLCacheRepository;
import org.jackhuang.hmcl.game.HMCLGameRepository;
import org.jackhuang.hmcl.game.Version;
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.util.*;
@ -174,32 +176,6 @@ public final class Profile implements Observable {
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
public String toString() {
return new ToStringBuilder(this)
@ -231,7 +207,7 @@ public final class Profile implements Observable {
}
protected void invalidate() {
observableHelper.invalidate();
Schedulers.computation().schedule(observableHelper::invalidate);
}
public static final class Serializer implements JsonSerializer<Profile>, JsonDeserializer<Profile> {

View File

@ -134,9 +134,9 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
// because versionSettings can be the global one.
// global versionSettings.usesGlobal is always true.
if (newValue)
profile.specializeVersionSetting(versionId);
profile.getRepository().specializeVersionSetting(versionId);
else
profile.globalizeVersionSetting(versionId);
profile.getRepository().globalizeVersionSetting(versionId);
Platform.runLater(() -> loadVersionSetting(profile, versionId));
});