Steamworks 对接
Galgo 提供可选 Steamworks 桥接,用于 DLC 检测、DLC 资源加载、成就同步和成就进度提示。
默认构建使用 no-op 后端,不需要 Steamworks SDK:
powershell
go test ./...
go build ./exampleSteam 构建使用 steamworks build tag:
powershell
go build -tags steamworks ./exampleSDK 放置方式
将 Steamworks SDK 放在仓库根目录的 steamworks_sdk:
text
steamworks_sdk/
public/steam/steam_api_flat.h
redistributable_bin/win64/steam_api64.lib
redistributable_bin/win64/steam_api64.dllLinux 和 macOS 使用 SDK 中对应的 linux64 或 osx redistributable 目录。
最终发布时,需要把 Steam 运行库放到游戏可执行文件旁边,例如 Windows 的 steam_api64.dll。
steamworks_sdk/ 已在 .gitignore 中忽略,不应提交 Valve SDK。
配置
go
engine, err := galgo.NewEngine(galgo.Config{
Title: "My VN",
Steam: galgo.SteamConfig{
Enabled: true,
AppID: 480,
RestartAppIfNecessary: true,
AutoSyncAchievements: true,
DLCs: []galgo.SteamDLCItem{
{
Key: "after_story",
AppID: 123456,
MountPath: "dlc/after_story",
AutoMount: true,
},
},
},
Achievements: []galgo.AchievementItem{
{Key: "first_clear", Title: "First Clear"},
},
}, nil)字段说明:
Enabled:启用 Steam 管理器。AppID:Steam 应用 ID。RequireSteam:Steam 初始化失败时是否让NewEngine返回错误。RestartAppIfNecessary:调用 Steam 的重启检查。AutoSyncAchievements:启动时双向同步本地和 Steam 成就。AchievementAPINamePrefix:给 Steam 成就 API 名增加统一前缀。DLCs:配置可检测和挂载的 DLC。
DLC 获取与加载
Steam 报告 DLC 已安装后,如果 AutoMount 为 true,MountPath 会被加入资源搜索根。
go
DLCs: []galgo.SteamDLCItem{
{
Key: "after_story",
AppID: 123456,
MountPath: "dlc/after_story",
AutoMount: true,
},
},当 DLC 已安装并挂载后,普通资源路径会自动从 DLC 根中查找:
go
galgo.Bg("after_room", "assets/after_room.png")等价于额外查找:
text
dlc/after_story/assets/after_room.png运行时 API:
go
engine.RefreshSteamDLCs()
engine.IsSteamDLCInstalled("after_story")
engine.MountSteamDLC("after_story")脚本 Step:
go
galgo.RefreshSteamDLC("after_story")
galgo.MountSteamDLC("after_story")
galgo.BranchSteamDLC("after_story", "after_story_start", "buy_dlc_prompt", true)运行时变量:
text
steam.available
steam.dlc.after_story.installed
steam.dlc.after_story.mounted成就同步
本地解锁:
go
galgo.UnlockAchievement("first_clear")如果 Steam 可用,会调用 Steam 成就解锁并 StoreStats。
手动同步:
go
engine.SyncSteamAchievement("first_clear")
engine.SyncSteamAchievements()成就进度:
go
galgo.SteamAchievementProgress("all_endings", 2, 5)构建注意事项
普通开发构建不需要 Steam SDK。Steam 构建需要:
CGO_ENABLED=1- 平台可用的 C 编译器
- Steamworks SDK 路径符合本文档布局
- 运行时库放在可执行文件旁边
如果只是本地调试非 Steam 版,建议保持:
go
Steam: galgo.SteamConfig{
Enabled: false,
}如果要测试 Steam AppID 480,可在可执行文件工作目录放置 steam_appid.txt,内容为:
text
480