### 安装依赖并启动开发服务器 Source: https://github.com/hsyhhssyy/industrialplanner/blob/v3/README.md 在项目根目录运行 npm install 安装依赖,然后使用 npm run dev 启动本地开发服务器。 ```bash npm install npm run dev ``` -------------------------------- ### 常用开发脚本 Source: https://github.com/hsyhhssyy/industrialplanner/blob/v3/README.md 列出项目常用的 npm 脚本,包括启动开发服务器、构建、预览、类型检查、代码检查和测试。 ```bash npm run dev # 启动本地开发服务器 npm run build # TypeScript 构建检查并打包 npm run preview # 预览生产构建 npm run typecheck # 仅运行 TypeScript 检查 npm run lint # 运行 ESLint npm run test # 运行常规 Vitest 测试 npm run test:blueprint # 运行蓝图仿真测试 ``` -------------------------------- ### Input event listeners for mouse, wheel, and keyboard Source: https://github.com/hsyhhssyy/industrialplanner/blob/v3/index.html Sets up event listeners to track mouse buttons, scroll wheel, and keyboard keys. Uses capture phase for mouse and key events, and passive mode for wheel. Clears all input states when the window loses focus. ```javascript document.addEventListener('mouseup', (e) => { if (e.button === 0) mouseLeft = false; if (e.button === 1) mouseMiddle = false; if (e.button === 2) mouseRight = false; }, true); document.addEventListener('wheel', (e) => { const now = performance.now(); if (e.deltaY < 0) scrollUpUntil = now + SCROLL_FADE_MS; if (e.deltaY > 0) scrollDownUntil = now + SCROLL_FADE_MS; }, { passive: true }); document.addEventListener('keydown', (e) => { if (KEY_SVG_MAP[e.code]) activeKeys.add(e.code); }, true); document.addEventListener('keyup', (e) => { activeKeys.delete(e.code); }, true); // 窗口失焦时清除所有按键状态 window.addEventListener('blur', () => { mouseLeft = mouseRight = mouseMiddle = false; activeKeys.clear(); }); ``` -------------------------------- ### 运行无头 EDA 任务(含分片与合并) Source: https://github.com/hsyhhssyy/industrialplanner/blob/v3/src/scripts/eda/HEADLESS.md 在网页“蓝图规划任务”中下载任务文件后,交给同一版本的客户端运行。`--proposals` 是本次追加计算在全部分片上的提案总上限,省略时持续计算;分片总数固定为 32,`--shard-count` 若提供只能是 32;`--shard-range A:B` 运行编号 A 至 B−1。默认输出到输入文件旁的 `.continued.json`,使用 `--output` 指定其他路径。 ```bash node src/scripts/run-eda-task.mjs --task /path/line.eda-task.json --proposals 100000 ``` ```bash node src/scripts/run-eda-task.mjs --task /path/line.eda-task.json ``` ```bash node src/scripts/run-eda-task.mjs --task /path/line.eda-task.json --proposals 100000 --shard-count 32 --shard-range 0:16 --output /path/part-0-1.json ``` ```bash node src/scripts/run-eda-task.mjs --task /path/line.eda-task.json --proposals 100000 --shard-count 32 --shard-range 16:32 --output /path/part-2-3.json ``` ```bash node src/scripts/run-eda-task.mjs merge --output /path/merged.json /path/part-0-1.json /path/part-2-3.json ``` -------------------------------- ### Render state builder and prompt updater Source: https://github.com/hsyhhssyy/industrialplanner/blob/v3/index.html Builds a comma-separated string representing the current input state (mouse buttons, scroll, keys) and updates the HUD prompts row. Includes a fast path to avoid DOM rebuilds when the state hasn't changed. ```javascript let lastRenderState = ''; function buildRenderState() { const now = performance.now(); const parts = []; // 鼠标按钮 if (mouseLeft) parts.push('mouse_left'); else if (mouseRight) parts.push('mouse_right'); else if (mouseMiddle) parts.push('mouse_move'); // 滚轮(有时效) if (scrollUpUntil > now) parts.push('mouse_scroll_up'); if (scrollDownUntil > now) parts.push('mouse_scroll_down'); // 键盘按键 for (const code of activeKeys) { parts.push(KEY_SVG_MAP[code]); } return parts.join(','); } function updatePrompts(state) { if (!state) { promptsRow.innerHTML = ''; return; } const parts = state.split(','); if (parts.length === 0 || (parts.length === 1 && parts[0] === '')) { promptsRow.innerHTML = ''; return; } // 快速比较避免 DOM 重建 const currentChildren = promptsRow.children; const expectedLen = parts.length * 2 - 1; if (currentChildren.length === expectedLen) { let same = true; for (let i = 0; i < parts.length; i++) { if (currentChildren[i * 2].dataset.name !== parts[i]) { same = false; break; } } if (same) return; } promptsRow.innerHTML = ''; for (let i = 0; i < parts.length; i++) { if (i > 0) promptsRow.appendChild(makePlus()); const img = makeImg(parts[i]); img.dataset.name = parts[i]; promptsRow.appendChild(img); } } ``` -------------------------------- ### 读取建筑资源清单与元数据(readJson 与 manifest.json 加载) Source: https://github.com/hsyhhssyy/industrialplanner/blob/v3/resources/building-port-effects/README.md 用于从 assets/manifest.json 入口加载建筑、端口、遮挡和特效资源。所有 JSON 文件引用均相对于其自身所在目录解析;净水节点 liquidcleanfactory_005_1 的旧 32×16 页面已撤回,不能直接按旧画布尺寸使用。 ```javascript async function readJson(url) { const response = await fetch(url); if (!response.ok) throw new Error(`${response.status}: ${url}`); return { url: response.url, value: await response.json() }; } const root = await readJson(new URL('assets/manifest.json', assetBaseUrl)); const item = root.value.buildings.find(x => x.buildingId === 'transmuter_1' && x.view === 'top'); const building = await readJson(new URL(item.package, root.url)); const ports = await readJson(new URL(building.value.portMetadata, building.url)); const occlusion = await readJson(new URL(building.value.occlusionMetadata, building.url)); const effects = await readJson(new URL(building.value.effectResources, building.url)); ``` -------------------------------- ### Main update loop with cursor hiding and HUD positioning Source: https://github.com/hsyhhssyy/industrialplanner/blob/v3/index.html The core animation loop that toggles a global cursor-none style, hides the HUD when disabled, positions the HUD at the mouse coordinates, and re-renders only when the input state changes. ```javascript function update() { const enabled = readEnabled(); if (enabled !== wasEnabled) { wasEnabled = enabled; if (enabled) { // 全局强制覆盖所有元素的 cursor,不依赖 body 继承 let styleEl = document.getElementById('__vc_cursor_style'); if (!styleEl) { styleEl = document.createElement('style'); styleEl.id = '__vc_cursor_style'; document.head.appendChild(styleEl); } styleEl.textContent = '* { cursor: none !important; }'; } else { const styleEl = document.getElementById('__vc_cursor_style'); if (styleEl) styleEl.textContent = ''; } if (!enabled) { hud.style.display = 'none'; promptsRow.innerHTML = ''; } } if (!enabled) { requestAnimationFrame(update); return; } if (mouseX < 0) { requestAnimationFrame(update); return; } hud.style.display = ''; hud.style.left = mouseX + 'px'; hud.style.top = mouseY + 'px'; const state = buildRenderState(); if (state !== lastRenderState) { lastRenderState = state; updatePrompts(state); } requestAnimationFrame(update); } requestAnimationFrame(update); })(); ``` -------------------------------- ### 通过 registry 解析 effect resource ID Source: https://github.com/hsyhhssyy/industrialplanner/blob/v3/resources/building-port-effects/README.md 从 effects registry 构建 resourceId 到资源的映射,并用 effectFor 将 binding 解析为包含 id、meta 和基于 registry path 的 URL 的对象。未知 ID 会抛出 Error。 ```javascript const registry = effects; const resourceById = new Map( registry.value.resources.map(resource => [resource.id ?? resource.resourceId, resource]) ); function effectFor(binding) { if (!binding) return null; const id = binding.resourceId; const resource = resourceById.get(id); if (!resource) throw new Error(`Unknown effect resource ID: ${id}`); return { id, meta: resource, effect: new URL(resource.path, registry.url) }; } const onEffect = effectFor(port.resourceBinding?.on); const offEffect = effectFor(port.resourceBinding?.off); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.