5 // Created by Hori,Masaki on 2014/06/01.
6 // Copyright (c) 2014年 Hori,Masaki. All rights reserved.
9 #import "HMUserDefaults.h"
11 HMUserDefaults *HMStandardDefaults = nil;
14 @implementation HMUserDefaults
16 @dynamic slotItemSortDescriptors, shipviewSortDescriptors, powerupSupportSortDecriptors;
17 @dynamic showsDebugMenu;
18 @dynamic hideMaxKaryoku, hideMaxRaisou, hideMaxLucky, hideMaxSoukou, hideMaxTaiku;
19 @dynamic appendKanColleTag;
20 @dynamic prevReloadDate;
25 static dispatch_once_t onceToken;
26 dispatch_once(&onceToken, ^{
27 HMStandardDefaults = [self new];
29 NSColor *plan01Color = [NSColor colorWithCalibratedRed:0.000 green:0.043 blue:0.518 alpha:1.000];
30 NSColor *plan02Color = [NSColor colorWithCalibratedRed:0.800 green:0.223 blue:0.000 alpha:1.000];
31 NSColor *plan03Color = [NSColor colorWithCalibratedRed:0.539 green:0.012 blue:0.046 alpha:1.000];
32 NSColor *plan04Color = [NSColor colorWithCalibratedRed:0.000 green:0.535 blue:0.535 alpha:1.000];
33 NSColor *plan05Color = [NSColor colorWithCalibratedRed:0.376 green:0.035 blue:0.535 alpha:1.000];
34 NSColor *plan06Color = [NSColor colorWithCalibratedRed:0.535 green:0.535 blue:0.000 alpha:1.000];
36 [[NSUserDefaults standardUserDefaults] registerDefaults:
38 @"screenShotBorderWidth" : @(0.0),
39 @"plan01Color" : [NSKeyedArchiver archivedDataWithRootObject:plan01Color],
40 @"plan02Color" : [NSKeyedArchiver archivedDataWithRootObject:plan02Color],
41 @"plan03Color" : [NSKeyedArchiver archivedDataWithRootObject:plan03Color],
42 @"plan04Color" : [NSKeyedArchiver archivedDataWithRootObject:plan04Color],
43 @"plan05Color" : [NSKeyedArchiver archivedDataWithRootObject:plan05Color],
44 @"plan06Color" : [NSKeyedArchiver archivedDataWithRootObject:plan06Color],
45 @"screenshotPreviewZoomValue" : @(0.4),
46 @"showEquipmentType" : @(-1),
47 @"fleetViewPosition" : @(1),
48 @"autoCombinedView" : @YES,
54 + (instancetype)hmStandardDefauls
56 return HMStandardDefaults;
59 - (void)setObject:(id)value forKey:(NSString *)key
61 [[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
63 - (id)objectForKey:(NSString *)key
65 return [[NSUserDefaults standardUserDefaults] objectForKey:key];
67 - (NSString *)stringForKey:(NSString *)key
69 return [[NSUserDefaults standardUserDefaults] stringForKey:key];
71 - (void)setInteger:(NSInteger)value forKey:(NSString *)key
73 [[NSUserDefaults standardUserDefaults] setInteger:value forKey:key];
75 - (NSInteger)integerForKey:(NSString *)key
77 return [[NSUserDefaults standardUserDefaults] integerForKey:key];
79 - (void)setDouble:(double)value forKey:(NSString *)key
81 [[NSUserDefaults standardUserDefaults] setDouble:value forKey:key];
83 - (double)doubleForKey:(NSString *)key
85 return [[NSUserDefaults standardUserDefaults] doubleForKey:key];
87 - (void)setBool:(BOOL)value forKey:(NSString *)key
89 [[NSUserDefaults standardUserDefaults] setBool:value forKey:key];
91 - (BOOL)boolForKey:(NSString *)key
93 return [[NSUserDefaults standardUserDefaults] boolForKey:key];
95 - (void)setKeyedArchiveObject:(id)value forKey:(NSString *)key
99 data = [NSKeyedArchiver archivedDataWithRootObject:value];
101 [[NSUserDefaults standardUserDefaults] setObject:data forKey:key];
103 - (id)keyedUnarchiveObject:(NSString *)key
105 NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:key];
106 return data ? [NSKeyedUnarchiver unarchiveObjectWithData:data] : nil;
109 #pragma mark-Properties
110 - (void)setSlotItemSortDescriptors:(NSArray *)slotItemSortDescriptors
112 [self setKeyedArchiveObject:slotItemSortDescriptors forKey:@"slotItemSortKey2"];
114 - (NSArray *)slotItemSortDescriptors
116 NSArray *array = [self keyedUnarchiveObject:@"slotItemSortKey2"];
118 NSMutableArray *result = [NSMutableArray new];
119 for(NSSortDescriptor *item in array) {
120 if(![item.key hasPrefix:@"master_ship"] && ![item.key hasPrefix:@"master_slotItem"]) {
121 [result addObject:item];
125 return [NSArray arrayWithArray:result];
127 return [NSArray new];
129 - (void)setShipviewSortDescriptors:(NSArray *)shipviewSortDescriptors
131 [self setKeyedArchiveObject:shipviewSortDescriptors forKey:@"shipviewsortdescriptor"];
133 - (NSArray *)shipviewSortDescriptors
135 NSArray *array = [self keyedUnarchiveObject:@"shipviewsortdescriptor"];
137 NSMutableArray *result = [NSMutableArray new];
138 for(NSSortDescriptor *item in array) {
139 if(![item.key hasPrefix:@"master_ship"]) {
140 [result addObject:item];
144 return [NSArray arrayWithArray:result];
146 return [NSArray new];
148 - (void)setPowerupSupportSortDecriptors:(NSArray *)powerupSupportSortDecriptors
150 [self setKeyedArchiveObject:powerupSupportSortDecriptors forKey:@"powerupsupportsortdecriptor"];
152 - (NSArray *)powerupSupportSortDecriptors
154 NSArray *array = [self keyedUnarchiveObject:@"powerupsupportsortdecriptor"];
156 NSMutableArray *result = [NSMutableArray new];
157 for(NSSortDescriptor *item in array) {
158 if(![item.key hasPrefix:@"master_ship"]) {
159 [result addObject:item];
163 return [NSArray arrayWithArray:result];
165 return [NSArray new];
168 - (void)setPrevReloadDate:(NSDate *)prevReloadDate
171 [self setObject:[prevReloadDate description] forKey:@"previousReloadDateString"];
174 - (NSDate *)prevReloadDate
176 NSString *dateString = [self stringForKey:@"previousReloadDateString"];
178 return [NSDate dateWithString:dateString];
183 - (void)setShowsDebugMenu:(BOOL)showsDebugMenu
185 [self setBool:showsDebugMenu forKey:@"ShowsDebugMenu"];
187 - (BOOL)showsDebugMenu
189 return [self boolForKey:@"ShowsDebugMenu"];
192 - (void)setAppendKanColleTag:(BOOL)appendKanColleTag
194 [self setBool:appendKanColleTag forKey:@"appendKanColleTag"];
196 - (BOOL)appendKanColleTag
198 return [self boolForKey:@"appendKanColleTag"];
201 - (void)setHideMaxKaryoku:(BOOL)hideMaxKaryoku
203 [self setBool:hideMaxKaryoku forKey:@"hideMaxKaryoku"];
205 - (BOOL)hideMaxKaryoku
207 return [self boolForKey:@"hideMaxKaryoku"];
209 - (void)setHideMaxLucky:(BOOL)hideMaxLucky
211 [self setBool:hideMaxLucky forKey:@"hideMaxLucky"];
215 return [self boolForKey:@"hideMaxLucky"];
217 - (void)setHideMaxRaisou:(BOOL)hideMaxRaisou
219 [self setBool:hideMaxRaisou forKey:@"hideMaxRaisou"];
221 - (BOOL)hideMaxRaisou
223 return [self boolForKey:@"hideMaxRaisou"];
225 - (void)setHideMaxSoukou:(BOOL)hideMaxSoukou
227 [self setBool:hideMaxSoukou forKey:@"hideMaxSoukou"];
229 - (BOOL)hideMaxSoukou
231 return [self boolForKey:@"hideMaxSoukou"];
233 - (void)setHideMaxTaiku:(BOOL)hideMaxTaiku
235 [self setBool:hideMaxTaiku forKey:@"hideMaxTaiku"];
239 return [self boolForKey:@"hideMaxTaiku"];
242 - (void)setShowsPlanColor:(BOOL)showsPlanColor
244 [self setBool:showsPlanColor forKey:@"showsPlanColor"];
246 - (BOOL)showsPlanColor
248 return [self boolForKey:@"showsPlanColor"];
250 - (void)setPlan01Color:(NSColor *)plan01Color
252 [self setKeyedArchiveObject:plan01Color forKey:@"plan01Color"];
254 - (NSColor *)plan01Color
256 return [self keyedUnarchiveObject:@"plan01Color"];
258 - (void)setPlan02Color:(NSColor *)plan02Color
260 [self setKeyedArchiveObject:plan02Color forKey:@"plan02Color"];
262 - (NSColor *)plan02Color
264 return [self keyedUnarchiveObject:@"plan02Color"];
266 - (void)setPlan03Color:(NSColor *)plan03Color
268 [self setKeyedArchiveObject:plan03Color forKey:@"plan03Color"];
270 - (NSColor *)plan03Color
272 return [self keyedUnarchiveObject:@"plan03Color"];
274 - (void)setPlan04Color:(NSColor *)plan04Color
276 [self setKeyedArchiveObject:plan04Color forKey:@"plan04Color"];
278 - (NSColor *)plan04Color
280 return [self keyedUnarchiveObject:@"plan04Color"];
282 - (void)setPlan05Color:(NSColor *)plan05Color
284 [self setKeyedArchiveObject:plan05Color forKey:@"plan05Color"];
286 - (NSColor *)plan05Color
288 return [self keyedUnarchiveObject:@"plan05Color"];
290 - (void)setPlan06Color:(NSColor *)plan06Color
292 [self setKeyedArchiveObject:plan06Color forKey:@"plan06Color"];
294 - (NSColor *)plan06Color
296 return [self keyedUnarchiveObject:@"plan06Color"];
299 - (void)setMinimumColoredShipCount:(NSInteger)minimumColoredShipCount
301 [self setInteger:minimumColoredShipCount forKey:@"minimumColoredShipCount"];
303 - (NSInteger)minimumColoredShipCount
305 return [self integerForKey:@"minimumColoredShipCount"];
308 #pragma mark - Screenshot
309 - (void)setUseMask:(BOOL)useMask
311 [self setBool:useMask forKey:@"useMask"];
315 return [self boolForKey:@"useMask"];
318 - (void)setScreenShotBorderWidth:(CGFloat)screenShotBorderWidth
320 if(screenShotBorderWidth < 0 || screenShotBorderWidth > 20) return;
322 [self setDouble:screenShotBorderWidth forKey:@"screenShotBorderWidth"];
324 - (CGFloat)screenShotBorderWidth
326 CGFloat result = [self doubleForKey:@"screenShotBorderWidth"];
329 [self setDouble:0 forKey:@"screenShotBorderWidth"];
333 [self setDouble:20 forKey:@"screenShotBorderWidth"];
340 - (void)setScreenShotSaveDirectory:(NSURL *)screenShotSaveDirectory
342 [self setObject:screenShotSaveDirectory forKey:@"screenShotSaveDirectory"];
344 - (NSString *)screenShotSaveDirectory
346 return [self objectForKey:@"screenShotSaveDirectory"];
349 - (void)setShowsListWindowAtScreenshot:(BOOL)showsListWindowAtScreenshot
351 [self setBool:showsListWindowAtScreenshot forKey:@"showsListWindowAtScreenshot"];
353 - (BOOL)showsListWindowAtScreenshot
355 return [self boolForKey:@"showsListWindowAtScreenshot"];
358 - (void)setScreenshotPreviewZoomValue:(NSNumber *)screenshotPreviewZoomValue
360 [self setObject:screenshotPreviewZoomValue forKey:@"screenshotPreviewZoomValue"];
362 - (NSNumber *)screenshotPreviewZoomValue
364 return [self objectForKey:@"screenshotPreviewZoomValue"];
367 #pragma mark - Notify Sound
368 - (void)setPlayFinishMissionSound:(BOOL)playFinishMissionSound
370 [self setBool:playFinishMissionSound forKey:@"playFinishMissionSound"];
372 - (BOOL)playFinishMissionSound
374 return [self boolForKey:@"playFinishMissionSound"];
376 - (void)setPlayFinishNyukyoSound:(BOOL)playFinishNyukyoSound
378 [self setBool:playFinishNyukyoSound forKey:@"playFinishNyukyoSound"];
380 - (BOOL)playFinishNyukyoSound
382 return [self boolForKey:@"playFinishNyukyoSound"];
384 - (void)setPlayFinishKenzoSound:(BOOL)playFinishKenzoSound
386 [self setBool:playFinishKenzoSound forKey:@"playFinishKenzoSound"];
388 - (BOOL)playFinishKenzoSound
390 return [self boolForKey:@"playFinishKenzoSound"];
394 #pragma mark - Upgradable List
395 - (void)setShowLevelOneShipInUpgradableList:(BOOL)showLevelOneShipInUpgradableList
397 [self setBool:showLevelOneShipInUpgradableList forKey:@"showLevelOneShipInUpgradableList"];
399 - (BOOL)showLevelOneShipInUpgradableList
401 return [self boolForKey:@"showLevelOneShipInUpgradableList"];
403 - (void)setShowsExcludedShipInUpgradableList:(BOOL)showsExcludedShipInUpgradableList
405 [self setBool:showsExcludedShipInUpgradableList forKey:@"showsExcludedShipInUpgradableList"];
407 - (BOOL)showsExcludedShipInUpgradableList
409 return [self boolForKey:@"showsExcludedShipInUpgradableList"];
413 #pragma mark - Equipment List
414 - (void)setShowEquipmentType:(NSNumber *)showEquipmentType
416 [self setObject:showEquipmentType forKey:@"showEquipmentType"];
418 - (NSNumber *)showEquipmentType
420 return [self objectForKey:@"showEquipmentType"];
423 #pragma mark - FleetView
424 - (void)setFleetViewPosition:(NSInteger)fleetViewPosition
426 [self setInteger:fleetViewPosition forKey:@"fleetViewPosition"];
428 - (NSInteger)fleetViewPosition
430 return [self integerForKey:@"fleetViewPosition"];
432 - (void)setFleetViewShipOrder:(NSInteger)fleetViewShipOrder
434 if(fleetViewShipOrder < 0 || fleetViewShipOrder > 1) return;
435 [self setInteger:fleetViewShipOrder forKey:@"fleetViewShipOrder"];
437 - (NSInteger)fleetViewShipOrder
439 return [self integerForKey:@"fleetViewShipOrder"];
442 - (void)setRepairTime:(NSDate *)repairTime
444 [self setKeyedArchiveObject:repairTime forKey:@"repairTime"];
446 - (NSDate *)repairTime
448 return [self keyedUnarchiveObject:@"repairTime"];
451 #pragma mark - combined view
452 - (void)setLastHasCombinedView:(BOOL)lastHasCombinedView
454 [self setBool:lastHasCombinedView forKey:@"lastHasCombinedView"];
456 - (BOOL)lastHasCombinedView
458 return [self boolForKey:@"lastHasCombinedView"];
460 - (void)setAutoCombinedView:(BOOL)autoCombinedView
462 [self setBool:autoCombinedView forKey:@"autoCombinedView"];
464 - (BOOL)autoCombinedView
466 return [self boolForKey:@"autoCombinedView"];
468 - (void)setUseSwipeChangeCombinedView:(BOOL)useSwipeChangeCombinedView
470 [self setBool:useSwipeChangeCombinedView forKey:@"useSwipeChangeCombinedView"];
472 - (BOOL)useSwipeChangeCombinedView
474 return [self boolForKey:@"useSwipeChangeCombinedView"];