feat(build): 程序图标使用原版素材 logo + 安装器运行/快捷方式选项

- scripts/make_icon.ps1:素材包 pack.png → go-winres 生成 icon.syso
  (嵌入 exe 图标与版本信息);窗口图标运行时 SetWindowIcon
- 安装.bat:桌面快捷方式 [Y/n](默认 Y)、安装后立即运行 [Y/n](默认 Y)
- build.ps1 在 syso 缺失时自动生成图标
This commit is contained in:
NianGao Dev
2026-08-16 23:23:31 +08:00
parent b0b632df05
commit 9e7d4d20e2
8 changed files with 83 additions and 6 deletions

View File

@@ -35,6 +35,11 @@ if (-not $Release) { $tags = "$tags dev" }
Push-Location $root
try {
New-Item -ItemType Directory -Force -Path bin | Out-Null
# exe 图标(原版素材 logo):缺失时自动生成 .syso(make_icon.ps1)
if (-not (Test-Path (Join-Path $root "cmd\client\icon.syso"))) {
& (Join-Path $PSScriptRoot "make_icon.ps1")
if ($LASTEXITCODE -ne 0) { throw "图标生成失败(make_icon.ps1)" }
}
go build -tags $tags -trimpath -ldflags "-s -w" -o bin/mc-client.exe ./cmd/client
go build -trimpath -ldflags "-s -w" -o bin/mc-server.exe ./cmd/server

View File

@@ -21,13 +21,30 @@ if not exist "!INSTALL_DIR!" mkdir "!INSTALL_DIR!"
echo 复制游戏文件...
xcopy /e /i /y "%~dp0*" "!INSTALL_DIR!\" >nul 2>&1
echo 创建桌面快捷方式...
powershell -NoProfile -Command "$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut([Environment]::GetFolderPath('Desktop') + '\年糕历险记.lnk'); $s.TargetPath = '!INSTALL_DIR!\mc-client.exe'; $s.WorkingDirectory = '!INSTALL_DIR!'; $s.Save()"
rem 选项 1:创建桌面快捷方式(默认选中 Y)
set "MAKE_LNK=Y"
set /p "MAKE_LNK=是否创建桌面快捷方式 [Y/n](默认 Y):"
if /i "!MAKE_LNK!"=="" set "MAKE_LNK=Y"
if /i "!MAKE_LNK!"=="y" (
echo 创建桌面快捷方式...
powershell -NoProfile -Command "$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut([Environment]::GetFolderPath('Desktop') + '\年糕历险记.lnk'); $s.TargetPath = '!INSTALL_DIR!\mc-client.exe'; $s.WorkingDirectory = '!INSTALL_DIR!'; $s.IconLocation = '!INSTALL_DIR!\mc-client.exe,0'; $s.Save()"
)
echo.
echo ============================================
echo 安装完成!桌面已创建「年糕历险记」快捷方式。
echo 安装完成!
echo 游戏存档保存在安装目录 worlds\ 下。
echo 按任意键退出...
echo ============================================
rem 选项 2:安装完成后是否立即运行(默认选中 Y)
set "RUN_NOW=Y"
set /p "RUN_NOW=是否立即运行游戏 [Y/n](默认 Y):"
if /i "!RUN_NOW!"=="" set "RUN_NOW=Y"
if /i "!RUN_NOW!"=="y" (
echo 正在启动游戏...
start "" /D "!INSTALL_DIR!" "!INSTALL_DIR!\mc-client.exe"
)
echo.
echo 按任意键退出...
pause >nul

28
scripts/make_icon.ps1 Normal file
View File

@@ -0,0 +1,28 @@
# 年糕历险记 —— 程序图标生成(构建与发布.md §8:exe/窗口使用原版素材 logo)
# 用法:pwsh -File scripts/make_icon.ps1
# 流程:素材包 pack.png → cmd/client/icon.png → go-winres 生成 cmd/client/icon.syso
# (资源目录树格式,Go 链接器自动嵌入 exe;资源管理器/任务栏/快捷方式显示图标)。
$ErrorActionPreference = "Stop"
$root = Split-Path $PSScriptRoot -Parent
# 1) 定位素材包 pack.png(原版 logo,高优先级包在前)→ 复制为 icon.png
$png = $null
foreach ($dir in Get-ChildItem (Join-Path $root "resourcepacks") -Directory -ErrorAction SilentlyContinue) {
$cand = Join-Path $dir.FullName "pack.png"
if (Test-Path $cand) { $png = $cand; break }
}
if (-not $png) { throw "未找到素材包 pack.png(resourcepacks/*/pack.png)" }
Copy-Item $png (Join-Path $root "cmd\client\icon.png") -Force
Write-Host "== 图标来源:$png =="
# 2) go-winres 生成 .syso(多尺寸图标组 + 版本资源;winres.json 引用 icon.png)
$env:GOCACHE = Join-Path $root ".gocache"
Push-Location (Join-Path $root "cmd\client")
try {
go run github.com/tc-hib/go-winres@latest make --in winres.json --out icon --arch amd64 --no-suffix
if ($LASTEXITCODE -ne 0) { throw "go-winres 生成失败" }
Move-Item -Force (Join-Path (Get-Location) "icon") (Join-Path (Get-Location) "icon.syso")
} finally {
Pop-Location
}
Write-Host "== 图标资源已嵌入:cmd/client/icon.syso =="

View File

@@ -33,7 +33,8 @@ Copy-Item (Join-Path $PSScriptRoot "installer\安装.bat") (Join-Path $stage "
年糕历险记 v$Version
====================
安装:双击 安装.bat(选择安装目录,自动创建桌面快捷方式)。
安装:双击 安装.bat(选择安装目录,可选创建桌面快捷方式,默认创建;
安装完成后可选立即运行游戏,默认运行)。
卸载:删除安装目录即可(存档保存在安装目录 worlds/ 下)。
素材包/光影包:解压到 mods/ 目录(原生 Minecraft 资源包格式直接支持)。