Loading/saving of set cache, game loading
This commit is contained in:
parent
577928c588
commit
7c0c671f2e
|
@ -87,6 +87,13 @@
|
||||||
</connections>
|
</connections>
|
||||||
</tableColumn>
|
</tableColumn>
|
||||||
</tableColumns>
|
</tableColumns>
|
||||||
|
<connections>
|
||||||
|
<binding destination="-2" name="doubleClickTarget" keyPath="self" id="WLF-Lh-4jC">
|
||||||
|
<dictionary key="options">
|
||||||
|
<string key="NSSelectorName">launchSet:</string>
|
||||||
|
</dictionary>
|
||||||
|
</binding>
|
||||||
|
</connections>
|
||||||
</outlineView>
|
</outlineView>
|
||||||
</subviews>
|
</subviews>
|
||||||
</clipView>
|
</clipView>
|
||||||
|
@ -125,7 +132,7 @@
|
||||||
</connections>
|
</connections>
|
||||||
<point key="canvasLocation" x="192" y="209.5"/>
|
<point key="canvasLocation" x="192" y="209.5"/>
|
||||||
</window>
|
</window>
|
||||||
<treeController objectClassName="NSDictionary" editable="NO" childrenKeyPath="subsets" id="IZb-g9-uEr">
|
<treeController objectClassName="FBLauncherItem" editable="NO" childrenKeyPath="subsets" id="IZb-g9-uEr">
|
||||||
<connections>
|
<connections>
|
||||||
<binding destination="-2" name="contentArray" keyPath="romSets" id="i4j-NI-FYk"/>
|
<binding destination="-2" name="contentArray" keyPath="romSets" id="i4j-NI-FYk"/>
|
||||||
<binding destination="Mk3-du-Xcu" name="sortDescriptors" keyPath="values.romSetSortDescriptor" id="XzZ-ve-L7D">
|
<binding destination="Mk3-du-Xcu" name="sortDescriptors" keyPath="values.romSetSortDescriptor" id="XzZ-ve-L7D">
|
||||||
|
|
|
@ -10,6 +10,15 @@
|
||||||
|
|
||||||
#import "FBScanner.h"
|
#import "FBScanner.h"
|
||||||
|
|
||||||
|
@interface FBLauncherItem: NSObject
|
||||||
|
|
||||||
|
@property NSString *name;
|
||||||
|
@property NSString *title;
|
||||||
|
@property unsigned char status;
|
||||||
|
@property (readonly) NSMutableArray<FBLauncherItem *> *subsets;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@interface FBLauncherController : NSWindowController<FBScannerDelegate>
|
@interface FBLauncherController : NSWindowController<FBScannerDelegate>
|
||||||
{
|
{
|
||||||
IBOutlet NSPanel *progressPanel;
|
IBOutlet NSPanel *progressPanel;
|
||||||
|
@ -22,7 +31,8 @@
|
||||||
|
|
||||||
- (IBAction) rescanSets:(id) sender;
|
- (IBAction) rescanSets:(id) sender;
|
||||||
- (IBAction) cancelProgress:(id) sender;
|
- (IBAction) cancelProgress:(id) sender;
|
||||||
|
- (IBAction) launchSet:(id) sender;
|
||||||
|
|
||||||
@property (readonly) NSArray<NSDictionary *> *romSets;
|
@property (readonly) NSArray<FBLauncherItem *> *romSets;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -11,9 +11,26 @@
|
||||||
#import "AppDelegate.h"
|
#import "AppDelegate.h"
|
||||||
#import "NSWindowController+Core.h"
|
#import "NSWindowController+Core.h"
|
||||||
|
|
||||||
|
#pragma mark - FBLauncherItem
|
||||||
|
|
||||||
|
@implementation FBLauncherItem
|
||||||
|
|
||||||
|
- (instancetype) init
|
||||||
|
{
|
||||||
|
if (self = [super init]) {
|
||||||
|
_subsets = [NSMutableArray new];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
#pragma mark - FBLauncherController
|
||||||
|
|
||||||
@interface FBLauncherController ()
|
@interface FBLauncherController ()
|
||||||
|
|
||||||
- (void) reloadSets:(NSArray<FBROMSet *> *) romSets;
|
- (void) reloadSets:(NSArray<FBROMSet *> *) romSets;
|
||||||
|
- (NSString *) setCachePath;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -33,14 +50,20 @@
|
||||||
|
|
||||||
- (void) awakeFromNib
|
- (void) awakeFromNib
|
||||||
{
|
{
|
||||||
|
if ([NSFileManager.defaultManager fileExistsAtPath:self.setCachePath]) {
|
||||||
|
NSArray<FBROMSet *> *cached = [NSKeyedUnarchiver unarchiveObjectWithFile:self.setCachePath];
|
||||||
|
if (cached)
|
||||||
|
[self reloadSets:cached];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_romSets.count == 0)
|
||||||
|
[self rescanSets:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - NSWindowDelegate
|
#pragma mark - NSWindowDelegate
|
||||||
|
|
||||||
- (void) windowWillLoad
|
- (void) windowWillLoad
|
||||||
{
|
{
|
||||||
if (_romSets.count == 0)
|
|
||||||
[self rescanSets:self];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) windowWillClose:(NSNotification *) notification
|
- (void) windowWillClose:(NSNotification *) notification
|
||||||
|
@ -58,11 +81,8 @@
|
||||||
progressPanelLabel.stringValue = NSLocalizedString(@"Scanning...", nil);
|
progressPanelLabel.stringValue = NSLocalizedString(@"Scanning...", nil);
|
||||||
progressPanelCancelButton.enabled = YES;
|
progressPanelCancelButton.enabled = YES;
|
||||||
|
|
||||||
[NSApp beginSheet:progressPanel
|
[self.window beginSheet:progressPanel
|
||||||
modalForWindow:[self window]
|
completionHandler:^(NSModalResponse returnCode) { }];
|
||||||
modalDelegate:self
|
|
||||||
didEndSelector:@selector(didEndSheet:returnCode:contextInfo:)
|
|
||||||
contextInfo:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) progressDidUpdate:(float) progress
|
- (void) progressDidUpdate:(float) progress
|
||||||
|
@ -76,22 +96,16 @@
|
||||||
scanner = nil;
|
scanner = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
[NSApp endSheet:progressPanel];
|
[self.window endSheet:progressPanel];
|
||||||
|
|
||||||
if (!romSets)
|
if (!romSets)
|
||||||
return; // Cancelled, or otherwise failed
|
return; // Cancelled, or otherwise failed
|
||||||
|
|
||||||
|
// Cache
|
||||||
|
[NSKeyedArchiver archiveRootObject:romSets
|
||||||
|
toFile:self.setCachePath];
|
||||||
|
|
||||||
[self reloadSets:romSets];
|
[self reloadSets:romSets];
|
||||||
[romSetTreeController rearrangeObjects];
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Callbacks
|
|
||||||
|
|
||||||
- (void) didEndSheet:(NSWindow *) sheet
|
|
||||||
returnCode:(NSInteger) returnCode
|
|
||||||
contextInfo:(void *) contextInfo
|
|
||||||
{
|
|
||||||
[sheet orderOut:self];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Actions
|
#pragma mark - Actions
|
||||||
|
@ -118,6 +132,18 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) launchSet:(id) sender
|
||||||
|
{
|
||||||
|
FBLauncherItem *item = romSetTreeController.selectedObjects.lastObject;
|
||||||
|
if (!item || item.status != FBROMSET_STATUS_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// FIXME: hack!
|
||||||
|
// Ask emulator to load a (possibly) non-existent file
|
||||||
|
NSString *file = [item.name stringByAppendingPathExtension:@"zip"];
|
||||||
|
[self.appDelegate loadPath:[self.appDelegate.romPath stringByAppendingPathComponent:file]];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - Private
|
#pragma mark - Private
|
||||||
|
|
||||||
- (void) reloadSets:(NSArray<FBROMSet *> *) romSets
|
- (void) reloadSets:(NSArray<FBROMSet *> *) romSets
|
||||||
|
@ -129,29 +155,36 @@
|
||||||
// and child sets to respective sub-list
|
// and child sets to respective sub-list
|
||||||
NSMutableDictionary<NSString *, NSMutableArray *> *childSetsByName = [NSMutableDictionary new];
|
NSMutableDictionary<NSString *, NSMutableArray *> *childSetsByName = [NSMutableDictionary new];
|
||||||
[romSets enumerateObjectsUsingBlock:^(FBROMSet *obj, NSUInteger idx, BOOL *stop) {
|
[romSets enumerateObjectsUsingBlock:^(FBROMSet *obj, NSUInteger idx, BOOL *stop) {
|
||||||
NSDictionary *set = @{
|
FBLauncherItem *item = [FBLauncherItem new];
|
||||||
@"name": obj.name,
|
item.name = obj.name;
|
||||||
@"title": obj.title,
|
item.title = obj.title;
|
||||||
@"subsets": [NSMutableArray new],
|
item.status = obj.status;
|
||||||
};
|
|
||||||
if (!obj.parent)
|
if (!obj.parent)
|
||||||
[(NSMutableArray *)_romSets addObject:set];
|
[(NSMutableArray *) _romSets addObject:item];
|
||||||
else {
|
else {
|
||||||
NSMutableArray *childSet = childSetsByName[obj.parent];
|
NSMutableArray *childSet = childSetsByName[obj.parent];
|
||||||
if (!childSet) {
|
if (!childSet) {
|
||||||
childSet = [NSMutableArray new];
|
childSet = [NSMutableArray new];
|
||||||
childSetsByName[obj.parent] = childSet;
|
childSetsByName[obj.parent] = childSet;
|
||||||
}
|
}
|
||||||
[childSet addObject:set];
|
[childSet addObject:item];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
// Sweep through master list and add any child sets
|
// Sweep through master list and add any child sets
|
||||||
[_romSets enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
|
[_romSets enumerateObjectsUsingBlock:^(FBLauncherItem *obj, NSUInteger idx, BOOL *stop) {
|
||||||
NSArray *children = childSetsByName[obj[@"name"]];
|
NSArray *children = childSetsByName[obj.name];
|
||||||
if (children)
|
if (children)
|
||||||
[obj[@"subsets"] addObjectsFromArray:children];
|
[obj.subsets addObjectsFromArray:children];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
[romSetTreeController rearrangeObjects];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *) setCachePath
|
||||||
|
{
|
||||||
|
return [self.appDelegate.supportPath stringByAppendingPathComponent:@"SetCache.plist"];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in New Issue