renpy web updater

最近因为一些原因,开始研究 renpy 这个 Visual Novel 框架了,把折腾的东西顺便写个教程分享下。

这个教程是有关 renpy 使用 web updater 功能来更新游戏内容的。

更新设置

Building an Update
Updates are built automatically when distributions are built. To build an update, set build.include_update to True in options.rpy. This will unlock the “Build Updates” option in the “Build Distributions” section of the launcher. Check this option, and Ren’Py will create the update files.

开启生成更新按钮

  • 打开 options.rpy
  • 在 init python 下面的 build 部分新增一个下面一行代码
build.include_update = True
  • 切换到 renpy 开发窗口,点击生成分发版,此时可以看到 生成更新 选项已经出现。

给主菜单添加 check for updates 按钮

  1. 打开 screens.rpy 定位到 main_menu 方法
  2. 在 main_menu_version 组件下新增 textbutton
## Updates via this button are for PC only
textbutton "check for updates":
    action updater.Update("http://127.0.0.1/TestChsGame/updates.json")

制作与测试游戏更新包

  1. 首先生成一个 1.0 版本的游戏包。(不勾选 生成更新)
  2. 修改下剧本文本内容和游戏版本号 1.0.1,勾选生成更新选项,生成下 1.0.1 版本的更新包内容


    1.0 和 1.0.1 的 build 包
  3. 上传 1.0.1 文件夹里的所有文件到本机 Web 服务器 TestChsGame 目录,上传完毕后,在浏览器里输入 http://127.0.0.1/TestChsGame/updates.json 可看到 json 文件内容
  4. 打开 1.0 build 运行游戏,点击 check for updates 按钮,可以看到有 1.0.1 版本更新提示

点击取消,Start 游戏,查看下第一行对白是显示 v1.0

返回到 Title,再次点击 check for updates 后,点击继续运行 updater 更新游戏

更新完毕后,会自动重启游戏

在 1.0.1 游戏启动后,点击开始游戏可以看到,剧本第一行对白已经显示为 1.0.1 了

至此,renpy web updater 测试游戏版本更新功能完毕。

测试用 Web 服务器

  1. 【推荐】系统有安装 python3 的话可以打开 cmd.exe 进入一个空目录后,使用 python -m http.server 来启动一个 web server

    默认端口是 8000,所以地址会变成 http://127.0.0.1:8000

  2. Windows 下可以安装个 wampserver
  3. 或使用搜索引擎跟着教程搭建一个 web server

Reference:

  1. 官方文档地址:Web Updater
  2. [Help] About the Web Updater