OSDN Git Service

UIを調整
[kcd/KCD.git] / KCD / HMUserDefaults.m
1 //
2 //  HMUserDefaults.m
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2014/06/01.
6 //  Copyright (c) 2014年 Hori,Masaki. All rights reserved.
7 //
8
9 #import "HMUserDefaults.h"
10
11 HMUserDefaults *HMStandardDefaults = nil;
12
13
14 @implementation HMUserDefaults
15
16 @dynamic slotItemSortDescriptors, shipviewSortDescriptors, powerupSupportSortDecriptors;
17 @dynamic showsDebugMenu;
18 @dynamic hideMaxKaryoku, hideMaxRaisou, hideMaxLucky, hideMaxSoukou, hideMaxTaiku;
19 @dynamic appendKanColleTag;
20 @dynamic prevReloadDate;
21 @dynamic repairTime;
22
23 + (void)load
24 {
25         static dispatch_once_t onceToken;
26         dispatch_once(&onceToken, ^{
27                 HMStandardDefaults = [self new];
28                 
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];
35                 
36                 [[NSUserDefaults standardUserDefaults] registerDefaults:
37                  @{
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,
49                    }
50                  ];
51         });
52 }
53
54 + (instancetype)hmStandardDefauls
55 {
56         return HMStandardDefaults;
57 }
58
59 - (void)setObject:(id)value forKey:(NSString *)key
60 {
61         [[NSUserDefaults standardUserDefaults] setObject:value forKey:key];
62 }
63 - (id)objectForKey:(NSString *)key
64 {
65         return [[NSUserDefaults standardUserDefaults] objectForKey:key];
66 }
67 - (NSString *)stringForKey:(NSString *)key
68 {
69         return [[NSUserDefaults standardUserDefaults] stringForKey:key];
70 }
71 - (void)setInteger:(NSInteger)value forKey:(NSString *)key
72 {
73         [[NSUserDefaults standardUserDefaults] setInteger:value forKey:key];
74 }
75 - (NSInteger)integerForKey:(NSString *)key
76 {
77         return [[NSUserDefaults standardUserDefaults] integerForKey:key];
78 }
79 - (void)setDouble:(double)value forKey:(NSString *)key
80 {
81         [[NSUserDefaults standardUserDefaults] setDouble:value forKey:key];
82 }
83 - (double)doubleForKey:(NSString *)key
84 {
85         return [[NSUserDefaults standardUserDefaults] doubleForKey:key];
86 }
87 - (void)setBool:(BOOL)value forKey:(NSString *)key
88 {
89         [[NSUserDefaults standardUserDefaults] setBool:value forKey:key];
90 }
91 - (BOOL)boolForKey:(NSString *)key
92 {
93         return [[NSUserDefaults standardUserDefaults] boolForKey:key];
94 }
95 - (void)setKeyedArchiveObject:(id)value forKey:(NSString *)key
96 {
97         NSData *data = nil;
98         if(value) {
99                 data = [NSKeyedArchiver archivedDataWithRootObject:value];
100         }
101         [[NSUserDefaults standardUserDefaults] setObject:data forKey:key];
102 }
103 - (id)keyedUnarchiveObject:(NSString *)key
104 {
105         NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:key];
106         return data ? [NSKeyedUnarchiver unarchiveObjectWithData:data] : nil;
107 }
108
109 #pragma mark-Properties
110 - (void)setSlotItemSortDescriptors:(NSArray *)slotItemSortDescriptors
111 {
112         [self setKeyedArchiveObject:slotItemSortDescriptors forKey:@"slotItemSortKey2"];
113 }
114 - (NSArray *)slotItemSortDescriptors
115 {
116         NSArray *array = [self keyedUnarchiveObject:@"slotItemSortKey2"];
117         if(array) {
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];
122                         }
123                 }
124                 
125                 return [NSArray arrayWithArray:result];
126         }
127         return [NSArray new];
128 }
129 - (void)setShipviewSortDescriptors:(NSArray *)shipviewSortDescriptors
130 {
131         [self setKeyedArchiveObject:shipviewSortDescriptors forKey:@"shipviewsortdescriptor"];
132 }
133 - (NSArray *)shipviewSortDescriptors
134 {
135         NSArray *array = [self keyedUnarchiveObject:@"shipviewsortdescriptor"];
136         if(array) {
137                 NSMutableArray *result = [NSMutableArray new];
138                 for(NSSortDescriptor *item in array) {
139                         if(![item.key hasPrefix:@"master_ship"]) {
140                                 [result addObject:item];
141                         }
142                 }
143                 
144                 return [NSArray arrayWithArray:result];
145         }
146         return [NSArray new];
147 }
148 - (void)setPowerupSupportSortDecriptors:(NSArray *)powerupSupportSortDecriptors
149 {
150         [self setKeyedArchiveObject:powerupSupportSortDecriptors forKey:@"powerupsupportsortdecriptor"];
151 }
152 - (NSArray *)powerupSupportSortDecriptors
153 {
154         NSArray *array = [self keyedUnarchiveObject:@"powerupsupportsortdecriptor"];
155         if(array) {
156                 NSMutableArray *result = [NSMutableArray new];
157                 for(NSSortDescriptor *item in array) {
158                         if(![item.key hasPrefix:@"master_ship"]) {
159                                 [result addObject:item];
160                         }
161                 }
162                 
163                 return [NSArray arrayWithArray:result];
164         }
165         return [NSArray new];
166 }
167
168 - (void)setPrevReloadDate:(NSDate *)prevReloadDate
169 {
170         if(prevReloadDate) {
171                 [self setObject:[prevReloadDate description] forKey:@"previousReloadDateString"];
172         }
173 }
174 - (NSDate *)prevReloadDate
175 {
176         NSString *dateString = [self stringForKey:@"previousReloadDateString"];
177         if(dateString) {
178                 return [NSDate dateWithString:dateString];
179         }
180         return nil;
181 }
182
183 - (void)setShowsDebugMenu:(BOOL)showsDebugMenu
184 {
185         [self setBool:showsDebugMenu forKey:@"ShowsDebugMenu"];
186 }
187 - (BOOL)showsDebugMenu
188 {
189         return [self boolForKey:@"ShowsDebugMenu"];
190 }
191
192 - (void)setAppendKanColleTag:(BOOL)appendKanColleTag
193 {
194         [self setBool:appendKanColleTag forKey:@"appendKanColleTag"];
195 }
196 - (BOOL)appendKanColleTag
197 {
198         return [self boolForKey:@"appendKanColleTag"];
199 }
200
201 - (void)setHideMaxKaryoku:(BOOL)hideMaxKaryoku
202 {
203         [self setBool:hideMaxKaryoku forKey:@"hideMaxKaryoku"];
204 }
205 - (BOOL)hideMaxKaryoku
206 {
207         return [self boolForKey:@"hideMaxKaryoku"];
208 }
209 - (void)setHideMaxLucky:(BOOL)hideMaxLucky
210 {
211         [self setBool:hideMaxLucky forKey:@"hideMaxLucky"];
212 }
213 - (BOOL)hideMaxLucky
214 {
215         return [self boolForKey:@"hideMaxLucky"];
216 }
217 - (void)setHideMaxRaisou:(BOOL)hideMaxRaisou
218 {
219         [self setBool:hideMaxRaisou forKey:@"hideMaxRaisou"];
220 }
221 - (BOOL)hideMaxRaisou
222 {
223         return [self boolForKey:@"hideMaxRaisou"];
224 }
225 - (void)setHideMaxSoukou:(BOOL)hideMaxSoukou
226 {
227         [self setBool:hideMaxSoukou forKey:@"hideMaxSoukou"];
228 }
229 - (BOOL)hideMaxSoukou
230 {
231         return [self boolForKey:@"hideMaxSoukou"];
232 }
233 - (void)setHideMaxTaiku:(BOOL)hideMaxTaiku
234 {
235         [self setBool:hideMaxTaiku forKey:@"hideMaxTaiku"];
236 }
237 - (BOOL)hideMaxTaiku
238 {
239         return [self boolForKey:@"hideMaxTaiku"];
240 }
241
242 - (void)setShowsPlanColor:(BOOL)showsPlanColor
243 {
244         [self setBool:showsPlanColor forKey:@"showsPlanColor"];
245 }
246 - (BOOL)showsPlanColor
247 {
248         return [self boolForKey:@"showsPlanColor"];
249 }
250 - (void)setPlan01Color:(NSColor *)plan01Color
251 {
252         [self setKeyedArchiveObject:plan01Color forKey:@"plan01Color"];
253 }
254 - (NSColor *)plan01Color
255 {
256         return [self keyedUnarchiveObject:@"plan01Color"];
257 }
258 - (void)setPlan02Color:(NSColor *)plan02Color
259 {
260         [self setKeyedArchiveObject:plan02Color forKey:@"plan02Color"];
261 }
262 - (NSColor *)plan02Color
263 {
264         return [self keyedUnarchiveObject:@"plan02Color"];
265 }
266 - (void)setPlan03Color:(NSColor *)plan03Color
267 {
268         [self setKeyedArchiveObject:plan03Color forKey:@"plan03Color"];
269 }
270 - (NSColor *)plan03Color
271 {
272         return [self keyedUnarchiveObject:@"plan03Color"];
273 }
274 - (void)setPlan04Color:(NSColor *)plan04Color
275 {
276         [self setKeyedArchiveObject:plan04Color forKey:@"plan04Color"];
277 }
278 - (NSColor *)plan04Color
279 {
280         return [self keyedUnarchiveObject:@"plan04Color"];
281 }
282 - (void)setPlan05Color:(NSColor *)plan05Color
283 {
284         [self setKeyedArchiveObject:plan05Color forKey:@"plan05Color"];
285 }
286 - (NSColor *)plan05Color
287 {
288         return [self keyedUnarchiveObject:@"plan05Color"];
289 }
290 - (void)setPlan06Color:(NSColor *)plan06Color
291 {
292         [self setKeyedArchiveObject:plan06Color forKey:@"plan06Color"];
293 }
294 - (NSColor *)plan06Color
295 {
296         return [self keyedUnarchiveObject:@"plan06Color"];
297 }
298
299 - (void)setMinimumColoredShipCount:(NSInteger)minimumColoredShipCount
300 {
301         [self setInteger:minimumColoredShipCount forKey:@"minimumColoredShipCount"];
302 }
303 - (NSInteger)minimumColoredShipCount
304 {
305         return [self integerForKey:@"minimumColoredShipCount"];
306 }
307
308 #pragma mark - Screenshot
309 - (void)setUseMask:(BOOL)useMask
310 {
311         [self setBool:useMask forKey:@"useMask"];
312 }
313 - (BOOL)useMask
314 {
315         return [self boolForKey:@"useMask"];
316 }
317
318 - (void)setScreenShotBorderWidth:(CGFloat)screenShotBorderWidth
319 {
320         if(screenShotBorderWidth < 0 || screenShotBorderWidth > 20) return;
321         
322         [self setDouble:screenShotBorderWidth forKey:@"screenShotBorderWidth"];
323 }
324 - (CGFloat)screenShotBorderWidth
325 {
326         CGFloat result = [self doubleForKey:@"screenShotBorderWidth"];
327         
328         if(result < 0) {
329                 [self setDouble:0 forKey:@"screenShotBorderWidth"];
330                 return 0;
331         }
332         if(result > 20) {
333                 [self setDouble:20 forKey:@"screenShotBorderWidth"];
334                 return 20;
335         }
336         
337         return result;
338 }
339
340 - (void)setScreenShotSaveDirectory:(NSURL *)screenShotSaveDirectory
341 {
342         [self setObject:screenShotSaveDirectory forKey:@"screenShotSaveDirectory"];
343 }
344 - (NSString *)screenShotSaveDirectory
345 {
346         return [self objectForKey:@"screenShotSaveDirectory"];
347 }
348
349 - (void)setShowsListWindowAtScreenshot:(BOOL)showsListWindowAtScreenshot
350 {
351         [self setBool:showsListWindowAtScreenshot forKey:@"showsListWindowAtScreenshot"];
352 }
353 - (BOOL)showsListWindowAtScreenshot
354 {
355         return [self boolForKey:@"showsListWindowAtScreenshot"];
356 }
357
358 - (void)setScreenshotPreviewZoomValue:(NSNumber *)screenshotPreviewZoomValue
359 {
360         [self setObject:screenshotPreviewZoomValue forKey:@"screenshotPreviewZoomValue"];
361 }
362 - (NSNumber *)screenshotPreviewZoomValue
363 {
364         return [self objectForKey:@"screenshotPreviewZoomValue"];
365 }
366
367 #pragma mark - Notify Sound
368 - (void)setPlayFinishMissionSound:(BOOL)playFinishMissionSound
369 {
370         [self setBool:playFinishMissionSound forKey:@"playFinishMissionSound"];
371 }
372 - (BOOL)playFinishMissionSound
373 {
374         return [self boolForKey:@"playFinishMissionSound"];
375 }
376 - (void)setPlayFinishNyukyoSound:(BOOL)playFinishNyukyoSound
377 {
378         [self setBool:playFinishNyukyoSound forKey:@"playFinishNyukyoSound"];
379 }
380 - (BOOL)playFinishNyukyoSound
381 {
382         return [self boolForKey:@"playFinishNyukyoSound"];
383 }
384 - (void)setPlayFinishKenzoSound:(BOOL)playFinishKenzoSound
385 {
386         [self setBool:playFinishKenzoSound forKey:@"playFinishKenzoSound"];
387 }
388 - (BOOL)playFinishKenzoSound
389 {
390         return [self boolForKey:@"playFinishKenzoSound"];
391 }
392
393
394 #pragma mark - Upgradable List
395 - (void)setShowLevelOneShipInUpgradableList:(BOOL)showLevelOneShipInUpgradableList
396 {
397         [self setBool:showLevelOneShipInUpgradableList forKey:@"showLevelOneShipInUpgradableList"];
398 }
399 - (BOOL)showLevelOneShipInUpgradableList
400 {
401         return [self boolForKey:@"showLevelOneShipInUpgradableList"];
402 }
403 - (void)setShowsExcludedShipInUpgradableList:(BOOL)showsExcludedShipInUpgradableList
404 {
405         [self setBool:showsExcludedShipInUpgradableList forKey:@"showsExcludedShipInUpgradableList"];
406 }
407 - (BOOL)showsExcludedShipInUpgradableList
408 {
409         return [self boolForKey:@"showsExcludedShipInUpgradableList"];
410 }
411
412
413 #pragma mark - Equipment List
414 - (void)setShowEquipmentType:(NSNumber *)showEquipmentType
415 {
416         [self setObject:showEquipmentType forKey:@"showEquipmentType"];
417 }
418 - (NSNumber *)showEquipmentType
419 {
420         return [self objectForKey:@"showEquipmentType"];
421 }
422
423 #pragma mark - FleetView
424 - (void)setFleetViewPosition:(NSInteger)fleetViewPosition
425 {
426         [self setInteger:fleetViewPosition forKey:@"fleetViewPosition"];
427 }
428 - (NSInteger)fleetViewPosition
429 {
430         return [self integerForKey:@"fleetViewPosition"];
431 }
432 - (void)setFleetViewShipOrder:(NSInteger)fleetViewShipOrder
433 {
434         if(fleetViewShipOrder < 0 || fleetViewShipOrder > 1) return;
435         [self setInteger:fleetViewShipOrder forKey:@"fleetViewShipOrder"];
436 }
437 - (NSInteger)fleetViewShipOrder
438 {
439         return [self integerForKey:@"fleetViewShipOrder"];
440 }
441
442 - (void)setRepairTime:(NSDate *)repairTime
443 {
444         [self setKeyedArchiveObject:repairTime forKey:@"repairTime"];
445 }
446 - (NSDate *)repairTime
447 {
448         return [self keyedUnarchiveObject:@"repairTime"];
449 }
450
451 #pragma mark - combined view
452 - (void)setLastHasCombinedView:(BOOL)lastHasCombinedView
453 {
454         [self setBool:lastHasCombinedView forKey:@"lastHasCombinedView"];
455 }
456 - (BOOL)lastHasCombinedView
457 {
458         return [self boolForKey:@"lastHasCombinedView"];
459 }
460 - (void)setAutoCombinedView:(BOOL)autoCombinedView
461 {
462         [self setBool:autoCombinedView forKey:@"autoCombinedView"];
463 }
464 - (BOOL)autoCombinedView
465 {
466         return [self boolForKey:@"autoCombinedView"];
467 }
468 - (void)setUseSwipeChangeCombinedView:(BOOL)useSwipeChangeCombinedView
469 {
470         [self setBool:useSwipeChangeCombinedView forKey:@"useSwipeChangeCombinedView"];
471 }
472 - (BOOL)useSwipeChangeCombinedView
473 {
474         return [self boolForKey:@"useSwipeChangeCombinedView"];
475 }
476 @end