From cdb13146eb0a30fc447a904a9d2408b8dbae59d3 Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Tue, 9 Aug 2016 20:00:00 -0400 Subject: [PATCH] v0.4.1a: fixed problems with rankings ids, implemented UUIDs for them as well --- .../shatteredpixeldungeon/Rankings.java | 4 +-- .../scenes/WelcomeScene.java | 30 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/Rankings.java b/src/com/shatteredpixel/shatteredpixeldungeon/Rankings.java index 6ae1cfa0a..77d37fe0c 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/Rankings.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/Rankings.java @@ -48,7 +48,6 @@ import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton; import com.watabou.noosa.Game; import com.watabou.utils.Bundlable; import com.watabou.utils.Bundle; -import com.watabou.utils.SystemTime; import java.io.IOException; import java.io.InputStream; @@ -57,6 +56,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Locale; +import java.util.UUID; public enum Rankings { @@ -87,7 +87,7 @@ public enum Rankings { INSTANCE.saveGameData(rec); - rec.gameID = String.valueOf(SystemTime.now); + rec.gameID = UUID.randomUUID().toString(); records.add( rec ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/WelcomeScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/WelcomeScene.java index bd2c6ee43..7110c416b 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/WelcomeScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/WelcomeScene.java @@ -36,6 +36,8 @@ import com.watabou.noosa.Image; import com.watabou.noosa.audio.Sample; import javax.microedition.khronos.opengles.GL10; +import java.util.ArrayList; +import java.util.UUID; public class WelcomeScene extends PixelScene { @@ -148,22 +150,26 @@ public class WelcomeScene extends PixelScene { private void updateVersion(int previousVersion){ //rankings conversion - if (previousVersion < 108){ + if (previousVersion <= 114){ Rankings.INSTANCE.load(); for (Rankings.Record rec : Rankings.INSTANCE.records){ - try{ - Dungeon.loadGame(rec.gameFile, false); - rec.gameID = rec.gameFile.replaceAll("\\D", ""); + if (rec.gameFile != null) { + try { + Dungeon.loadGame(rec.gameFile, false); + rec.gameID = rec.gameFile.replaceAll("\\D", ""); - Rankings.INSTANCE.saveGameData(rec); - } catch (Exception e){ - rec.gameID = rec.gameFile.replaceAll("\\D", ""); - rec.gameData = null; + Rankings.INSTANCE.saveGameData(rec); + } catch (Exception e) { + rec.gameID = rec.gameFile.replaceAll("\\D", ""); + rec.gameData = null; + } + + String file = rec.gameFile; + rec.gameFile = ""; + Game.instance.deleteFile(file); + } else if (rec.gameID == null){ + rec.gameID = UUID.randomUUID().toString(); } - - String file = rec.gameFile; - rec.gameFile = ""; - Game.instance.deleteFile(file); } Rankings.INSTANCE.save(); }