diff options
author | Starla Insigna <starla4444@gmail.com> | 2011-08-24 11:53:40 -0400 |
---|---|---|
committer | Starla Insigna <starla4444@gmail.com> | 2011-08-24 11:53:40 -0400 |
commit | d8f00310e486aed1ab289a0f816acec571193c32 (patch) | |
tree | 5f2ce4b1a1187035514bcd4e3c8b0b0f17b7c12c /Classes/Cart_CollectAppDelegate.m | |
parent | 21294a54c49ab67e04898aac3482035bab6c79ae (diff) | |
download | cartcollect-d8f00310e486aed1ab289a0f816acec571193c32.tar.gz cartcollect-d8f00310e486aed1ab289a0f816acec571193c32.tar.bz2 cartcollect-d8f00310e486aed1ab289a0f816acec571193c32.zip |
Added support for multiple local highscore lists
This revision increments the database version to 2. Also fixed a small problem with GameModeSelection that aligned the highscore text incorrectly.
Diffstat (limited to 'Classes/Cart_CollectAppDelegate.m')
-rwxr-xr-x | Classes/Cart_CollectAppDelegate.m | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/Classes/Cart_CollectAppDelegate.m b/Classes/Cart_CollectAppDelegate.m index 0af3ac0..ba9d60b 100755 --- a/Classes/Cart_CollectAppDelegate.m +++ b/Classes/Cart_CollectAppDelegate.m | |||
@@ -142,6 +142,8 @@ | |||
142 | 142 | ||
143 | -(void) applicationDidEnterBackground:(UIApplication*)application { | 143 | -(void) applicationDidEnterBackground:(UIApplication*)application { |
144 | [[CCDirector sharedDirector] stopAnimation]; | 144 | [[CCDirector sharedDirector] stopAnimation]; |
145 | |||
146 | [[NSUserDefaults standardUserDefaults] synchronize]; | ||
145 | 147 | ||
146 | if ([[CCDirector sharedDirector] runningScene].tag == GAME_SCENE) | 148 | if ([[CCDirector sharedDirector] runningScene].tag == GAME_SCENE) |
147 | { | 149 | { |
@@ -194,20 +196,48 @@ | |||
194 | { | 196 | { |
195 | NSString* databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; | 197 | NSString* databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName]; |
196 | [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; | 198 | [fileManager copyItemAtPath:databasePathFromApp toPath:databasePath error:nil]; |
197 | //[fileManager release]; | ||
198 | 199 | ||
199 | [userDefaults setInteger:1 forKey:@"databaseVersion"]; | 200 | [userDefaults setInteger:2 forKey:@"databaseVersion"]; |
201 | } | ||
202 | |||
203 | if (sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK) | ||
204 | { | ||
205 | NSLog(@"Failed to open database"); | ||
200 | } | 206 | } |
201 | 207 | ||
208 | // Database migrations! | ||
202 | if ([userDefaults integerForKey:@"databaseVersion"] < 1) | 209 | if ([userDefaults integerForKey:@"databaseVersion"] < 1) |
203 | { | 210 | { |
204 | // Upgrade the database to version 1, which is completely unnecessary as no prior version exists | 211 | // Upgrade the database to version 1, which is completely unnecessary as no prior version exists |
205 | } | 212 | } |
206 | 213 | ||
207 | if (sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK) | 214 | if ([userDefaults integerForKey:@"databaseVersion"] < 2) |
208 | { | 215 | { |
209 | NSLog(@"Failed to open database"); | 216 | // Database version 2 adds a "gameMode" column to highscores to allow for multiple highscore lists |
217 | const char* sqlQuery = "ALTER TABLE highscores ADD gameMode varchar(255)"; | ||
218 | sqlite3_stmt* compiled_statement; | ||
219 | |||
220 | if (sqlite3_prepare_v2(database, sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) | ||
221 | { | ||
222 | sqlite3_step(compiled_statement); | ||
223 | |||
224 | sqlQuery = "UPDATE highscores SET gameMode = \"Collect\""; | ||
225 | if (sqlite3_prepare_v2(database, sqlQuery, -1, &compiled_statement, NULL) == SQLITE_OK) | ||
226 | { | ||
227 | sqlite3_step(compiled_statement); | ||
228 | |||
229 | NSLog(@"Updated database to version 2."); | ||
230 | [userDefaults setInteger:2 forKey:@"databaseVersion"]; | ||
231 | } else { | ||
232 | NSLog(@"Error while updating database to version 2. '%s'", sqlite3_errmsg(database)); | ||
233 | } | ||
234 | } else { | ||
235 | NSLog(@"Error while updating database to version 2. '%s'", sqlite3_errmsg(database)); | ||
236 | } | ||
210 | } | 237 | } |
238 | |||
239 | // It's rather important that the database version gets saved | ||
240 | [userDefaults synchronize]; | ||
211 | } | 241 | } |
212 | 242 | ||
213 | return database; | 243 | return database; |