Skip to content
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

在into、choose、textbox上增加对常用的符号转义 #508

Merged
merged 14 commits into from
Jul 3, 2024
Merged
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![WebGAL](https://user-images.githubusercontent.com/30483415/227242979-297ff392-f210-47ef-b0e9-d4788ddc8df0.png)
![WebGAL Slogan](https://github.com/OpenWebGAL/WebGAL/assets/30483415/ede38a39-d054-4fee-a3e9-fc5e764f358d)

### **[English Version](/README_EN.md)** | **[日本語版](/README_JP.md)** | **[한국어](/README_KO.md)** | **[Français](/README_FR.md)**

Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![WebGAL](https://user-images.githubusercontent.com/30483415/227242979-297ff392-f210-47ef-b0e9-d4788ddc8df0.png)
![WebGAL Slogan](https://github.com/OpenWebGAL/WebGAL/assets/30483415/ede38a39-d054-4fee-a3e9-fc5e764f358d)

**[中文版本](/README.md)**

Expand Down
4 changes: 1 addition & 3 deletions README_FR.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Voici la traduction du texte en français :

![WebGAL](https://user-images.githubusercontent.com/30483415/227242979-297ff392-f210-47ef-b0e9-d4788ddc8df0.png)
![WebGAL Slogan](https://github.com/OpenWebGAL/WebGAL/assets/30483415/ede38a39-d054-4fee-a3e9-fc5e764f358d)

**[中文版本](/README.md)**
**[English](/README_EN.md)**
Expand Down
2 changes: 1 addition & 1 deletion README_JP.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![WebGAL](https://user-images.githubusercontent.com/30483415/227242979-297ff392-f210-47ef-b0e9-d4788ddc8df0.png)
![WebGAL Slogan](https://github.com/OpenWebGAL/WebGAL/assets/30483415/ede38a39-d054-4fee-a3e9-fc5e764f358d)

**[中文版本](/README.md)**

Expand Down
2 changes: 1 addition & 1 deletion README_KO.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![WebGAL](https://user-images.githubusercontent.com/30483415/227242979-297ff392-f210-47ef-b0e9-d4788ddc8df0.png)
![WebGAL Slogan](https://github.com/OpenWebGAL/WebGAL/assets/30483415/ede38a39-d054-4fee-a3e9-fc5e764f358d)

**[中文版本](/README.md)**

Expand Down
6 changes: 3 additions & 3 deletions packages/parser/src/scriptParser/contentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export const contentParser = (
};

function getChooseContent(contentRaw: string, assetSetter: any): string {
const chooseList = contentRaw.split('|');
const chooseList = contentRaw.split(/(?<!\\)\|/);
const chooseKeyList: Array<string> = [];
const chooseValueList: Array<string> = [];
for (const e of chooseList) {
chooseKeyList.push(e.split(':')[0] ?? '');
chooseValueList.push(e.split(':')[1] ?? '');
chooseKeyList.push(e.split(/(?<!\\):/)[0] ?? '');
chooseValueList.push(e.split(/(?<!\\):/)[1] ?? '');
}
const parsedChooseList = chooseValueList.map((e) => {
if (e.match(/\./)) {
Expand Down
3 changes: 3 additions & 0 deletions packages/webgal/public/game/scene/demo_escape.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
intro:我会显示出来:\:\,\.\;不信你看看 -hold;
WebGal:我会显示出来:\:\,\.\;不信你看看;
choose:我会显示出来:\:\,\.\;不信你看看;
1 change: 1 addition & 0 deletions packages/webgal/public/game/scene/function_test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
choose:Lip Sync Animation Test:demo_animation.txt | Variable interpolation test:demo_var.txt | Escape test:demo_escape.txt;
2 changes: 1 addition & 1 deletion packages/webgal/public/game/scene/start.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
setVar:heroine=WebGAL;
setVar:egine=WebGAL;
choose:简体中文:demo_zh_cn.txt|日本語:demo_ja.txt|English:demo_en.txt|Lip Sync Animation Test:demo_animation.txt | Variable interpolation test:demo_var.txt;
choose:简体中文:demo_zh_cn.txt|日本語:demo_ja.txt|English:demo_en.txt|Function Test:function_test.txt
10 changes: 5 additions & 5 deletions packages/webgal/src/Core/gameScripts/choose/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PerformController } from '@/Core/Modules/perform/performController';
import { useSEByWebgalStore } from '@/hooks/useSoundEffect';
import { WebGAL } from '@/Core/WebGAL';
import { whenChecker } from '@/Core/controller/gamePlay/scriptExecutor';
import useEscape from '@/hooks/useEscape';
import useApplyStyle from '@/hooks/useApplyStyle';
import { Provider } from 'react-redux';

Expand All @@ -23,8 +24,7 @@ class ChooseOption {
const parts = script.split('->');
const conditonPart = parts.length > 1 ? parts[0] : null;
const mainPart = parts.length > 1 ? parts[1] : parts[0];
const mainPartNodes = mainPart.split(':');

const mainPartNodes = mainPart.split(/(?<!\\):/g);
const option = new ChooseOption(mainPartNodes[0], mainPartNodes[1]);
if (conditonPart !== null) {
const showConditionPart = conditonPart.match(/\((.*)\)/);
Expand All @@ -45,9 +45,9 @@ class ChooseOption {
public enableCondition?: string;

public constructor(text: string, jump: string) {
this.text = text;
this.text = useEscape(text);
this.jump = jump;
this.jumpToScene = jump.match(/\./) !== null;
this.jumpToScene = jump.match(/(?<!\\)\./) !== null;
}
}

Expand All @@ -56,7 +56,7 @@ class ChooseOption {
* @param sentence
*/
export const choose = (sentence: ISentence): IPerform => {
const chooseOptionScripts = sentence.content.split('|');
const chooseOptionScripts = sentence.content.split(/(?<!\\)\|/);
const chooseOptions = chooseOptionScripts.map((e) => ChooseOption.parse(e));

// eslint-disable-next-line react/no-deprecated
Expand Down
4 changes: 3 additions & 1 deletion packages/webgal/src/Core/gameScripts/intro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { nextSentence } from '@/Core/controller/gamePlay/nextSentence';
import { PerformController } from '@/Core/Modules/perform/performController';
import { logger } from '@/Core/util/logger';
import { WebGAL } from '@/Core/WebGAL';
import { replace } from 'lodash';
import useEscape from '@/hooks/useEscape';
/**
* 显示一小段黑屏演示
* @param sentence
Expand Down Expand Up @@ -81,7 +83,7 @@ export const intro = (sentence: ISentence): IPerform => {
width: '100%',
height: '100%',
};
const introArray: Array<string> = sentence.content.split(/\|/);
const introArray: Array<string> = sentence.content.split(/(?<!\\)\|/).map((val: string) => useEscape(val));

let endWait = 1000;
let baseDuration = endWait + delayTime * introArray.length;
Expand Down
3 changes: 2 additions & 1 deletion packages/webgal/src/Stage/TextBox/TextBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { match } from '@/Core/util/match';
import { textSize } from '@/store/userDataInterface';
import IMSSTextbox from '@/Stage/TextBox/IMSSTextbox';
import { SCREEN_CONSTANTS } from '@/Core/util/constants';
import useEscape from '@/hooks/useEscape';

const userAgent = navigator.userAgent;
const isFirefox = /firefox/i.test(userAgent);
Expand Down Expand Up @@ -100,7 +101,7 @@ function isCJK(character: string) {

export function compileSentence(sentence: string, lineLimit: number, ignoreLineLimit?: boolean): EnhancedNode[][] {
// 先拆行
const lines = sentence.split('|');
const lines = sentence.split(/(?<!\\)\|/).map((val: string) => useEscape(val));
// 对每一行进行注音处理
const rubyLines = lines.map((line) => parseString(line));
const nodeLines = rubyLines.map((line) => {
Expand Down
34 changes: 34 additions & 0 deletions packages/webgal/src/hooks/useEscape.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const escapeMap = [
{
reg: /\\\\/g,
val: '\\',
},
{
reg: /\\\|/g,
val: '|',
},
{
reg: /\\:/g,
val: ':',
},
{
reg: /\\,/g,
val: ',',
},
{
reg: /\\;/g,
val: ';',
},
{
reg: /\\./g,
val: '.',
},
];
const useEscape = (val: string): string => {
let _res = val;
for (let i of escapeMap) {
_res = _res.replaceAll(i.reg, i.val);
}
return _res;
};
export default useEscape;
Loading