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

4.5.0 #490

Merged
merged 18 commits into from
May 3, 2024
Merged

4.5.0 #490

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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webgal/base",
"version": "4.4",
"version": "4.5",
"description": "A brand new web Visual Novel engine.",
"repository": "https://github.com/MakinoharaShoko/WebGAL.git",
"author": "Mahiru <[email protected]>",
Expand Down
5 changes: 3 additions & 2 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "webgal-parser",
"version": "4.4.9-fix1",
"version": "4.4.15",
"description": "WebGAL script parser",
"scripts": {
"test": "vitest",
"coverage": "vitest run --coverage",
"build": "rimraf -rf ./build && rollup --config",
"build-ci": "rollup --config",
"debug": "tsx test/debug.ts"
"debug": "tsx test/debug.ts",
"debug-scss-parser": "tsx test/debugCssParser.ts"
},
"types": "./build/types/index.d.ts",
"module": "./build/es/index.js",
Expand Down
3 changes: 2 additions & 1 deletion packages/parser/src/config/scriptConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { commandType } from '../interface/sceneInterface';
import {commandType} from '../interface/sceneInterface';

export const SCRIPT_CONFIG = [
{ scriptString: 'intro', scriptType: commandType.intro },
Expand Down Expand Up @@ -30,6 +30,7 @@ export const SCRIPT_CONFIG = [
{ scriptString: 'setTextbox', scriptType: commandType.setTextbox },
{ scriptString: 'setAnimation', scriptType: commandType.setAnimation },
{ scriptString: 'playEffect', scriptType: commandType.playEffect },
{ scriptString: 'applyStyle', scriptType: commandType.applyStyle },
];
export const ADD_NEXT_ARG_LIST = [
commandType.bgm,
Expand Down
6 changes: 6 additions & 0 deletions packages/parser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { configParser, WebgalConfig } from './configParser/configParser';
import { fileType } from './interface/assets';
import { IAsset } from './interface/sceneInterface';
import { sceneParser } from './sceneParser';
import {IWebGALStyleObj, scss2cssinjsParser} from "./styleParser";

export default class SceneParser {
private readonly SCRIPT_CONFIG_MAP: ConfigMap;
Expand Down Expand Up @@ -67,6 +68,11 @@ export default class SceneParser {
'',
);
}

parseScssToWebgalStyleObj(scssString: string): IWebGALStyleObj{
return scss2cssinjsParser(scssString);
}

}

export { ADD_NEXT_ARG_LIST, SCRIPT_CONFIG };
1 change: 1 addition & 0 deletions packages/parser/src/interface/sceneInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export enum commandType {
setTransform,
setTransition,
getUserInput,
applyStyle
}

/**
Expand Down
39 changes: 39 additions & 0 deletions packages/parser/src/styleParser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export interface IWebGALStyleObj {
classNameStyles: Record<string, string>;
others: string;
}

export function scss2cssinjsParser(scssString: string): IWebGALStyleObj {
const [classNameStyles, others] = parseCSS(scssString);
return {
classNameStyles,
others,
};
}

/**
* GPT 4 写的,临时用,以后要重构!!!
* TODO:用人类智能重构,要是用着一直没问题,也不是不可以 trust AI
* @param css
*/
function parseCSS(css: string): [Record<string, string>, string] {
const result: Record<string, string> = {};
let specialRules = '';
let matches;

// 使用非贪婪匹配,尝试正确处理任意层次的嵌套
const classRegex = /\.([^{\s]+)\s*{((?:[^{}]*|{[^}]*})*)}/g;
const specialRegex = /(@[^{]+{\s*(?:[^{}]*{[^}]*}[^{}]*)+\s*})/g;

while ((matches = classRegex.exec(css)) !== null) {
const key = matches[1];
const value = matches[2].trim().replace(/\s*;\s*/g, ';\n');
result[key] = value;
}

while ((matches = specialRegex.exec(css)) !== null) {
specialRules += matches[1].trim() + '\n';
}

return [result, specialRules.trim()];
}
18 changes: 18 additions & 0 deletions packages/parser/test/debugCssParser.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/debug.scss');
const sceneText = sceneRaw.toString();

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

const configFesult = parser.parseScssToWebgalStyleObj(sceneText)
console.log(configFesult)
}

debug();
64 changes: 64 additions & 0 deletions packages/parser/test/test-resources/debug.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
.Title_main {
width: 100%;
height: 100%;
position: absolute;
z-index: 13;
}

.Title_buttonList {
font-family: "思源宋体", serif;
display: flex;
position: absolute;
left: 0;
min-width: 25%;
height: 100%;
justify-content: center;
align-items: flex-start;
flex-flow: column;
transition: background 0.75s;
padding-left: 120px;
}

.Title_button {
font-weight: bold;
text-align: center;
flex: 0 1 auto;
cursor: pointer;
padding: 1em 2em 1em 2em;
margin: 20px 0;
transition: all 0.33s;
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(5px);
border-radius: 4px;
transform: skewX(-10deg);
background: linear-gradient(to right, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.1));

&:hover {
font-weight: bold;
text-shadow: 0 0 10px rgba(255, 255, 255, 1);
padding: 1em 6em 1em 3em;
}
&:active {
font-weight: bold;
}
}

.Title_button_text {
color: transparent;
background: linear-gradient(135deg, #fdfbfb 0%, #dcddde 100%);
-webkit-background-clip: text;
padding: 0 0.5em 0 0.5em;
font-size: 200%;
font-family: WebgalUI, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
letter-spacing: 0.15em;
}

.Title_backup_background {
width: 100%;
height: 100%;
position: absolute;
z-index: 13;
background: linear-gradient(135deg, #fdfbfb 0%, #dcddde 100%);
}


18 changes: 10 additions & 8 deletions packages/webgal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@
flex-flow: column;
align-items: center ">
<div style="padding: 0 0 0.25em 0">
Powered by <a href="https://github.com/MakinoharaShoko/WebGAL"
onclick="jump(event, 'https://github.com/MakinoharaShoko/WebGAL')">WebGAL</a> Framework
Powered by <a href="https://github.com/OpenWebGAL/WebGAL"
onclick="jump(event, 'https://github.com/OpenWebGAL/WebGAL')">WebGAL</a> Framework
</div>
<div>
Made with ❤ by <a href="https://github.com/MakinoharaShoko"
onclick="jump(event, 'https://github.com/MakinoharaShoko')">Mahiru</a>
Made with ❤ by <a href="https://github.com/OpenWebGAL"
onclick="jump(event, 'https://github.com/OpenWebGAL')">OpenWebGAL</a>
</div>
</div>
</div>
Expand Down Expand Up @@ -186,12 +186,14 @@
};
} else {
// ios
// 创建一个新的 meta 标签
const meta = document.createElement('meta');
meta.name = "viewport";
meta.content = "width=device-width, initial-scale=0.2, minimum-scale=0.01, maximum-scale=1";
// 将该标签添加到 head 中
meta.content = "width=device-width, initial-scale=0.22, minimum-scale=0.01, maximum-scale=1";
document.getElementsByTagName('head')[0].appendChild(meta);
const style = document.createElement('style');
style.type = 'text/css';
style.textContent = '* { font-synthesis: none !important; }';
document.head.appendChild(style);
}

</script>
Expand Down Expand Up @@ -283,4 +285,4 @@
</script>
</body>

</html>
</html>
2 changes: 1 addition & 1 deletion 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.13",
"version": "4.5.0",
"scripts": {
"dev": "vite --host --port 3000",
"build": "cross-env NODE_ENV=production tsc && vite build --base=./",
Expand Down
6 changes: 4 additions & 2 deletions packages/webgal/public/game/animation/shockwaveIn.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[
{
"shockwaveFilter": 0,
"alpha": 0,
"alpha": 1,
"radiusAlphaFilter": 0,
"duration": 0
},
{
"shockwaveFilter": 3,
"shockwaveFilter": 3.05,
"alpha": 1,
"radiusAlphaFilter": 1.05,
"duration": 2000
}
]
2 changes: 1 addition & 1 deletion packages/webgal/public/game/animation/shockwaveOut.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
{
"shockwaveFilter": 3,
"alpha": 0,
"alpha": 1,
"duration": 2000
}
]
Loading
Loading