From a2d6a7bda592c2ab84b3e1c653fbfd2a6585bd9e Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 7 Feb 2016 19:30:51 -0500 Subject: [PATCH] v0.3.4: improved how pre-0.3.4 rankings are handled --- .../shatteredpixeldungeon/Rankings.java | 95 ++++++++++--------- .../messages/Messages.java | 2 +- .../messages/misc/misc.properties | 2 + .../scenes/RankingsScene.java | 2 +- 4 files changed, 56 insertions(+), 45 deletions(-) diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/Rankings.java b/src/com/shatteredpixel/shatteredpixeldungeon/Rankings.java index 9c1a23a90..e286181b2 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/Rankings.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/Rankings.java @@ -20,7 +20,21 @@ */ package com.shatteredpixel.shatteredpixeldungeon; +import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.ToxicGas; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Bleeding; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Burning; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Hunger; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Ooze; +import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Poison; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.DM300; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Goo; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.King; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Tengu; +import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Yog; +import com.shatteredpixel.shatteredpixeldungeon.items.Amulet; +import com.shatteredpixel.shatteredpixeldungeon.levels.features.Chasm; +import com.shatteredpixel.shatteredpixeldungeon.messages.Languages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.watabou.noosa.Game; import com.watabou.utils.Bundlable; @@ -191,14 +205,21 @@ public enum Rankings { public String gameFile; public String desc(){ - if (cause == null && (info == null || info.equals(""))) - return "Killed by Something"; - else if (cause == null){ - return info; //pre 0.3.4 saves + if (cause == null) { + if (info != null){ + //support for pre-0.3.4 saves + if (Messages.lang() == Languages.ENGLISH) { + return info; + } else { + return Messages.get(this, "something"); + } + } else { + return Messages.get(this, "something"); + } } else { String result = Messages.get(cause, "rankings_desc", (Messages.get(cause, "name"))); if (result.contains("!!!NO TEXT FOUND!!!")){ - return "Killed By Something"; + return Messages.get(this, "something"); } else { return result; } @@ -208,10 +229,30 @@ public enum Rankings { @Override public void restoreFromBundle( Bundle bundle ) { - //pre-0.3.4 - info = bundle.getString( REASON ); + //conversion logic for pre-0.3.4 saves + if (bundle.contains( REASON )){ + String info = bundle.getString( REASON ).toLowerCase(); + if (info.equals("obtained the amulet of yendor")) cause = Amulet.class; + else if (info.contains("goo")) cause = Goo.class; + else if (info.contains("tengu")) cause = Tengu.class; + else if (info.contains("dm-300")) cause = DM300.class; + else if (info.contains("king")) cause = King.class; + else if (info.contains("yog")) cause = Yog.class; + else if (info.contains("fist")) cause = Yog.class; + else if (info.contains("larva")) cause = Yog.class; + else if (info.equals("burned to ash")) cause = Burning.class; + else if (info.equals("starved to death")) cause = Hunger.class; + else if (info.equals("succumbed to poison")) cause = Poison.class; + else if (info.equals("suffocated")) cause = ToxicGas.class; + else if (info.equals("bled to death")) cause = Bleeding.class; + else if (info.equals("melted away")) cause = Ooze.class; + else if (info.equals("died on impact")) cause = Chasm.class; + //can't get the all, just keep what remains as-is + else this.info = info; + } else { + cause = bundle.getClass( CAUSE ); + } - cause = bundle.getClass( CAUSE ); win = bundle.getBoolean( WIN ); score = bundle.getInt( SCORE ); @@ -220,47 +261,15 @@ public enum Rankings { gameFile = bundle.getString( GAME ); - //Here lies a collection of messy logic, some to account for transferring pre-0.2.3 rankings to the new - //system, some to account for errors in that process which were patched. - //commented here is info about what was added when, and why, eventually after almost everyone has - //dropped 0.2.2 this can be phased out. - - //0.2.3, adds depth and parses info, works almost perfectly, except for the edge case in the next comment. - if (!bundle.contains(DEPTH)){ - try { - depth = Integer.parseInt(info.replaceAll("[\\D]", "")); - } catch (Exception e) { - depth = 0; - } - info = info.split("on level")[0].trim(); - } else - depth = bundle.getInt( DEPTH ); - - //0.2.3d, fixes a case where a player who died to dm-300 would have a recorded depth of 30015. - if (depth == 30015) depth = 15; - - //basically every patch until 0.2.3d, extracts the hero's level from the bundle structure. - //the second condition in the if is important, helps account for bugged rankings from pre 0.2.3d - if (!bundle.contains(LEVEL) || bundle.getInt(LEVEL) == 0 && ShatteredPixelDungeon.version() < 30) { - try { - - InputStream input = Game.instance.openFileInput(gameFile); - Bundle gameBundle = Bundle.read(input); - input.close(); - - herolevel = gameBundle.getBundle("hero").getInt("lvl"); - } catch (Exception e) { - herolevel = 0; - } - } else - herolevel = bundle.getInt( LEVEL ); + depth = bundle.getInt( DEPTH ); + herolevel = bundle.getInt( LEVEL ); } @Override public void storeInBundle( Bundle bundle ) { - if (info != null && !info.equals("")) bundle.put( REASON, info ); + if (info != null) bundle.put( REASON, info ); else bundle.put( CAUSE, cause ); bundle.put( WIN, win ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java b/src/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java index daaf0ccba..a08cdf3c2 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/messages/Messages.java @@ -153,7 +153,7 @@ public class Messages { private static final HashSet noCaps = new HashSet<>( Arrays.asList(new String[]{ //English - "a", "of", "by", "to", + "a", "of", "by", "to", "the" }) ); diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/messages/misc/misc.properties b/src/com/shatteredpixel/shatteredpixeldungeon/messages/misc/misc.properties index b8fee88e0..ff476b7a2 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/messages/misc/misc.properties +++ b/src/com/shatteredpixel/shatteredpixeldungeon/messages/misc/misc.properties @@ -84,3 +84,5 @@ journal$feature.ghost=Sad ghost journal$feature.wandmaker=Old wandmaker journal$feature.troll=Troll blacksmith journal$feature.imp=Ambitious imp + +rankings$record.something=Killed by Something \ No newline at end of file diff --git a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/RankingsScene.java b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/RankingsScene.java index 448cab3b3..a4db7b040 100644 --- a/src/com/shatteredpixel/shatteredpixeldungeon/scenes/RankingsScene.java +++ b/src/com/shatteredpixel/shatteredpixeldungeon/scenes/RankingsScene.java @@ -185,7 +185,7 @@ public class RankingsScene extends PixelScene { position.text(" "); position.measure(); - desc.text( rec.desc() ); + desc.text( Messages.titleCase(rec.desc()) ); //desc.measure();