2.0 -> 3.0 Save Importer [NEED HELP!]

Dom818

  • *
  • Posts: 1296
I finally got an app running on iOS with 3.0 and was shocked to find that saving algorithms are different. 2.2 used the data.plist file in Documents folder while 3.0 uses a different .plist file in the Library folder. If the save data from 2.2 apps cannot be transfered to the new 3.0 format, then upgrading any app to the 3.0 format would be very inconvenient to any user. Any thoughts on how this can be resolved?

BTW: I looked at the new saving format, and it seems much more protected than the previous one.

« Last Edit: November 07, 2012, 11:40:29 pm by Jon »

Jon

  • *
  • Posts: 17524
The only feasible solution I can think of is providing a utility behavior that can read the old format in for you and then you can save to transfer it to the newer format. We're leaning on what NME provides, so this wasn't a deliberate change per se.

Dom818

  • *
  • Posts: 1296
The only feasible solution I can think of is providing a utility behavior that can read the old format in for you and then you can save to transfer it to the newer format. We're leaning on what NME provides, so this wasn't a deliberate change per se.

That would be a perfect solution. :)

Dom818

  • *
  • Posts: 1296
I think you will have to make this utility so it only runs once then gets rid of the old save file. How will this utility work?

Jon

  • *
  • Posts: 17524
1) Check for the existence of a new kind of save file for the game. If it doesn't exist, proceed.
2) Check for the existence of an old save file. If it exists, proceed.
3) Load old save file.
4) Resave using the new format.

Dom818

  • *
  • Posts: 1296
Not trying to be annoying, but can this be implemented soon? I have a few games I can release/ update on iOS using 3.0 and this is the last thing stopping me.

Jon

  • *
  • Posts: 17524
With the state of the release bugs-wise, I can't make any guarantees, let along any commitments that I can do it "soon" - the best I can do is open the prior source and let you guys (I'm sure Jens or another dev with a published game may be interested) take one over.

An extension is the correct path to take here.

Next post will have the details.

Jon

  • *
  • Posts: 17524
This is the code for the save/load game attributes routine in 2.x and below.

Code: [Select]
- (void)saveGame
{
    if(mGameAttributes == nil)
    {
        return;
    }
   
    if(mDocPath == nil)
    {
        NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString* documentsDirectory = [paths objectAtIndex:0];
        mDocPath = [[NSMutableString alloc] initWithString:documentsDirectory];
        [mDocPath stringByAppendingPathComponent:@"/Saves/"];
    }
   
    NSError *error;
    BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:mDocPath withIntermediateDirectories:YES attributes:nil error:&error];
   
    if(!success)
    {
        NSLog(@"Error creating data path: %@", [error localizedDescription]);
    }
   
    NSString *dataPath = [mDocPath stringByAppendingPathComponent:kDataFile];
    NSMutableData *data = [[NSMutableData alloc] init];
    NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];         
    [archiver encodeObject:mGameAttributes forKey:kDataKey];
    [archiver finishEncoding];
    [data writeToFile:dataPath atomically:YES];
    [archiver release];
    [data release];
}

- (void)loadGame
{
    if(mDocPath == nil)
    {
        NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString* documentsDirectory = [paths objectAtIndex:0];
        mDocPath = [[NSMutableString alloc] initWithString:documentsDirectory];
        [mDocPath stringByAppendingPathComponent:@"/Saves/"];
    }

    NSString *dataPath = [mDocPath stringByAppendingPathComponent:kDataFile];
    NSData *codedData = [[[NSData alloc] initWithContentsOfFile:dataPath] autorelease];
   
    if(codedData == nil)
    {
        NSLog(@"Error loading save: %@", dataPath);
        return;
    }
   
    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:codedData];
   
    if(mGameAttributes != nil)
    {
        [mGameAttributes removeAllObjects];
        [mGameAttributes release];
    }
   
    mGameAttributes = [[unarchiver decodeObjectForKey:kDataKey] retain];   
    [unarchiver finishDecoding];
    [unarchiver release];
   
    NSLog(@"%@", mGameAttributes);
}

mGameAttributes is a dictionary.

What you'll want to do is create a native iOS extension (I just wrote a doc on that!) that can use adapt this load routine. Load the data into a dictionary like this, then send it back to Haxe.

I do the exact same thing in several native extensions. I've attached the source for the Purchases extension to show how it's done - the Pedia doc I wrote explains the approach.

sandsoftimer

  • Posts: 316
I Solved this problem as you said, but i want to know, is this a bug that will be solved in stencyl 3. or i have to do this always.
iOS ->          

Android ->
iOS -> Bubble Tapping
 Android -> Bubble Tapping

Dom818

  • *
  • Posts: 1296
I Solved this problem as you said, but i want to know, is this a bug that will be solved in stencyl 3. or i have to do this always.

You solved this? Can you post you solution?

sandsoftimer

  • Posts: 316
EDIT your topics title as "SOLVED" if it is...
I don't know why but it work's for me.  8) 8) 8)
i thing jon will concentrate and will be solved in stencyl 3.
and yes must let me know that your problem is solved or not please.
iOS ->          

Android ->
iOS -> Bubble Tapping
 Android -> Bubble Tapping

Dom818

  • *
  • Posts: 1296
How is it loading the data from the old 2.2 save file?

sandsoftimer

  • Posts: 316
don't know yet. but what about your problem. is it solved or not.
iOS ->          

Android ->
iOS -> Bubble Tapping
 Android -> Bubble Tapping

Dom818

  • *
  • Posts: 1296
This doesn't seem to work for me. :(

sandsoftimer

  • Posts: 316
why don't you thing this won't work.  :o :o :o at least try. by the way, it's your choice. it works for me and thought also for you. as your wish. Good Luck.   ::) ::) ::)
iOS ->          

Android ->
iOS -> Bubble Tapping
 Android -> Bubble Tapping