Skip to content

Conversation

@MakinoharaShoko
Copy link
Member

在模板的描述文件 template.json 中,添加了 font 字段,用于描述用户的自定义字体。这一字体由引擎在初始化阶段通过插入 style 标签的方式被加载到页面中,并在 Options 中注册并成为可选项。

如果有自定义字体,其将会被添加到默认字体之前的位置。并且由于引擎默认选中第一个字体作为对话框和选项等 UI 的字体,所以一般来说自定义字体会被优先选中。

@gemini-code-assist
Copy link

Summary of Changes

Hello @MakinoharaShoko, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求引入了对自定义模板字体的支持,允许游戏开发者通过 template.json 文件定义和加载自己的字体。这些字体会在游戏启动时自动加载并注入到页面中,同时在游戏选项菜单中提供给玩家选择。这一改进使得游戏在字体方面具有更高的定制性,提升了用户体验。

Highlights

  • 自定义字体支持: 在 template.json 描述文件中新增 fonts 字段,允许用户定义自定义字体,极大地增强了游戏的视觉定制能力。
  • 字体加载机制: 引擎在初始化阶段会读取 template.json 中的字体配置,并通过动态插入 <style> 标签的方式将自定义字体加载到页面中。
  • 字体选项集成: 自定义字体会被注册到游戏选项中,并优先于默认字体显示。引擎默认会选中列表中的第一个字体作为对话框和UI的默认字体。
  • 字体管理重构: 重构了字体选择和应用逻辑,引入了 useFontFamily hook 和新的 Redux store 状态来统一管理所有可用字体,包括默认字体和自定义字体。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

你好!感谢你对自定义字体功能所做的贡献。这次的 Pull Request 整体结构清晰,通过重构将原先硬编码的字体逻辑替换为从模板动态加载,这是一个很棒的改进。代码在状态管理、UI 组件和核心逻辑上的更新都比较到位。我发现了一些潜在问题,主要涉及初始化时的竞态条件和 CSS 生成的一个小 bug,这些可能会影响功能的稳定性和开发者的使用体验。具体的修改建议请看下面的评论。

logger.info(`WebGAL v${__INFO.version}`);
logger.info('Github: https://github.com/OpenWebGAL/WebGAL ');
logger.info('Made with ❤ by OpenWebGAL');
loadTemplate();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

loadTemplate 是一个异步函数,但在这里它被同步调用(“fire-and-forget”模式)。这可能会导致竞态条件:在 loadTemplate 完成加载模板和字体之前,后续的初始化代码(如 sceneFetcher)可能已经开始执行。如果场景依赖于模板中定义的自定义字体,字体可能无法被正确应用,或导致内容闪烁(FOUT)。为了保证初始化顺序的正确性,建议将 initializeScript 函数修改为 async 函数,并使用 await 等待 loadTemplate 完成。

if (/^(https?:)?\/\//i.test(path) || path.startsWith('data:')) {
return path;
}
const normalized = path.replace(/^[./]+/, '');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

resolveTemplateAssetPath 函数中的路径规范化逻辑 path.replace(/^[./]+/, '') 会将以 ../ 开头的路径(例如 ../fonts/myfont.woff)静默地处理成 fonts/myfont.woff。这可能会让模板制作者感到困惑,因为他们可能期望路径能够回溯到上级目录。虽然这可能是出于安全考虑,将资源限制在模板目录内,但这种隐式行为容易引发错误。建议添加一个警告日志,当检测到路径中包含 .. 时通知用户,以避免意外行为。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants