Skip to content

Commit

Permalink
fix(ConfigPanel): hide removed module
Browse files Browse the repository at this point in the history
  • Loading branch information
tutinoko2048 committed Aug 14, 2024
1 parent deba071 commit 45829d6
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions scripts/form/ConfigPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { DataManager } from '../util/DataManager';
import { DROPDOWNS, confirmForm } from './static_form';
import { canAdd } from '../util/config_setting';

const MODULE_EXCLUDE_LIST = ['flyA']

export class ConfigPanel {
/**
* @param {import('../ac').TNAntiCheat} ac
Expand All @@ -20,6 +22,10 @@ export class ConfigPanel {
if (Util.isOP(player)) this.selectModule(busy).catch(e => console.error(e, e.stack));
}

/**
* @param {boolean} [busy]
* @param {string} [message]
*/
async selectModule(busy, message) {
let body = '編集したいConfigを選択してください';
if (message) body = `§o${message}§r\n\n${body}`;
Expand All @@ -28,18 +34,19 @@ export class ConfigPanel {
.body(body);
const modules = Object.keys(config);
for (const moduleName of modules) {
if (MODULE_EXCLUDE_LIST.includes(moduleName)) continue;
const moduleData = config[moduleName];
const color = moduleData.state ? '§2' : (moduleData.state === false) ? '§4' : '';
const desc = description[moduleName]?.desc ? `\n§o§9${description[moduleName].desc}§r` : '';
form.button(`${color}§l${moduleName}§r${desc}`, null, 'moduleName');
form.button(`${color}§l${moduleName}§r${desc}`, null, moduleName);
}
form.button('§l§c初期設定に戻す', Icons.reset, 'reset');
const { selection, canceled, button } = busy
form.button('§l§c初期設定に戻す', Icons.reset, '.reset');
const { canceled, button } = busy
? await Util.showFormToBusy(this.player, form) // from chat
: await form.show(this.player);
if (canceled) return;

if (button.id === 'reset') {
if (button.id === '.reset') {
const res = await confirmForm(this.player, {
body: `全てのConfigを初期設定に戻しますか?`,
yes: '§cリセットする',
Expand All @@ -51,7 +58,7 @@ export class ConfigPanel {
Util.writeLog({ type: 'config.resetAll', message: `全ての設定をリセットしました` }, this.player);
return await this.selectModule(false, `§a全ての設定をリセットしました`);
}
const moduleName = modules[selection];
const moduleName = /** @type {string} */ (button.id);
const diff = {};
const moduleData = Util.cloneObject(config[moduleName]);
if (!moduleData) return Util.notify(`§cError: unexpected index`, this.player);
Expand All @@ -66,6 +73,7 @@ export class ConfigPanel {
if (res.reopen) await this.selectModule(false, res.message);
}

/** @returns {Promise<{ reopen?: boolean, edited?: boolean, message?: string }>} */
async selectValue(value, key, ref, { deletable = false, title, isModule = false }) {
switch (typeof value) {
case 'object': {
Expand Down

0 comments on commit 45829d6

Please sign in to comment.