Skip to content

feat: add scene arguments#892

Open
xiaoxustudio wants to merge 6 commits intoOpenWebGAL:devfrom
xiaoxustudio:feat/add-scene-arguments
Open

feat: add scene arguments#892
xiaoxustudio wants to merge 6 commits intoOpenWebGAL:devfrom
xiaoxustudio:feat/add-scene-arguments

Conversation

@xiaoxustudio
Copy link
Member

@xiaoxustudio xiaoxustudio commented Mar 7, 2026

相关issue: #421

  • callScenechangeScenechoose切换场景时,将会在运行时注入传入的场景参数。

使用getArg获取传入的场景参数。

start.txt:

setVar:heroine=WebGAL;
setVar:egine=WebGAL;
changeScene:ss.txt -egine={egine};

ss.txt:

setVar:a=getArg("egine"); return "WebGAL"
webgal:拿到传入变量:{a} 
  • 此pr还统一了say的content、when的执行表达式逻辑,统一使用EvaluateExpression函数

按理来说js表达式都可以运行,因为是依赖第三方包,比较新的语法可能还未支持

测试脚本如下(测试用例可能会有遗漏,还需测试其他表达式):

setVar:egine=WebGAL;
webgal:拿到egine变量:{egine};
webgal:尝试获取不存在变量,不存在返回{asdasd}原值;
webgal:这个表达式无法运行:{a+asd=+=!ds=/ww},返回原值。;

; when语法的测试
webgal:when字符串正常,我会正常显示 -when="1"=="1";
webgal:when布尔值正常 -when=true;
webgal:when的null无法打印 -when=null;
webgal:when的undefined无法打印 -when=undefined;
webgal:when数字正常 -when=111==111;
webgal:when取反正常 -when=!!true;
webgal:when非运算无法打印,结果应是false -when=~-1;
webgal:when三元可以显示 -when=1==1?true:false
webgal:when空值合并可以显示 -when=null??true

; 支持在变量插值中调用函数
webgal:运行random函数:{random()};


; 支持数组、对象等变量类型,但无法使用他们的方法,后期可增加内置方法
setVar:egine=[1,"xuran",3,4,5,6,7];
webgal:打印数组{egine};
webgal:打印数组{egine[1]},注音语法:『[笑顔](えがお)』なんて、『[笑う](わらう)』なんて、[誰](だれ)でも[出来](でき)るもん…!;
; 对象索引也是可以正常索引的
setVar:egine={a:1,b:"xuran",c:3,d:4,e:5,f:6,g:7};
webgal:索引对象{egine.b}是否是"xuran";

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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!

此拉取请求引入了场景参数功能,允许开发者在调用或切换场景时传递动态数据,从而增强了游戏逻辑的灵活性和交互性。同时,它还通过引入一个统一的表达式评估函数,标准化了系统中变量和条件表达式的处理方式,显著提升了代码的一致性和可维护性。

Highlights

  • 场景参数引入: callScene、changeScene 和 choose 函数现在支持传入场景参数,并在运行时注入。
  • 参数获取: 新增 getArg 函数,允许在场景中获取传入的参数。
  • 统一表达式评估: say 内容和 when 条件的表达式评估逻辑已统一使用新的 EvaluateExpression 函数。
  • 变量设置优化: setVar 函数重构,采用 EvaluateExpression 进行变量值的计算和设置。
Changelog
  • packages/webgal/src/Core/controller/gamePlay/scriptExecutor.ts
    • whenChecker 函数已更新,使用 EvaluateExpression 来评估条件表达式。
    • scriptExecutor 中处理句子内容变量的逻辑已修改,使用 EvaluateExpression 进行值解析。
  • packages/webgal/src/Core/controller/scene/callScene.ts
    • callScene 函数的签名已更新,现在接受一个 args 数组参数。
    • 在调用场景后,传入的场景参数会被存储到 Redux store 中。
  • packages/webgal/src/Core/controller/scene/changeScene.ts
    • changeScene 函数的签名已更新,现在接受一个 args 数组参数。
    • 在切换场景后,传入的场景参数会被存储到 Redux store 中。
  • packages/webgal/src/Core/gameScripts/callSceneScript.ts
    • callSceneScript 函数已更新,将 sentence.args 传递给 callScene。
  • packages/webgal/src/Core/gameScripts/changeSceneScript.ts
    • changeSceneScript 函数已更新,将 sentence.args 传递给 changeScene。
  • packages/webgal/src/Core/gameScripts/choose/index.tsx
    • Choose React 组件的 props 已更新,新增 args 属性。
    • Choose 组件内部调用 changeScene 时,现在会传递 props.args。
  • packages/webgal/src/Core/gameScripts/setVar.ts
    • 移除了旧的表达式评估和变量获取逻辑。
    • 重构了 setVar 函数,使其使用新的 EvaluateExpression 工具函数来处理变量赋值。
  • packages/webgal/src/Core/util/evalSentenceFn.ts
    • 新增文件,定义了 EvaluateExpression 函数,用于统一处理运行时表达式的评估,并提供了 isFunctionCall 工具函数。
  • packages/webgal/src/store/stageInterface.ts
    • 新增了 sceneArguments 属性到 IStageState 接口。
    • 定义了 ISceneArgument 和 ISceneArgumentPayload 接口,用于管理场景参数。
  • packages/webgal/src/store/stageReducer.ts
    • 在 initState 中初始化了 sceneArguments 为空对象。
    • 新增了 addSceneArgument reducer,用于将场景参数添加到 Redux store。
Activity
  • 此拉取请求自创建以来,尚未有评论或评审活动。
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
Contributor

@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

你好,感谢你的贡献。这个 PR 引入了两个很棒的改进:

  1. 场景参数功能:通过 callScenechangeScenechoose 为场景添加了参数传递能力,并提供了 getArg 函数在运行时获取这些参数。这是一个非常有用的新功能。
  2. 表达式评估重构:你将 say 的内容插值和 when 条件的逻辑统一到了新的 EvaluateExpression 函数中。这极大地简化了代码,提高了可维护性和可扩展性,是一个非常出色的重构。

代码整体质量很高。我只在 evalSentenceFn.ts 文件中发现了一个可以小幅优化性能的地方,并给出了建议。请查看我的具体评论。

@xiaoxustudio xiaoxustudio force-pushed the feat/add-scene-arguments branch from 12bc1c7 to ab3f2af Compare March 8, 2026 06:28
@xiaoxustudio
Copy link
Member Author

因为两个改动都涉及到EvaluateExpression,故重构表达式无法独立为新pr

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.

1 participant