1
0
Fork 0

Better reading/writing

This commit is contained in:
Carlos Galindo 2015-02-21 17:08:00 +01:00
parent 7d3b032f89
commit 78b1f2ddd6
6 changed files with 108 additions and 83 deletions

View file

@ -5,6 +5,7 @@
<inspection_tool class="AndroidLintButtonOrder" enabled="false" level="WARNING" enabled_by_default="false" /> <inspection_tool class="AndroidLintButtonOrder" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="AndroidLintDeprecated" enabled="false" level="WARNING" enabled_by_default="false" /> <inspection_tool class="AndroidLintDeprecated" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="AndroidLintRelativeOverlap" enabled="false" level="WARNING" enabled_by_default="false" /> <inspection_tool class="AndroidLintRelativeOverlap" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="AndroidLintRtlCompat" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="AndroidLintRtlHardcoded" enabled="false" level="WARNING" enabled_by_default="false" /> <inspection_tool class="AndroidLintRtlHardcoded" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false"> <inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" /> <option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />

View file

@ -9,6 +9,7 @@ import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
public class HealthDialogFragment extends DialogFragment { public class HealthDialogFragment extends DialogFragment {
//TODO: convert to method and dialog, without class
static HealthDialogFragment newInstance(int curativeEfforts) { static HealthDialogFragment newInstance(int curativeEfforts) {
HealthDialogFragment f = new HealthDialogFragment(); HealthDialogFragment f = new HealthDialogFragment();
@ -20,7 +21,7 @@ public class HealthDialogFragment extends DialogFragment {
} }
public interface HealthDialogListener { public interface HealthDialogListener {
public void curativeEffort(DialogFragment dialog, boolean uses); public void heal(DialogFragment dialog, boolean uses);
} }
@ -46,13 +47,13 @@ public class HealthDialogFragment extends DialogFragment {
.setTitle(R.string.new_energies_title) .setTitle(R.string.new_energies_title)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
mListener.curativeEffort(HealthDialogFragment.this, true); mListener.heal(HealthDialogFragment.this, true);
} }
}) })
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
mListener.curativeEffort(HealthDialogFragment.this, false); mListener.heal(HealthDialogFragment.this, false);
} }
}) })
.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() { .setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {

View file

@ -99,10 +99,10 @@ public class MainActivity extends ActionBarActivity
}); });
alert.show(); alert.show();
} else if (id == R.id.action_save) { // } else if (id == R.id.action_save) {
saveData(); // saveData();
} else if (id == R.id.action_load) { // } else if (id == R.id.action_load) {
restoreData(); // restoreData();
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
@ -141,7 +141,7 @@ public class MainActivity extends ActionBarActivity
} }
@Override @Override
public void curativeEffort(DialogFragment dialog, boolean uses) { public void heal(DialogFragment dialog, boolean uses) {
int hasCured = player.recoverPg(Player.USE_CURATIVE_EFFORT, uses); int hasCured = player.recoverPg(Player.USE_CURATIVE_EFFORT, uses);
if (hasCured == Player.NOT_CURED) { if (hasCured == Player.NOT_CURED) {
Toast.makeText( Toast.makeText(
@ -157,12 +157,16 @@ public class MainActivity extends ActionBarActivity
Toast.LENGTH_LONG Toast.LENGTH_LONG
).show(); ).show();
} }
getSharedPreferences("basics", MODE_PRIVATE).edit()
.putInt("pg", player.getPg())
.putInt("curativeEfforts", player.getCurativeEfforts())
.apply();
updateCurativeString(); updateCurativeString();
healthStatusCheck(); healthStatusCheck();
} }
} }
public void onCurrentPgClick(final View view){ public void damage(final View view){
AlertDialog.Builder alert = new AlertDialog.Builder(this); AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(getString(R.string.suffer_damage)); alert.setTitle(getString(R.string.suffer_damage));
@ -187,6 +191,9 @@ public class MainActivity extends ActionBarActivity
undo = true; undo = true;
undoPreviousValue = preValue; undoPreviousValue = preValue;
undoObject = CURRENT_PG; undoObject = CURRENT_PG;
getSharedPreferences("basics", MODE_PRIVATE).edit()
.putInt("pg", player.getPg())
.apply();
healthStatusCheck(); healthStatusCheck();
invalidateOptionsMenu(); invalidateOptionsMenu();
} catch (Exception e) {} } catch (Exception e) {}
@ -279,11 +286,15 @@ public class MainActivity extends ActionBarActivity
player.setClassName(p.getString("className", getString(R.string.class_name))); player.setClassName(p.getString("className", getString(R.string.class_name)));
player.setRaceName(p.getString("raceName", getString(R.string.race_name))); player.setRaceName(p.getString("raceName", getString(R.string.race_name)));
player.setLevel(p.getInt("level", 1)); player.setLevel(p.getInt("level", 1));
player.setMaxPg(p.getInt("maxPg", 15)); player.setAtk(new int[]{
player.setPg(p.getInt("pg", 15)); p.getInt("fue", 10),
p.getInt("con", 10),
p.getInt("des", 10),
p.getInt("int", 10),
p.getInt("sab", 10),
p.getInt("car", 10),
});
healthStatusCheck(); healthStatusCheck();
player.setMaxCurativeEfforts(p.getInt("maxCurativeEfforts", 5));
player.setCurativeEffort(p.getInt("curativeEfforts", 5));
updateCurativeString(); updateCurativeString();
} }
//set restored values to the respective fields //set restored values to the respective fields
@ -316,15 +327,15 @@ public class MainActivity extends ActionBarActivity
} }
private void saveData() { // private void saveData() {
getSharedPreferences("basics", MODE_PRIVATE).edit() // getSharedPreferences("basics", MODE_PRIVATE).edit()
.putInt("level", player.getLevel()) // .putInt("level", player.getLevel())
.putInt("maxPg", player.getMaxPg()) // .putInt("maxPg", player.getMaxPg())
.putInt("pg", player.getPg()) // .putInt("pg", player.getPg())
.putInt("maxCurativeEfforts", player.getMaxCurativeEfforts()) // .putInt("maxCurativeEfforts", player.getMaxCurativeEfforts())
.putInt("curativeEfforts", player.getCurativeEfforts()) // .putInt("curativeEfforts", player.getCurativeEfforts())
.apply(); // .apply();
} // }
private void updateCurativeString() { private void updateCurativeString() {
((TextView) findViewById(R.id.curativeEffortsText)).setText( ((TextView) findViewById(R.id.curativeEffortsText)).setText(

View file

@ -66,51 +66,14 @@ public class Player {
String name, String className, String raceName, String name, String className, String raceName,
int level, int[] atk, int[] def, int[] abilities, int level, int[] atk, int[] def, int[] abilities,
Power[] powers Power[] powers
) { ){
setState();
this.name = name; this.name = name;
this.className = className; this.className = className;
setAtk(atk);
if(className.equals(classStrings[1])){ setState();
//Ardiente
} else if (className.equals(classStrings[2])) {
//Brujo
//TODO: Kauron
maxPg = atk[CON] + 12;
maxCurativeEfforts = 6 + atk[CON];
} else if (className.equals(classStrings[3])) {
//Buscador
} else if (className.equals(classStrings[4])) {
//Clérigo
//TODO: Gárafran
} else if (className.equals(classStrings[5])) {
//Explorador
//TODO: Aria Saferi
} else if (className.equals(classStrings[6])) {
//Guerrero
} else if (className.equals(classStrings[7])) {
//Mago
} else if (className.equals(classStrings[8])) {
//Mente de Batalla
} else if (className.equals(classStrings[9])) {
//Monje
} else if (className.equals(classStrings[10])) {
//Paladín
//TODO: Ceaelynna
} else if (className.equals(classStrings[11])) {
//Pícaro
} else if (className.equals(classStrings[12])) {
//Psiónico
} else if (className.equals(classStrings[13])) {
//Sacerdote rúnico
} else {
//Señor de la Guerra
//TODO: Mushu
}
this.raceName = raceName; this.raceName = raceName;
this.level = level; this.level = level;
this.atk = atk;
this.def = def; this.def = def;
this.abilities = abilities; this.abilities = abilities;
this.powers = powers; this.powers = powers;
@ -172,7 +135,10 @@ public class Player {
public void setName(String name) {this.name = name;} public void setName(String name) {this.name = name;}
public String getClassName() {return className;} public String getClassName() {return className;}
public void setClassName(String className) {this.className = className;} public void setClassName(String className) {
this.className = className;
if(atk!=null) setClass();
}
public String getRaceName() {return raceName;} public String getRaceName() {return raceName;}
public void setRaceName(String raceName) {this.raceName = raceName;} public void setRaceName(String raceName) {this.raceName = raceName;}
@ -186,15 +152,7 @@ public class Player {
} }
} }
public void setAtk(int[] atk) {this.atk = atk;} public void setAtk(int[] atk) {this.atk = atk; if(className!=null) setClass();}
public int[] getAtk() {return atk;}
public void setFue(int fue) {atk[FUE] = fue;}
public void setCon(int con) {atk[CON] = con;}
public void setSab(int sab) {atk[SAB] = sab;}
public void setCar(int car) {atk[CAR] = car;}
public void setDes(int des) {atk[DES] = des;}
public void setInt(int intel) {atk[INT] = intel;}
public int getFue() {return atk[FUE];} public int getFue() {return atk[FUE];}
public int getCon() {return atk[CON];} public int getCon() {return atk[CON];}
@ -202,4 +160,58 @@ public class Player {
public int getCar() {return atk[CAR];} public int getCar() {return atk[CAR];}
public int getDes() {return atk[DES];} public int getDes() {return atk[DES];}
public int getInt() {return atk[INT];} public int getInt() {return atk[INT];}
public void setClass() {
if(className.equals(classStrings[1])){
//Ardiente
} else if (className.equals(classStrings[2])) {
//Brujo
//TODO: Kauron
pg = maxPg = 12 + atk[CON];
curativeEfforts = maxCurativeEfforts = 6 + Player.getModifier(atk[CON]);
return; //TODO: temporal
} else if (className.equals(classStrings[3])) {
//Buscador
} else if (className.equals(classStrings[4])) {
//Clérigo
//TODO: Gárafran
} else if (className.equals(classStrings[5])) {
//Explorador
//TODO: Aria Saferi
} else if (className.equals(classStrings[6])) {
//Guerrero
} else if (className.equals(classStrings[7])) {
//Mago
} else if (className.equals(classStrings[8])) {
//Mente de Batalla
} else if (className.equals(classStrings[9])) {
//Monje
} else if (className.equals(classStrings[10])) {
//Paladín
//TODO: Ceaelynna
} else if (className.equals(classStrings[11])) {
//Pícaro
} else if (className.equals(classStrings[12])) {
//Psiónico
} else if (className.equals(classStrings[13])) {
//Sacerdote rúnico
} else {
//Señor de la Guerra
//TODO: Mushu
}
pg = maxPg = 15;
curativeEfforts = maxCurativeEfforts = 15;
}
public static int getModifier(int i) {
return i / 2 - 5;
}
public int getTotalModifier(int i) {
return getModifier(i) + level / 2;
}
public static int getLevel (int px) {
return 0; //TODO: substitute level by px and autoconvert
}
} }

View file

@ -11,7 +11,7 @@
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/pgCurrent" android:id="@+id/pgCurrent"
android:textSize="40sp" android:textSize="40sp"
android:onClick="onCurrentPgClick" android:onClick="damage"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" /> android:layout_alignParentEnd="true" />

View file

@ -13,16 +13,16 @@
android:orderInCategory="2" android:orderInCategory="2"
app:showAsAction="always" app:showAsAction="always"
android:icon="@drawable/ic_action_heal"/> android:icon="@drawable/ic_action_heal"/>
<item <!--<item-->
android:id="@+id/action_load" <!--android:id="@+id/action_load"-->
android:title="@string/action_load" <!--android:title="@string/action_load"-->
android:orderInCategory="10" <!--android:orderInCategory="10"-->
app:showAsAction="never"/> <!--app:showAsAction="never"/>-->
<item <!--<item-->
android:id="@+id/action_save" <!--android:id="@+id/action_save"-->
android:title="@string/action_save" <!--android:title="@string/action_save"-->
android:orderInCategory="11" <!--android:orderInCategory="11"-->
app:showAsAction="never"/> <!--app:showAsAction="never"/>-->
<item <item
android:id="@+id/action_edit_basics" android:id="@+id/action_edit_basics"
android:title="@string/action_edit_basics" android:title="@string/action_edit_basics"