Skip to content

Commit

Permalink
Merge pull request #300 from MakinoharaShoko/dev
Browse files Browse the repository at this point in the history
fix parser
  • Loading branch information
MakinoharaShoko authored Jul 14, 2023
2 parents 4a6525d + ea46192 commit 38ffa10
Show file tree
Hide file tree
Showing 16 changed files with 340 additions and 18 deletions.
8 changes: 5 additions & 3 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "webgal-parser",
"version": "4.3.13-10",
"version": "4.4.2",
"description": "WebGAL script parser",
"scripts": {
"test": "vitest",
"coverage": "vitest run --coverage",
"build": "rimraf -rf ./build && rollup --config"
"build": "rimraf -rf ./build && rollup --config",
"debug": "tsx test/debug.ts"
},
"types": "./build/types/index.d.ts",
"module": "./build/es/index.js",
Expand All @@ -15,7 +16,8 @@
"dependencies": {
"chevrotain": "^10.5.0",
"cloudlogjs": "^1.0.11",
"lodash": "^4.17.21"
"lodash": "^4.17.21",
"tsx": "^3.12.7"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^23.0.2",
Expand Down
5 changes: 3 additions & 2 deletions packages/parser/src/scriptParser/argsParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export function argsParser(argsRaw: string, assetSetter: (fileName: string, asse
return e !== "";
});
rawArgsList.forEach((e) => {
const argName = e.split("=")[0];
const argValue = e.split("=")[1];
const equalSignIndex = e.indexOf('=');
const argName = e.slice(0, equalSignIndex);
const argValue = e.slice(equalSignIndex + 1);
// 判断是不是语音参数
if (e.match(/.ogg|.mp3|.wav/)) {
returnArrayList.push({
Expand Down
18 changes: 18 additions & 0 deletions packages/parser/test/debug.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as fsp from "fs/promises";
import SceneParser, {ADD_NEXT_ARG_LIST, SCRIPT_CONFIG} from "../src";


async function debug() {
const sceneRaw = await fsp.readFile('test/test-resources/var.txt');
const sceneText = sceneRaw.toString();

const parser = new SceneParser((assetList) => {
}, (fileName, assetType) => {
return fileName;
}, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);

const result = parser.parse(sceneText, "var", "/var.txt");
console.log(result)
}

debug();
22 changes: 22 additions & 0 deletions packages/parser/test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,25 @@ test("long-script", async () => {
};
expect(result.sentenceList).toContainEqual(expectSentenceItem);
});

test("var", async () => {

const sceneRaw = await fsp.readFile('test/test-resources/var.txt');
const sceneText = sceneRaw.toString();

const parser = new SceneParser((assetList) => {
}, (fileName, assetType) => {
return fileName;
}, ADD_NEXT_ARG_LIST, SCRIPT_CONFIG);

const result = parser.parse(sceneText, "var", "/var.txt");
const expectSentenceItem: ISentence = {
command: commandType.say,
commandRaw: "WebGAL",
content: "a=1?",
args: [{key:'speaker',value:'WebGAL'},{key:'when',value:"a==1"}],
sentenceAssets: [],
subScene: []
};
expect(result.sentenceList).toContainEqual(expectSentenceItem);
});
2 changes: 2 additions & 0 deletions packages/parser/test/test-resources/var.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
setVar:a=1;
WebGAL:a=1? -when=a==1;
6 changes: 6 additions & 0 deletions packages/webgal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@
if (target) {
target.dispatchEvent(event);
}
if(event){
const logo = document.getElementById("logo_target");
if(logo){
logo.style.display= "contents";
}
}
});

function jump(event, url) {
Expand Down
4 changes: 2 additions & 2 deletions packages/webgal/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "webgal",
"private": true,
"version": "4.4.1",
"version": "4.4.2",
"scripts": {
"dev": "vite --host --port 3000",
"build": "cross-env NODE_ENV=production tsc && vite build --base=./",
Expand Down Expand Up @@ -29,7 +29,7 @@
"sass": "^1.49.9",
"uuid": "^9.0.0",
"vite-plugin-package-version": "^1.0.2",
"webgal-parser": "4.3.13-5"
"webgal-parser": "4.4.2"
},
"devDependencies": {
"@types/lodash": "^4.14.180",
Expand Down
2 changes: 2 additions & 0 deletions packages/webgal/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Title from './Components/UI/Title/Title';
import Logo from './Components/UI/Logo/Logo';
import { useEffect } from 'react';
import { initializeScript } from './Core/initializeScript';
import Menu from './Components/UI/Menu/Menu';
Expand Down Expand Up @@ -29,6 +30,7 @@ function App() {
<BottomControlPanelFilm />
<Backlog />
<Title />
{/* <Logo /> */}
<Extra />
<Menu />
<GlobalDialog />
Expand Down
38 changes: 38 additions & 0 deletions packages/webgal/src/Components/UI/Logo/Logo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { FC } from 'react';
import styles from './logo.module.scss';
import { useSelector } from 'react-redux';
import { RootState } from '@/store/store';
/**
* 标识
* @constructor
*/
const Logo: FC = () => {
const GUIState = useSelector((state: RootState) => state.GUI);
const logoImage = GUIState.logoImage;
const logoList = logoImage.split(' ');

const logo = logoList.map((logo,index)=>
<li
key = {index}
className={styles.Logo_main}
style={{
backgroundImage: `url("${logo}")`,
animationDelay: `${index*1.5}s`,
}}
></li>
);

return (
<>
{GUIState.showTitle && (
<div id = "logo_target" className={styles.Logo_target}>
<ul>
{logo}
</ul>
</div>
)}
</>
);
};

export default Logo;
32 changes: 32 additions & 0 deletions packages/webgal/src/Components/UI/Logo/logo.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.Logo_target {
display: none;
}
.Logo_main {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
animation: change-img-anim 2.5s infinite;
background-size: cover;
animation-iteration-count: 1;
animation-direction: alternate;
}
@keyframes change-img-anim {
0%{
opacity: 0;
z-index: 14;
}
10%{
opacity: 1;
}
90%{
opacity: 1;
}
100%{
opacity: 0;
z-index: 14;
}
}
14 changes: 14 additions & 0 deletions packages/webgal/src/Core/util/coreInitialFunction/infoFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getStorage } from '../../controller/storage/storageController';
import { webgalStore } from '@/store/store';
import { setGuiAsset } from '@/store/GUIReducer';
import { setEbg } from '@/Core/util/setEbg';
import { setLogo } from '@/Core/util/setLogo';
import { WebGAL } from '@/main';
import { initKey } from '@/Core/controller/storage/fastSaveLoad';

Expand Down Expand Up @@ -34,6 +35,19 @@ export const infoFetcher = (url: string) => {
dispatch(setGuiAsset({ asset: 'titleBg', value: url }));
setEbg(url);
}
if (e[0] === 'LogoImage') {
const logoList:any = e[1].split(' ');
let urlList = "";
for(let i = 0; i < logoList.length; i++){
let url: string = assetSetter(logoList[i], fileType.background);
if(i + 1 == logoList.length){
urlList += url;
} else {
urlList += url + ' ';
}
}
dispatch(setGuiAsset({ asset: 'logoImage' , value: urlList}));
}
// 设置标题背景音乐
if (e[0] === 'Title_bgm') {
const url: string = assetSetter(e[1], fileType.bgm);
Expand Down
6 changes: 6 additions & 0 deletions packages/webgal/src/Core/util/setLogo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function setLogo(logoName :string , url: string ) {
const logoImage = document.getElementById('logoImage');
if (logoImage) {
logoImage.style.backgroundImage = `url("${url}")`;
}
}
2 changes: 1 addition & 1 deletion packages/webgal/src/config/info.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const __INFO = {
version: 'WebGAL 4.4.1',
version: 'WebGAL 4.4.2',
contributors: [
{ username: 'Mahiru', link: 'https://github.com/MakinoharaShoko' },
{ username: 'Hoshinokinya', link: 'https://github.com/hshqwq' },
Expand Down
1 change: 1 addition & 0 deletions packages/webgal/src/store/GUIReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const initState: IGuiState = {
currentMenuTag: MenuPanelTag.Option,
titleBg: '',
titleBgm: '',
logoImage: '',
showExtra: false,
showGlobalDialog: false,
showPanicOverlay: false,
Expand Down
5 changes: 3 additions & 2 deletions packages/webgal/src/store/guiInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ export interface IGuiState {
showBacklog: boolean;
titleBgm: string; // 标题背景音乐
titleBg: string; // 标题背景图片
logoImage: string;
showExtra: boolean;
showGlobalDialog: boolean;
showPanicOverlay: boolean;
}

export type componentsVisibility = Pick<IGuiState, Exclude<keyof IGuiState, 'currentMenuTag' | 'titleBg' | 'titleBgm'>>;
export type componentsVisibility = Pick<IGuiState, Exclude<keyof IGuiState, 'currentMenuTag' | 'titleBg' | 'titleBgm' | 'logoImage' >>;
// 标题资源
export type GuiAsset = Pick<IGuiState, 'titleBgm' | 'titleBg'>;
export type GuiAsset = Pick<IGuiState, 'titleBgm' | 'titleBg' | 'logoImage' >;

export interface IGuiStore {
GuiState: IGuiState;
Expand Down
Loading

0 comments on commit 38ffa10

Please sign in to comment.