2021-08-13 21:03:21 +08:00
|
|
|
import { ConfigEntry, ConfigEntryType } from "../types"
|
|
|
|
import { trimEnd } from "../utils";
|
|
|
|
|
|
|
|
export default function (data: ConfigEntry[]): string {
|
|
|
|
let result = `using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
2021-12-19 21:10:34 +08:00
|
|
|
using BililiveRecorder.Core.Config;
|
2021-12-19 20:58:32 +08:00
|
|
|
using BililiveRecorder.Core.Config.V3;
|
2021-08-13 21:03:21 +08:00
|
|
|
|
|
|
|
namespace BililiveRecorder.Cli.Configure
|
|
|
|
{`;
|
|
|
|
|
|
|
|
result += `
|
|
|
|
public enum GlobalConfigProperties
|
|
|
|
{
|
|
|
|
[Description("[grey]Exit[/]")]
|
|
|
|
Exit,
|
2022-06-10 16:34:25 +08:00
|
|
|
${data.filter(x => x.configType != 'roomOnly').map(x => x.id).join(",\n")}
|
2021-08-13 21:03:21 +08:00
|
|
|
}`;
|
|
|
|
|
|
|
|
result += `
|
|
|
|
public enum RoomConfigProperties
|
|
|
|
{
|
|
|
|
[Description("[grey]Exit[/]")]
|
|
|
|
Exit,
|
2022-06-10 16:34:25 +08:00
|
|
|
${data.filter(x => x.configType != 'globalOnly').map(x => x.id).join(",\n")}
|
2021-08-13 21:03:21 +08:00
|
|
|
}`;
|
|
|
|
|
|
|
|
|
|
|
|
result += `
|
|
|
|
public static class ConfigInstructions
|
|
|
|
{
|
|
|
|
public static Dictionary<GlobalConfigProperties, ConfigInstructionBase<GlobalConfig>> GlobalConfig = new();
|
|
|
|
public static Dictionary<RoomConfigProperties, ConfigInstructionBase<RoomConfig>> RoomConfig = new();
|
|
|
|
|
|
|
|
static ConfigInstructions()
|
|
|
|
{
|
|
|
|
${data
|
|
|
|
.filter(x => x.configType != 'roomOnly')
|
2022-06-10 16:34:25 +08:00
|
|
|
.map(r => `GlobalConfig.Add(GlobalConfigProperties.${r.id}, new ConfigInstruction<GlobalConfig, ${trimEnd(r.type, '?')}>(config => config.Has${r.id} = false, (config, value) => config.${r.id} = value) { Name = "${r.id}", CanBeOptional = true });`)
|
2021-08-13 21:03:21 +08:00
|
|
|
.join("\n")
|
|
|
|
}
|
|
|
|
|
2022-06-10 16:34:25 +08:00
|
|
|
${data.filter(x => x.configType != 'globalOnly').map(r => `RoomConfig.Add(RoomConfigProperties.${r.id}, new ConfigInstruction<RoomConfig, ${trimEnd(r.type, '?')}>(config => config.Has${r.id} = false, (config, value) => config.${r.id} = value) { Name = "${r.id}", CanBeOptional = ${r.configType != 'roomOnly'} });`).join("\n")}
|
2021-08-13 21:03:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
result += `\n}\n`;
|
|
|
|
return result;
|
|
|
|
}
|