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"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
|||||||
@@ -284,4 +284,59 @@ public class Monster {
|
|||||||
private static final int SPLINT_ARMOR_CLASS = BASE_ARMOR_CLASS + 7;
|
private static final int SPLINT_ARMOR_CLASS = BASE_ARMOR_CLASS + 7;
|
||||||
private static final int PLATE_ARMOR_CLASS = BASE_ARMOR_CLASS + 8;
|
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.setShieldBonus(0);
|
||||||
monster.setNaturalArmorBonus(7);
|
monster.setNaturalArmorBonus(7);
|
||||||
monster.setOtherArmorDescription("14");
|
monster.setOtherArmorDescription("14");
|
||||||
|
// Hit Points
|
||||||
|
monster.setHitDice(1);
|
||||||
|
monster.setCustomHP(false);
|
||||||
|
monster.setHPText("11 (2d8 + 2)");
|
||||||
|
|
||||||
// END remove block
|
// END remove block
|
||||||
monsterViewModel = new ViewModelProvider(this).get(MonsterViewModel.class);
|
monsterViewModel = new ViewModelProvider(this).get(MonsterViewModel.class);
|
||||||
View root = inflater.inflate(R.layout.fragment_monster, container, false);
|
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;
|
return root;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ public class MonsterViewModel extends ViewModel {
|
|||||||
mMeta.setValue("");
|
mMeta.setValue("");
|
||||||
mArmorClass = new MutableLiveData<>();
|
mArmorClass = new MutableLiveData<>();
|
||||||
mArmorClass.setValue("");
|
mArmorClass.setValue("");
|
||||||
|
mHitPoints = new MutableLiveData<>();
|
||||||
|
mHitPoints.setValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
private MutableLiveData<String> mName;
|
private MutableLiveData<String> mName;
|
||||||
@@ -31,6 +32,10 @@ public class MonsterViewModel extends ViewModel {
|
|||||||
public LiveData<String> getArmorClass() {
|
public LiveData<String> getArmorClass() {
|
||||||
return mArmorClass;
|
return mArmorClass;
|
||||||
}
|
}
|
||||||
|
private MutableLiveData<String> mHitPoints;
|
||||||
|
public LiveData<String> getHitPoints() {
|
||||||
|
return mHitPoints;
|
||||||
|
}
|
||||||
|
|
||||||
private Monster mMonster;
|
private Monster mMonster;
|
||||||
public void setMonster(Monster monster) {
|
public void setMonster(Monster monster) {
|
||||||
@@ -38,5 +43,6 @@ public class MonsterViewModel extends ViewModel {
|
|||||||
mName.setValue(mMonster.getName());
|
mName.setValue(mMonster.getName());
|
||||||
mMeta.setValue(mMonster.getMeta());
|
mMeta.setValue(mMonster.getMeta());
|
||||||
mArmorClass.setValue(mMonster.getArmorClass());
|
mArmorClass.setValue(mMonster.getArmorClass());
|
||||||
|
mHitPoints.setValue(mMonster.getHitPoints());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,5 +69,18 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@+id/divider1"
|
app:layout_constraintTop_toBottomOf="@+id/divider1"
|
||||||
tools:text="Armor Class 15" />
|
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>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
Reference in New Issue
Block a user