diff --git a/apps/launcher/src/main/ipc/handlers.ts b/apps/launcher/src/main/ipc/handlers.ts index 02dac46..f08af21 100644 --- a/apps/launcher/src/main/ipc/handlers.ts +++ b/apps/launcher/src/main/ipc/handlers.ts @@ -24,7 +24,6 @@ import { exportModPreset, getModsState, importModPreset, - openModDocs, openModsFolder, saveModPreset, setModEnabled, @@ -224,7 +223,6 @@ export function registerIpcHandlers(): void { return importModPreset(copyId, BrowserWindow.fromWebContents(sender)); }); handle('mods:openFolder', () => openModsFolder()); - handle('mods:openDocs', (input) => openModDocs(input?.language)); handle('mods:setFolder', async ({ copyId, path }) => { requireModsWritable(); const state = await setModsFolder(copyId, path); diff --git a/apps/launcher/src/main/services/mods/mods-service.ts b/apps/launcher/src/main/services/mods/mods-service.ts index 99c78d3..46dc6af 100644 --- a/apps/launcher/src/main/services/mods/mods-service.ts +++ b/apps/launcher/src/main/services/mods/mods-service.ts @@ -118,20 +118,6 @@ export async function openModsFolder(): Promise { if (failure) console.warn('[mods] opening the mods folder failed:', modsDir, failure); } -export async function openModDocs(language?: string): Promise { - const docsRoot = resourcePaths().modDocs; - const preferred = language && language.toLowerCase().startsWith('zh') ? 'zh-CN.html' : 'en.html'; - const fallback = preferred === 'zh-CN.html' ? 'en.html' : 'zh-CN.html'; - const target = (await pathExists(join(docsRoot, preferred))) - ? join(docsRoot, preferred) - : join(docsRoot, fallback); - if (!(await pathExists(target))) { - throw new AppError('folder_unreadable', { path: docsRoot }); - } - const failure = await shell.openPath(target); - if (failure) console.warn('[mods] opening the mod docs failed:', target, failure); -} - export async function getModsState(copyId: string): Promise { const copy = await requireCopy(copyId); return buildModsStateView(copy); diff --git a/apps/launcher/src/main/services/resources/resource-paths.ts b/apps/launcher/src/main/services/resources/resource-paths.ts index 50dfa77..231994a 100644 --- a/apps/launcher/src/main/services/resources/resource-paths.ts +++ b/apps/launcher/src/main/services/resources/resource-paths.ts @@ -19,8 +19,6 @@ export interface ResourcePaths { readonly appIcon: string; /** Bundled example mod templates seeded into an empty mods folder on first use. */ readonly modTemplates: string; - /** Offline HTML mod development handbook (zh-CN.html and en.html). */ - readonly modDocs: string; } export function resourcePaths(): ResourcePaths { @@ -37,7 +35,6 @@ export function bundledResourcePaths(): ResourcePaths { networkHookLibrary: join(process.resourcesPath, 'native', 'wto_ws.dll'), appIcon: join(process.resourcesPath, 'icon.ico'), modTemplates: join(process.resourcesPath, 'mod-templates'), - modDocs: join(process.resourcesPath, 'mod-dev-docs'), }; } // The app path is apps/launcher; the repository is two levels up. @@ -47,7 +44,6 @@ export function bundledResourcePaths(): ResourcePaths { networkHookLibrary: join(repository, 'build', 'native', 'wto_ws.dll'), appIcon: join(repository, 'apps', 'launcher', 'resources', 'icon.ico'), modTemplates: join(repository, 'mod-dev-docs', 'templates'), - modDocs: join(repository, 'build', 'mod-dev-docs'), }; } diff --git a/apps/launcher/src/renderer/src/pages/mods/ModsPage.tsx b/apps/launcher/src/renderer/src/pages/mods/ModsPage.tsx index 74db439..a69f3a4 100644 --- a/apps/launcher/src/renderer/src/pages/mods/ModsPage.tsx +++ b/apps/launcher/src/renderer/src/pages/mods/ModsPage.tsx @@ -7,6 +7,8 @@ import { Sheet } from '../../components/Sheet.tsx'; import { ipcInvoke } from '../../ipc.ts'; import type { ModsSection } from '../../shell/navigation.ts'; +const MOD_DOCS_URL = 'https://wto-project.net/mod-docs'; + interface Props { readonly copy: InstallRecord; readonly section: ModsSection; @@ -255,9 +257,9 @@ export function ModsPage({ copy, section, readOnly, onError }: Props) { - + {state.discoveryErrors.length > 0 && ( diff --git a/apps/launcher/src/shared/ipc/contract.ts b/apps/launcher/src/shared/ipc/contract.ts index d3eaeeb..d87aa0f 100644 --- a/apps/launcher/src/shared/ipc/contract.ts +++ b/apps/launcher/src/shared/ipc/contract.ts @@ -303,10 +303,6 @@ export const ipcContract = { input: z.void(), output: z.void(), }, - 'mods:openDocs': { - input: z.object({ language: z.string().optional() }).optional(), - output: z.void(), - }, 'mods:setFolder': { input: z.object({ copyId: CopyIdSchema, path: z.string().min(1).nullable() }), output: ModsStateViewSchema, diff --git a/scripts/build-mod-docs-html.ts b/scripts/build-mod-docs-html.ts deleted file mode 100644 index 075f66d..0000000 --- a/scripts/build-mod-docs-html.ts +++ /dev/null @@ -1,411 +0,0 @@ -/** - * Generate self-contained offline HTML mod authoring guides (zh-CN.html and en.html) - * from `mod-dev-docs//01..07.md`. Supports built-in sidebar navigation, copyable code - * blocks, language switching, and clean print-to-PDF styling with zero external dependencies. - */ -import { mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'; -import { join, resolve } from 'node:path'; - -interface Chapter { - readonly slug: string; - readonly title: string; - readonly html: string; -} - -export function buildOfflineModDocs(docsRoot: string, outputDir: string): { readonly zh: string; readonly en: string } { - mkdirSync(outputDir, { recursive: true }); - const zhPath = join(outputDir, 'zh-CN.html'); - const enPath = join(outputDir, 'en.html'); - writeFileSync(zhPath, renderHandbook(docsRoot, 'zh-CN'), 'utf8'); - writeFileSync(enPath, renderHandbook(docsRoot, 'en'), 'utf8'); - return { zh: zhPath, en: enPath }; -} - -function renderHandbook(docsRoot: string, lang: 'zh-CN' | 'en'): string { - const dir = join(docsRoot, lang); - const files = readdirSync(dir) - .filter((name) => name.endsWith('.md')) - .sort((a, b) => a.localeCompare(b)); - - const chapters: Chapter[] = files.map((file) => { - const markdown = readFileSync(join(dir, file), 'utf8'); - const titleMatch = /^#\s+(.+)$/m.exec(markdown); - const title = titleMatch ? titleMatch[1]!.trim() : file.replace(/\.md$/, ''); - const slug = file.replace(/\.md$/, ''); - return { slug, title, html: renderMarkdown(markdown) }; - }); - - const isZh = lang === 'zh-CN'; - const pageTitle = isZh ? 'WTOffline 模组开发手册(离线版)' : 'WTOffline Mod Development Handbook (Offline)'; - const subtitle = isZh ? 'API 0.1-experimental · 实验期随时可能变动' : 'API 0.1-experimental · Subject to breaking changes'; - const switchHref = isZh ? 'en.html' : 'zh-CN.html'; - const switchLabel = isZh ? 'English' : '简体中文'; - const printLabel = isZh ? '打印 / 另存为 PDF' : 'Print / Save as PDF'; - const copyLabel = isZh ? '复制' : 'Copy'; - const copiedLabel = isZh ? '已复制' : 'Copied'; - - const navLinks = chapters - .map((ch) => `${escapeHtml(ch.title)}`) - .join('\n'); - - const sections = chapters - .map((ch) => `
${ch.html}
`) - .join('\n
\n'); - - return ` - - - - -${escapeHtml(pageTitle)} - - - - -
- ${sections} -
- - - -`; -} - -function renderMarkdown(source: string): string { - const lines = source.replace(/\r\n/g, '\n').split('\n'); - const out: string[] = []; - let i = 0; - - while (i < lines.length) { - const line = lines[i]!; - - if (line.trim() === '') { - i += 1; - continue; - } - - // Fenced code block. - const fence = /^```([A-Za-z0-9_-]*)/.exec(line); - if (fence) { - const codeLines: string[] = []; - i += 1; - while (i < lines.length && !lines[i]!.startsWith('```')) { - codeLines.push(lines[i]!); - i += 1; - } - if (i < lines.length) i += 1; - out.push(`
${escapeHtml(codeLines.join('\n'))}
`); - continue; - } - - // Horizontal rule. - if (/^---+$/.test(line.trim())) { - out.push('
'); - i += 1; - continue; - } - - // Headings. - const heading = /^(#{1,4})\s+(.+)$/.exec(line); - if (heading) { - const level = heading[1]!.length; - out.push(`${renderInline(heading[2]!)}`); - i += 1; - continue; - } - - // Blockquote. - if (line.startsWith('>')) { - const quoteLines: string[] = []; - while (i < lines.length && lines[i]!.startsWith('>')) { - quoteLines.push(lines[i]!.replace(/^>\s?/, '')); - i += 1; - } - out.push(`

${quoteLines.map(renderInline).join('
')}

`); - continue; - } - - // GFM table. - if (line.includes('|') && i + 1 < lines.length && /^\s*\|?[\s:-]+\|[\s|:-]*$/.test(lines[i + 1]!)) { - const headers = splitTableRow(line); - i += 2; - const rows: string[][] = []; - while (i < lines.length && lines[i]!.includes('|') && lines[i]!.trim() !== '') { - rows.push(splitTableRow(lines[i]!)); - i += 1; - } - const thead = `${headers.map((cell) => `${renderInline(cell)}`).join('')}`; - const tbody = `${rows.map((row) => `${row.map((cell) => `${renderInline(cell)}`).join('')}`).join('')}`; - out.push(`${thead}${tbody}
`); - continue; - } - - // Unordered or ordered list. - if (/^\s*[-*]\s+/.test(line) || /^\s*\d+\.\s+/.test(line)) { - const ordered = /^\s*\d+\.\s+/.test(line); - const tag = ordered ? 'ol' : 'ul'; - const items: string[] = []; - while (i < lines.length && (ordered ? /^\s*\d+\.\s+/.test(lines[i]!) : /^\s*[-*]\s+/.test(lines[i]!))) { - items.push(lines[i]!.replace(ordered ? /^\s*\d+\.\s+/ : /^\s*[-*]\s+/, '')); - i += 1; - } - out.push(`<${tag}>${items.map((item) => `
  • ${renderInline(item)}
  • `).join('')}`); - continue; - } - - // Paragraph. - const para: string[] = []; - while ( - i < lines.length - && lines[i]!.trim() !== '' - && !lines[i]!.startsWith('#') - && !lines[i]!.startsWith('```') - && !lines[i]!.startsWith('>') - && !/^---+$/.test(lines[i]!.trim()) - && !/^\s*[-*]\s+/.test(lines[i]!) - && !/^\s*\d+\.\s+/.test(lines[i]!) - ) { - para.push(lines[i]!); - i += 1; - } - out.push(`

    ${para.map(renderInline).join(' ')}

    `); - } - - return out.join('\n'); -} - -function splitTableRow(line: string): string[] { - return line.trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map((cell) => cell.trim()); -} - -function renderInline(text: string): string { - const tokens: string[] = []; - let work = text.replace(/`([^`]+)`/g, (_m, code: string) => { - const idx = tokens.length; - tokens.push(`${escapeHtml(code)}`); - return `\u0000T${idx}\u0000`; - }); - work = escapeHtml(work); - work = work.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'); - work = work.replace(/\*\*([^*]+)\*\*/g, '$1'); - work = work.replace(/\u0000T(\d+)\u0000/g, (_m, idx: string) => tokens[Number(idx)] ?? ''); - return work; -} - -function escapeHtml(text: string): string { - return text - .replaceAll('&', '&') - .replaceAll('<', '<') - .replaceAll('>', '>') - .replaceAll('"', '"'); -} - -if (process.argv[1] && resolve(process.argv[1]) === resolve(import.meta.filename)) { - const repo = resolve(import.meta.dirname, '..'); - const outArgIdx = process.argv.indexOf('--out'); - const outDir = outArgIdx >= 0 && process.argv[outArgIdx + 1] - ? resolve(process.argv[outArgIdx + 1]!) - : join(repo, 'build', 'mod-dev-docs'); - const result = buildOfflineModDocs(join(repo, 'mod-dev-docs'), outDir); - console.log('Generated offline mod docs:', result.zh, result.en); -} diff --git a/scripts/build-windows-installer.ts b/scripts/build-windows-installer.ts index 75e231a..befcd3c 100644 --- a/scripts/build-windows-installer.ts +++ b/scripts/build-windows-installer.ts @@ -5,7 +5,6 @@ import { dirname, join, relative, resolve, sep } from 'node:path'; import { Arch, build, Platform } from 'electron-builder'; import { launcherReleaseFiles, portableLauncherReleaseFiles } from '../apps/launcher/src/shared/schemas/app-update.ts'; import { formatManifest, MANIFEST_FILE, PATCH_PACK_FORMAT, recordedGameVersions } from '../packages/patcher/src/index.ts'; -import { buildOfflineModDocs } from './build-mod-docs-html.ts'; const repository = resolve(import.meta.dirname, '..'); const launcher = join(repository, 'apps', 'launcher'); @@ -72,7 +71,6 @@ async function stageInstaller(stage: string, manifest: LauncherManifest): Promis await cp(join(repository, 'LICENSE'), join(resources, 'LICENSE-WTOffline')); await cp(join(native, 'wto_ws.dll'), join(resources, 'native', 'wto_ws.dll')); await cp(join(repository, 'mod-dev-docs', 'templates'), join(resources, 'mod-templates'), { recursive: true }); - buildOfflineModDocs(join(repository, 'mod-dev-docs'), join(resources, 'mod-dev-docs')); for (const folder of ['exe', 'gui', 'native', 'versions']) { await cp(join(repository, 'patches', folder), join(resources, 'patches', folder), { recursive: true }); }