@@ -13,6 +13,9 @@ import { getStringArgByKey } from '@/Core/util/getSentenceArg';
1313import { nextSentence } from '@/Core/controller/gamePlay/nextSentence' ;
1414import { setStageVar } from '@/store/stageReducer' ;
1515import { getCurrentFontFamily } from '@/hooks/useFontFamily' ;
16+ import { logger } from '@/Core/util/logger' ;
17+ import { tryToRegex } from '@/Core/util/global' ;
18+ import { showGlogalDialog } from '@/UI/GlobalDialog/GlobalDialog' ;
1619
1720/**
1821 * 显示选择枝
@@ -26,6 +29,10 @@ export const getUserInput = (sentence: ISentence): IPerform => {
2629 let buttonText = getStringArgByKey ( sentence , 'buttonText' ) ?? '' ;
2730 buttonText = buttonText === '' ? 'OK' : buttonText ;
2831 const defaultValue = getStringArgByKey ( sentence , 'defaultValue' ) ;
32+ const rule = getStringArgByKey ( sentence , 'rule' ) ;
33+ const ruleFlag = getStringArgByKey ( sentence , 'ruleFlag' ) ;
34+ const ruleText = getStringArgByKey ( sentence , 'ruleText' ) ;
35+ const ruleButtonText = getStringArgByKey ( sentence , 'ruleButtonText' ) ?? 'OK' ;
2936
3037 const font = getCurrentFontFamily ( ) ;
3138
@@ -39,6 +46,20 @@ export const getUserInput = (sentence: ISentence): IPerform => {
3946 onMouseEnter = { playSeEnter }
4047 onClick = { ( ) => {
4148 const userInput : HTMLInputElement = document . getElementById ( 'user-input' ) as HTMLInputElement ;
49+ if ( rule ) {
50+ const reg = tryToRegex ( rule , ruleFlag ) ;
51+ if ( reg && ! reg . test ( userInput . value ) ) {
52+ if ( ruleText )
53+ showGlogalDialog ( {
54+ title : ruleText . replaceAll ( / \$ 0 / g, userInput . value ) ,
55+ leftText : ruleButtonText ,
56+ } ) ;
57+ return ;
58+ }
59+ if ( ! reg ) {
60+ logger . warn ( `getUserInput: rule ${ rule } is not a valid regex` ) ;
61+ }
62+ }
4263 if ( userInput ) {
4364 webgalStore . dispatch (
4465 setStageVar ( {
0 commit comments