Adds damage types to monster cards.
Adds oxfordJoin to StringHelper.
This commit is contained in:
@@ -35,4 +35,27 @@ public final class StringHelper {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String oxfordJoin(String delimiter, String lastDelimiter, String onlyDelimiter, Collection<String> strings) {
|
||||||
|
int length = strings.size();
|
||||||
|
if (length < 1) {
|
||||||
|
return "";
|
||||||
|
} else if (length == 2) {
|
||||||
|
return join(onlyDelimiter, strings);
|
||||||
|
} else {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
int index = 0;
|
||||||
|
int lastIndex = length - 1;
|
||||||
|
for(String element : strings) {
|
||||||
|
if (index > 0 && index < lastIndex) {
|
||||||
|
sb.append(delimiter);
|
||||||
|
} else if (index > 0 && index >= lastIndex) {
|
||||||
|
sb.append(lastDelimiter);
|
||||||
|
}
|
||||||
|
sb.append(element);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.majinnaibu.monstercards.models;
|
||||||
|
|
||||||
|
public class DamageType {
|
||||||
|
|
||||||
|
public DamageType(String name, String note, String type) {
|
||||||
|
mName = name;
|
||||||
|
mNote = note;
|
||||||
|
mType = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mName;
|
||||||
|
public String getName() {
|
||||||
|
return mName;
|
||||||
|
}
|
||||||
|
public void setName(String value) {
|
||||||
|
mName = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mNote;
|
||||||
|
public String getNote() {
|
||||||
|
return mNote;
|
||||||
|
}
|
||||||
|
public void setNote(String value) {
|
||||||
|
mNote = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String mType;
|
||||||
|
public String getType() {
|
||||||
|
return mType;
|
||||||
|
}
|
||||||
|
public void setType(String value) {
|
||||||
|
mType = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import com.majinnaibu.monstercards.helpers.StringHelper;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -14,6 +15,7 @@ public class Monster {
|
|||||||
public Monster() {
|
public Monster() {
|
||||||
mSavingThrows = new HashSet<>();
|
mSavingThrows = new HashSet<>();
|
||||||
mSkills = new HashSet<>();
|
mSkills = new HashSet<>();
|
||||||
|
mDamageTypes = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String mName;
|
private String mName;
|
||||||
@@ -619,4 +621,50 @@ public class Monster {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HashSet<DamageType> mDamageTypes;
|
||||||
|
public Set<DamageType> getDamageTypes() {
|
||||||
|
return mDamageTypes;
|
||||||
|
}
|
||||||
|
public void addDamageType(DamageType damageType) {
|
||||||
|
// TODO: make this remove the damage type with the same name if it exists first
|
||||||
|
mDamageTypes.add(damageType);
|
||||||
|
}
|
||||||
|
public void removeDamageType(DamageType damageType) {
|
||||||
|
mDamageTypes.remove(damageType);
|
||||||
|
}
|
||||||
|
public void clearDamageTypes() {
|
||||||
|
mDamageTypes.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDamageVulnerabilitiesDescription() {
|
||||||
|
ArrayList<String> vulnerabilities = new ArrayList<>();
|
||||||
|
for (DamageType damageType : mDamageTypes) {
|
||||||
|
if (damageType != null && "v".equals(damageType.getType()) && !StringHelper.isNullOrEmpty(damageType.getName())) {
|
||||||
|
vulnerabilities.add(damageType.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(vulnerabilities);
|
||||||
|
return StringHelper.oxfordJoin(", ", ", and ", " and ", vulnerabilities);
|
||||||
|
}
|
||||||
|
public String getDamageResistancesDescription() {
|
||||||
|
ArrayList<String> vulnerabilities = new ArrayList<>();
|
||||||
|
for (DamageType damageType : mDamageTypes) {
|
||||||
|
if (damageType != null && "r".equals(damageType.getType()) && !StringHelper.isNullOrEmpty(damageType.getName())) {
|
||||||
|
vulnerabilities.add(damageType.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(vulnerabilities);
|
||||||
|
return StringHelper.oxfordJoin(", ", ", and ", " and ", vulnerabilities);
|
||||||
|
}
|
||||||
|
public String getDamageImmunitiesDescription() {
|
||||||
|
ArrayList<String> vulnerabilities = new ArrayList<>();
|
||||||
|
for (DamageType damageType : mDamageTypes) {
|
||||||
|
if (damageType != null && "i".equals(damageType.getType()) && !StringHelper.isNullOrEmpty(damageType.getName())) {
|
||||||
|
vulnerabilities.add(damageType.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(vulnerabilities);
|
||||||
|
return StringHelper.oxfordJoin(", ", ", and ", " and ", vulnerabilities);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import androidx.lifecycle.ViewModelProvider;
|
|||||||
|
|
||||||
import com.majinnaibu.monstercards.R;
|
import com.majinnaibu.monstercards.R;
|
||||||
import com.majinnaibu.monstercards.helpers.StringHelper;
|
import com.majinnaibu.monstercards.helpers.StringHelper;
|
||||||
|
import com.majinnaibu.monstercards.models.DamageType;
|
||||||
import com.majinnaibu.monstercards.models.Monster;
|
import com.majinnaibu.monstercards.models.Monster;
|
||||||
import com.majinnaibu.monstercards.models.SavingThrow;
|
import com.majinnaibu.monstercards.models.SavingThrow;
|
||||||
import com.majinnaibu.monstercards.models.Skill;
|
import com.majinnaibu.monstercards.models.Skill;
|
||||||
@@ -70,6 +71,16 @@ public class MonsterFragment extends Fragment {
|
|||||||
//Skills
|
//Skills
|
||||||
monster.addSkill(new Skill("perception", "wis"));
|
monster.addSkill(new Skill("perception", "wis"));
|
||||||
monster.addSkill(new Skill("stealth", "dexterity"));
|
monster.addSkill(new Skill("stealth", "dexterity"));
|
||||||
|
// Damage Types
|
||||||
|
monster.addDamageType(new DamageType("acid", " (Vulnerable)", "v"));
|
||||||
|
monster.addDamageType(new DamageType("bludgeoning", " (Vulnerable)", "v"));
|
||||||
|
monster.addDamageType(new DamageType("cold", " (Resistant)", "r"));
|
||||||
|
monster.addDamageType(new DamageType("fire", " (Resistant)", "r"));
|
||||||
|
monster.addDamageType(new DamageType("force", " (Immune)", "i"));
|
||||||
|
monster.addDamageType(new DamageType("lightning", " (Immune)", "i"));
|
||||||
|
monster.addDamageType(new DamageType("necrotic", " (Vulnerable)", "v"));
|
||||||
|
monster.addDamageType(new DamageType("piercing", " (Resistant)", "r"));
|
||||||
|
monster.addDamageType(new DamageType("poison", " (Immune)", "i"));
|
||||||
|
|
||||||
// Challenge Rating
|
// Challenge Rating
|
||||||
monster.setChallengeRating("*");
|
monster.setChallengeRating("*");
|
||||||
@@ -194,6 +205,45 @@ public class MonsterFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
final TextView monsterDamageVulnerabilities = root.findViewById(R.id.damage_vulnerabilities);
|
||||||
|
monsterViewModel.getDamageVulnerabilities().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(String damageType) {
|
||||||
|
if (StringHelper.isNullOrEmpty(damageType)) {
|
||||||
|
monsterDamageVulnerabilities.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
monsterDamageVulnerabilities.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
monsterDamageVulnerabilities.setText(Html.fromHtml("<b>Damage Vulnerabilities</b> " + damageType));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final TextView monsterDamageResistances = root.findViewById(R.id.damage_resistances);
|
||||||
|
monsterViewModel.getDamageResistances().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(String damageType) {
|
||||||
|
if (StringHelper.isNullOrEmpty(damageType)) {
|
||||||
|
monsterDamageResistances.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
monsterDamageResistances.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
monsterDamageResistances.setText(Html.fromHtml("<b>Damage Resistances</b> " + damageType));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final TextView monsterDamageImmunities = root.findViewById(R.id.damage_immunities);
|
||||||
|
monsterViewModel.getDamageImmunities().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(String damageType) {
|
||||||
|
if (StringHelper.isNullOrEmpty(damageType)) {
|
||||||
|
monsterDamageImmunities.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
monsterDamageImmunities.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
monsterDamageImmunities.setText(Html.fromHtml("<b>Damage Immunities</b> " + damageType));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,12 @@ public class MonsterViewModel extends ViewModel {
|
|||||||
mSavingThrows.setValue("");
|
mSavingThrows.setValue("");
|
||||||
mSkills = new MutableLiveData<>();
|
mSkills = new MutableLiveData<>();
|
||||||
mSkills.setValue("");
|
mSkills.setValue("");
|
||||||
|
mDamageVulnerabilities = new MutableLiveData<>();
|
||||||
|
mDamageVulnerabilities.setValue("");
|
||||||
|
mDamageResistances = new MutableLiveData<>();
|
||||||
|
mDamageResistances.setValue("");
|
||||||
|
mDamageImmunities = new MutableLiveData<>();
|
||||||
|
mDamageImmunities.setValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
private MutableLiveData<String> mName;
|
private MutableLiveData<String> mName;
|
||||||
@@ -90,6 +96,18 @@ public class MonsterViewModel extends ViewModel {
|
|||||||
public LiveData<String> getSkills() {
|
public LiveData<String> getSkills() {
|
||||||
return mSkills;
|
return mSkills;
|
||||||
}
|
}
|
||||||
|
private MutableLiveData<String> mDamageVulnerabilities;
|
||||||
|
public LiveData<String> getDamageVulnerabilities() {
|
||||||
|
return mDamageVulnerabilities;
|
||||||
|
}
|
||||||
|
private MutableLiveData<String> mDamageResistances;
|
||||||
|
public LiveData<String> getDamageResistances() {
|
||||||
|
return mDamageResistances;
|
||||||
|
}
|
||||||
|
private MutableLiveData<String> mDamageImmunities;
|
||||||
|
public LiveData<String> getDamageImmunities() {
|
||||||
|
return mDamageImmunities;
|
||||||
|
}
|
||||||
|
|
||||||
private Monster mMonster;
|
private Monster mMonster;
|
||||||
public void setMonster(Monster monster) {
|
public void setMonster(Monster monster) {
|
||||||
@@ -107,5 +125,9 @@ public class MonsterViewModel extends ViewModel {
|
|||||||
mCharisma.setValue(monster.getCharismaDescription());
|
mCharisma.setValue(monster.getCharismaDescription());
|
||||||
mSavingThrows.setValue(monster.getSavingThrowsDescription());
|
mSavingThrows.setValue(monster.getSavingThrowsDescription());
|
||||||
mSkills.setValue(monster.getSkillsDescription());
|
mSkills.setValue(monster.getSkillsDescription());
|
||||||
|
mDamageVulnerabilities.setValue(mMonster.getDamageVulnerabilitiesDescription());
|
||||||
|
mDamageResistances.setValue(mMonster.getDamageResistancesDescription());
|
||||||
|
mDamageImmunities.setValue(mMonster.getDamageImmunitiesDescription());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,5 +331,44 @@
|
|||||||
app:layout_constraintTop_toBottomOf="@+id/saving_throws"
|
app:layout_constraintTop_toBottomOf="@+id/saving_throws"
|
||||||
tools:text="Skills" />
|
tools:text="Skills" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/damage_vulnerabilities"
|
||||||
|
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/skills"
|
||||||
|
tools:text="Damage Vulnerabilities" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/damage_resistances"
|
||||||
|
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/damage_vulnerabilities"
|
||||||
|
tools:text="Damage Resistances" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/damage_immunities"
|
||||||
|
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/damage_resistances"
|
||||||
|
tools:text="Damage Immunities" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
Reference in New Issue
Block a user