Edit skill cleanup.

This commit is contained in:
2021-06-20 14:06:46 -07:00
parent 8e29dc2440
commit 3ddf25905e
3 changed files with 26 additions and 47 deletions

View File

@@ -266,6 +266,28 @@ public class Monster {
regionalActions = new HashSet<>();
}
public static int getAbilityModifierForScore(int score) {
return (int) Math.floor((score - 10) / 2.0);
}
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;
}
}
public String getMeta() {
StringBuilder sb = new StringBuilder();
boolean isFirstOutput = true;
@@ -321,10 +343,6 @@ public class Monster {
}
}
public static int getAbilityModifierForScore(int score) {
return (int) Math.floor((score - 10) / 2.0);
}
public int getAbilityModifier(AbilityScore abilityScore) {
switch (abilityScore) {
case STRENGTH:
@@ -477,24 +495,6 @@ public class Monster {
}
}
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;
}
}
public String getSpeedText() {
if (hasCustomSpeed) {
return customSpeedDescription;

View File

@@ -30,12 +30,12 @@ public class EditSkillFragment extends MCFragment {
private Skill mOldSkill;
@Override
public void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
public void onCreate(@Nullable Bundle savedInstanceState) {
mViewModel = new ViewModelProvider(this).get(EditSkillViewModel.class);
if (getArguments() != null) {
EditSkillFragmentArgs args = EditSkillFragmentArgs.fromBundle(getArguments());
mViewModel.copyFromSkill(args.getName(), args.getAbilityScore(), args.getProficiency(), args.getAdvantage());
mOldSkill = new Skill(args.getName(), args.getAbilityScore(), args.getAdvantage(), args.getProficiency());
mViewModel.copyFromSkill(mOldSkill);
} else {
Logger.logWTF("This should never happen. EditSkillFragment needs arguments.");
mOldSkill = null;

View File

@@ -29,17 +29,6 @@ public class EditSkillViewModel extends ViewModel {
mSkill = new ChangeTrackedLiveData<>(makeSkill(), onDirtied);
}
public EditSkillViewModel(Skill skill) {
mHasChanges = new MutableLiveData<>(false);
ChangeTrackedLiveData.OnValueDirtiedCallback onDirtied = () -> mHasChanges.setValue(true);
mAbilityScore = new ChangeTrackedLiveData<>(skill.abilityScore, onDirtied);
mAdvantageType = new ChangeTrackedLiveData<>(skill.advantageType, onDirtied);
mProficiencyType = new ChangeTrackedLiveData<>(skill.proficiencyType, onDirtied);
mName = new ChangeTrackedLiveData<>(skill.name, onDirtied);
mSkill = new ChangeTrackedLiveData<>(makeSkill(), onDirtied);
}
public void copyFromSkill(Skill skill) {
mAbilityScore.resetValue(skill.abilityScore);
mAdvantageType.resetValue(skill.advantageType);
@@ -47,13 +36,6 @@ public class EditSkillViewModel extends ViewModel {
mName.resetValue(skill.name);
}
public void copyFromSkill(String name, AbilityScore abilityScore, ProficiencyType proficiency, AdvantageType advantage) {
mAbilityScore.resetValue(abilityScore);
mAdvantageType.resetValue(advantage);
mProficiencyType.resetValue(proficiency);
mName.resetValue(name);
}
public LiveData<Skill> getSkill() {
return mSkill;
}
@@ -94,12 +76,9 @@ public class EditSkillViewModel extends ViewModel {
mSkill.setValue(makeSkill());
}
public LiveData<Boolean> getHasChanges() {
return mHasChanges;
}
public boolean hasChanges() {
return mHasChanges.getValue();
Boolean value = mHasChanges.getValue();
return value != null && value;
}
private Skill makeSkill() {