Edit skill cleanup.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user