refactor: 游戏按键

This commit is contained in:
unanmed 2023-11-18 23:03:47 +08:00
parent 9bf27f58e3
commit 337aaade8c
4 changed files with 67 additions and 147 deletions

View File

@ -344,147 +344,6 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = {
core.items.quickLoadEquip(keyCode - 48); core.items.quickLoadEquip(keyCode - 48);
return; return;
} }
const [x, y] = flags.mouseLoc ?? [];
const mx = Math.round(x + core.bigmap.offsetX / 32);
const my = Math.round(y + core.bigmap.offsetY / 32);
// 根据keyCode值来执行对应操作
switch (keyCode) {
case 74: // J:打开技能树
core.useItem('skill1', true);
break;
case 27: // ESC打开菜单栏
core.openSettings(true);
break;
case 88: // X使用怪物手册
core.openBook(true);
break;
case 71: // G使用楼传器
core.useFly(true);
break;
case 65: // A读取自动存档回退
core.doSL('autoSave', 'load');
break;
case 87: // W撤销回退
core.doSL('autoSave', 'reload');
break;
case 83: // S存档
core.save(true);
break;
case 68: // D读档
core.load(true);
break;
case 84: // T打开道具栏
core.openToolbox(true);
break;
case 81: // Q打开装备栏
core.openEquipbox(true);
break;
case 90: // Z转向
core.turnHero();
break;
case 86: // V打开快捷商店列表
core.openQuickShop(true);
break;
case 32: // SPACE轻按
core.getNextItem();
break;
case 82: // R回放录像
core.ui._drawReplay();
break;
case 33:
case 34: // PgUp/PgDn浏览地图
core.ui._drawViewMaps();
break;
case 66: // B打开数据统计
core.ui._drawStatistics();
break;
case 72: // H打开帮助页面
core.useItem('I560', true);
break;
case 67: // C怪物临界
if (core.getBlockCls(mx, my)?.startsWith('enemy')) {
// mota.plugin.fixed.showFixed.value = false;
mota.ui.main.open('fixedDetail', {
panel: 'critical'
});
}
break;
case 69: // E怪物属性
if (core.getBlockCls(mx, my)?.startsWith('enemy')) {
// mota.plugin.fixed.showFixed.value = false;
mota.ui.main.open('fixedDetail', {
panel: 'special'
});
}
break;
case 77: // M快速标记
// todo: refactor
const blocks = core.getMapBlocksObj();
const block = blocks[`${mx},${my}`];
break;
case 78: // N重新开始
core.confirmRestart();
break;
case 79: // O查看工程
core.actions._clickGameInfo_openProject();
break;
case 80: // P游戏主页
core.actions._clickGameInfo_openComments();
break;
case 49: // 1: 断灭之刃
if (!flags.bladeOn) break;
if (flags.autoSkill) {
mota.plugin.utils.tip('error', '已开启自动切换技能!');
break;
}
core.status.route.push('key:49'); // 将按键记在录像中
core.playSound('光标移动');
if (flags.blade) flags.blade = false;
else flags.blade = true;
core.updateStatusBar();
break;
case 50: // 快捷键2: 跳跃技能 || 破
if (
!flags.chase &&
!core.status.floorId.startsWith('tower') &&
flags.skill2
) {
core.plugin.skillEffects.jumpSkill();
core.status.route.push('key:50'); // 将按键记在录像中
} else {
if (core.hasItem('pickaxe')) {
core.status.route.push('key:50'); // 将按键记在录像中
core.useItem('pickaxe', true); // 第二个参数true代表该次使用道具是被按键触发的使用过程不计入录像
}
}
break;
case 51: // 3: 铸剑为盾
if (!flags.shieldOn) break;
if (flags.autoSkill) {
mota.plugin.utils.tip('error', '已开启自动切换技能!');
break;
}
core.status.route.push('key:51'); // 将按键记在录像中
core.playSound('光标移动');
if (flags.shield) flags.shield = false;
else flags.shield = true;
core.updateStatusBar();
break;
case 53: // 5读取自动存档回退方便手机版操作
core.doSL('autoSave', 'load');
break;
case 54: // 6撤销回退方便手机版操作
core.doSL('autoSave', 'reload');
break;
case 55: // 快捷键7绑定为轻按方便手机版操作
core.getNextItem();
break;
case 119: // F8开启debug模式
core.debug();
break;
}
} }
}, },
control: { control: {

View File

@ -327,6 +327,69 @@ gameKey.use(mainScope);
// ----- Realization // ----- Realization
gameKey
.when(() => !core.status.lockControl)
.realize('book', () => {
core.openBook(true);
})
.realize('save', () => {
core.save(true);
})
.realize('load', () => {
core.load(true);
})
.realize('toolbox', () => {
core.openToolbox(true);
})
.realize('equipbox', () => {
core.openEquipbox(true);
})
.realize('fly', () => {
core.useFly(true);
})
.realize('menu', () => {
core.openSettings(true);
})
.realize('replay', () => {
core.ui._drawReplay();
})
.realize('shop', () => {
core.openQuickShop(true);
})
.realize('statistics', () => {
core.ui._drawStatistics();
})
.realize('viewMap', () => {
core.ui._drawViewMaps();
})
.realize('skillTree', () => {
core.useItem('skill1', true);
})
.realize('desc', () => {
core.useItem('I560', true);
})
.realize('undo', () => {
core.doSL('autoSave', 'load');
})
.realize('redo', () => {
core.doSL('autoSave', 'reload');
})
.realize('turn', () => {
core.turnHero();
})
.realize('getNext', () => {
core.getNextItem();
})
.realize('mark', () => {})
.realize('special', () => {})
.realize('critical', () => {})
.realize('restart', () => {
core.confirmRestart();
})
.realize('comment', () => {
core.actions._clickGameInfo_openComments();
});
// ----- Listening // ----- Listening
document.addEventListener('keyup', e => { document.addEventListener('keyup', e => {
const assist = generateBinary([e.ctrlKey, e.shiftKey, e.altKey]); const assist = generateBinary([e.ctrlKey, e.shiftKey, e.altKey]);

6
src/types/ui.d.ts vendored
View File

@ -821,11 +821,11 @@ interface Ui {
/** /**
* *
*/ */
_drawViewMaps(); _drawViewMaps(): void;
_drawReplay(); _drawReplay(): void;
_drawStatistics(); _drawStatistics(): void;
} }
declare const ui: new () => Ui; declare const ui: new () => Ui;

View File

@ -93,9 +93,7 @@ import {
DoubleRightOutlined DoubleRightOutlined
} from '@ant-design/icons-vue'; } from '@ant-design/icons-vue';
import { debounce } from 'lodash-es'; import { debounce } from 'lodash-es';
import { downloadCanvasImage, keycode, tip } from '../plugin/utils'; import { downloadCanvasImage, tip } from '../plugin/utils';
import { sleep } from 'mutate-animate';
import { KeyCode } from '../plugin/keyCodes';
import { GameUi } from '@/core/main/custom/ui'; import { GameUi } from '@/core/main/custom/ui';
import { gameKey } from '@/core/main/init/hotkey'; import { gameKey } from '@/core/main/init/hotkey';