package com.arconus.dicecommander.interactors;
import android.content.res.Resources;
import android.os.Bundle;
import com.arconus.dicecommander.Application;
import com.arconus.dicecommander.R;
import com.arconus.dicecommander.model.entities.character.power.CharPower;
import com.arconus.dicecommander.utilities.IResourceAndDBPair;
import com.example.android.wizardpager.wizard.model.Page;
public class PowerWizardBundler {
private final CharPower power;
private final Resources res;
public PowerWizardBundler(CharPower power) {
this.power = power;
res = Application.appContext.getResources();
}
public Bundle createBundleFromPower() {
Bundle bundle = new Bundle();
bundle.putBundle(getKey(R.string.power_wizard_name), getSimpleDataBundle(power.getName()));
bundle.putBundle(getKey(R.string.power_wizard_usage_type), getDataOrbBundle(power.getPowerUsage()));
bundle.putBundle(getKey(R.string.power_wizard_action_type), getDataOrbBundle(power.getActionType()));
bundle.putBundle(getKey(R.string.power_wizard_attack_type), getDataOrbBundle(power.getAttackType()));
addAttackRoll(bundle);
addDamageRoll(bundle);
return bundle;
}
private void addAttackRoll(Bundle bundle) {
boolean hasAttackRoll = power.hasAttackRoll();
bundle.putBundle(getKey(R.string.power_wizard_attack_roll_q), getSimpleDataBundle(res.getString(translateBooleanToYesNoResourceID(hasAttackRoll))));
if (hasAttackRoll) {
bundle.putBundle(getKey(R.string.wizard_yes, R.string.power_wizard_attack_modifier), getSimpleDataBundle(String.valueOf(power.getAttackRollMod())));
bundle.putBundle(getKey(R.string.wizard_yes, R.string.power_wizard_defense_type), getDataOrbBundle(power.getTargetDefense()));
}
}
private void addDamageRoll(Bundle bundle) {
boolean hasDamageRoll = power.hasDamageRoll();
bundle.putBundle(getKey(R.string.power_wizard_damage_roll_q), getSimpleDataBundle(res.getString(translateBooleanToYesNoResourceID(hasDamageRoll))));
if (hasDamageRoll) {
bundle.putBundle(getKey(R.string.wizard_yes, R.string.power_wizard_number_of_damage_dice), getSimpleDataBundle(String.valueOf(power.getDamageDieMod())));
bundle.putBundle(getKey(R.string.wizard_yes, R.string.power_wizard_damage_die_type), getDamageDieDataOrbBundle());
bundle.putBundle(getKey(R.string.wizard_yes, R.string.power_wizard_damage_modifier), getSimpleDataBundle(String.valueOf(power.getDamageRollMod())));
}
}
private String getKey(int key) {
return getKey(-1, key);
}
private String getKey(int parentKey, int key) {
StringBuilder stringBuilder = new StringBuilder();
if (parentKey > 0) {
stringBuilder.append(res.getString(parentKey));
stringBuilder.append(":");
}
stringBuilder.append(res.getString(key));
return stringBuilder.toString();
}
private Bundle getSimpleDataBundle(String simpleData) {
Bundle bundle = new Bundle();
bundle.putString(Page.SIMPLE_DATA_KEY, simpleData);
return bundle;
}
private Bundle getDataOrbBundle(IResourceAndDBPair data) {
Bundle bundle = new Bundle();
bundle.putString(Page.SIMPLE_DATA_KEY, res.getString(data.getResourceID()));
bundle.putInt(Page.DATA_TAG_KEY, data.getDatabaseID());
return bundle;
}
private Bundle getDamageDieDataOrbBundle() {
Bundle bundle = new Bundle();
String dieSize = power.getDamageDie();
bundle.putString(Page.SIMPLE_DATA_KEY, dieSize);
String substring = dieSize.substring(1);
bundle.putInt(Page.DATA_TAG_KEY, Integer.parseInt(substring));
return bundle;
}
private int translateBooleanToYesNoResourceID(boolean b) {
return b ? R.string.wizard_yes : R.string.wizard_no;
}
}