- Rewrote LauncherPreferences -> PLPreferences + Now the file layout is the same as UI layout + (get/set)Preference are replaced with corresponding get/set types + Getting/setting is now done through keyPath instead of manually iterating over subdictionaries. + Implemented an isolation layer, allowing an instance to have its own settings. This is off by default - Implemented launcher_profiles + Added Profile manager that can be accessed from the sidebar + Moved "Game directory (instances)" to this screen + Replaced version selector with profile selector. Version selector is moved into profile editor. - Other changes + Cleanup code by using NSPredicate instead of huge for loops + Titles in settings are made multilined + Controller config: replaced bar button items with localized ones Due to how large the changes are, this is committed directly to the mainline branch. Bugs are expected to be found (although I did enough tests for this locally)
97 lines
2.2 KiB
Objective-C
97 lines
2.2 KiB
Objective-C
#import "LauncherPreferences.h"
|
|
#import "PLProfiles.h"
|
|
#import "utils.h"
|
|
|
|
static PLProfiles* current;
|
|
|
|
@interface PLProfiles()
|
|
@end
|
|
|
|
@implementation PLProfiles
|
|
|
|
+ (id)defaultProfiles {
|
|
return @{
|
|
@"profiles": @{
|
|
@"(Default)": @{
|
|
@"name": @"(Default)",
|
|
@"lastVersionId": @"latest-release"
|
|
}
|
|
},
|
|
@"selectedProfile": @"(Default)"
|
|
}.mutableCopy;
|
|
}
|
|
|
|
+ (PLProfiles *)current {
|
|
if (!current) {
|
|
[self updateCurrent];
|
|
}
|
|
return current;
|
|
}
|
|
|
|
+ (void)updateCurrent {
|
|
current = [[PLProfiles alloc] initWithCurrentInstance];
|
|
}
|
|
|
|
+ (id)profile:(NSMutableDictionary *)profile resolveKey:(id)key {
|
|
NSString *value = profile[key];
|
|
if (value.length > 0) {
|
|
//NSDebugLog(@"[PLProfiles] Applying %@: \"%@\"", key, value);
|
|
return value;
|
|
}
|
|
|
|
NSDictionary *valueDefaults = @{
|
|
@"javaVersion": @"0",
|
|
@"gameDir": @"."
|
|
};
|
|
if (valueDefaults[key]) {
|
|
return valueDefaults[key];
|
|
}
|
|
|
|
NSDictionary *prefDefaults = @{
|
|
@"defaultTouchCtrl": @"control.default_ctrl",
|
|
@"defaultGamepadCtrl": @"control.default_gamepad_ctrl",
|
|
@"javaArgs": @"java.java_args",
|
|
@"renderer": @"video.renderer"
|
|
};
|
|
return getPrefObject(prefDefaults[key]);
|
|
}
|
|
|
|
+ (id)resolveKeyForCurrentProfile:(id)key {
|
|
return [self profile:self.current.selectedProfile resolveKey:key];
|
|
}
|
|
|
|
- (id)initWithCurrentInstance {
|
|
self = [super init];
|
|
self.profilePath = [@(getenv("POJAV_GAME_DIR")) stringByAppendingPathComponent:@"launcher_profiles.json"];
|
|
self.profileDict = parseJSONFromFile(self.profilePath);
|
|
if (self.profileDict[@"error"]) {
|
|
self.profileDict = PLProfiles.defaultProfiles;
|
|
[self save];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (id)profiles {
|
|
return self.profileDict[@"profiles"];
|
|
}
|
|
|
|
- (id)selectedProfile {
|
|
return self.profiles[self.selectedProfileName];
|
|
}
|
|
|
|
- (NSString *)selectedProfileName {
|
|
return (id)self.profileDict[@"selectedProfile"];
|
|
}
|
|
|
|
- (void)setSelectedProfileName:(NSString *)name {
|
|
self.profileDict[@"selectedProfile"] = (id)name;
|
|
[self save];
|
|
}
|
|
|
|
- (void)save {
|
|
saveJSONToFile(self.profileDict, self.profilePath);
|
|
}
|
|
|
|
@end
|