refactor(scum): remove legacy projection workflows
This commit is contained in:
@@ -1,130 +1,17 @@
|
||||
type StateSetter<T> = (next: T | ((previous: T) => T)) => void;
|
||||
type ReactLike = { createElement: (...args: any[]) => any };
|
||||
|
||||
export type ReactLike = {
|
||||
createElement: (...args: any[]) => any;
|
||||
useEffect?: (effect: () => void | (() => void), deps: readonly unknown[]) => void;
|
||||
useState?: <T>(initialState: T | (() => T)) => [T, StateSetter<T>];
|
||||
};
|
||||
|
||||
export type SCUMPageContext = {
|
||||
pageKey?: string;
|
||||
pageTitle?: string;
|
||||
serverInstanceId?: string;
|
||||
permissions: string[];
|
||||
availability: { available: boolean; reason?: string };
|
||||
featureAvailability?: Array<{ key: string; available: boolean; reason?: string }>;
|
||||
workspaceActions?: SCUMWorkspaceActions;
|
||||
};
|
||||
|
||||
type SCUMWorkspaceActions = {
|
||||
listSCUMPlayers?: () => Promise<unknown>;
|
||||
listSCUMSquads?: () => Promise<unknown>;
|
||||
listSCUMSquadMembers?: () => Promise<unknown>;
|
||||
listSCUMVehicles?: () => Promise<unknown>;
|
||||
listSCUMFlags?: () => Promise<unknown>;
|
||||
listSCUMPositions?: () => Promise<unknown>;
|
||||
};
|
||||
|
||||
type RecordMap = Record<string, unknown>;
|
||||
type DataState = { status: "loading" } | { status: "error"; reason: string } | { status: "ready"; data: SCUMSurfaceData };
|
||||
type SCUMSurfaceData = { players: RecordMap[]; squads: RecordMap[]; members: RecordMap[]; vehicles: RecordMap[]; flags: RecordMap[]; positions: RecordMap[] };
|
||||
|
||||
const emptyData: SCUMSurfaceData = { players: [], squads: [], members: [], vehicles: [], flags: [], positions: [] };
|
||||
export type SCUMPageContext = { pageKey?: string; pageTitle?: string; serverInstanceId?: string; permissions: string[]; availability: { available: boolean; reason?: string }; featureAvailability?: Array<{ key: string; available: boolean; reason?: string }> };
|
||||
|
||||
export function renderSCUMFeaturePage(react: ReactLike, input: SCUMPageContext) {
|
||||
const e = react.createElement;
|
||||
const [state, setState] = usePluginState<DataState>(react, { status: "loading" });
|
||||
const pageKey = normalizePageKey(input.pageKey);
|
||||
|
||||
const refresh = () => {
|
||||
const actions = input.workspaceActions;
|
||||
if (!input.serverInstanceId || !actions) {
|
||||
setState({ status: "error", reason: "插件页面没有绑定服务器,无法读取本地 SCUM 记录。" });
|
||||
return;
|
||||
}
|
||||
setState({ status: "loading" });
|
||||
void Promise.all([
|
||||
safeList(actions.listSCUMPlayers), safeList(actions.listSCUMSquads), safeList(actions.listSCUMSquadMembers), safeList(actions.listSCUMVehicles),
|
||||
safeList(actions.listSCUMFlags), safeList(actions.listSCUMPositions)
|
||||
]).then(([players, squads, members, vehicles, flags, positions]) => setState({ status: "ready", data: { players, squads, members, vehicles, flags, positions } }))
|
||||
.catch((error) => setState({ status: "error", reason: error instanceof Error ? error.message : "SCUM 本地记录读取失败。" }));
|
||||
};
|
||||
|
||||
if (react.useEffect) react.useEffect(() => { refresh(); return undefined; }, [input.serverInstanceId, pageKey, input.workspaceActions]);
|
||||
|
||||
const data = state.status === "ready" ? state.data : emptyData;
|
||||
return e("section", { className: "console-panel", "aria-label": input.pageTitle ?? surfaceTitle(pageKey) },
|
||||
e("div", { className: "panel-header" },
|
||||
e("div", null, e("h2", null, input.pageTitle ?? surfaceTitle(pageKey)), e("p", { className: "provider-id" }, surfaceSummary(pageKey))),
|
||||
e("div", { className: "console-row-actions" },
|
||||
e("span", { className: "page-status" }, input.availability.available ? "本地数据通道可读" : input.availability.reason ?? "等待本地数据通道"),
|
||||
e("button", { type: "button", className: "icon-command", onClick: refresh }, "重试本地读取")
|
||||
)
|
||||
),
|
||||
state.status === "loading" ? e("p", { className: "page-status" }, "正在读取平台本地 SCUM 记录…") : null,
|
||||
state.status === "error" ? e("p", { className: "page-status", "data-state": "error" }, state.reason) : null,
|
||||
state.status === "ready" ? renderSurfaceBody(e, pageKey, data) : null
|
||||
);
|
||||
}
|
||||
|
||||
function renderSurfaceBody(e: ReactLike["createElement"], pageKey: string, data: SCUMSurfaceData) {
|
||||
switch (pageKey) {
|
||||
case "players": return playersSurface(e, data);
|
||||
case "squads": return squadsSurface(e, data);
|
||||
case "live-map": return mapSurface(e, data);
|
||||
case "gifts": return giftsSurface(e, data);
|
||||
default: return playersSurface(e, data);
|
||||
}
|
||||
}
|
||||
|
||||
function playersSurface(e: ReactLike["createElement"], data: SCUMSurfaceData) {
|
||||
return e("div", { className: "console-record-list" },
|
||||
statsStrip(e, [["玩家记录", data.players.length], ["当前在线", data.players.filter((p) => boolField(p, "Online", "online")).length], ["坐标记录", data.positions.length]]),
|
||||
data.players.length ? data.players.slice(0, 80).map((player) => e("article", { key: idOf(player), className: "console-record" },
|
||||
e("div", { className: "console-record-head" }, e("strong", null, textField(player, "DisplayName", "displayName") || textField(player, "GamePlayerID", "gamePlayerId") || "未知玩家"), e("span", { className: `status-pill ${boolField(player, "Online", "online") ? "status-active" : "status-disabled"}` }, boolField(player, "Online", "online") ? "在线" : "离线/未知")),
|
||||
e("div", { className: "console-record-meta" }, e("span", null, `Steam ${textField(player, "SteamID", "steamId") || "unknown"}`), e("span", null, `Profile ${textField(player, "UserProfileID", "userProfileId") || "unknown"}`), e("span", null, `队伍 ${textField(player, "SquadName", "squadName") || textField(player, "SquadID", "squadId") || "unknown"}`), e("span", null, sourceStatus(player))),
|
||||
e("span", { className: "provider-id" }, `Fame ${numField(player, "FamePoints", "famePoints")} · Cash ${numField(player, "NormalBalance", "normalBalance")} · Gold ${numField(player, "GoldBalance", "goldBalance")} · ${coords(field(player, "Position", "position") as RecordMap | undefined)}`)
|
||||
)) : e("p", { className: "page-status" }, "暂无玩家记录。登录日志或已完成的本地同步产生记录后会显示。")
|
||||
);
|
||||
}
|
||||
|
||||
function squadsSurface(e: ReactLike["createElement"], data: SCUMSurfaceData) {
|
||||
return e("div", { className: "overview-two-col" },
|
||||
tablePanel(e, "队伍", data.squads, (squad) => [textField(squad, "Name", "name") || textField(squad, "SquadID", "squadId"), `成员 ${numField(squad, "MemberCount", "memberCount")}`, `队长 ${textField(squad, "LeaderProfileID", "leaderProfileId") || "unknown"}`, sourceStatus(squad)]),
|
||||
tablePanel(e, "成员 / 旗帜", [...data.members.slice(0, 40), ...data.flags.slice(0, 40)], (item) => [textField(item, "DisplayName", "displayName") || textField(item, "FlagID", "flagId") || "unknown", textField(item, "Rank", "rank") || textField(item, "OwnershipConfidence", "ownershipConfidence") || "unknown", textField(item, "SquadID", "squadId") || textField(item, "OwnerSquadID", "ownerSquadId") || "unknown", sourceStatus(item)])
|
||||
);
|
||||
}
|
||||
|
||||
function mapSurface(e: ReactLike["createElement"], data: SCUMSurfaceData) {
|
||||
const overlays = [...data.positions.filter(hasUsableCoordinate), ...data.vehicles.map((v) => field(v, "Position", "position") as RecordMap).filter(hasUsableCoordinate), ...data.flags.map((f) => field(f, "Position", "position") as RecordMap).filter(hasUsableCoordinate)];
|
||||
return e("div", { className: "console-record-list" },
|
||||
statsStrip(e, [["玩家", data.players.length], ["载具", data.vehicles.length], ["旗帜", data.flags.length], ["坐标点", overlays.length]]),
|
||||
overlays.length ? e("div", { className: "map-local-board" }, overlays.slice(0, 120).map((point, index) => e("span", { key: `${idOf(point)}:${index}`, className: "map-local-dot", title: `${textField(point, "SubjectType", "subjectType") || "point"} ${coords(point)}`, style: dotStyle(point) }, ""))) : e("p", { className: "page-status" }, "暂无可渲染坐标。地图只显示已验证且位于边界内的坐标。"),
|
||||
tablePanel(e, "地图覆盖物", overlays, (point) => [textField(point, "SubjectType", "subjectType") || "unknown", textField(point, "SubjectID", "subjectId") || textField(point, "GamePlayerID", "gamePlayerId") || textField(point, "VehicleID", "vehicleId") || "unknown", coords(point), sourceStatus(point)])
|
||||
);
|
||||
}
|
||||
|
||||
function giftsSurface(e: ReactLike["createElement"], data: SCUMSurfaceData) {
|
||||
return e("div", { className: "console-record-list" },
|
||||
statsStrip(e, [["可选玩家", data.players.length], ["礼包包", 0], ["发放记录", 0]]),
|
||||
e("p", { className: "page-status" }, "礼包包和发放记录会从本地礼包接口读取;在接口启用前不展示固定礼包或模拟发放。")
|
||||
const title = input.pageTitle ?? surfaceTitle(pageKey);
|
||||
const reason = input.availability.reason ?? "等待当前服务器完成兼容性验证。";
|
||||
return react.createElement("section", { className: "console-panel", "aria-label": title },
|
||||
react.createElement("div", { className: "panel-header" }, react.createElement("div", null, react.createElement("h2", null, title), react.createElement("p", { className: "provider-id" }, surfaceSummary(pageKey))), react.createElement("span", { className: "page-status" }, input.availability.available ? "本地数据接口准备中" : reason)),
|
||||
react.createElement("p", { className: "page-status" }, "当前页面不会读取遗留快照或派发远程查询;兼容的本地数据接口启用后将显示已验证记录。")
|
||||
);
|
||||
}
|
||||
|
||||
function normalizePageKey(pageKey?: string): string { return pageKey === "squads" || pageKey === "live-map" || pageKey === "gifts" || pageKey === "players" ? pageKey : "players"; }
|
||||
function surfaceTitle(pageKey: string): string { return pageKey === "squads" ? "队伍管理" : pageKey === "live-map" ? "实时地图" : pageKey === "gifts" ? "礼包管理" : "用户管理"; }
|
||||
function surfaceSummary(pageKey: string): string { return pageKey === "live-map" ? "玩家、载具、旗帜坐标只来自已验证的本地当前数据。" : pageKey === "gifts" ? "礼包包、资格和发放历史只来自本地礼包记录。" : pageKey === "squads" ? "队伍、成员和旗帜关系只显示已验证的当前服务事实。" : "玩家列表由登录日志和已验证同步结果创建,不显示样例数据。"; }
|
||||
|
||||
function statsStrip(e: ReactLike["createElement"], items: Array<[string, number]>) { return e("dl", { className: "console-stat-strip" }, items.map(([label, value]) => e("div", { key: label, className: "server-card-stat" }, e("dt", null, label), e("dd", null, String(value))))); }
|
||||
function tablePanel(e: ReactLike["createElement"], title: string, rows: RecordMap[], render: (row: RecordMap) => unknown[]) { return e("article", { className: "console-module" }, e("div", { className: "panel-header" }, e("h2", null, title), e("span", { className: "page-status" }, `${rows.length} 条`)), e("div", { className: "console-row-list" }, rows.length ? rows.slice(0, 100).map((row) => e("div", { key: idOf(row), className: "console-row" }, render(row).map((part, i) => i === 0 ? e("span", { key: i }, String(part ?? "unknown")) : e("strong", { key: i }, String(part ?? "unknown"))))) : e("p", { className: "page-status" }, "暂无本地记录。"))); }
|
||||
function dotStyle(point: RecordMap): Record<string, string> { const x = Number(field(point, "X", "x")); const y = Number(field(point, "Y", "y")); return { left: `${Math.max(2, Math.min(98, 50 + x / 10000))}%`, top: `${Math.max(2, Math.min(98, 50 - y / 10000))}%` }; }
|
||||
function safeList(fn?: () => Promise<unknown>): Promise<RecordMap[]> { return fn ? fn().then((value) => Array.isArray((value as RecordMap)?.items) ? (value as { items: RecordMap[] }).items : []) : Promise.resolve([]); }
|
||||
function usePluginState<T>(react: ReactLike, initial: T): [T, StateSetter<T>] { return react.useState ? react.useState<T>(initial) : [initial, () => undefined]; }
|
||||
function field(row: RecordMap | undefined, ...keys: string[]): unknown { if (!row) return undefined; for (const key of keys) if (row[key] !== undefined) return row[key]; return undefined; }
|
||||
function textField(row: RecordMap | unknown, ...keys: string[]): string { const value = field(row as RecordMap, ...keys); return value === undefined || value === null ? "" : String(value); }
|
||||
function boolField(row: RecordMap, ...keys: string[]): boolean { const value = field(row, ...keys); return value === true || value === "true"; }
|
||||
function numField(row: RecordMap, ...keys: string[]): string { const value = field(row, ...keys); return value === undefined || value === null || value === "" ? "--" : String(value); }
|
||||
function idOf(row: RecordMap): string { return textField(row, "ID", "id", "GamePlayerID", "gamePlayerId", "SquadID", "squadId", "VehicleID", "vehicleId", "FlagID", "flagId", "StepKey", "stepKey") || Math.random().toString(36).slice(2); }
|
||||
function sourceStatus(row: RecordMap): string { const fresh = field(row, "Freshness", "freshness") as RecordMap | undefined; return textField(fresh, "Status", "status") || textField(row, "CollectedAt", "collectedAt") || "unknown"; }
|
||||
function coords(row?: RecordMap): string { if (!row) return "坐标 unknown"; const ok = field(row, "HasCoordinates", "hasCoordinates"); return ok === false ? "坐标 unknown" : `X ${numField(row, "X", "x")} / Y ${numField(row, "Y", "y")} / Z ${numField(row, "Z", "z")}`; }
|
||||
function hasUsableCoordinate(row: RecordMap | undefined): row is RecordMap { if (!row) return false; if (field(row, "HasCoordinates", "hasCoordinates") === false) return false; const x = Number(field(row, "X", "x")); const y = Number(field(row, "Y", "y")); return Number.isFinite(x) && Number.isFinite(y); }
|
||||
function surfaceSummary(pageKey: string): string { return pageKey === "live-map" ? "地图仅显示经当前服务器验证的坐标。" : pageKey === "gifts" ? "礼包、资格和发放历史仅来自本地业务记录。" : pageKey === "squads" ? "队伍、成员和旗帜仅显示经当前服务器验证的事实。" : "玩家记录将由已验证登录事件和同步结果建立。"; }
|
||||
|
||||
@@ -2,4 +2,4 @@ import { renderSCUMFeaturePage } from "../features/page.js";
|
||||
|
||||
export const pluginPageBundle = { key: "scum-server-plugin", version: "1.0.4", integritySha256: "sha256:8b57e66b529dd35cd277ee2e5b839d8844c557b690f1d57db3ec026c26b713dc" };
|
||||
|
||||
export function renderPluginPage(react: any, input: any) { return renderSCUMFeaturePage(react, { pageKey: input.page?.key ?? "players", pageTitle: input.page?.title ?? "用户管理", serverInstanceId: input.context.serverInstanceId, permissions: input.context.permissions, availability: input.availability, featureAvailability: input.availability.features, workspaceActions: input.workspaceActions }); }
|
||||
export function renderPluginPage(react: any, input: any) { return renderSCUMFeaturePage(react, { pageKey: input.page?.key ?? "players", pageTitle: input.page?.title ?? "用户管理", serverInstanceId: input.context.serverInstanceId, permissions: input.context.permissions, availability: input.availability, featureAvailability: input.availability.features }); }
|
||||
|
||||
@@ -7,122 +7,31 @@ import { renderPluginPage } from "../examples/scum-server-plugin/page-bundle/ind
|
||||
import { configurationCatalog, validateConfigPatch } from "../examples/scum-server-plugin/features/schemas.js";
|
||||
|
||||
const pageSource = readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), "../examples/scum-server-plugin/features/page.ts"), "utf8");
|
||||
const projectionData = {
|
||||
players: [{ gamePlayerId: "steam-1", steamId: "76561198000000001", userProfileId: "profile-1", displayName: "Mira", squadName: "Wolves", online: true, famePoints: 42, normalBalance: 1000, goldBalance: 3, position: { x: 10, y: 20, z: 3, hasCoordinates: true }, freshness: { status: "fresh" } }],
|
||||
squads: [{ squadId: "squad-1", name: "Wolves", memberCount: 3, leaderProfileId: "profile-1", freshness: { status: "fresh" } }],
|
||||
members: [{ gamePlayerId: "steam-1", displayName: "Mira", squadId: "squad-1", rank: "Leader", freshness: { status: "fresh" } }],
|
||||
vehicles: [{ vehicleId: "veh-1", label: "Laika", position: { subjectType: "vehicle", subjectId: "veh-1", x: 400, y: 200, z: 0, hasCoordinates: true }, freshness: { status: "fresh" } }],
|
||||
flags: [{ flagId: "flag-1", ownerSquadId: "squad-1", ownershipConfidence: "verified", position: { subjectType: "flag", subjectId: "flag-1", x: 100, y: 80, z: 0, hasCoordinates: true }, freshness: { status: "fresh" } }],
|
||||
positions: [{ subjectType: "player", subjectId: "steam-1", gamePlayerId: "steam-1", x: 10, y: 20, z: 3, hasCoordinates: true, freshness: { status: "fresh" } }]
|
||||
};
|
||||
|
||||
describe("SCUM plugin feature module", () => {
|
||||
it("owns runtime allowlists without a version gate", () => {
|
||||
expect(configurationCatalog.map((field) => field.key)).toContain("welcome-message");
|
||||
expect(validateConfigPatch({ reason: "adjust capacity", idempotencyKey: "cfg-1", changes: [{ key: "max-players", value: "129" }] })).toContain("超出允许范围");
|
||||
expect(validateConfigPatch({ reason: "adjust capacity", idempotencyKey: "cfg-2", changes: [{ key: "unknown", value: "1" }] })).toContain("受控目录");
|
||||
});
|
||||
|
||||
it("renders local user management without projection or fake-write controls", () => {
|
||||
const view = renderAndCollect();
|
||||
it("keeps the five management pages free of legacy snapshot reads and fake controls", () => {
|
||||
for (const pageKey of ["players", "squads", "live-map", "gifts", "workflows"]) {
|
||||
const view = renderAndCollect(pageKey);
|
||||
expect(view.texts.join("\n")).toContain("不会读取遗留快照");
|
||||
}
|
||||
for (const removed of ["listSCUM", "map-local-board", "Fame +100", "starter-pack", "855", "Workflow", "投影"]) expect(pageSource).not.toContain(removed);
|
||||
});
|
||||
|
||||
it("falls legacy routes back to user management", () => {
|
||||
const view = renderAndCollect("workflows");
|
||||
expect(view.nodes).toContain("section:用户管理");
|
||||
expect(view.texts.join("\n")).toContain("登录日志和已验证同步结果");
|
||||
expect(view.texts).toContain("本地数据通道可读");
|
||||
expect(view.buttons.find((button) => button.label === "重试本地读取")?.disabled).toBe(false);
|
||||
expect(view.texts).toContain("Mira");
|
||||
expect(view.texts.join("\n")).toContain("Steam 76561198000000001");
|
||||
expect(view.texts.join("\n")).toContain("Profile profile-1");
|
||||
expect(view.texts.join("\n")).toContain("Fame 42");
|
||||
expect(view.buttons.map((button) => button.label)).not.toEqual(expect.arrayContaining(["Fame +100", "现金 +1000", "855 审批"]));
|
||||
for (const removedText of ["ServerSettings.ini", "Game.ini", "配置表单", "键值视图", "原文模式", "读取文件", "提交写入"]) expect(view.texts.join("\n")).not.toContain(removedText);
|
||||
});
|
||||
|
||||
it("does not invent fake players when local records are empty", () => {
|
||||
const view = renderAndCollect({ data: { ...projectionData, players: [], positions: [] } });
|
||||
expect(view.texts.join("\n")).toContain("暂无玩家记录");
|
||||
expect(view.texts.join("\n")).toContain("登录日志或已完成的本地同步");
|
||||
expect(view.texts).not.toContain("Mira");
|
||||
expect(pageSource).not.toContain("fallbackFiles");
|
||||
expect(pageSource).not.toContain("samplePlayers");
|
||||
});
|
||||
|
||||
it("renders squad and flag governance from local records", () => {
|
||||
const view = renderAndCollect({ pageKey: "squads", pageTitle: "队伍管理" });
|
||||
expect(view.nodes).toContain("section:队伍管理");
|
||||
expect(view.texts).toContain("队伍");
|
||||
expect(view.texts).toContain("成员 / 旗帜");
|
||||
expect(view.texts).toContain("Wolves");
|
||||
expect(view.texts.join("\n")).toContain("成员 3");
|
||||
expect(view.texts.join("\n")).toContain("verified");
|
||||
});
|
||||
|
||||
it("renders realtime map overlays without sample coordinates or arbitrary fallback points", () => {
|
||||
const view = renderAndCollect({ pageKey: "live-map", pageTitle: "实时地图" });
|
||||
expect(view.nodes).toContain("section:实时地图");
|
||||
expect(view.texts).toContain("地图覆盖物");
|
||||
expect(view.texts.join("\n")).toContain("坐标点");
|
||||
expect(view.texts.join("\n")).toContain("X 10 / Y 20 / Z 3");
|
||||
expect(pageSource).toContain("map-local-board");
|
||||
expect(pageSource).not.toContain("sampleCoordinates");
|
||||
});
|
||||
|
||||
it("renders gift management without hard-coded delivery actions", () => {
|
||||
const gifts = renderAndCollect({ pageKey: "gifts", pageTitle: "礼包管理" });
|
||||
expect(gifts.nodes).toContain("section:礼包管理");
|
||||
expect(gifts.texts.join("\n")).toContain("本地礼包接口");
|
||||
expect(gifts.buttons.map((button) => button.label)).not.toEqual(expect.arrayContaining(["创建礼包发放", "发送通知"]));
|
||||
expect(pageSource).not.toContain("starter-pack");
|
||||
});
|
||||
|
||||
it("falls legacy workflow routes back to user management", () => {
|
||||
const legacy = renderAndCollect({ pageKey: "workflows" });
|
||||
expect(legacy.nodes).toContain("section:用户管理");
|
||||
expect(legacy.texts.join("\n")).not.toContain("scum.world-refresh");
|
||||
});
|
||||
|
||||
it("loads local SCUM resources without write or workflow workspace actions", () => {
|
||||
expect(pageSource).toContain("listSCUMPlayers");
|
||||
expect(pageSource).not.toContain("createSCUMOperation");
|
||||
expect(pageSource).not.toContain("createSCUMWorkflow");
|
||||
expect(pageSource).not.toContain("getFileSnapshot");
|
||||
expect(pageSource).not.toContain("requestFile");
|
||||
expect(pageSource).not.toContain("writeFile");
|
||||
expect(pageSource).not.toContain("setInterval");
|
||||
});
|
||||
});
|
||||
|
||||
function renderAndCollect(options: { data?: typeof projectionData; permissions?: string[]; pageKey?: string; pageTitle?: string } = {}) {
|
||||
const nodes: string[] = [];
|
||||
const texts: string[] = [];
|
||||
const buttons: Array<{ label: string; disabled: boolean }> = [];
|
||||
const collectText = (value: unknown): void => { if (typeof value === "string") texts.push(value); else if (Array.isArray(value)) value.forEach(collectText); else if (value && typeof value === "object" && "children" in value) collectText((value as { children?: unknown }).children); };
|
||||
let stateCall = 0;
|
||||
const react = {
|
||||
createElement: (type: unknown, props: Record<string, unknown> | null, ...children: unknown[]) => {
|
||||
if (typeof type === "string") nodes.push(`${type}:${String(props?.["aria-label"] ?? "")}`);
|
||||
children.forEach(collectText);
|
||||
if (type === "button") buttons.push({ label: String(children[0]), disabled: Boolean(props?.disabled) });
|
||||
return { type, props, children };
|
||||
},
|
||||
useEffect: () => undefined,
|
||||
useState: <T,>(initial: T | (() => T)): [T, (next: T | ((previous: T) => T)) => void] => {
|
||||
stateCall += 1;
|
||||
if (stateCall === 1) return [{ status: "ready", data: options.data ?? projectionData } as T, () => undefined];
|
||||
return [typeof initial === "function" ? (initial as () => T)() : initial, () => undefined];
|
||||
}
|
||||
};
|
||||
renderPluginPage(react, {
|
||||
page: { key: options.pageKey ?? "players", title: options.pageTitle ?? "用户管理" },
|
||||
context: { serverInstanceId: "server-1", permissions: options.permissions ?? ["server.game-client.read", "server.game-client.command", "server.game-client.maintenance"] },
|
||||
availability: { available: true, features: [{ key: "player.intelligence", available: true }] },
|
||||
workspaceActions: {
|
||||
listSCUMPlayers: async () => ({ items: projectionData.players, count: projectionData.players.length }),
|
||||
listSCUMSquads: async () => ({ items: projectionData.squads, count: projectionData.squads.length }),
|
||||
listSCUMSquadMembers: async () => ({ items: projectionData.members, count: projectionData.members.length }),
|
||||
listSCUMVehicles: async () => ({ items: projectionData.vehicles, count: projectionData.vehicles.length }),
|
||||
listSCUMFlags: async () => ({ items: projectionData.flags, count: projectionData.flags.length }),
|
||||
listSCUMPositions: async () => ({ items: projectionData.positions, count: projectionData.positions.length })
|
||||
}
|
||||
});
|
||||
return { nodes, texts, buttons };
|
||||
function renderAndCollect(pageKey: string) {
|
||||
const nodes: string[] = []; const texts: string[] = [];
|
||||
const collect = (value: unknown): void => { if (typeof value === "string") texts.push(value); else if (Array.isArray(value)) value.forEach(collect); else if (value && typeof value === "object" && "children" in value) collect((value as { children?: unknown }).children); };
|
||||
const react = { createElement: (type: unknown, props: Record<string, unknown> | null, ...children: unknown[]) => { if (typeof type === "string") nodes.push(`${type}:${String(props?.["aria-label"] ?? "")}`); children.forEach(collect); return { type, props, children }; } };
|
||||
renderPluginPage(react, { page: { key: pageKey, title: pageKey === "squads" ? "队伍管理" : pageKey === "live-map" ? "实时地图" : pageKey === "gifts" ? "礼包管理" : "用户管理" }, context: { serverInstanceId: "server-1", permissions: ["server.game-client.read"] }, availability: { available: false, reason: "等待当前服务器完成兼容性验证。" } });
|
||||
return { nodes, texts };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user