Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ export const whenChecker = (whenValue: string | undefined): boolean => {
// 先把变量解析出来
const valExpArr = whenValue.split(/([+\-*\/()><!]|>=|<=|==|&&|\|\||!=)/g);
const valExp = valExpArr
.map((e) => {
.map((_e) => {
const e = _e.trim();
if (e.match(/[a-zA-Z]/)) {
if (e.match(/true/) || e.match(/false/)) {
if (e.match(/^(true|false)$/)) {
return e;
}
return getValueFromStateElseKey(e, true);
return getValueFromStateElseKey(e, true, true);
} else return e;
})
.reduce((pre, curr) => pre + curr, '');
Expand Down
6 changes: 5 additions & 1 deletion packages/webgal/src/Core/gameScripts/setVar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function getValueFromState(key: string) {
/**
* 取不到时返回 {key}
*/
export function getValueFromStateElseKey(key: string, useKeyNameAsReturn = false) {
export function getValueFromStateElseKey(key: string, useKeyNameAsReturn = false, quoteString = false) {
const valueFromState = getValueFromState(key);
if (valueFromState === null || valueFromState === undefined) {
logger.warn('valueFromState result null, key = ' + key);
Expand All @@ -134,5 +134,9 @@ export function getValueFromStateElseKey(key: string, useKeyNameAsReturn = false
}
return `{${key}}`;
}
// 用 "" 包裹字符串,用于使用 compile 条件判断,处理字符串类型的变量
if (quoteString && typeof valueFromState === 'string') {
return `"${valueFromState.replaceAll('"', '\\"')}"`;
}
return valueFromState;
}