mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-19 12:49:25 +08:00
fix: 设置
This commit is contained in:
parent
a825b268bc
commit
c61e789ddf
@ -24,8 +24,6 @@ type EmitFn<F extends (...params: any) => any> = (
|
||||
...params: Parameters<F>
|
||||
) => any;
|
||||
|
||||
console.log(1);
|
||||
|
||||
export class EventEmitter<T extends EmitableEvent = {}> {
|
||||
protected events: {
|
||||
[P in keyof T]?: Listener<T[P]>[];
|
||||
|
@ -40,8 +40,6 @@ export interface HotkeyJSON {
|
||||
assist: number;
|
||||
}
|
||||
|
||||
console.log(2);
|
||||
|
||||
export class Hotkey extends EventEmitter<HotkeyEvent> {
|
||||
static list: Hotkey[];
|
||||
|
||||
|
@ -48,7 +48,7 @@ function BooleanSetting(props: SettingComponentProps) {
|
||||
size="large"
|
||||
onClick={changeValue}
|
||||
>
|
||||
{item.value ? '开启' : '关闭'}设置
|
||||
{item.value ? '关闭' : '开启'}设置
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
@ -56,25 +56,52 @@ function BooleanSetting(props: SettingComponentProps) {
|
||||
|
||||
function NumberSetting(props: SettingComponentProps) {
|
||||
const { setting, displayer, item } = props;
|
||||
const changeValue = () => {
|
||||
setting.setValue(displayer.selectStack.join('.'), !item.value);
|
||||
const changeValue = (value: number) => {
|
||||
if (typeof value !== 'number') return;
|
||||
setting.setValue(displayer.selectStack.join('.'), value);
|
||||
displayer.update();
|
||||
};
|
||||
|
||||
return (
|
||||
<div class="editor-number">
|
||||
<div class="editor-number-input">
|
||||
<span> 修改设置: </span>
|
||||
<InputNumber
|
||||
class="number-input"
|
||||
size="large"
|
||||
keyboard={true}
|
||||
// keyboard={true}
|
||||
min={item.step?.[0] ?? 0}
|
||||
max={item.step?.[1] ?? 100}
|
||||
step={item.step?.[2] ?? 1}
|
||||
value={item.value as number}
|
||||
onChange={changeValue}
|
||||
onChange={value => changeValue(value as number)}
|
||||
></InputNumber>
|
||||
</div>
|
||||
<div class="editor-number-button">
|
||||
<Button
|
||||
class="number-button"
|
||||
type="primary"
|
||||
onClick={() =>
|
||||
changeValue(
|
||||
(item.value as number) - (item.step?.[2] ?? 1)
|
||||
)
|
||||
}
|
||||
>
|
||||
减少
|
||||
</Button>
|
||||
<Button
|
||||
class="number-button"
|
||||
type="primary"
|
||||
onClick={() =>
|
||||
changeValue(
|
||||
(item.value as number) + (item.step?.[2] ?? 1)
|
||||
)
|
||||
}
|
||||
>
|
||||
增加
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -124,6 +124,7 @@ export class MotaSetting extends EventEmitter<SettingEvent> {
|
||||
}
|
||||
const old = setting.value as boolean | number;
|
||||
setting.value = value;
|
||||
|
||||
this.emit('valueChange', key, value, old);
|
||||
}
|
||||
|
||||
@ -472,7 +473,7 @@ mainSetting
|
||||
'小地图楼传缩放',
|
||||
300,
|
||||
COM.Number,
|
||||
[50, 50, 1000]
|
||||
[50, 1000, 50]
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -23,7 +23,8 @@ export function getEnemy(
|
||||
return enemy;
|
||||
}
|
||||
|
||||
export function canBattle(
|
||||
function init() {
|
||||
core.enemys.canBattle = function canBattle(
|
||||
x: number,
|
||||
y: number,
|
||||
floorId: FloorIds = core.status.floorId
|
||||
@ -31,9 +32,9 @@ export function canBattle(
|
||||
const enemy = getEnemy(x, y, floorId);
|
||||
const { damage } = enemy.calDamage();
|
||||
return damage < core.status.hero.hp;
|
||||
}
|
||||
};
|
||||
|
||||
export function battle(
|
||||
core.events.battle = function battle(
|
||||
x: number,
|
||||
y: number,
|
||||
force: boolean = false,
|
||||
@ -42,7 +43,7 @@ export function battle(
|
||||
core.saveAndStopAutomaticRoute();
|
||||
const enemy = getEnemy(x, y);
|
||||
// 非强制战斗
|
||||
if (!canBattle(x, y) && !force && !core.status.event.id) {
|
||||
if (!core.canBattle(x, y) && !force && !core.status.event.id) {
|
||||
core.stopSound();
|
||||
core.playSound('操作失败');
|
||||
core.drawTip('你打不过此怪物!', enemy.id);
|
||||
@ -52,11 +53,15 @@ export function battle(
|
||||
if (!core.status.event.id) core.autosave(true);
|
||||
// 战前事件
|
||||
// 战后事件
|
||||
afterBattle(enemy, x, y);
|
||||
core.afterBattle(enemy, x, y);
|
||||
callback?.();
|
||||
}
|
||||
};
|
||||
|
||||
export function afterBattle(enemy: DamageEnemy, x?: number, y?: number) {
|
||||
core.events.afterBattle = function afterBattle(
|
||||
enemy: DamageEnemy,
|
||||
x?: number,
|
||||
y?: number
|
||||
) {
|
||||
const floorId = core.status.floorId;
|
||||
const special = enemy.info.special;
|
||||
|
||||
@ -143,7 +148,9 @@ export function afterBattle(enemy: DamageEnemy, x?: number, y?: number) {
|
||||
// 战后事件
|
||||
if (has(core.status.floorId)) {
|
||||
const loc = `${x},${y}` as LocString;
|
||||
todo.push(...(core.floors[core.status.floorId].afterBattle[loc] ?? []));
|
||||
todo.push(
|
||||
...(core.floors[core.status.floorId].afterBattle[loc] ?? [])
|
||||
);
|
||||
}
|
||||
todo.push(...(enemy.enemy.afterBattle ?? []));
|
||||
|
||||
@ -158,9 +165,11 @@ export function afterBattle(enemy: DamageEnemy, x?: number, y?: number) {
|
||||
// 如果已有事件正在处理中
|
||||
if (core.status.event.id == null) core.continueAutomaticRoute();
|
||||
else core.clearContinueAutomaticRoute();
|
||||
}
|
||||
};
|
||||
|
||||
export function getCurrentEnemys(floorId = core.status.floorId) {
|
||||
core.enemys.getCurrentEnemys = function getCurrentEnemys(
|
||||
floorId = core.status.floorId
|
||||
) {
|
||||
floorId = floorId || core.status.floorId;
|
||||
const enemys: CurrentEnemy[] = [];
|
||||
const used: Record<string, DamageEnemy[]> = {};
|
||||
@ -188,9 +197,8 @@ export function getCurrentEnemys(floorId = core.status.floorId) {
|
||||
const bd = b.enemy.calDamage().damage;
|
||||
return ad - bd;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function init() {
|
||||
core.events._sys_battle = function (data: Block, callback?: () => void) {
|
||||
// 检查战前事件
|
||||
const floor = core.floors[core.status.floorId];
|
||||
@ -215,7 +223,7 @@ function init() {
|
||||
core.insertAction(beforeBattle, data.x, data.y, callback);
|
||||
}
|
||||
} else {
|
||||
battle(data.x, data.y, false, callback);
|
||||
core.battle(data.x, data.y, false, callback);
|
||||
}
|
||||
};
|
||||
|
||||
@ -234,8 +242,14 @@ function init() {
|
||||
y,
|
||||
prefix
|
||||
) as LocArr;
|
||||
battle(ex, ey, true, core.doAction);
|
||||
core.battle(ex, ey, true, core.doAction);
|
||||
}
|
||||
};
|
||||
}
|
||||
loading.once('coreInit', init);
|
||||
|
||||
declare global {
|
||||
interface Enemys {
|
||||
getCurrentEnemys(floorId: FloorIds): CurrentEnemy[];
|
||||
}
|
||||
}
|
||||
|
@ -14,11 +14,7 @@ Mota.register('class', 'EventEmitter', EventEmitter);
|
||||
Mota.register('class', 'IndexedEventEmitter', IndexedEventEmitter);
|
||||
Mota.register('class', 'Range', Range);
|
||||
// ----- 函数注册
|
||||
Mota.register('fn', 'battle', battle.battle);
|
||||
Mota.register('fn', 'getEnemy', battle.getEnemy);
|
||||
Mota.register('fn', 'afterBattle', battle.afterBattle);
|
||||
Mota.register('fn', 'canBattle', battle.canBattle);
|
||||
Mota.register('fn', 'getCurrentEnemys', battle.getCurrentEnemys);
|
||||
// ----- 变量注册
|
||||
Mota.register('var', 'enemySpecials', specials);
|
||||
Mota.register('var', 'hook', hook);
|
||||
|
@ -25,11 +25,12 @@ const MAX_ROTATE = 0.5;
|
||||
const FRAG_TIMING = linear();
|
||||
|
||||
export function init() {
|
||||
const fn = Mota.requireAll('fn');
|
||||
Mota.rewrite(fn, 'afterBattle', 'add', (_, enemy, x, y) => {
|
||||
Mota.rewrite(core.events, 'afterBattle', 'add', (_, enemy, x, y) => {
|
||||
// 打怪特效
|
||||
const setting = Mota.require('var', 'mainSetting');
|
||||
if (setting.getValue('screen.frag') && has(x) && has(y)) {
|
||||
console.log(setting.getValue('fx.frag'));
|
||||
|
||||
if (setting.getValue('fx.frag') && has(x) && has(y)) {
|
||||
const frame = core.status.globalAnimateStatus % 2;
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = 32;
|
||||
|
@ -29,7 +29,7 @@ export function getDetailedEnemy(
|
||||
return typeof func === 'string' ? func : func(enemy);
|
||||
};
|
||||
const special: [string, string, string][] = enemy.enemy.special.map(vv => {
|
||||
const s = Mota.Plugin.require('special_g').special[vv];
|
||||
const s = Mota.require('var', 'enemySpecials')[vv];
|
||||
return [
|
||||
fromFunc(s.name, enemy.enemy),
|
||||
fromFunc(s.desc, enemy.enemy),
|
||||
|
6
src/types/function.d.ts
vendored
6
src/types/function.d.ts
vendored
@ -110,11 +110,7 @@ interface EventData {
|
||||
* @param x 怪物横坐标
|
||||
* @param y 怪物纵坐标
|
||||
*/
|
||||
afterBattle(
|
||||
enemyId: AllIdsOf<'enemys' | 'enemy48'>,
|
||||
x?: number,
|
||||
y?: number
|
||||
): void;
|
||||
afterBattle(enemyId: any, x?: number, y?: number): void;
|
||||
|
||||
/**
|
||||
* 开门后
|
||||
|
@ -83,7 +83,7 @@ const special = (() => {
|
||||
};
|
||||
|
||||
const show = s.slice(0, 2).map(v => {
|
||||
const s = Mota.Plugin.require('special_g').specials[v];
|
||||
const s = Mota.require('var', 'enemySpecials')[v];
|
||||
return [fromFunc(s.name, enemy.enemy), s.color];
|
||||
});
|
||||
if (s.length > 2) show.push(['...', 'white']);
|
||||
|
@ -58,6 +58,7 @@
|
||||
:item="selectedItem"
|
||||
:displayer="displayer"
|
||||
:setting="setting"
|
||||
:update="update"
|
||||
></component>
|
||||
</div>
|
||||
</div>
|
||||
@ -67,7 +68,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, onUnmounted, shallowRef } from 'vue';
|
||||
import { computed, onMounted, onUnmounted, ref, shallowRef } from 'vue';
|
||||
import {
|
||||
mainSetting,
|
||||
MotaSetting,
|
||||
@ -78,11 +79,9 @@ import {
|
||||
} from '../core/main/setting';
|
||||
import settingText from '../data/settings.json';
|
||||
import { RightOutlined, LeftOutlined } from '@ant-design/icons-vue';
|
||||
import { keycode, splitText } from '../plugin/utils';
|
||||
import { splitText } from '../plugin/utils';
|
||||
import Scroll from '../components/scroll.vue';
|
||||
import { isMobile } from '../plugin/use';
|
||||
import { sleep } from 'mutate-animate';
|
||||
import { KeyCode } from '../plugin/keyCodes';
|
||||
import { gameKey } from '@/core/main/init/hotkey';
|
||||
import { GameUi } from '@/core/main/custom/ui';
|
||||
import { mainUi } from '@/core/main/init/ui';
|
||||
@ -98,10 +97,12 @@ const setting = props.info ?? mainSetting;
|
||||
const text = props.text ?? (settingText as SettingText);
|
||||
const display = shallowRef<SettingDisplayInfo[]>([]);
|
||||
const selectedItem = computed(() => display.value.at(-1)?.item);
|
||||
const update = ref(false);
|
||||
|
||||
const displayer = new SettingDisplayer(setting, text);
|
||||
displayer.on('update', (stack, dis) => {
|
||||
display.value = dis;
|
||||
update.value = !update.value;
|
||||
});
|
||||
display.value = displayer.displayInfo;
|
||||
|
||||
@ -276,15 +277,28 @@ onUnmounted(() => {
|
||||
|
||||
.setting-info::v-deep(.editor-number) {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-direction: column;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
padding: 0 10% 0 5%;
|
||||
|
||||
.number-input {
|
||||
.number-input,
|
||||
.number-button {
|
||||
font-size: 80%;
|
||||
width: 40%;
|
||||
}
|
||||
|
||||
.number-button {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.editor-number-button {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-around;
|
||||
margin-top: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
|
Loading…
Reference in New Issue
Block a user