-
-
Notifications
You must be signed in to change notification settings - Fork 341
feat: add scene arguments #892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xiaoxustudio
wants to merge
8
commits into
OpenWebGAL:dev
Choose a base branch
from
xiaoxustudio:feat/add-scene-arguments
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ab3f2af
feat: add scene arguments support
xiaoxustudio def6f44
refactor: use EvaluateExpression for variable evaluation
xiaoxustudio a0df80e
chore: remove strIf file
xiaoxustudio abf6243
chore: change the filter function to the find function
xiaoxustudio 12bc1c7
update: upgrade angular-expressions to 1.5.1
xiaoxustudio a185082
fix: phonetic grammar
xiaoxustudio 4457a97
Merge branch 'dev' of https://github.com/OpenWebGAL/WebGAL into feat/…
xiaoxustudio 94a731c
Merge branch 'dev' of https://github.com/OpenWebGAL/WebGAL into feat/…
xiaoxustudio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { webgalStore } from '@/store/store'; | ||
| import { random } from 'lodash'; | ||
| import { WebGAL } from '../WebGAL'; | ||
| import expression from 'angular-expressions'; | ||
| import { logger } from '@/Core/util/logger'; | ||
|
|
||
| // 是否是函数调用 | ||
| export const isFunctionCall = (valExp: string) => { | ||
| return /^\s*[a-zA-Z_$][\w$]*\s*\(.*\)\s*$/.test(valExp); | ||
| }; | ||
|
|
||
| export interface EvaluateExpressionOptions { | ||
| /** | ||
| * 当是无效值 `null | undefined | 报错` 时返回原值还是返回{...}包裹 | ||
| * @default block {...}包裹 | ||
| */ | ||
| InvalidValueReturns?: 'origin' | 'block'; | ||
| /** | ||
| * 当是表达式报错时,是否返回布尔值 | ||
| */ | ||
| ErrorReturnsBoolean?: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * 执行运行时表达式 | ||
| */ | ||
| export const EvaluateExpression = (val: string, options: EvaluateExpressionOptions = {}) => { | ||
| const sceneUrl = WebGAL.sceneManager.sceneData.currentScene.sceneUrl; | ||
| const sceneArguments = webgalStore.getState().stage.sceneArguments; | ||
| const stage = webgalStore.getState().stage; | ||
| const userData = webgalStore.getState().userData; | ||
| const globalVars = userData.globalGameVar; | ||
| const localVars = stage.GameVar; | ||
| const _Merge = { $stage: stage, $userData: userData }; // 不要直接合并到一起,防止可能的键冲突 | ||
| try { | ||
| const instance = expression.compile(val); | ||
| const evalResult = instance({ | ||
| // 注入变量 | ||
| ...globalVars, | ||
| ...localVars, | ||
| ..._Merge, | ||
| // 随机函数 | ||
| random(...args: any[]) { | ||
| return args.length ? random(...args) : Math.random(); | ||
| }, | ||
| // 获取场景调用参数 | ||
| getArg(key: string) { | ||
| const target = sceneArguments[sceneUrl]; | ||
| if (target) { | ||
| return target.filter((item) => item.key === key)[0]?.value ?? null; | ||
| } | ||
| return null; | ||
| }, | ||
| }); | ||
|
|
||
| if ((evalResult === null || evalResult === undefined) && options) { | ||
| switch (options.InvalidValueReturns) { | ||
| case 'block': | ||
| return `{${val}}`; | ||
| case 'origin': | ||
| return val; | ||
| default: | ||
| return evalResult; | ||
| } | ||
| } | ||
|
|
||
| return evalResult; | ||
| } catch { | ||
| logger.warn('EvaluateExpression throw error, expr = ' + val); | ||
| if (options.ErrorReturnsBoolean) { | ||
| return false; | ||
| } | ||
| switch (options.InvalidValueReturns) { | ||
| case 'block': | ||
| return `{${val}}`; | ||
| case 'origin': | ||
| return val; | ||
| default: | ||
| return `{${val}}`; | ||
| } | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.