mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
refactor casting spells on the client side (#9949)
This commit is contained in:
@@ -188,22 +188,12 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
this.$root.$on('castEnd', (target, type, $event) => {
|
|
||||||
this.castEnd(target, type, $event);
|
|
||||||
});
|
|
||||||
|
|
||||||
document.addEventListener('keyup', this.handleKeyUp);
|
|
||||||
|
|
||||||
// @TODO: should we abstract the drawer state/local store to a library and mixing combo? We use a similar pattern in equipment
|
// @TODO: should we abstract the drawer state/local store to a library and mixing combo? We use a similar pattern in equipment
|
||||||
const spellDrawerState = getLocalSetting(CONSTANTS.keyConstants.SPELL_DRAWER_STATE);
|
const spellDrawerState = getLocalSetting(CONSTANTS.keyConstants.SPELL_DRAWER_STATE);
|
||||||
if (spellDrawerState === CONSTANTS.valueConstants.DRAWER_CLOSED) {
|
if (spellDrawerState === CONSTANTS.valueConstants.DRAWER_CLOSED) {
|
||||||
this.$store.state.spellOptions.spellDrawOpen = false;
|
this.$store.state.spellOptions.spellDrawOpen = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
|
||||||
this.$root.$off('castEnd');
|
|
||||||
document.removeEventListener('keyup', this.handleKeyUp);
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({user: 'user.data'}),
|
...mapState({user: 'user.data'}),
|
||||||
openStatus () {
|
openStatus () {
|
||||||
@@ -211,10 +201,6 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleKeyUp (keyEvent) {
|
|
||||||
if (keyEvent.keyCode !== 27) return;
|
|
||||||
this.castCancel();
|
|
||||||
},
|
|
||||||
drawerToggled (newState) {
|
drawerToggled (newState) {
|
||||||
this.$store.state.spellOptions.spellDrawOpen = newState;
|
this.$store.state.spellOptions.spellDrawOpen = newState;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ import isArray from 'lodash/isArray';
|
|||||||
// @TODO: Let's separate some of the business logic out of Vue if possible
|
// @TODO: Let's separate some of the business logic out of Vue if possible
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
|
handleCastCancelKeyUp (keyEvent) {
|
||||||
|
if (keyEvent.keyCode !== 27) return;
|
||||||
|
this.castCancel();
|
||||||
|
},
|
||||||
async castStart (spell) {
|
async castStart (spell) {
|
||||||
if (this.$store.state.spellOptions.castingSpell) {
|
if (this.$store.state.spellOptions.castingSpell) {
|
||||||
this.castCancel();
|
this.castCancel();
|
||||||
@@ -47,6 +51,13 @@ export default {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
this.castEnd(tasks, spell.target);
|
this.castEnd(tasks, spell.target);
|
||||||
|
} else {
|
||||||
|
// If the cast target has to be selected (and can be cancelled)
|
||||||
|
document.addEventListener('keyup', this.handleCastCancelKeyUp);
|
||||||
|
|
||||||
|
this.$root.$on('castEnd', (target, type, $event) => {
|
||||||
|
this.castEnd(target, type, $event);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async castEnd (target, type) {
|
async castEnd (target, type) {
|
||||||
@@ -61,17 +72,12 @@ export default {
|
|||||||
if (target && target.challenge && target.challenge.id) return this.text(this.$t('invalidTarget'));
|
if (target && target.challenge && target.challenge.id) return this.text(this.$t('invalidTarget'));
|
||||||
if (target && target.group && target.group.id) return this.text(this.$t('invalidTarget'));
|
if (target && target.group && target.group.id) return this.text(this.$t('invalidTarget'));
|
||||||
|
|
||||||
// @TODO: just call castCancel?
|
|
||||||
this.$store.state.spellOptions.castingSpell = false;
|
|
||||||
this.potionClickMode = false;
|
|
||||||
|
|
||||||
this.spell.cast(this.user, target);
|
this.spell.cast(this.user, target);
|
||||||
// User.save(); // @TODO:
|
|
||||||
|
|
||||||
let spell = this.spell;
|
let spell = this.spell;
|
||||||
let targetId = target ? target._id : null;
|
let targetId = target ? target._id : null;
|
||||||
this.spell = null;
|
|
||||||
this.applyingAction = false;
|
this.castCancel();
|
||||||
|
|
||||||
let spellUrl = `/api/v3/user/class/cast/${spell.key}`;
|
let spellUrl = `/api/v3/user/class/cast/${spell.key}`;
|
||||||
if (targetId) spellUrl += `?targetId=${targetId}`;
|
if (targetId) spellUrl += `?targetId=${targetId}`;
|
||||||
@@ -123,6 +129,10 @@ export default {
|
|||||||
this.spell = null;
|
this.spell = null;
|
||||||
document.querySelector('body').style.cursor = 'initial';
|
document.querySelector('body').style.cursor = 'initial';
|
||||||
this.$store.state.spellOptions.castingSpell = false;
|
this.$store.state.spellOptions.castingSpell = false;
|
||||||
|
|
||||||
|
// Remove listeners
|
||||||
|
this.$root.$off('castEnd');
|
||||||
|
document.removeEventListener('keyup', this.handleCastCancelKeyUp);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user