Skip to content

Commit

Permalink
#43: Added BUNDLE_KEY_ prefix to all (or almost all) the bundle keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcnor committed Oct 13, 2014
1 parent 9f54069 commit 7ba3a6c
Show file tree
Hide file tree
Showing 43 changed files with 464 additions and 461 deletions.
8 changes: 4 additions & 4 deletions PD-classes/src/com/watabou/utils/Bundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public class Bundle {

private static final String CLASS_NAME = "__className";
private static final String BUNDLE_KEY_CLASS_NAME = "__className";

private static HashMap<String,String> aliases = new HashMap<String, String>();

Expand Down Expand Up @@ -81,7 +81,7 @@ public Bundle getBundle( String key ) {

private Bundlable get() {
try {
String clName = getString( CLASS_NAME );
String clName = getString(BUNDLE_KEY_CLASS_NAME);
if (aliases.containsKey( clName )) {
clName = aliases.get( clName );
}
Expand Down Expand Up @@ -206,7 +206,7 @@ public void put( String key, Bundlable object ) {
if (object != null) {
try {
Bundle bundle = new Bundle();
bundle.put( CLASS_NAME, object.getClass().getName() );
bundle.put(BUNDLE_KEY_CLASS_NAME, object.getClass().getName());
object.storeInBundle( bundle );
data.put( key, bundle.data );
} catch (JSONException e) {
Expand Down Expand Up @@ -254,7 +254,7 @@ public void put( String key, Collection<? extends Bundlable> collection ) {
JSONArray array = new JSONArray();
for (Bundlable object : collection) {
Bundle bundle = new Bundle();
bundle.put( CLASS_NAME, object.getClass().getName() );
bundle.put(BUNDLE_KEY_CLASS_NAME, object.getClass().getName() );
object.storeInBundle( bundle );
array.put( bundle.data );
}
Expand Down
12 changes: 6 additions & 6 deletions core/src/com/watabou/pixeldungeon/Bones.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class Bones {

private static final String BONES_FILE = "bones.dat";

private static final String LEVEL = "level";
private static final String ITEM = "item";
private static final String BUNDLE_KEY_LEVEL = "level";
private static final String BUNDLE_KEY_ITEM = "item";

private static int depth = -1;
private static Item item;
Expand Down Expand Up @@ -66,8 +66,8 @@ public static void leave() {
depth = Dungeon.depth;

Bundle bundle = new Bundle();
bundle.put( LEVEL, depth );
bundle.put( ITEM, item );
bundle.put(BUNDLE_KEY_LEVEL, depth );
bundle.put(BUNDLE_KEY_ITEM, item );

try {
OutputStream output = Game.instance.openFileOutput( BONES_FILE );
Expand All @@ -86,8 +86,8 @@ public static Item get() {
Bundle bundle = Bundle.read( input );
input.close();

depth = bundle.getInt( LEVEL );
item = (Item)bundle.get( ITEM );
depth = bundle.getInt(BUNDLE_KEY_LEVEL);
item = (Item)bundle.get(BUNDLE_KEY_ITEM);

return get();

Expand Down
88 changes: 44 additions & 44 deletions core/src/com/watabou/pixeldungeon/Dungeon.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,20 +322,20 @@ public static boolean asNeeded() {
private static final String RN_GAME_FILE = "ranger.dat";
private static final String RN_DEPTH_FILE = "ranger%d.dat";

private static final String VERSION = "version";
private static final String HERO = "hero";
private static final String GOLD = "gold";
private static final String DEPTH = "depth";
private static final String QUICKSLOT = "quickslot";
private static final String LEVEL = "level";
private static final String POS = "potionsOfStrength";
private static final String SOU = "scrollsOfEnhancement";
private static final String AS = "arcaneStyli";
private static final String DV = "dewVial";
private static final String WT = "transmutation";
private static final String CHAPTERS = "chapters";
private static final String QUESTS = "quests";
private static final String BADGES = "badges";
private static final String BUNDLE_KEY_VERSION = "version";
private static final String BUNDLE_KEY_HERO = "hero";
private static final String BUNDLE_KEY_GOLD = "gold";
private static final String BUNDLE_KEY_DEPTH = "depth";
private static final String BUNDLE_KEY_QUICKSLOT = "quickslot";
private static final String BUNDLE_KEY_LEVEL = "level";
private static final String BUNDLE_KEY_POS = "potionsOfStrength";
private static final String BUNDLE_KEY_SOU = "scrollsOfEnhancement";
private static final String BUNDLE_KEY_AS = "arcaneStyli";
private static final String BUNDLE_KEY_DV = "dewVial";
private static final String BUNDLE_KEY_WT = "transmutation";
private static final String BUNDLE_KEY_CHAPTERS = "chapters";
private static final String BUNDLE_KEY_QUESTS = "quests";
private static final String BUNDLE_KEY_BADGES = "badges";

public static String gameFile( HeroClass cl ) {
switch (cl) {
Expand Down Expand Up @@ -367,38 +367,38 @@ public static void saveGame( String fileName ) throws IOException {
try {
Bundle bundle = new Bundle();

bundle.put( VERSION, Game.version );
bundle.put( HERO, hero );
bundle.put( GOLD, gold );
bundle.put( DEPTH, depth );
bundle.put(BUNDLE_KEY_VERSION, Game.version );
bundle.put(BUNDLE_KEY_HERO, hero );
bundle.put(BUNDLE_KEY_GOLD, gold );
bundle.put(BUNDLE_KEY_DEPTH, depth );

bundle.put( POS, potionOfStrength );
bundle.put( SOU, scrollsOfUpgrade );
bundle.put( AS, arcaneStyli );
bundle.put( DV, dewVial );
bundle.put( WT, transmutation );
bundle.put(BUNDLE_KEY_POS, potionOfStrength );
bundle.put(BUNDLE_KEY_SOU, scrollsOfUpgrade );
bundle.put(BUNDLE_KEY_AS, arcaneStyli );
bundle.put(BUNDLE_KEY_DV, dewVial );
bundle.put(BUNDLE_KEY_WT, transmutation );

int count = 0;
int ids[] = new int[chapters.size()];
for (Integer id : chapters) {
ids[count++] = id;
}
bundle.put( CHAPTERS, ids );
bundle.put(BUNDLE_KEY_CHAPTERS, ids );

Bundle quests = new Bundle();
Ghost .Quest.storeInBundle( quests );
Wandmaker .Quest.storeInBundle( quests );
Blacksmith .Quest.storeInBundle( quests );
Imp .Quest.storeInBundle( quests );
bundle.put( QUESTS, quests );
bundle.put(BUNDLE_KEY_QUESTS, quests );

Room.storeRoomsInBundle( bundle );

Statistics.storeInBundle( bundle );
Journal.storeInBundle( bundle );

if (quickslot instanceof Class) {
bundle.put( QUICKSLOT, ((Class<?>)quickslot).getName() );
bundle.put(BUNDLE_KEY_QUICKSLOT, ((Class<?>)quickslot).getName() );
}

Scroll.save( bundle );
Expand All @@ -408,7 +408,7 @@ public static void saveGame( String fileName ) throws IOException {

Bundle badges = new Bundle();
Badges.saveLocal( badges );
bundle.put( BADGES, badges );
bundle.put(BUNDLE_KEY_BADGES, badges );

OutputStream output = Game.instance.openFileOutput( fileName );
Bundle.write( bundle, output );
Expand All @@ -422,7 +422,7 @@ public static void saveGame( String fileName ) throws IOException {

public static void saveLevel() throws IOException {
Bundle bundle = new Bundle();
bundle.put( LEVEL, level );
bundle.put(BUNDLE_KEY_LEVEL, level );

OutputStream output = Game.instance.openFileOutput(
Utils.format( depthFile( hero.heroClass ), depth ) );
Expand Down Expand Up @@ -475,22 +475,22 @@ public static void loadGame( String fileName, boolean fullLoad ) throws IOExcept
Wand.restore( bundle );
Ring.restore( bundle );

potionOfStrength = bundle.getInt( POS );
scrollsOfUpgrade = bundle.getInt( SOU );
arcaneStyli = bundle.getInt( AS );
dewVial = bundle.getBoolean( DV );
transmutation = bundle.getInt( WT );
potionOfStrength = bundle.getInt(BUNDLE_KEY_POS);
scrollsOfUpgrade = bundle.getInt(BUNDLE_KEY_SOU);
arcaneStyli = bundle.getInt(BUNDLE_KEY_AS);
dewVial = bundle.getBoolean(BUNDLE_KEY_DV);
transmutation = bundle.getInt(BUNDLE_KEY_WT);

if (fullLoad) {
chapters = new HashSet<Integer>();
int ids[] = bundle.getIntArray( CHAPTERS );
int ids[] = bundle.getIntArray(BUNDLE_KEY_CHAPTERS);
if (ids != null) {
for (int id : ids) {
chapters.add( id );
}
}

Bundle quests = bundle.getBundle( QUESTS );
Bundle quests = bundle.getBundle(BUNDLE_KEY_QUESTS);
if (!quests.isNull()) {
Ghost.Quest.restoreFromBundle( quests );
Wandmaker.Quest.restoreFromBundle( quests );
Expand All @@ -506,14 +506,14 @@ public static void loadGame( String fileName, boolean fullLoad ) throws IOExcept
Room.restoreRoomsFromBundle( bundle );
}

Bundle badges = bundle.getBundle( BADGES );
Bundle badges = bundle.getBundle(BUNDLE_KEY_BADGES);
if (!badges.isNull()) {
Badges.loadLocal( badges );
} else {
Badges.reset();
}

String qsClass = bundle.getString( QUICKSLOT );
String qsClass = bundle.getString(BUNDLE_KEY_QUICKSLOT);
if (qsClass != null) {
try {
quickslot = Class.forName( qsClass );
Expand All @@ -524,13 +524,13 @@ public static void loadGame( String fileName, boolean fullLoad ) throws IOExcept
}

@SuppressWarnings("unused")
String version = bundle.getString( VERSION );
String version = bundle.getString(BUNDLE_KEY_VERSION);

hero = null;
hero = (Hero)bundle.get( HERO );
hero = (Hero)bundle.get(BUNDLE_KEY_HERO);

gold = bundle.getInt( GOLD );
depth = bundle.getInt( DEPTH );
gold = bundle.getInt(BUNDLE_KEY_GOLD);
depth = bundle.getInt(BUNDLE_KEY_DEPTH);

Statistics.restoreFromBundle( bundle );
Journal.restoreFromBundle( bundle );
Expand All @@ -545,7 +545,7 @@ public static Level loadLevel( HeroClass cl ) throws IOException {
Bundle bundle = Bundle.read( input );
input.close();

return (Level)bundle.get( "level" );
return (Level)bundle.get(BUNDLE_KEY_LEVEL);
}

public static void deleteGame( HeroClass cl, boolean deleteLevels ) {
Expand All @@ -572,11 +572,11 @@ public static Bundle gameBundle( String fileName ) throws IOException {
}

public static void preview( GamesInProgress.Info info, Bundle bundle ) {
info.depth = bundle.getInt( DEPTH );
info.depth = bundle.getInt(BUNDLE_KEY_DEPTH);
if (info.depth == -1) {
info.depth = bundle.getInt( "maxDepth" ); // <-- It has to be refactored!
}
Hero.preview( info, bundle.getBundle( HERO ) );
Hero.preview( info, bundle.getBundle(BUNDLE_KEY_HERO) );
}

public static void fail( String desc ) {
Expand Down
12 changes: 6 additions & 6 deletions core/src/com/watabou/pixeldungeon/Journal.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ private Feature( String desc ) {

public static class Record implements Comparable<Record>, Bundlable {

private static final String FEATURE = "feature";
private static final String DEPTH = "depth";
private static final String BUNDLE_KEY_FEATURE = "feature";
private static final String BUNDLE_KEY_DEPTH = "depth";

public Feature feature;
public int depth;
Expand All @@ -67,14 +67,14 @@ public int compareTo( Record another ) {

@Override
public void restoreFromBundle( Bundle bundle ) {
feature = Feature.valueOf( bundle.getString( FEATURE ) );
depth = bundle.getInt( DEPTH );
feature = Feature.valueOf( bundle.getString(BUNDLE_KEY_FEATURE) );
depth = bundle.getInt(BUNDLE_KEY_DEPTH);
}

@Override
public void storeInBundle( Bundle bundle ) {
bundle.put( FEATURE, feature.toString() );
bundle.put( DEPTH, depth );
bundle.put(BUNDLE_KEY_FEATURE, feature.toString());
bundle.put(BUNDLE_KEY_DEPTH, depth);
}
}

Expand Down
38 changes: 19 additions & 19 deletions core/src/com/watabou/pixeldungeon/Rankings.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ public void load() {

public static class Record implements Bundlable {

private static final String REASON = "reason";
private static final String WIN = "win";
private static final String SCORE = "score";
private static final String TIER = "tier";
private static final String GAME = "gameFile";
private static final String BUNDLE_KEY_REASON = "reason";
private static final String BUNDLE_KEY_WIN = "win";
private static final String BUNDLE_KEY_SCORE = "score";
private static final String BUNDLE_KEY_TIER = "tier";
private static final String BUNDLE_KEY_GAME = "gameFile";

public String info;
public boolean win;
Expand All @@ -162,27 +162,27 @@ public static class Record implements Bundlable {
@Override
public void restoreFromBundle( Bundle bundle ) {

info = bundle.getString( REASON );
win = bundle.getBoolean( WIN );
score = bundle.getInt( SCORE );
info = bundle.getString(BUNDLE_KEY_REASON);
win = bundle.getBoolean(BUNDLE_KEY_WIN);
score = bundle.getInt(BUNDLE_KEY_SCORE);

heroClass = HeroClass.restoreInBundle( bundle );
armorTier = bundle.getInt( TIER );
armorTier = bundle.getInt(BUNDLE_KEY_TIER);

gameFile = bundle.getString( GAME );
gameFile = bundle.getString(BUNDLE_KEY_GAME);
}

@Override
public void storeInBundle( Bundle bundle ) {
bundle.put( REASON, info );
bundle.put( WIN, win );
bundle.put( SCORE, score );
heroClass.storeInBundle( bundle );
bundle.put( TIER, armorTier );
bundle.put( GAME, gameFile );

bundle.put(BUNDLE_KEY_REASON, info);
bundle.put(BUNDLE_KEY_WIN, win);
bundle.put(BUNDLE_KEY_SCORE, score);

heroClass.storeInBundle(bundle);
bundle.put(BUNDLE_KEY_TIER, armorTier);

bundle.put(BUNDLE_KEY_GAME, gameFile);
}
}

Expand Down
Loading

0 comments on commit 7ba3a6c

Please sign in to comment.