Expand SCUM configuration catalog
This commit is contained in:
@@ -115,7 +115,7 @@ export function ServerConfigEditor({ instance, operations, requester, onClose }:
|
||||
{message && <ResultBadge status={error ? "failed" : "pending"} label={message} />}
|
||||
{error && workspace && <ErrorState title="配置操作失败" reason={error} diagnosticId={`server-config:${instance.id}:${selectedFile?.key ?? "unknown"}`} compact />}
|
||||
{loading && <LoadingState label="正在读取配置文件…" compact />}
|
||||
{!loading && mode === "friendly" && <div className="file-workbench-fields">{fields.length === 0 && <span className="provider-id">该配置文件没有声明可视化字段,请切换到源码模式。</span>}{fields.map((field) => <ConfigField key={field.key} field={field} value={values[field.key] ?? ""} onChange={(value) => setValues((current) => ({ ...current, [field.key]: value }))} />)}</div>}
|
||||
{!loading && mode === "friendly" && <div className="file-workbench-fields">{fields.length === 0 && <span className="provider-id">该配置文件没有声明可视化字段,请切换到源码模式。</span>}{configFieldGroups(fields).map((group) => <div key={group.label} className="file-workbench-group"><h4>{group.label}</h4>{group.fields.map((field) => <ConfigField key={field.key} field={field} value={values[field.key] ?? ""} onChange={(value) => setValues((current) => ({ ...current, [field.key]: value }))} />)}</div>)}</div>}
|
||||
{!loading && mode === "source" && <div className="file-workbench-raw"><textarea className="file-workbench-raw-editor" value={raw} spellCheck={false} onChange={(event) => setRaw(event.target.value)} aria-label={`${selectedFile?.label ?? "配置文件"}源码`} /><small>保存会把完整原文交给 Run 写回服务器工作区。</small></div>}
|
||||
<div className="action-strip file-workbench-actions"><button type="button" className="primary-command" disabled={loading || saving || !snapshot} onClick={() => void save()}><Save size={14} /><span>{saving ? "保存中…" : "保存配置"}</span></button><button type="button" className="icon-command" onClick={onClose}>取消</button></div>
|
||||
</div>
|
||||
@@ -131,5 +131,14 @@ function ConfigField({ field, value, onChange }: { field: PluginConfigFieldRespo
|
||||
return <label className="file-workbench-field"><span><strong>{field.label}</strong><small>{field.description}{field.restartImpact === "restart-required" ? " · 修改后需要重启" : ""}</small></span>{field.control === "boolean" ? <select value={value || field.defaultValue || "false"} onChange={(event) => onChange(event.target.value)}><option value="true">是</option><option value="false">否</option></select> : <input type={inputType} min={field.minimum} max={field.maximum} value={value} placeholder={field.defaultValue ?? ""} onChange={(event) => onChange(event.target.value)} />}</label>;
|
||||
}
|
||||
|
||||
function configFieldGroups(fields: PluginConfigFieldResponse[]): Array<{ label: string; fields: PluginConfigFieldResponse[] }> {
|
||||
const groups = new Map<string, PluginConfigFieldResponse[]>();
|
||||
for (const field of fields) {
|
||||
const label = field.configKey.startsWith("scum.Server") || field.configKey.startsWith("scum.Welcome") || field.configKey.startsWith("scum.Message") ? "服务器基础" : field.configKey.includes("Zombie") || field.configKey.includes("Character") || field.configKey.includes("Animal") ? "世界与生物" : field.configKey.includes("Vehicle") || field.configKey.includes("Fuel") ? "载具" : field.configKey.includes("Raid") || field.configKey.includes("Quest") || field.configKey.includes("NewPlayer") ? "玩法规则" : "其他设置";
|
||||
groups.set(label, [...(groups.get(label) ?? []), field]);
|
||||
}
|
||||
return [...groups.entries()].map(([label, groupFields]) => ({ label, fields: groupFields }));
|
||||
}
|
||||
|
||||
function configOperationKey(operation: string, serverId: string, fileKey: string): string { return `web:server-config:${operation}:${serverId}:${fileKey}`; }
|
||||
function formatReadTime(value: string): string { const date = new Date(value); return Number.isNaN(date.getTime()) ? value : date.toLocaleString("zh-CN"); }
|
||||
|
||||
Reference in New Issue
Block a user