feat: 自定义设置值修改组件

This commit is contained in:
unanmed 2023-11-12 18:48:42 +08:00
parent 4796334ec4
commit 8fc7e03c97
3 changed files with 12 additions and 47 deletions

View File

@ -1,4 +1,4 @@
import { reactive } from 'vue'; import { Component, reactive } from 'vue';
import { EmitableEvent, EventEmitter } from '../common/eventEmitter'; import { EmitableEvent, EventEmitter } from '../common/eventEmitter';
import { loading } from '../loader/load'; import { loading } from '../loader/load';
import { hook } from './game'; import { hook } from './game';
@ -14,6 +14,7 @@ export interface MotaSettingItem<T extends MotaSettingType = MotaSettingType> {
defaults?: boolean | number; defaults?: boolean | number;
step?: [number, number, number]; step?: [number, number, number];
display?: (value: T) => string; display?: (value: T) => string;
controller?: Component;
special?: string; special?: string;
} }
@ -147,6 +148,12 @@ export class MotaSetting extends EventEmitter<SettingEvent> {
return this; return this;
} }
setValueController(key: string, com: Component) {
const setting = this.getSettingBy(key.split('.'));
setting.controller = com;
return this;
}
private getSettingBy(list: string[]) { private getSettingBy(list: string[]) {
let now: MotaSetting = this; let now: MotaSetting = this;

View File

@ -56,50 +56,6 @@ export {};
console.log(`Floor hot reload: ${data}`); console.log(`Floor hot reload: ${data}`);
} }
/**
* 热重载脚本编辑
*/
async function reloadScript() {
// 脚本编辑略微麻烦点
const before = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a;
// 这里不能用动态导入,因为动态导入会变成模块,变量就不是全局的了
const script = document.createElement('script');
script.src = `/forceTem/project/functions.js?v=${Date.now()}`;
document.body.appendChild(script);
await new Promise(res => {
script.onload = () => res('success');
});
const after = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a;
// 找到差异的函数
for (const mod in before) {
const fns = before[mod];
for (const id in fns) {
const fn = fns[id];
if (typeof fn !== 'function') continue;
const now = after[mod][id];
if (fn.toString() !== now.toString()) {
try {
if (mod === 'events') {
core.events.eventdata[id] = now;
} else if (mod === 'enemys') {
core.enemys.enemydata[id] = now;
} else if (mod === 'actions') {
core.actions.actionsdata[id] = now;
} else if (mod === 'control') {
core.control.controldata[id] = now;
} else if (mod === 'ui') {
core.ui.uidata[id] = now;
}
core.updateStatusBar(true, true);
console.log(`Function hot reload: ${mod}.${id}`);
} catch (e) {
console.error(e);
}
}
}
}
}
/** /**
* 属性热重载包括全塔属性等 * 属性热重载包括全塔属性等
* @param {string} data * @param {string} data
@ -168,7 +124,6 @@ export {};
if (data.type === 'reload') location.reload(); if (data.type === 'reload') location.reload();
if (data.type === 'floorHotReload') reloadFloor(data.floor); if (data.type === 'floorHotReload') reloadFloor(data.floor);
if (data.type === 'dataHotReload') reloadData(data.data); if (data.type === 'dataHotReload') reloadData(data.data);
if (data.type === 'functionsHotReload') reloadScript();
if (data.type === 'cssHotReload') reloadCss(data.path); if (data.type === 'cssHotReload') reloadCss(data.path);
}); });
})(); })();

View File

@ -52,7 +52,10 @@
></div> ></div>
<a-divider class="info-divider" dashed></a-divider> <a-divider class="info-divider" dashed></a-divider>
<div class="info-editor" v-if="!!selectedItem"> <div class="info-editor" v-if="!!selectedItem">
<div v-if="!!selectedItem.special"></div> <div class="editor-custom" v-if="!!selectedItem.controller">
<component :is="selectedItem.controller"></component>
</div>
<div v-else-if="!!selectedItem.special"></div>
<div <div
class="editor-number" class="editor-number"
v-else-if="typeof selectedItem.value === 'number'" v-else-if="typeof selectedItem.value === 'number'"