/** * If you want to attempt a manual merge, this would be the way to do it. * Note that in general, manual merges work best if you have "union" type of merges where taking * the highest value is the best resolution (i.e. high scores on a level, stars per level, * unlocked levels, etc.) */ void resolveSnapshot(SnapshotMetadata conflictingSnapshotBase, SnapshotMetadata conflictingSnapshotRemote, string conflictId) { Console.WriteLine("Resolving snapshot conflicts: {0} >> {1}", conflictingSnapshotBase, conflictingSnapshotRemote); conflictingSnapshotBase.Read(async delegate(NSData baseData, NSError baseError) { if (baseError == null) { conflictingSnapshotRemote.Read(async delegate(NSData remoteData, NSError remoteError) { if (remoteError == null) { var baseInv = StarInventory.FromCloudData(baseData); var remoteInv = StarInventory.FromCloudData(remoteData); var merged = new StarInventory(); for (int world = 1; world <= 20; world++) { for (int level = 1; level <= 12; level++) { var baseStars = baseInv.GetStars(world, level); var remoteStars = remoteInv.GetStars(world, level); var maxStars = Math.Max(baseStars, remoteStars); if (maxStars > 0) { Console.WriteLine("Level {0}-{1} had {2} stars on base, {3} stars on remote. Merging to {4}", world, level, baseStars, remoteStars, maxStars); merged.SetStars(maxStars, world, level); } } } // We have a merged data set, we need to create a merged metadata change var change = new SnapshotMetadataChange(); change.SnapshotDescription = "Merged save data"; change.PlayedTime = Math.Max(conflictingSnapshotBase.PlayedTime, conflictingSnapshotRemote.PlayedTime); var mergedData = merged.GetCloudData(); // [base resolveWithMetadataChange:change conflictId:conflictId data:mergedData completionHandler:^(GPGSnapshotMetadata *snapshotMetadata, NSError *error) { // if (!error) { // // Once we're done, we need to re-read the returned snapshot in case there are further // // conflicts waiting to be merged // [self loadSnapshot:snapshotMetadata]; // } // }]; } }); } }); }
// - (void)readCurrentSnapshot { // [self.currentSnapshotMetadata readWithCompletionHandler:^(NSData *data, NSError *error) { // if (!error) { // NSLog(@"Successfully read %d blocks", (int) data.length); // self.inventory = [GCATStarInventory starInventoryFromCloudData:data]; // [self.screenViewController allDoneWithCloud]; // // } else { // NSLog(@"Error while loading snapshot data: %@", error); // NSLog(@"Error description: %@", [error description]); // } // }]; // } void readCurrentSnapshot() { CurrentSnapshotMetadata.Read(async delegate(NSData data, NSError error) { if (error == null) { Console.WriteLine("Successfully read {0} blocks", data.Length); Inventory = StarInventory.FromCloudData(data); ScreenViewController.AllDoneWithCloud(); } else { Console.WriteLine("Error while loading snapshot data: {0}", error); Console.WriteLine("Error description: {0}", error.Description); } }); }
public Model() { StarSaveSlot = NSNumber.FromInt32(0); Inventory = new StarInventory(); }