feat: 跟进 2.A 的更改

This commit is contained in:
AncTe committed 2024-04-20 12:27:38 +08:00
1 parent 0dfb7e4b99
commit 86e6e76286
38 files changed
+851 -493

No files matched your search

+2 -2
View File
@@ -80,8 +80,8 @@ export class BgmController
this.playing = true;
if (!this.disable) {
this.setTransitionAnimate(id, 1);
if (this.now) this.setTransitionAnimate(this.now, 0, when);
this.setTransitionAnimate(id, 1, when);
if (this.now) this.setTransitionAnimate(this.now, 0);
}
if (!noStack) {
+13 -24
View File
@@ -1,6 +1,5 @@
import { has } from '@/plugin/utils';
import { AudioParamOf, AudioPlayer } from './audio';
import resource from '@/data/resource.json';
import { ResourceController } from '../loader/controller';
// todo: 立体声,可设置音源位置
@@ -24,7 +23,6 @@ export class SoundEffect extends AudioPlayer {
gain: GainNode = AudioPlayer.ac.createGain();
panner: PannerNode | null = null;
merger: ChannelMergerNode | null = null;
set volumn(value: number) {
this.gain.gain.value = value * SoundEffect.volume;
@@ -63,9 +61,7 @@ export class SoundEffect extends AudioPlayer {
* 设置音频路由线路
* ```txt
* 不启用立体声:source -> gain -> destination
* 启用立体声:source -> panner -> gain --> destination
* 单声道立体声:source -> merger -> panner -> gain -> destination
* 单声道立体声指音源为单声道,合成为双声道后模拟为立体声
* 启用立体声:source -> panner -> gain -> destination
* ```
* @param stereo 是否启用立体声
*/
@@ -74,20 +70,10 @@ export class SoundEffect extends AudioPlayer {
const ac = AudioPlayer.ac;
if (!channel) return;
this.panner = null;
this.merger = null;
if (stereo) {
this.panner = ac.createPanner();
this.panner.connect(this.gain);
if (channel === 1) {
this.merger = ac.createChannelMerger();
this.merger.connect(this.panner);
this.baseNode = [
{ node: this.merger, channel: 0 },
{ node: this.merger, channel: 1 }
];
} else {
this.baseNode = [{ node: this.panner }];
}
this.baseNode = [{ node: this.panner }];
} else {
this.baseNode = [{ node: this.gain }];
}
@@ -136,15 +122,18 @@ export class SoundEffect extends AudioPlayer {
* @param source 立体声声源位置与朝向
* @param listener 听者的位置、头顶方向、面朝方向
*/
setPanner(source: Partial<Panner>, listener: Partial<Listener>) {
setPanner(source?: Partial<Panner>, listener?: Partial<Listener>) {
if (!this.panner) return;
console.log(2);
for (const [key, value] of Object.entries(source)) {
this.panner[key as keyof Panner].value = value;
if (source) {
for (const [key, value] of Object.entries(source)) {
this.panner[key as keyof Panner].value = value;
}
}
const l = AudioPlayer.ac.listener;
for (const [key, value] of Object.entries(listener)) {
l[key as keyof Listener].value = value;
if (listener) {
const l = AudioPlayer.ac.listener;
for (const [key, value] of Object.entries(listener)) {
l[key as keyof Listener].value = value;
}
}
}
}
@@ -161,7 +150,6 @@ export class SoundController extends ResourceController<
* @param data 音频的ArrayBuffer信息,会被解析为AudioBuffer
*/
add(uri: string, data: ArrayBuffer) {
const stereo = resource.stereoSE.includes(uri);
const se = new SoundEffect(data, true);
if (this.list[uri]) {
console.warn(`Repeated sound effect: '${uri}'.`);
@@ -176,6 +164,7 @@ export class SoundController extends ResourceController<
*/
play(sound: SoundIds, end?: () => void): number {
const se = this.get(sound);
if (!se) return -1;
const index = se.playSE();
if (!has(index)) return -1;
this.seIndex[index] = se;
+84 -23
View File
@@ -1,13 +1,5 @@
import { BgmController, bgm } from './audio/bgm';
import { SoundController, SoundEffect, sound } from './audio/sound';
import { readyAllResource } from './loader/load';
import {
Resource,
ResourceStore,
ZippedResource,
resource,
zipResource
} from './loader/resource';
import { Focus, GameUi, UiController } from './main/custom/ui';
import { GameStorage } from './main/storage';
import './main/init/';
@@ -20,19 +12,51 @@ import {
mainSetting,
settingStorage
} from './main/setting';
import { KeyCode } from '@/plugin/keyCodes';
import { KeyCode, ScanCode } from '@/plugin/keyCodes';
import { status } from '@/plugin/ui/statusBar';
import './plugin';
import './package';
import { AudioPlayer } from './audio/audio';
import { CustomToolbar } from './main/custom/toolbar';
import { Hotkey } from './main/custom/hotkey';
import { Keyboard } from './main/custom/keyboard';
import {
Hotkey,
checkAssist,
isAssist,
unwarpBinary
} from './main/custom/hotkey';
import { Keyboard, generateKeyboardEvent } from './main/custom/keyboard';
import './main/layout';
function ready() {
readyAllResource();
}
import { MComponent, m } from './main/layout';
import { createSettingComponents } from './main/init/settings';
import {
createToolbarComponents,
createToolbarEditorComponents
} from './main/init/toolbar';
import { VirtualKey } from './main/init/misc';
import * as utils from '@/plugin/utils';
import * as use from '@/plugin/use';
import * as mark from '@/plugin/mark';
import * as keyCodes from '@/plugin/keyCodes';
import { addAnimate, removeAnimate } from '@/plugin/animateController';
import * as bookTools from '@/plugin/ui/book';
import * as commonTools from '@/plugin/ui/common';
import * as equipboxTools from '@/plugin/ui/equipbox';
import * as fixedTools from '@/plugin/ui/fixed';
import * as flyTools from '@/plugin/ui/fly';
import * as statusBarTools from '@/plugin/ui/statusBar';
import * as toolboxTools from '@/plugin/ui/toolbox';
import * as UI from '@ui/index';
import Box from '@/components/box.vue';
import BoxAnimate from '@/components/boxAnimate.vue';
import Colomn from '@/components/colomn.vue';
import EnemyOne from '@/components/enemyOne.vue';
import Scroll from '@/components/scroll.vue';
import EnemyCritical from '@/panel/enemyCritical.vue';
import EnemySpecial from '@/panel/enemySpecial.vue';
import EnemyTarget from '@/panel/enemyTarget.vue';
import KeyboardPanel from '@/panel/keyboard.vue';
import { MCGenerator } from './main/layout';
import { ResourceController } from './loader/controller';
// ----- 类注册
Mota.register('class', 'AudioPlayer', AudioPlayer);
@@ -44,15 +68,20 @@ Mota.register('class', 'GameUi', GameUi);
Mota.register('class', 'Hotkey', Hotkey);
Mota.register('class', 'Keyboard', Keyboard);
Mota.register('class', 'MotaSetting', MotaSetting);
Mota.register('class', 'Resource', Resource);
Mota.register('class', 'ResourceStore', ResourceStore);
Mota.register('class', 'SettingDisplayer', SettingDisplayer);
Mota.register('class', 'SoundController', SoundController);
Mota.register('class', 'SoundEffect', SoundEffect);
Mota.register('class', 'UiController', UiController);
Mota.register('class', 'ZippedResource', ZippedResource);
Mota.register('class', 'MComponent', MComponent);
Mota.register('class', 'ResourceController', ResourceController);
// ----- 函数注册
Mota.register('fn', 'm', m);
Mota.register('fn', 'unwrapBinary', unwarpBinary);
Mota.register('fn', 'checkAssist', checkAssist);
Mota.register('fn', 'isAssist', isAssist);
Mota.register('fn', 'generateKeyboardEvent', generateKeyboardEvent);
Mota.register('fn', 'addAnimate', addAnimate);
Mota.register('fn', 'removeAnimate', removeAnimate);
// ----- 变量注册
Mota.register('var', 'mainUi', mainUi);
Mota.register('var', 'fixedUi', fixedUi);
@@ -61,11 +90,43 @@ Mota.register('var', 'sound', sound);
Mota.register('var', 'gameKey', gameKey);
Mota.register('var', 'mainSetting', mainSetting);
Mota.register('var', 'KeyCode', KeyCode);
Mota.register('var', 'resource', resource);
Mota.register('var', 'zipResource', zipResource);
Mota.register('var', 'settingStorage', settingStorage);
Mota.register('var', 'status', status);
// ----- 模块注册
Mota.register('module', 'CustomComponents', {
createSettingComponents,
createToolbarComponents,
createToolbarEditorComponents
});
Mota.register('module', 'MiscComponents', {
VirtualKey
});
Mota.register('module', 'RenderUtils', utils);
Mota.register('module', 'Use', use);
Mota.register('module', 'Mark', mark);
Mota.register('module', 'KeyCodes', keyCodes);
Mota.register('module', 'UITools', {
book: bookTools,
common: commonTools,
equipbox: equipboxTools,
fixed: fixedTools,
fly: flyTools,
statusBar: statusBarTools,
toolbox: toolboxTools
});
Mota.register('module', 'UI', UI);
Mota.register('module', 'UIComponents', {
Box,
BoxAnimate,
Colomn,
EnemyOne,
Scroll,
EnemyCritical,
EnemySpecial,
EnemyTarget,
Keyboard: KeyboardPanel
});
Mota.register('module', 'MCGenerator', MCGenerator);
ready();
main.renderLoaded = true;
Mota.require('var', 'hook').emit('renderLoaded');
+1 -1
View File
@@ -137,7 +137,7 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
* 释放一个作用域,释放后作用域将退回至删除的作用域的上一级
* @param symbol 要释放的作用域的symbol
*/
dispose(symbol: symbol) {
dispose(symbol: symbol = this.scopeStack.at(-1) ?? Symbol()) {
for (const key of Object.values(this.data)) {
key.func.delete(symbol);
}
+38 -15
View File
@@ -116,6 +116,14 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
constructor(id: string) {
super();
this.id = id;
// 按比例设置初始大小
const setting = Mota.require('var', 'mainSetting');
const scale = setting.getValue('ui.toolbarScale', 100) / 100;
this.width *= scale;
this.height *= scale;
this.x *= scale;
this.y *= scale;
this.show();
CustomToolbar.list.push(this);
}
@@ -188,22 +196,31 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
/**
* 强制刷新这个自定义工具栏的所有显示
*/
refresh() {
const items = this.items.splice(0);
nextTick(() => {
this.items.push(...items);
});
refresh(reopen: boolean = false) {
if (reopen && this.showIds.length > 0) {
this.closeAll();
nextTick(() => {
this.show();
});
} else {
const items = this.items.splice(0);
nextTick(() => {
this.items.push(...items);
});
}
return this;
}
setPos(x?: number, y?: number) {
has(x) && (this.x = x);
has(y) && (this.y = y);
this.emit('posChange', this);
}
setSize(width?: number, height?: number) {
has(width) && (this.width = width);
has(height) && (this.height = height);
this.emit('posChange', this);
}
/**
@@ -269,12 +286,14 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
static save() {
toolbarStorage.clear();
const setting = Mota.require('var', 'mainSetting');
const scale = setting.getValue('ui.toolbarScale', 100) / 100;
this.list.forEach(v => {
const toSave: ToolbarSaveData = {
x: v.x,
y: v.y,
w: v.width,
h: v.height,
w: v.width / scale,
h: v.height / scale,
items: []
};
v.items.forEach(v => {
@@ -288,7 +307,7 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
static load() {
toolbarStorage.read();
for (const [key, value] of Object.entries(toolbarStorage.data)) {
const bar = new CustomToolbar(key);
const bar = this.get(key) ?? new CustomToolbar(key);
bar.x = value.x;
bar.y = value.y;
bar.width = value.w;
@@ -299,6 +318,10 @@ export class CustomToolbar extends EventEmitter<CustomToolbarEvent> {
}
}
static refreshAll(reopen: boolean = false): void {
CustomToolbar.list.forEach(v => v.refresh(reopen));
}
static showAll(): number[] {
return CustomToolbar.list.map(v => v.show());
}
@@ -376,16 +399,16 @@ CustomToolbar.register(
}
);
window.addEventListener('beforeunload', () => {
CustomToolbar.save();
});
window.addEventListener('blur', () => {
CustomToolbar.save();
});
Mota.require('var', 'loading').once('coreInit', () => {
CustomToolbar.load();
CustomToolbar.closeAll();
window.addEventListener('beforeunload', e => {
CustomToolbar.save();
});
window.addEventListener('blur', () => {
CustomToolbar.save();
});
});
Mota.require('var', 'hook').on('reset', () => {
CustomToolbar.showAll();
+4 -6
View File
@@ -9,8 +9,6 @@ interface FocusEvent<T> extends EmitableEvent {
unfocus: (before: T | null) => void;
add: (item: T) => void;
pop: (item: T | null) => void;
register: (item: T[]) => void;
unregister: (item: T[]) => void;
splice: (spliced: T[]) => void;
}
@@ -163,7 +161,7 @@ interface IndexedGameUi extends ShowableGameUi {
}
interface HoldOnController {
end(): void;
end(noClosePanel?: boolean): void;
}
export class UiController extends Focus<IndexedGameUi> {
@@ -182,7 +180,7 @@ export class UiController extends Focus<IndexedGameUi> {
v.ui.emit('close');
});
if (this.stack.length === 0) {
if (!this.hold) this.emit('end');
if (!this.hold) this.emit('end', false);
this.hold = false;
}
});
@@ -227,8 +225,8 @@ export class UiController extends Focus<IndexedGameUi> {
this.hold = true;
return {
end: () => {
this.emit('end');
end: (noClosePanel: boolean = false) => {
this.emit('end', noClosePanel);
}
};
}
+20 -3
View File
@@ -9,7 +9,8 @@ interface Components {
Number: SettingComponent;
HotkeySetting: SettingComponent;
ToolbarEditor: SettingComponent;
RadioSetting: (items: string[]) => SettingComponent;
Radio: (items: string[]) => SettingComponent;
Performance: SettingComponent;
}
export type { Components as SettingDisplayComponents };
@@ -21,7 +22,8 @@ export function createSettingComponents() {
Number: NumberSetting,
HotkeySetting,
ToolbarEditor,
RadioSetting
Radio: RadioSetting,
Performance: PerformanceSetting
};
return com;
}
@@ -63,7 +65,7 @@ function NumberSetting(props: SettingComponentProps) {
if (value < (item.step?.[0] ?? 0) || value > (item.step?.[1] ?? 100)) {
return;
}
setting.setValue(displayer.selectStack.join('.'), value);
setting.setValue(displayer.selectStack.join('.'), Math.round(value));
displayer.update();
};
@@ -180,3 +182,18 @@ function ToolbarEditor(props: SettingComponentProps) {
</div>
);
}
function PerformanceSetting(props: SettingComponentProps) {
return (
<div style="display: flex; justify-content: center">
<Button
style="font-size: 75%"
type="primary"
size="large"
onClick={() => showSpecialSetting('performance')}
>
打开性能界面
</Button>
</div>
);
}
+7 -3
View File
@@ -8,6 +8,7 @@ import { checkAssist } from '../custom/hotkey';
import { getVitualKeyOnce } from '@/plugin/utils';
import { cloneDeep } from 'lodash-es';
import { Select, SelectOption } from 'ant-design-vue';
import { mainSetting } from '../setting';
// todo: 新增更改设置的ToolItem
@@ -53,15 +54,18 @@ function KeyTool(props: CustomToolbarProps<'hotkey'>) {
function ItemTool(props: CustomToolbarProps<'item'>) {
const { item, toolbar } = props;
const scale = mainSetting.getValue('ui.toolbarScale', 100) / 100;
return (
<div
style="display: flex; justify-content: center; width: 50px"
style={`display: flex; justify-content: center; width: ${
50 * scale
}px`}
onClick={() => toolbar.emitTool(item.id)}
>
<BoxAnimate
noborder={true}
width={50}
height={50}
width={50 * scale}
height={50 * scale}
id={item.item}
></BoxAnimate>
</div>
+30 -6
View File
@@ -1,6 +1,7 @@
import * as UI from '@ui/.';
import * as MiscUI from './misc';
import { GameUi, UiController } from '../custom/ui';
import { mainSetting } from '../setting';
export const mainUi = new UiController();
mainUi.register(
@@ -35,20 +36,34 @@ fixedUi.register(
);
fixedUi.showAll();
let loaded = false;
let mounted = false;
const hook = Mota.require('var', 'hook');
hook.once('mounted', () => {
const ui = document.getElementById('ui-main')!;
const fixed = document.getElementById('ui-fixed')!;
const blur = mainSetting.getSetting('screen.blur');
mainUi.on('start', () => {
ui.style.display = 'flex';
if (blur?.value) {
ui.style.backdropFilter = 'blur(5px)';
ui.style.backgroundColor = 'rgba(0,0,0,0.7333)';
} else {
ui.style.backdropFilter = 'none';
ui.style.backgroundColor = 'rgba(0,0,0,0.85)';
}
core.lockControl();
});
mainUi.on('end', () => {
mainUi.on('end', noClosePanel => {
ui.style.display = 'none';
try {
core.closePanel();
} catch {}
if (!noClosePanel) {
try {
core.closePanel();
} catch {}
}
});
fixedUi.on('start', () => {
fixed.style.display = 'block';
@@ -57,6 +72,15 @@ hook.once('mounted', () => {
fixed.style.display = 'none';
});
// todo: 暂时先这么搞,之后重写加载界面,需要改成先显示加载界面,加载完毕后再打开这个界面
fixedUi.open('start');
if (loaded && !mounted) {
fixedUi.open('start');
}
mounted = true;
});
hook.once('load', () => {
if (mounted) {
// todo: 暂时先这么搞,之后重写加载界面,需要改成先显示加载界面,加载完毕后再打开这个界面
fixedUi.open('start');
}
loaded = true;
});
+135 -61
View File
@@ -5,10 +5,12 @@ import {
VNode,
VNodeChild,
defineComponent,
h,
h as hVue,
isVNode,
onMounted
} from 'vue';
import BoxAnimate from '@/components/boxAnimate.vue';
import { ensureArray } from '@/plugin/utils';
interface VForRenderer {
type: '@v-for';
@@ -18,7 +20,7 @@ interface VForRenderer {
interface MotaComponent extends MotaComponentConfig {
type: string;
children: MComponent[] | MComponent;
children: (MComponent | MotaComponent | VNode)[];
}
interface MotaComponentConfig {
@@ -32,7 +34,7 @@ interface MotaComponentConfig {
velse?: boolean;
}
type OnSetupFunction = (props: Record<string, any>) => void;
type OnSetupFunction = (props: Record<string, any>, ctx: SetupContext) => void;
type SetupFunction = (
props: Record<string, any>,
ctx: SetupContext
@@ -43,6 +45,7 @@ type RetFunction = (
) => VNodeChild | VNodeChild[];
type OnMountedFunction = (
props: Record<string, any>,
ctx: SetupContext,
canvas: HTMLCanvasElement[]
) => void;
@@ -51,6 +54,12 @@ type NonComponentConfig = Omit<
'innerText' | 'component' | 'slots' | 'dComponent'
>;
type MComponentChildren =
| (MComponent | MotaComponent | VNode)[]
| MComponent
| MotaComponent
| VNode;
export class MComponent {
static mountNum: number = 0;
@@ -88,7 +97,7 @@ export class MComponent {
* @param children 渲染内容的子内容
* @param config 渲染内容的配置信息,参考 {@link MComponent.h}
*/
div(children?: MComponent[] | MComponent, config?: NonComponentConfig) {
div(children?: MComponentChildren, config?: NonComponentConfig) {
return this.h('div', children, config);
}
@@ -97,7 +106,7 @@ export class MComponent {
* @param children 渲染内容的子内容
* @param config 渲染内容的配置信息,参考 {@link MComponent.h}
*/
span(children?: MComponent[] | MComponent, config?: NonComponentConfig) {
span(children?: MComponentChildren, config?: NonComponentConfig) {
return this.h('span', children, config);
}
@@ -124,7 +133,7 @@ export class MComponent {
*/
com(
component: Component | MComponent,
config: Omit<MotaComponentConfig, 'innerText' | 'component'>
config?: Omit<MotaComponentConfig, 'innerText' | 'component'>
) {
return this.h(component, [], config);
}
@@ -136,11 +145,7 @@ export class MComponent {
* 或者MComponent.vNode函数生成。
*/
vfor<T>(items: T[] | (() => T[]), map: (value: T, index: number) => VNode) {
this.content.push({
type: '@v-for',
items,
map
});
this.content.push(MCGenerator.vfor(items, map));
return this;
}
@@ -180,32 +185,10 @@ export class MComponent {
*/
h(
type: string | Component | MComponent,
children?: MComponent[] | MComponent,
children?: MComponentChildren,
config: MotaComponentConfig = {}
): this {
if (typeof type === 'string') {
this.content.push({
type,
children: children ?? [],
props: config.props,
innerText: config.innerText,
slots: config.slots,
vif: config.vif,
velse: config.velse,
component: config.component
});
} else {
this.content.push({
type: 'component',
children: children ?? [],
props: config.props,
innerText: config.innerText,
slots: config.slots,
vif: config.vif,
velse: config.velse,
component: type
});
}
this.content.push(MCGenerator.h(type, children, config));
return this;
}
@@ -253,11 +236,12 @@ export class MComponent {
return defineComponent(
(props, ctx) => {
const mountNum = MComponent.mountNum++;
this.onSetupFn?.(props);
this.onSetupFn?.(props, ctx);
onMounted(() => {
this.onMountedFn?.(
props,
ctx,
Array.from(
document.getElementsByClassName(
`--mota-component-canvas-${mountNum}`
@@ -269,8 +253,6 @@ export class MComponent {
if (this.retFn) return () => this.retFn!(props, ctx);
else {
return () => {
console.log(ctx.slots.default);
const vNodes = MComponent.vNode(
this.content,
mountNum
@@ -312,12 +294,19 @@ export class MComponent {
* @param children 要生成VNode的内容列表
* @param mount 组件生成时的挂载id,一般不需要填,用于画布获取
*/
static vNode(children: (MotaComponent | VForRenderer)[], mount?: number) {
static vNode(
children: (MotaComponent | VForRenderer | VNode)[],
mount?: number
) {
const mountNum = mount ?? this.mountNum++;
const res: VNode[] = [];
const vifRes: Map<number, boolean> = new Map();
children.forEach((v, i) => {
if (isVNode(v)) {
res.push(v);
return;
}
if (v.type === '@v-for') {
const node = v as VForRenderer;
const items =
@@ -346,7 +335,7 @@ export class MComponent {
);
}
if (v.dComponent) {
res.push(h(v.dComponent(), props, v.slots));
res.push(hVue(v.dComponent(), props, v.slots));
} else {
if (v.component instanceof MComponent) {
res.push(
@@ -356,12 +345,12 @@ export class MComponent {
)
);
} else {
res.push(h(v.component!, props, v.slots));
res.push(hVue(v.component!, props, v.slots));
}
}
} else if (v.type === 'text') {
res.push(
h(
hVue(
'span',
typeof v.innerText === 'function'
? v.innerText()
@@ -372,15 +361,17 @@ export class MComponent {
const cls = `--mota-component-canvas-${mountNum}`;
const mix = !!props.class ? cls + ' ' + props.class : cls;
props.class = mix;
res.push(h('canvas', props, node.slots));
res.push(hVue('canvas', props, node.slots));
} else {
// 这个时候不可能会有插槽,只会有子内容,因此直接渲染子内容
const content = [node.children].flat(2);
const content = node.children;
const vn = this.vNode(
content.map(v => v.content).flat(),
content
.map(v => (v instanceof MComponent ? v.content : v))
.flat(),
mountNum
);
res.push(h(v.type, props, vn));
res.push(hVue(v.type, props, vn));
}
}
});
@@ -406,7 +397,7 @@ export class MComponent {
* @param props 要传递的props
*/
static prop(component: Component, props: Record<string, any>) {
return h(component, props);
return hVue(component, props);
}
}
@@ -418,18 +409,101 @@ export function m() {
return new MComponent();
}
/**
* 生成一个图标的VNode
* @param id 图标的id
* @param width 显示宽度,单位像素
* @param height 显示高度,单位像素
* @param noBoarder 显示的时候是否没有边框和背景
*/
export function icon(
id: AllIds,
width?: number,
height?: number,
noBoarder?: number
) {
return h(BoxAnimate, { id, width, height, noBoarder });
export namespace MCGenerator {
export function h(
type: string | Component | MComponent,
children?: MComponentChildren,
config: MotaComponentConfig = {}
): MotaComponent {
if (typeof type === 'string') {
return {
type,
children: ensureArray(children ?? []),
props: config.props,
innerText: config.innerText,
slots: config.slots,
vif: config.vif,
velse: config.velse,
component: config.component
};
} else {
return {
type: 'component',
children: ensureArray(children ?? []),
props: config.props,
innerText: config.innerText,
slots: config.slots,
vif: config.vif,
velse: config.velse,
component: type
};
}
}
export function div(
children?: MComponentChildren,
config?: NonComponentConfig
): MotaComponent {
return h('div', children, config);
}
export function span(
children?: MComponentChildren,
config?: NonComponentConfig
): MotaComponent {
return h('span', children, config);
}
export function canvas(config?: NonComponentConfig): MotaComponent {
return h('canvas', [], config);
}
export function text(
text: string | (() => string),
config: NonComponentConfig = {}
): MotaComponent {
return h('text', [], { ...config, innerText: text });
}
export function com(
component: Component | MComponent,
config: Omit<MotaComponentConfig, 'innerText' | 'component'>
): MotaComponent {
return h(component, [], config);
}
/**
* 生成一个图标的VNode
* @param id 图标的id
* @param width 显示宽度,单位像素
* @param height 显示高度,单位像素
* @param noBoarder 显示的时候是否没有边框和背景
*/
export function icon(
id: AllIds,
width?: number,
height?: number,
noBoarder?: number
): VNode {
return hVue(BoxAnimate, { id, width, height, noBoarder });
}
export function vfor<T>(
items: T[] | (() => T[]),
map: (value: T, index: number) => VNode
): VForRenderer {
return {
type: '@v-for',
items,
map
};
}
/**
* 为一个常量创建为一个函数
* @param value 要创建成函数的值
*/
export function f<T>(value: T): () => T {
return () => value;
}
}
+55 -10
View File
@@ -7,6 +7,8 @@ import { bgm } from '../audio/bgm';
import { SoundEffect } from '../audio/sound';
import settingsText from '@/data/settings.json';
import { isMobile } from '@/plugin/use';
import { fontSize } from '@/plugin/ui/statusBar';
import { CustomToolbar } from './custom/toolbar';
export interface SettingComponentProps {
item: MotaSettingItem;
@@ -334,6 +336,8 @@ mainSetting.on('valueChange', (key, n, o) => {
handleActionSetting(setting, n, o);
} else if (root === 'audio') {
handleAudioSetting(setting, n, o);
} else if (root === 'ui') {
handleUiSetting(setting, n, o);
}
});
@@ -363,6 +367,11 @@ function handleScreenSetting<T extends number | boolean>(
} else if (key === 'fontSize') {
// 字体大小
root.style.fontSize = `${n}px`;
const absoluteSize = (n as number) * devicePixelRatio;
storage.setValue('@@absoluteFontSize', absoluteSize);
storage.write();
} else if (key === 'fontSizeStatus') {
fontSize.value = n as number;
}
}
@@ -394,6 +403,16 @@ function handleAudioSetting<T extends number | boolean>(
}
}
function handleUiSetting<T extends number | boolean>(key: string, n: T, o: T) {
if (key === 'toolbarScale') {
const scale = (n as number) / (o as number);
CustomToolbar.list.forEach(v => {
v.setSize(v.width * scale, v.height * scale);
});
CustomToolbar.refreshAll(true);
}
}
// ----- 游戏的所有设置项
// todo: 虚拟键盘缩放,小地图楼传缩放
mainSetting
@@ -407,11 +426,13 @@ mainSetting
.register('heroDetail', '勇士显伤', false, COM.Boolean)
.register('transition', '界面动画', false, COM.Boolean)
.register('antiAlias', '抗锯齿', false, COM.Boolean)
.register('fontSize', '字体大小', 16, COM.Number, [8, 28, 1])
.register('fontSize', '字体大小', 16, COM.Number, [2, 48, 1])
.register('fontSizeStatus', '状态栏字体', 16, COM.Number, [2, 48, 1])
.register('smoothView', '平滑镜头', true, COM.Boolean)
.register('criticalGem', '临界显示方式', false, COM.Boolean)
.setDisplayFunc('criticalGem', value => (value ? '宝石数' : '攻击'))
.register('keyScale', '虚拟键盘缩放', 100, COM.Number, [25, 5, 500])
.register('blur', '背景虚化', !isMobile, COM.Boolean)
)
.register(
'action',
@@ -450,13 +471,13 @@ mainSetting
.register(
'ui',
'ui设置',
new MotaSetting().register(
'mapScale',
'小地图楼传缩放',
100,
COM.Number,
[50, 1000, 50]
)
new MotaSetting()
.register('mapScale', '小地图缩放', 100, COM.Number, [50, 1000, 50])
.setDisplayFunc('mapScale', value => `${value}%`)
.register('toolbarScale', '工具栏缩放', 100, COM.Number, [10, 500, 10])
.setDisplayFunc('toolbarScale', value => `${value}%`)
.register('bookScale', '怪物手册缩放', 100, COM.Number, [10, 500, 10])
.setDisplayFunc('bookScale', value => `${value}%`)
);
const loading = Mota.require('var', 'loading');
@@ -471,6 +492,7 @@ loading.once('coreInit', () => {
'screen.fontSize': storage.getValue('screen.fontSize', 16),
'screen.smoothView': !!storage.getValue('screen.smoothView', true),
'screen.criticalGem': !!storage.getValue('screen.criticalGem', false),
'screen.fontSizeStatus': storage.getValue('screen.fontSizeStatus', 100),
'action.fixed': !!storage.getValue('action.fixed', true),
'audio.bgmEnabled': !!storage.getValue('audio.bgmEnabled', true),
'audio.bgmVolume': storage.getValue('audio.bgmVolume', 80),
@@ -483,7 +505,12 @@ loading.once('coreInit', () => {
'ui.mapScale': storage.getValue(
'ui.mapScale',
isMobile ? 300 : Math.floor(window.innerWidth / 600) * 50
)
),
'ui.toolbarScale': storage.getValue(
'ui.toolbarScale',
isMobile ? 50 : Math.floor((window.innerWidth / 1700) * 10) * 10
),
'ui.bookScale': storage.getValue('ui.bookScale', isMobile ? 100 : 80),
});
});
@@ -515,4 +542,22 @@ mainSetting
.setDescription('audio.bgmVolume', `背景音乐的音量`)
.setDescription('audio.soundEnabled', `是否开启音效`)
.setDescription('audio.soundVolume', `音效的音量`)
.setDescription('ui.mapScale', `楼传小地图的缩放,百分比格式`);
.setDescription('ui.mapScale', `楼传小地图的缩放,百分比格式`)
.setDescription('ui.toolbarScale', `自定义工具栏的缩放比例`)
.setDescription('ui.bookScale', `怪物手册界面中每个怪物框体的高度缩放,最小值限定为 20% 屏幕高度`)
.setDescription('screen.fontSizeStatus', `修改状态栏的字体大小`)
.setDescription('screen.blur', '打开任意ui界面时是否有背景虚化效果,移动端打开后可能会有掉帧或者发热现象。关闭ui后生效');
function setFontSize() {
const absoluteSize = storage.getValue(
'@@absoluteFontSize',
16 * devicePixelRatio
);
const size = Math.round(absoluteSize / devicePixelRatio);
mainSetting.setValue('screen.fontSize', size);
}
setFontSize();
window.addEventListener('resize', () => {
setFontSize();
});