- 패널이 자기 드롭다운 목록(pickGroups — 군 차례 · 정의 이름 · 켜진 종류 · 옛 대피 뺌 · 숨김)을 내고 우클릭 메뉴가 그것을 그대로 씀 - 옛 메뉴 = 꺼진 종류(F 야생동물 이동통로 · 비탈면 녹화 · G 쇄석 포설) · 옛 대피 종류(대피소 · 정차작업장 · 차돌림곳) 더 보임 · 군 이름은 정의(48) 대신 고정 이름 - 시험 test_129(실제 레지스트리 + 정의로 패널 = 메뉴 · B05 · B06) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UoSr2sqvYtBf1dtQdus88s
83 lines
3.4 KiB
JavaScript
83 lines
3.4 KiB
JavaScript
/* 129-1 우클릭 목록 = 좌측 패널 목록 헬퍼 — 종류 목록 JSON(argv[2] · 서버 응답) · 구조물 정의(argv[3])를
|
|
* 화면처럼 `withDefinition` 으로 얹어 패널 군 · 종류 드롭다운(`groupOptions` · `typeOptions` — `syncTypeOptions` 와 같은 후보)과 우클릭 메뉴
|
|
* (`structureGroupMenuItems(pickGroups)`)를 B05(켜진 종류) · B06(전부) 두 거르기로 뽑아 표준출력 JSON 한 벌로.
|
|
* TS 로더는 `helper_116_right_click_add.cjs` 와 같다.
|
|
*/
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
|
|
|
|
const ROOT = path.join(__dirname, "..", "..");
|
|
const cache = new Map();
|
|
const STUBS = { "@config/config_frontend": { API_BASE_URL: "/api", API_TIMEOUT_MS: 1000 } };
|
|
// 드롭다운 항목 — 브라우저 `new Option(text, value)` 과 같은 칸만.
|
|
globalThis.Option = class {
|
|
constructor(text, value) {
|
|
this.text = text;
|
|
this.value = value;
|
|
this.hidden = false;
|
|
this.dataset = {};
|
|
}
|
|
};
|
|
|
|
function loadTs(file) {
|
|
const full = path.resolve(file);
|
|
if (cache.has(full)) return cache.get(full);
|
|
const js = ts.transpileModule(fs.readFileSync(full, "utf8"), {
|
|
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
|
}).outputText;
|
|
const box = { exports: {} };
|
|
cache.set(full, box.exports);
|
|
const localRequire = (request) => {
|
|
if (STUBS[request]) return STUBS[request];
|
|
if (request.startsWith(".")) return loadTs(path.join(path.dirname(full), `${request}.ts`));
|
|
if (request.startsWith("@")) return new Proxy({}, { get: () => () => {} });
|
|
if (request.endsWith(".css")) return {};
|
|
return require(request);
|
|
};
|
|
new Function("exports", "module", "require", js)(box.exports, box, localRequire);
|
|
cache.set(full, box.exports);
|
|
return box.exports;
|
|
}
|
|
|
|
const B05 = path.join(ROOT, "B05_Profile");
|
|
const T = loadTs(path.join(B05, "B05_Profile_UI_Structures_Panel_Types.ts"));
|
|
const M = loadTs(path.join(B05, "B05_Profile_UI_Profile_Structures.ts"));
|
|
const D = loadTs(path.join(B05, "B05_Profile_UI_Structures_Define.ts"));
|
|
|
|
const read = (file) => JSON.parse(fs.readFileSync(file, "utf8"));
|
|
const types = D.withDefinition(read(process.argv[2]), read(process.argv[3]));
|
|
|
|
/** 패널 드롭다운에 보이는 것 — 군(차례 · 이름) → 그 군 고르면 보이는 종류(차례 · 이름 · id). */
|
|
function panelList(pick) {
|
|
return T.groupOptions(types, pick)
|
|
.filter((option) => !option.hidden)
|
|
.map((group) => {
|
|
const candidates = types.filter((t) => t.group === group.value && D.pickable(t));
|
|
const kinds = T.typeOptions(candidates, pick).filter((option) => !option.hidden);
|
|
return { label: group.text, types: kinds.map((option) => [option.text, option.value]) };
|
|
});
|
|
}
|
|
|
|
/** 우클릭 메뉴 — 군 라벨 → 종류 이름 · 누르면 넘어가는 id. */
|
|
function menuList(pick) {
|
|
const picked = [];
|
|
const items = M.structureGroupMenuItems(T.pickGroups(types, pick), (id) => picked.push(id));
|
|
return items.map((item) => ({
|
|
label: item.label,
|
|
types: item.children.map(([name, run]) => {
|
|
run();
|
|
return [name, picked.pop()];
|
|
}),
|
|
}));
|
|
}
|
|
|
|
const enabled = (t) => t.enabled;
|
|
const all = () => true;
|
|
process.stdout.write(
|
|
JSON.stringify({
|
|
b05: { panel: panelList(enabled), menu: menuList(enabled) },
|
|
b06: { panel: panelList(all), menu: menuList(all) },
|
|
}),
|
|
);
|