Better reading/writing
This commit is contained in:
parent
7d3b032f89
commit
78b1f2ddd6
6 changed files with 108 additions and 83 deletions
|
@ -5,6 +5,7 @@
|
|||
<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="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="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" />
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.content.DialogInterface;
|
|||
import android.os.Bundle;
|
||||
|
||||
public class HealthDialogFragment extends DialogFragment {
|
||||
//TODO: convert to method and dialog, without class
|
||||
|
||||
static HealthDialogFragment newInstance(int curativeEfforts) {
|
||||
HealthDialogFragment f = new HealthDialogFragment();
|
||||
|
@ -20,7 +21,7 @@ public class HealthDialogFragment extends DialogFragment {
|
|||
}
|
||||
|
||||
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)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
mListener.curativeEffort(HealthDialogFragment.this, true);
|
||||
mListener.heal(HealthDialogFragment.this, true);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
mListener.curativeEffort(HealthDialogFragment.this, false);
|
||||
mListener.heal(HealthDialogFragment.this, false);
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
|
|
|
@ -99,10 +99,10 @@ public class MainActivity extends ActionBarActivity
|
|||
});
|
||||
|
||||
alert.show();
|
||||
} else if (id == R.id.action_save) {
|
||||
saveData();
|
||||
} else if (id == R.id.action_load) {
|
||||
restoreData();
|
||||
// } else if (id == R.id.action_save) {
|
||||
// saveData();
|
||||
// } else if (id == R.id.action_load) {
|
||||
// restoreData();
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
@ -141,7 +141,7 @@ public class MainActivity extends ActionBarActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
public void curativeEffort(DialogFragment dialog, boolean uses) {
|
||||
public void heal(DialogFragment dialog, boolean uses) {
|
||||
int hasCured = player.recoverPg(Player.USE_CURATIVE_EFFORT, uses);
|
||||
if (hasCured == Player.NOT_CURED) {
|
||||
Toast.makeText(
|
||||
|
@ -157,12 +157,16 @@ public class MainActivity extends ActionBarActivity
|
|||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
}
|
||||
getSharedPreferences("basics", MODE_PRIVATE).edit()
|
||||
.putInt("pg", player.getPg())
|
||||
.putInt("curativeEfforts", player.getCurativeEfforts())
|
||||
.apply();
|
||||
updateCurativeString();
|
||||
healthStatusCheck();
|
||||
}
|
||||
}
|
||||
|
||||
public void onCurrentPgClick(final View view){
|
||||
public void damage(final View view){
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||
alert.setTitle(getString(R.string.suffer_damage));
|
||||
|
||||
|
@ -187,6 +191,9 @@ public class MainActivity extends ActionBarActivity
|
|||
undo = true;
|
||||
undoPreviousValue = preValue;
|
||||
undoObject = CURRENT_PG;
|
||||
getSharedPreferences("basics", MODE_PRIVATE).edit()
|
||||
.putInt("pg", player.getPg())
|
||||
.apply();
|
||||
healthStatusCheck();
|
||||
invalidateOptionsMenu();
|
||||
} catch (Exception e) {}
|
||||
|
@ -279,11 +286,15 @@ public class MainActivity extends ActionBarActivity
|
|||
player.setClassName(p.getString("className", getString(R.string.class_name)));
|
||||
player.setRaceName(p.getString("raceName", getString(R.string.race_name)));
|
||||
player.setLevel(p.getInt("level", 1));
|
||||
player.setMaxPg(p.getInt("maxPg", 15));
|
||||
player.setPg(p.getInt("pg", 15));
|
||||
player.setAtk(new int[]{
|
||||
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();
|
||||
player.setMaxCurativeEfforts(p.getInt("maxCurativeEfforts", 5));
|
||||
player.setCurativeEffort(p.getInt("curativeEfforts", 5));
|
||||
updateCurativeString();
|
||||
}
|
||||
//set restored values to the respective fields
|
||||
|
@ -316,15 +327,15 @@ public class MainActivity extends ActionBarActivity
|
|||
|
||||
}
|
||||
|
||||
private void saveData() {
|
||||
getSharedPreferences("basics", MODE_PRIVATE).edit()
|
||||
.putInt("level", player.getLevel())
|
||||
.putInt("maxPg", player.getMaxPg())
|
||||
.putInt("pg", player.getPg())
|
||||
.putInt("maxCurativeEfforts", player.getMaxCurativeEfforts())
|
||||
.putInt("curativeEfforts", player.getCurativeEfforts())
|
||||
.apply();
|
||||
}
|
||||
// private void saveData() {
|
||||
// getSharedPreferences("basics", MODE_PRIVATE).edit()
|
||||
// .putInt("level", player.getLevel())
|
||||
// .putInt("maxPg", player.getMaxPg())
|
||||
// .putInt("pg", player.getPg())
|
||||
// .putInt("maxCurativeEfforts", player.getMaxCurativeEfforts())
|
||||
// .putInt("curativeEfforts", player.getCurativeEfforts())
|
||||
// .apply();
|
||||
// }
|
||||
|
||||
private void updateCurativeString() {
|
||||
((TextView) findViewById(R.id.curativeEffortsText)).setText(
|
||||
|
|
|
@ -67,50 +67,13 @@ public class Player {
|
|||
int level, int[] atk, int[] def, int[] abilities,
|
||||
Power[] powers
|
||||
){
|
||||
setState();
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
|
||||
if(className.equals(classStrings[1])){
|
||||
//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
|
||||
}
|
||||
setAtk(atk);
|
||||
setState();
|
||||
|
||||
this.raceName = raceName;
|
||||
this.level = level;
|
||||
this.atk = atk;
|
||||
this.def = def;
|
||||
this.abilities = abilities;
|
||||
this.powers = powers;
|
||||
|
@ -172,7 +135,10 @@ public class Player {
|
|||
public void setName(String name) {this.name = name;}
|
||||
|
||||
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 void setRaceName(String raceName) {this.raceName = raceName;}
|
||||
|
@ -186,15 +152,7 @@ public class Player {
|
|||
}
|
||||
}
|
||||
|
||||
public void setAtk(int[] atk) {this.atk = atk;}
|
||||
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 void setAtk(int[] atk) {this.atk = atk; if(className!=null) setClass();}
|
||||
|
||||
public int getFue() {return atk[FUE];}
|
||||
public int getCon() {return atk[CON];}
|
||||
|
@ -202,4 +160,58 @@ public class Player {
|
|||
public int getCar() {return atk[CAR];}
|
||||
public int getDes() {return atk[DES];}
|
||||
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
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@
|
|||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:id="@+id/pgCurrent"
|
||||
android:textSize="40sp"
|
||||
android:onClick="onCurrentPgClick"
|
||||
android:onClick="damage"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_alignParentEnd="true" />
|
||||
|
|
|
@ -13,16 +13,16 @@
|
|||
android:orderInCategory="2"
|
||||
app:showAsAction="always"
|
||||
android:icon="@drawable/ic_action_heal"/>
|
||||
<item
|
||||
android:id="@+id/action_load"
|
||||
android:title="@string/action_load"
|
||||
android:orderInCategory="10"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/action_save"
|
||||
android:title="@string/action_save"
|
||||
android:orderInCategory="11"
|
||||
app:showAsAction="never"/>
|
||||
<!--<item-->
|
||||
<!--android:id="@+id/action_load"-->
|
||||
<!--android:title="@string/action_load"-->
|
||||
<!--android:orderInCategory="10"-->
|
||||
<!--app:showAsAction="never"/>-->
|
||||
<!--<item-->
|
||||
<!--android:id="@+id/action_save"-->
|
||||
<!--android:title="@string/action_save"-->
|
||||
<!--android:orderInCategory="11"-->
|
||||
<!--app:showAsAction="never"/>-->
|
||||
<item
|
||||
android:id="@+id/action_edit_basics"
|
||||
android:title="@string/action_edit_basics"
|
||||
|
|
Reference in a new issue