Adds skills to monster cards.
This commit is contained in:
@@ -13,6 +13,7 @@ public class Monster {
|
||||
|
||||
public Monster() {
|
||||
mSavingThrows = new HashSet<>();
|
||||
mSkills = new HashSet<>();
|
||||
}
|
||||
|
||||
private String mName;
|
||||
@@ -586,4 +587,36 @@ public class Monster {
|
||||
public void setCustomProficiencyBonus(int proficiencyBonus) {
|
||||
mCustomProficiencyBonus = proficiencyBonus;
|
||||
}
|
||||
|
||||
private HashSet<Skill> mSkills;
|
||||
public Set<Skill> getSkills() {
|
||||
return mSkills;
|
||||
}
|
||||
public void addSkill(Skill skill) {
|
||||
mSkills.add(skill);
|
||||
}
|
||||
public void removeSkill(Skill skill) {
|
||||
mSkills.remove(skill);
|
||||
}
|
||||
public void clearSkill(Skill skill) {
|
||||
mSkills.clear();
|
||||
}
|
||||
|
||||
public String getSkillsDescription() {
|
||||
Skill[] elements = new Skill[mSkills.size()];
|
||||
elements = mSkills.toArray(elements);
|
||||
Arrays.sort(elements);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean isFirst = true;
|
||||
for (Skill skill : elements) {
|
||||
if (!isFirst) {
|
||||
sb.append(", ");
|
||||
}
|
||||
String name = skill.getName();
|
||||
sb.append(skill.getText(this));
|
||||
isFirst = false;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.majinnaibu.monstercards.models;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Skill implements Comparator<Skill>, Comparable<Skill> {
|
||||
|
||||
private String mName;
|
||||
private String mAbilityScoreName;
|
||||
private String mNote;
|
||||
|
||||
public Skill(String name, String abilityScoreName) {
|
||||
mName = name;
|
||||
mAbilityScoreName = abilityScoreName;
|
||||
mNote = "";
|
||||
}
|
||||
|
||||
public Skill(String name, String abilityScoreName, String note) {
|
||||
mName = name;
|
||||
mAbilityScoreName = abilityScoreName;
|
||||
mNote = note;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return mName;
|
||||
}
|
||||
public void setName(String name) {
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public String getAbilityScoreName() {
|
||||
return mAbilityScoreName;
|
||||
}
|
||||
public void setAbilityScoreName(String abilityScoreName) {
|
||||
mAbilityScoreName = abilityScoreName;
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return mNote;
|
||||
}
|
||||
|
||||
public int getSkillBonus(Monster monster) {
|
||||
int bonus = monster.getAbilityModifier(mAbilityScoreName);
|
||||
if (" (ex)".equals(getNote())) {
|
||||
bonus += 2 * monster.getProficiencyBonus();
|
||||
} else {
|
||||
bonus += monster.getProficiencyBonus();
|
||||
}
|
||||
return bonus;
|
||||
}
|
||||
|
||||
public String getText(Monster monster) {
|
||||
int bonus = getSkillBonus(monster);
|
||||
|
||||
return String.format(Locale.US, "%s%s %d", mName.substring(0,1), mName.substring(1), bonus);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Skill o) {
|
||||
return this.getName().compareToIgnoreCase(o.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(Skill o1, Skill o2) {
|
||||
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import com.majinnaibu.monstercards.R;
|
||||
import com.majinnaibu.monstercards.helpers.StringHelper;
|
||||
import com.majinnaibu.monstercards.models.Monster;
|
||||
import com.majinnaibu.monstercards.models.SavingThrow;
|
||||
import com.majinnaibu.monstercards.models.Skill;
|
||||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
public class MonsterFragment extends Fragment {
|
||||
@@ -66,6 +67,9 @@ public class MonsterFragment extends Fragment {
|
||||
monster.addSavingThrow(new SavingThrow("int", 3));
|
||||
monster.addSavingThrow(new SavingThrow("wis", 4));
|
||||
monster.addSavingThrow(new SavingThrow("cha", 5));
|
||||
//Skills
|
||||
monster.addSkill(new Skill("perception", "wis"));
|
||||
monster.addSkill(new Skill("stealth", "dexterity"));
|
||||
|
||||
// Challenge Rating
|
||||
monster.setChallengeRating("*");
|
||||
@@ -177,6 +181,19 @@ public class MonsterFragment extends Fragment {
|
||||
}
|
||||
});
|
||||
|
||||
final TextView monsterSkills = root.findViewById(R.id.skills);
|
||||
monsterViewModel.getSkills().observe(getViewLifecycleOwner(), new Observer<String>() {
|
||||
@Override
|
||||
public void onChanged(String skills) {
|
||||
if (StringHelper.isNullOrEmpty(skills)) {
|
||||
monsterSkills.setVisibility(View.GONE);
|
||||
} else {
|
||||
monsterSkills.setVisibility(View.VISIBLE);
|
||||
}
|
||||
monsterSkills.setText(Html.fromHtml("<b>Skills</b> " + skills));
|
||||
}
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ public class MonsterViewModel extends ViewModel {
|
||||
mCharisma.setValue("");
|
||||
mSavingThrows = new MutableLiveData<>();
|
||||
mSavingThrows.setValue("");
|
||||
mSkills = new MutableLiveData<>();
|
||||
mSkills.setValue("");
|
||||
}
|
||||
|
||||
private MutableLiveData<String> mName;
|
||||
@@ -84,6 +86,10 @@ public class MonsterViewModel extends ViewModel {
|
||||
public LiveData<String> getSavingThrows() {
|
||||
return mSavingThrows;
|
||||
}
|
||||
private MutableLiveData<String> mSkills;
|
||||
public LiveData<String> getSkills() {
|
||||
return mSkills;
|
||||
}
|
||||
|
||||
private Monster mMonster;
|
||||
public void setMonster(Monster monster) {
|
||||
@@ -100,5 +106,6 @@ public class MonsterViewModel extends ViewModel {
|
||||
mWisdom.setValue(monster.getWisdomDescription());
|
||||
mCharisma.setValue(monster.getCharismaDescription());
|
||||
mSavingThrows.setValue(monster.getSavingThrowsDescription());
|
||||
mSkills.setValue(monster.getSkillsDescription());
|
||||
}
|
||||
}
|
||||
@@ -318,5 +318,18 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/divider3"
|
||||
tools:text="Saving Throws" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/skills"
|
||||
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/saving_throws"
|
||||
tools:text="Skills" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</ScrollView>
|
||||
Reference in New Issue
Block a user