Adds hit points to monster card.
This commit is contained in:
1
.idea/gradle.xml
generated
1
.idea/gradle.xml
generated
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
|
||||
@@ -284,4 +284,59 @@ public class Monster {
|
||||
private static final int SPLINT_ARMOR_CLASS = BASE_ARMOR_CLASS + 7;
|
||||
private static final int PLATE_ARMOR_CLASS = BASE_ARMOR_CLASS + 8;
|
||||
|
||||
private int mHitDice;
|
||||
public int getHitDice() {
|
||||
return mHitDice;
|
||||
}
|
||||
public void setHitDice(int value) {
|
||||
mHitDice = value;
|
||||
}
|
||||
|
||||
private boolean mCustomHP;
|
||||
public boolean getCustomHP() {
|
||||
return mCustomHP;
|
||||
}
|
||||
public void setCustomHP(boolean value) {
|
||||
mCustomHP = value;
|
||||
}
|
||||
|
||||
private String mHPText;
|
||||
public String getHPText() {
|
||||
return mHPText;
|
||||
}
|
||||
public void setHPText(String value) {
|
||||
mHPText = value;
|
||||
}
|
||||
|
||||
public String getHitPoints() {
|
||||
if (getCustomHP()) {
|
||||
return getHPText();
|
||||
} else {
|
||||
int hitDice = getHitDice();
|
||||
int dieSize = getHitDieForSize(getSize());
|
||||
int conMod = getConstitutionModifier();
|
||||
int hpTotal = (int) Math.max(1, Math.ceil(hitDice * ((dieSize + 1) / 2.0 + conMod)));
|
||||
return String.format(Locale.US, "%d (%dd%d %+d)", hpTotal, hitDice, dieSize, conMod * hitDice);
|
||||
}
|
||||
}
|
||||
|
||||
private static int getHitDieForSize(String size) {
|
||||
if ("tiny".equals(size)) {
|
||||
return 4;
|
||||
} else if ("small".equals(size)) {
|
||||
return 6;
|
||||
} else if ("medium".equals(size)) {
|
||||
return 8;
|
||||
} else if ("large".equals(size)) {
|
||||
return 10;
|
||||
} else if ("huge".equals(size)) {
|
||||
return 12;
|
||||
} else if ("gargantuan".equals(size)) {
|
||||
return 20;
|
||||
} else {
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -38,6 +38,11 @@ public class MonsterFragment extends Fragment {
|
||||
monster.setShieldBonus(0);
|
||||
monster.setNaturalArmorBonus(7);
|
||||
monster.setOtherArmorDescription("14");
|
||||
// Hit Points
|
||||
monster.setHitDice(1);
|
||||
monster.setCustomHP(false);
|
||||
monster.setHPText("11 (2d8 + 2)");
|
||||
|
||||
// END remove block
|
||||
monsterViewModel = new ViewModelProvider(this).get(MonsterViewModel.class);
|
||||
View root = inflater.inflate(R.layout.fragment_monster, container, false);
|
||||
@@ -67,6 +72,14 @@ public class MonsterFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
final TextView monsterHitPoints = root.findViewById(R.id.hit_points);
|
||||
monsterViewModel.getHitPoints().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(String hitPoints) {
|
||||
monsterHitPoints.setText(Html.fromHtml("<b>Hit Points</b> " + hitPoints));
|
||||
}
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,8 @@ public class MonsterViewModel extends ViewModel {
|
||||
mMeta.setValue("");
|
||||
mArmorClass = new MutableLiveData<>();
|
||||
mArmorClass.setValue("");
|
||||
|
||||
mHitPoints = new MutableLiveData<>();
|
||||
mHitPoints.setValue("");
|
||||
}
|
||||
|
||||
private MutableLiveData<String> mName;
|
||||
@@ -31,6 +32,10 @@ public class MonsterViewModel extends ViewModel {
|
||||
public LiveData<String> getArmorClass() {
|
||||
return mArmorClass;
|
||||
}
|
||||
private MutableLiveData<String> mHitPoints;
|
||||
public LiveData<String> getHitPoints() {
|
||||
return mHitPoints;
|
||||
}
|
||||
|
||||
private Monster mMonster;
|
||||
public void setMonster(Monster monster) {
|
||||
@@ -38,5 +43,6 @@ public class MonsterViewModel extends ViewModel {
|
||||
mName.setValue(mMonster.getName());
|
||||
mMeta.setValue(mMonster.getMeta());
|
||||
mArmorClass.setValue(mMonster.getArmorClass());
|
||||
mHitPoints.setValue(mMonster.getHitPoints());
|
||||
}
|
||||
}
|
||||
@@ -69,5 +69,18 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/divider1"
|
||||
tools:text="Armor Class 15" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/hit_points"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/armor_class"
|
||||
tools:text="Hit Points 1 (1d4 - 1)" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</ScrollView>
|
||||
Reference in New Issue
Block a user