This commit is contained in:
ntr
2018-12-05 20:10:32 +11:00
parent 50e2c7b931
commit 3accbf5193
2 changed files with 45 additions and 41 deletions
+35 -36
View File
@@ -97,6 +97,7 @@ class CombatSkills extends Phaser.Scene {
renderSkillPhase(game) {
const { account, scene } = this;
const { keyboard } = this.input;
const { events } = this.game;
const addSkill = (i, j, skill, cryp) => {
const skillTextPos = skillTextPosition(i, j + 2);
@@ -120,15 +121,12 @@ class CombatSkills extends Phaser.Scene {
// draw the skills
const skillButtons = cryp.skills.map((skill, j) => addSkill(i, j, skill, cryp));
keyboard.on(CRYP_KEY_MAP[i],
() => this.mapSkillKeys(skillButtons, game.id, cryp.id, team.id, enemyTeam.id),
this
);
const bindCrypKeys = () => this.mapSkillKeys(skillButtons, game.id, cryp.id, team.id, enemyTeam.id, i);
keyboard.on('keydown_ESC',
() => this.mapSkillKeys(skillButtons, game.id, cryp.id, team.id, enemyTeam.id),
this
);
// reset everything
keyboard.on('keydown_ESC', bindCrypKeys, this);
events.on('SEND_SKILL', bindCrypKeys, this);
bindCrypKeys();
return true;
});
@@ -136,46 +134,47 @@ class CombatSkills extends Phaser.Scene {
return true;
}
mapSkillKeys(skillButtons, gameId, crypId, alliesId, enemyId) {
mapSkillKeys(skillButtons, gameId, crypId, alliesId, enemyId, i) {
const { keyboard } = this.input;
SKILL_KEY_MAP.forEach(k => keyboard.removeListener(k));
// deselect any currently active button
if (this.activeSkill) {
this.activeSkill.deselect();
}
skillButtons.forEach((button, i) => {
keyboard.on(SKILL_KEY_MAP[i], () => {
this.activeSkill = button;
button.select();
keyboard.removeListener(CRYP_KEY_MAP[i]);
// clear existing keys
CRYP_KEY_MAP.forEach(k => keyboard.removeListener(k));
TARGET_KEY_MAP.forEach(k => keyboard.removeListener(k));
keyboard.on(CRYP_KEY_MAP[i], () => {
SKILL_KEY_MAP.forEach(k => keyboard.removeListener(k));
CRYP_KEY_MAP.forEach(k => keyboard.on(k, () => {
this.game.events.emit('SEND_SKILL', gameId, crypId, alliesId, button.skill.skill);
button.activate();
this.activeSkill = null;
}));
// deselect any currently active button
if (this.activeSkill) {
this.activeSkill.deselect();
}
TARGET_KEY_MAP.forEach(k => keyboard.on(k, () => {
this.game.events.emit('SEND_SKILL', gameId, crypId, enemyId, button.skill.skill);
button.activate();
this.activeSkill = null;
}));
skillButtons.forEach((button, j) => {
keyboard.on(SKILL_KEY_MAP[j], () => {
this.activeSkill = button;
button.select();
keyboard.on('keydown_ESC',
() => {
CRYP_KEY_MAP.forEach(k => keyboard.removeListener(k));
TARGET_KEY_MAP.forEach(k => keyboard.removeListener(k));
},
this
);
// clear existing keys
CRYP_KEY_MAP.forEach(k => keyboard.removeListener(k));
TARGET_KEY_MAP.forEach(k => keyboard.removeListener(k));
}, this);
});
CRYP_KEY_MAP.forEach(k => keyboard.on(k, () => {
button.activate();
this.activeSkill = null;
this.game.events.emit('SEND_SKILL', gameId, crypId, alliesId, button.skill.skill);
}));
TARGET_KEY_MAP.forEach(k => keyboard.on(k, () => {
button.activate();
this.activeSkill = null;
this.game.events.emit('SEND_SKILL', gameId, crypId, enemyId, button.skill.skill);
}));
}, this);
});
}, this);
return true;
}