v1.3.0: custom seeds now show their original input text

This commit is contained in:
Evan Debenham
2022-05-20 16:23:10 -04:00
parent 654bce1f65
commit a9a6c13d95
12 changed files with 59 additions and 41 deletions
@@ -958,7 +958,7 @@ public class Badges {
private static void displayBadge( Badge badge ) { private static void displayBadge( Badge badge ) {
if (badge == null || Dungeon.usingCustomSeed) { if (badge == null || !Dungeon.customSeedText.isEmpty()) {
return; return;
} }
@@ -995,7 +995,7 @@ public class Badges {
} }
public static void unlock( Badge badge ){ public static void unlock( Badge badge ){
if (!isUnlocked(badge) && !Dungeon.usingCustomSeed){ if (!isUnlocked(badge) && Dungeon.customSeedText.isEmpty()){
global.add( badge ); global.add( badge );
saveNeeded = true; saveNeeded = true;
} }
@@ -51,7 +51,7 @@ public class Bones {
depth = Dungeon.depth; depth = Dungeon.depth;
//heroes drop no bones if they have the amulet, die far above their farthest depth, are challenged, or are playing with a custom seed. //heroes drop no bones if they have the amulet, die far above their farthest depth, are challenged, or are playing with a custom seed.
if (Statistics.amuletObtained || (Statistics.deepestFloor - 5) >= depth || Dungeon.challenges > 0 || Dungeon.usingCustomSeed) { if (Statistics.amuletObtained || (Statistics.deepestFloor - 5) >= depth || Dungeon.challenges > 0 || !Dungeon.customSeedText.isEmpty()) {
depth = -1; depth = -1;
return; return;
} }
@@ -142,7 +142,7 @@ public class Bones {
} else { } else {
//heroes who are challenged or on a seeded run cannot find bones //heroes who are challenged or on a seeded run cannot find bones
if (depth == Dungeon.depth && Dungeon.challenges == 0 && !Dungeon.usingCustomSeed) { if (depth == Dungeon.depth && Dungeon.challenges == 0 && Dungeon.customSeedText.isEmpty()) {
Bundle emptyBones = new Bundle(); Bundle emptyBones = new Bundle();
emptyBones.put(LEVEL, 0); emptyBones.put(LEVEL, 0);
try { try {
@@ -179,6 +179,7 @@ public class Dungeon {
public static int initialVersion; public static int initialVersion;
public static int version; public static int version;
public static String customSeedText;
public static long seed; public static long seed;
public static boolean usingCustomSeed; public static boolean usingCustomSeed;
@@ -188,12 +189,12 @@ public class Dungeon {
challenges = SPDSettings.challenges(); challenges = SPDSettings.challenges();
mobsToChampion = -1; mobsToChampion = -1;
if (SPDSettings.customSeed() != -1){ if (SPDSettings.customSeed() != ""){
seed = SPDSettings.customSeed(); customSeedText = SPDSettings.customSeed();
usingCustomSeed = true; seed = DungeonSeed.convertFromText(customSeedText);
} else { } else {
customSeedText = "";
seed = DungeonSeed.randomSeed(); seed = DungeonSeed.randomSeed();
usingCustomSeed = false;
} }
Actor.clear(); Actor.clear();
@@ -495,7 +496,7 @@ public class Dungeon {
bundle.put( INIT_VER, initialVersion ); bundle.put( INIT_VER, initialVersion );
bundle.put( VERSION, version = Game.versionCode ); bundle.put( VERSION, version = Game.versionCode );
bundle.put( SEED, seed ); bundle.put( SEED, seed );
bundle.put( CUSTOM_SEED, usingCustomSeed ); bundle.put( CUSTOM_SEED, customSeedText );
bundle.put( CHALLENGES, challenges ); bundle.put( CHALLENGES, challenges );
bundle.put( MOBS_TO_CHAMPION, mobsToChampion ); bundle.put( MOBS_TO_CHAMPION, mobsToChampion );
bundle.put( HERO, hero ); bundle.put( HERO, hero );
@@ -573,7 +574,7 @@ public class Dungeon {
saveGame( GamesInProgress.curSlot ); saveGame( GamesInProgress.curSlot );
saveLevel( GamesInProgress.curSlot ); saveLevel( GamesInProgress.curSlot );
GamesInProgress.set( GamesInProgress.curSlot, depth, challenges, seed, usingCustomSeed, hero ); GamesInProgress.set( GamesInProgress.curSlot, depth, challenges, seed, customSeedText, hero );
} }
} }
@@ -596,7 +597,7 @@ public class Dungeon {
version = bundle.getInt( VERSION ); version = bundle.getInt( VERSION );
seed = bundle.contains( SEED ) ? bundle.getLong( SEED ) : DungeonSeed.randomSeed(); seed = bundle.contains( SEED ) ? bundle.getLong( SEED ) : DungeonSeed.randomSeed();
usingCustomSeed = bundle.getBoolean( CUSTOM_SEED ); customSeedText = bundle.getString( CUSTOM_SEED );
Actor.clear(); Actor.clear();
Actor.restoreNextID( bundle ); Actor.restoreNextID( bundle );
@@ -729,7 +730,7 @@ public class Dungeon {
info.version = bundle.getInt( VERSION ); info.version = bundle.getInt( VERSION );
info.challenges = bundle.getInt( CHALLENGES ); info.challenges = bundle.getInt( CHALLENGES );
info.seed = bundle.getLong( SEED ); info.seed = bundle.getLong( SEED );
info.customSeed = bundle.getBoolean( CUSTOM_SEED ); info.customSeed = bundle.getString( CUSTOM_SEED );
Hero.preview( info, bundle.getBundle( HERO ) ); Hero.preview( info, bundle.getBundle( HERO ) );
Statistics.preview( info, bundle ); Statistics.preview( info, bundle );
@@ -126,7 +126,7 @@ public class GamesInProgress {
} }
} }
public static void set(int slot, int depth, int challenges, long seed, boolean customSeed, public static void set(int slot, int depth, int challenges, long seed, String customSeed,
Hero hero) { Hero hero) {
Info info = new Info(); Info info = new Info();
info.slot = slot; info.slot = slot;
@@ -170,7 +170,7 @@ public class GamesInProgress {
public int challenges; public int challenges;
public long seed; public long seed;
public boolean customSeed; public String customSeed;
public int level; public int level;
public int str; public int str;
@@ -63,7 +63,7 @@ public enum Rankings {
public void submit( boolean win, Class cause ) { public void submit( boolean win, Class cause ) {
//games with custom seeds do not appear in rankings //games with custom seeds do not appear in rankings
if (Dungeon.usingCustomSeed) return; if (!Dungeon.customSeedText.isEmpty()) return;
load(); load();
@@ -209,12 +209,12 @@ public class SPDSettings extends GameSettings {
return getInt( KEY_CHALLENGES, 0, 0, Challenges.MAX_VALUE ); return getInt( KEY_CHALLENGES, 0, 0, Challenges.MAX_VALUE );
} }
public static void customSeed( long value ){ public static void customSeed( String value ){
put( KEY_CUSTOM_SEED, value ); put( KEY_CUSTOM_SEED, value );
} }
public static long customSeed() { public static String customSeed() {
return getLong( KEY_CUSTOM_SEED, -1, -1, DungeonSeed.TOTAL_SEEDS-1); return getString( KEY_CUSTOM_SEED, "", 20);
} }
public static void supportNagged( boolean value ) { public static void supportNagged( boolean value ) {
@@ -199,22 +199,23 @@ public class HeroSelectScene extends PixelScene {
seedButton = new IconButton( Icons.get(Icons.SEED)){ seedButton = new IconButton( Icons.get(Icons.SEED)){
@Override @Override
protected void onClick() { protected void onClick() {
String existingSeedtext = SPDSettings.customSeed() == -1 ? "" : DungeonSeed.convertToCode(SPDSettings.customSeed()); String existingSeedtext = SPDSettings.customSeed();
ShatteredPixelDungeon.scene().addToFront( new WndTextInput(Messages.get(HeroSelectScene.class, "custom_seed_title"), ShatteredPixelDungeon.scene().addToFront( new WndTextInput(Messages.get(HeroSelectScene.class, "custom_seed_title"),
Messages.get(HeroSelectScene.class, "custom_seed_desc"), Messages.get(HeroSelectScene.class, "custom_seed_desc"),
existingSeedtext, existingSeedtext,
30, 20,
false, false,
Messages.get(HeroSelectScene.class, "custom_seed_set"), Messages.get(HeroSelectScene.class, "custom_seed_set"),
Messages.get(HeroSelectScene.class, "custom_seed_clear")){ Messages.get(HeroSelectScene.class, "custom_seed_clear")){
@Override @Override
public void onSelect(boolean positive, String text) { public void onSelect(boolean positive, String text) {
text = DungeonSeed.formatText(text);
long seed = DungeonSeed.convertFromText(text); long seed = DungeonSeed.convertFromText(text);
if (positive && seed != -1){ if (positive && seed != -1){
SPDSettings.customSeed(seed); SPDSettings.customSeed(text);
icon.hardlight(1f, 1.5f, 0.67f); icon.hardlight(1f, 1.5f, 0.67f);
} else { } else {
SPDSettings.customSeed(-1); SPDSettings.customSeed("");
icon.resetColor(); icon.resetColor();
} }
} }
@@ -223,7 +224,7 @@ public class HeroSelectScene extends PixelScene {
@Override @Override
protected void onPointerUp() { protected void onPointerUp() {
if (SPDSettings.customSeed() != -1){ if (!SPDSettings.customSeed().isEmpty()){
icon.hardlight(1f, 1.5f, 0.67f); icon.hardlight(1f, 1.5f, 0.67f);
} else { } else {
icon.resetColor(); icon.resetColor();
@@ -243,7 +244,7 @@ public class HeroSelectScene extends PixelScene {
return Messages.get(HeroSelectScene.class, "custom_seed_title"); return Messages.get(HeroSelectScene.class, "custom_seed_title");
} }
}; };
if (SPDSettings.customSeed() != -1) seedButton.icon().hardlight(1f, 1.5f, 0.67f); if (!SPDSettings.customSeed().isEmpty()) seedButton.icon().hardlight(1f, 1.5f, 0.67f);
seedButton.setRect(challengeButton.left()-16, challengeButton.top(), 16, 21); seedButton.setRect(challengeButton.left()-16, challengeButton.top(), 16, 21);
seedButton.visible = false; seedButton.visible = false;
@@ -253,7 +254,7 @@ public class HeroSelectScene extends PixelScene {
} else { } else {
Dungeon.challenges = 0; Dungeon.challenges = 0;
SPDSettings.challenges(0); SPDSettings.challenges(0);
SPDSettings.customSeed(-1); SPDSettings.customSeed("");
} }
btnExit = new ExitButton(); btnExit = new ExitButton();
@@ -203,7 +203,7 @@ public class StartScene extends PixelScene {
level.resetColor(); level.resetColor();
} }
if (info.customSeed){ if (!info.customSeed.isEmpty()){
steps.hardlight(1f, 1.5f, 0.67f); steps.hardlight(1f, 1.5f, 0.67f);
} }
@@ -295,28 +295,28 @@ public enum Icons {
icon.frame( icon.texture.uvRectBySize( 40, 72, 8, 8 ) ); icon.frame( icon.texture.uvRectBySize( 40, 72, 8, 8 ) );
break; break;
case DEPTH: case DEPTH:
icon.frame( icon.texture.uvRectBySize( 48, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 6, 7 ) ); icon.frame( icon.texture.uvRectBySize( 48, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 6, 7 ) );
break; break;
case DEPTH_CHASM: case DEPTH_CHASM:
icon.frame( icon.texture.uvRectBySize( 56, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); icon.frame( icon.texture.uvRectBySize( 56, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) );
break; break;
case DEPTH_WATER: case DEPTH_WATER:
icon.frame( icon.texture.uvRectBySize( 64, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); icon.frame( icon.texture.uvRectBySize( 64, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) );
break; break;
case DEPTH_GRASS: case DEPTH_GRASS:
icon.frame( icon.texture.uvRectBySize( 72, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); icon.frame( icon.texture.uvRectBySize( 72, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) );
break; break;
case DEPTH_DARK: case DEPTH_DARK:
icon.frame( icon.texture.uvRectBySize( 80, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); icon.frame( icon.texture.uvRectBySize( 80, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) );
break; break;
case DEPTH_LARGE: case DEPTH_LARGE:
icon.frame( icon.texture.uvRectBySize( 88, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); icon.frame( icon.texture.uvRectBySize( 88, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) );
break; break;
case DEPTH_TRAPS: case DEPTH_TRAPS:
icon.frame( icon.texture.uvRectBySize( 96, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); icon.frame( icon.texture.uvRectBySize( 96, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) );
break; break;
case DEPTH_SECRETS: case DEPTH_SECRETS:
icon.frame( icon.texture.uvRectBySize( 104, 64 + (Dungeon.usingCustomSeed ? 8 : 0), 7, 7 ) ); icon.frame( icon.texture.uvRectBySize( 104, 64 + (Dungeon.customSeedText.isEmpty() ? 0 : 8), 7, 7 ) );
break; break;
case CHAL_COUNT: case CHAL_COUNT:
icon.frame( icon.texture.uvRectBySize( 112, 64, 7, 7 ) ); icon.frame( icon.texture.uvRectBySize( 112, 64, 7, 7 ) );
@@ -23,6 +23,8 @@ package com.shatteredpixel.shatteredpixeldungeon.utils;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import java.util.Locale;
//This class defines the parameters for seeds in ShatteredPD and contains a few convenience methods //This class defines the parameters for seeds in ShatteredPD and contains a few convenience methods
public class DungeonSeed { public class DungeonSeed {
@@ -122,4 +124,15 @@ public class DungeonSeed {
return total; return total;
} }
public static String formatText( String inputText ){
try {
//if the seed matches a code, then just convert it to using the code system
return convertToCode(convertFromCode(inputText));
} catch (IllegalArgumentException e){
//otherwise just return the input text
return inputText;
}
}
} }
@@ -103,8 +103,8 @@ public class WndGameInProgress extends Window {
pos += GAP; pos += GAP;
statSlot( Messages.get(this, "gold"), info.goldCollected ); statSlot( Messages.get(this, "gold"), info.goldCollected );
statSlot( Messages.get(this, "depth"), info.maxDepth ); statSlot( Messages.get(this, "depth"), info.maxDepth );
if (info.customSeed){ if (!info.customSeed.isEmpty()){
statSlot( Messages.get(this, "custom_seed"), "_" + DungeonSeed.convertToCode(info.seed) + "_" ); statSlot( Messages.get(this, "custom_seed"), "_" + info.customSeed + "_" );
} else { } else {
statSlot( Messages.get(this, "dungeon_seed"), DungeonSeed.convertToCode(info.seed) ); statSlot( Messages.get(this, "dungeon_seed"), DungeonSeed.convertToCode(info.seed) );
} }
@@ -162,9 +162,12 @@ public class WndGameInProgress extends Window {
RenderedTextBlock txt = PixelScene.renderTextBlock( label, 8 ); RenderedTextBlock txt = PixelScene.renderTextBlock( label, 8 );
txt.setPos(0, pos); txt.setPos(0, pos);
add( txt ); add( txt );
txt = PixelScene.renderTextBlock( value, 8 ); int size = 8;
txt.setPos(WIDTH * 0.55f, pos); if (value.length() >= 14) size -=2;
if (value.length() >= 18) size -=1;
txt = PixelScene.renderTextBlock( value, size );
txt.setPos(WIDTH * 0.55f, pos + (6 - txt.height())/2);
PixelScene.align(txt); PixelScene.align(txt);
add( txt ); add( txt );
@@ -185,8 +185,8 @@ public class WndHero extends WndTabbed {
statSlot( Messages.get(this, "gold"), Statistics.goldCollected ); statSlot( Messages.get(this, "gold"), Statistics.goldCollected );
statSlot( Messages.get(this, "depth"), Statistics.deepestFloor ); statSlot( Messages.get(this, "depth"), Statistics.deepestFloor );
if (Dungeon.usingCustomSeed){ if (!Dungeon.customSeedText.isEmpty()){
statSlot( Messages.get(this, "custom_seed"), "_" + DungeonSeed.convertToCode(Dungeon.seed) + "_" ); statSlot( Messages.get(this, "custom_seed"), "_" + Dungeon.customSeedText + "_" );
} else { } else {
statSlot( Messages.get(this, "dungeon_seed"), DungeonSeed.convertToCode(Dungeon.seed) ); statSlot( Messages.get(this, "dungeon_seed"), DungeonSeed.convertToCode(Dungeon.seed) );
} }