Skip to content

Commit 6faf573

Browse files
Merge pull request #939 from OpenWebGAL/dev
4.5.20
2 parents a360054 + a58b13f commit 6faf573

67 files changed

Lines changed: 1176 additions & 410 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,56 @@ on:
55
tags:
66
- '*.*'
77

8+
permissions:
9+
contents: write
10+
811
jobs:
12+
build-webgal-static-webpage:
13+
name: Build WebGAL Static Webpage
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
with:
19+
persist-credentials: false
20+
21+
- name: Setup Node.js environment
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version-file: package.json
25+
cache: 'yarn'
26+
27+
- name: Install
28+
run: npm install yarn -g && yarn install
29+
30+
- name: Build
31+
run: yarn build
32+
33+
- name: Package WebGAL Engine Web
34+
run: |
35+
cd packages/webgal/dist
36+
zip -r "$GITHUB_WORKSPACE/webgal-engine-web.zip" .
37+
38+
- name: Upload WebGAL Engine Artifact
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: webgal-engine-web
42+
path: webgal-engine-web.zip
43+
if-no-files-found: error
44+
945
release:
1046
name: Release
1147
runs-on: ubuntu-latest
48+
needs: build-webgal-static-webpage
1249
steps:
1350
- name: Checkout
1451
uses: actions/checkout@v2
1552

53+
- name: Download WebGAL Engine Artifact
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: webgal-engine-web
57+
1658
- name: Create Release
1759
id: create_release
1860
uses: actions/create-release@v1
@@ -24,3 +66,13 @@ jobs:
2466
body_path: releasenote.md
2567
draft: true
2668
prerelease: false
69+
70+
- name: Upload WebGAL Engine Web
71+
uses: actions/upload-release-asset@v1
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
with:
75+
upload_url: ${{ steps.create_release.outputs.upload_url }}
76+
asset_path: webgal-engine-web.zip
77+
asset_name: WebGAL-${{ github.ref_name }}-web.zip
78+
asset_content_type: application/zip

packages/parser/rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default [
4040
tsconfigOverride: {
4141
compilerOptions: {
4242
sourceMap: !isProd,
43+
rootDir: "src",
4344
declarationDir: "build/cjs"
4445
}, include: ["src"]
4546
}
@@ -61,6 +62,7 @@ export default [
6162
tsconfigOverride: {
6263
compilerOptions: {
6364
sourceMap: !isProd,
65+
rootDir: "src",
6466
declarationDir: "build/types"
6567
}, include: ["src"]
6668
}

packages/parser/src/sceneParser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ export const sceneParser = (
3838
let assetsList: Array<IAsset> = []; // 场景资源列表
3939
let subSceneList: Array<string> = []; // 子场景列表
4040
const sentenceList: Array<ISentence> = rawSentenceListWithoutEmpty.map(
41-
(sentence) => {
41+
(sentence, index) => {
4242
const returnSentence: ISentence = scriptParser(
4343
sentence,
4444
assetSetter,
4545
ADD_NEXT_ARG_LIST,
4646
SCRIPT_CONFIG_MAP,
47+
index,
4748
);
4849
// 在这里解析出语句可能携带的资源和场景,合并到 assetsList 和 subSceneList
4950
assetsList = [...assetsList, ...returnSentence.sentenceAssets];

packages/parser/src/scriptParser/assetsScanner.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const assetsScanner = (
1212
command: commandType,
1313
content: string,
1414
args: Array<arg>,
15+
lineNumber: number,
1516
): Array<IAsset> => {
1617
let hasVocalArg = false;
1718
const returnAssetsList: Array<IAsset> = [];
@@ -22,7 +23,7 @@ export const assetsScanner = (
2223
returnAssetsList.push({
2324
name: e.value as string,
2425
url: e.value as string,
25-
lineNumber: 0,
26+
lineNumber,
2627
type: fileType.vocal,
2728
});
2829
}
@@ -36,39 +37,39 @@ export const assetsScanner = (
3637
returnAssetsList.push({
3738
name: content,
3839
url: content,
39-
lineNumber: 0,
40+
lineNumber,
4041
type: fileType.background,
4142
});
4243
}
4344
if (command === commandType.changeFigure) {
4445
returnAssetsList.push({
4546
name: content,
4647
url: content,
47-
lineNumber: 0,
48+
lineNumber,
4849
type: fileType.figure,
4950
});
5051
}
5152
if (command === commandType.miniAvatar) {
5253
returnAssetsList.push({
5354
name: content,
5455
url: content,
55-
lineNumber: 0,
56+
lineNumber,
5657
type: fileType.figure,
5758
});
5859
}
5960
if (command === commandType.video) {
6061
returnAssetsList.push({
6162
name: content,
6263
url: content,
63-
lineNumber: 0,
64+
lineNumber,
6465
type: fileType.video,
6566
});
6667
}
6768
if (command === commandType.bgm) {
6869
returnAssetsList.push({
6970
name: content,
7071
url: content,
71-
lineNumber: 0,
72+
lineNumber,
7273
type: fileType.bgm,
7374
});
7475
}

packages/parser/src/scriptParser/scriptParser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const scriptParser = (
2424
assetSetter: any,
2525
ADD_NEXT_ARG_LIST: commandType[],
2626
SCRIPT_CONFIG_MAP: ConfigMap,
27+
lineNumber = 0,
2728
): ISentence => {
2829
let command: commandType; // 默认为对话
2930
let content: string; // 语句内容
@@ -105,7 +106,7 @@ export const scriptParser = (
105106
}
106107

107108
content = contentParser(newSentenceRaw.trim(), command, assetSetter); // 将语句内容里的文件名转为相对或绝对路径
108-
sentenceAssets = assetsScanner(command, content, args); // 扫描语句携带资源
109+
sentenceAssets = assetsScanner(command, content, args, lineNumber); // 扫描语句携带资源
109110
subScene = subSceneScanner(command, content); // 扫描语句携带子场景
110111
return {
111112
command: command, // 语句类型

packages/parser/test/parser.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test("args", async () => {
4949
{ key: "left", value: true },
5050
{ key: "next", value: true }
5151
],
52-
sentenceAssets: [{ name: "m2.png", url: 'm2.png', type: fileType.figure, lineNumber: 0 }],
52+
sentenceAssets: [{ name: "m2.png", url: 'm2.png', type: fileType.figure, lineNumber: 24 }],
5353
subScene: [],
5454
inlineComment: ""
5555
};

packages/webgal/index.html

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,68 @@
320320
<script>
321321
(() => {
322322
const isIOS = window.__WEBGAL_DEVICE_INFO__?.isIOS ?? false;
323-
if ('serviceWorker' in navigator && !isIOS) {
324-
navigator.serviceWorker
325-
.register('./webgal-serviceworker.js')
326-
.then((reg) => {
327-
console.log('Registration succeeded. Scope is ' + reg.scope);
328-
})
329-
.catch((error) => {
330-
console.log('Registration failed with ' + error);
331-
});
323+
const localHostnames = ['localhost', '127.0.0.1', '::1'];
324+
const isLocalPreview = localHostnames.includes(window.location.hostname) || window.location.protocol === 'file:';
325+
const isElectron = Boolean(window.electronFuncs) || /Electron/i.test(navigator.userAgent || '');
326+
const shouldBypassServiceWorker = isIOS || isLocalPreview || isElectron;
327+
const webgalServiceWorkerUrl = new URL('./webgal-serviceworker.js', window.location.href).href;
328+
const bypassReloadKey = 'webgal-sw-bypass-reloaded';
329+
const isWebGALRegistration = (registration) => {
330+
const workers = [registration.active, registration.installing, registration.waiting];
331+
return workers.some((worker) => worker?.scriptURL === webgalServiceWorkerUrl);
332+
};
333+
const markBypassReload = () => {
334+
try {
335+
if (sessionStorage.getItem(bypassReloadKey) === 'true') {
336+
return false;
337+
}
338+
sessionStorage.setItem(bypassReloadKey, 'true');
339+
return true;
340+
} catch {
341+
return false;
342+
}
343+
};
344+
const clearBypassReloadMark = () => {
345+
try {
346+
sessionStorage.removeItem(bypassReloadKey);
347+
} catch {}
348+
};
349+
const clearWebGALServiceWorker = async () => {
350+
try {
351+
const registrations = await navigator.serviceWorker.getRegistrations();
352+
const webgalRegistrations = registrations.filter(isWebGALRegistration);
353+
const hasWebGALController = navigator.serviceWorker.controller?.scriptURL === webgalServiceWorkerUrl;
354+
await Promise.all(webgalRegistrations.map((registration) => registration.unregister()));
355+
if ('caches' in window) {
356+
const cacheKeys = await caches.keys();
357+
await Promise.all(cacheKeys.filter((key) => key.startsWith('webgal-')).map((key) => caches.delete(key)));
358+
}
359+
if ((webgalRegistrations.length > 0 || hasWebGALController) && navigator.serviceWorker.controller && markBypassReload()) {
360+
window.location.reload();
361+
}
362+
} catch (error) {
363+
console.warn('Failed to clear WebGAL Service Worker cache', error);
364+
}
365+
};
366+
if (!('serviceWorker' in navigator)) {
367+
return;
368+
}
369+
if (shouldBypassServiceWorker) {
370+
clearWebGALServiceWorker();
371+
return;
332372
}
373+
if (!window.isSecureContext) {
374+
return;
375+
}
376+
clearBypassReloadMark();
377+
navigator.serviceWorker
378+
.register('./webgal-serviceworker.js')
379+
.then((reg) => {
380+
console.log('Registration succeeded. Scope is ' + reg.scope);
381+
})
382+
.catch((error) => {
383+
console.log('Registration failed with ' + error);
384+
});
333385
})();
334386
</script>
335387
<!-- 首屏加载 -->

packages/webgal/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webgal-engine",
3-
"version": "4.5.19",
3+
"version": "4.5.20",
44
"scripts": {
55
"dev": "vite --host --port 3000",
66
"build": "node scripts/update-engine-version.js && cross-env NODE_ENV=production tsc && vite build --base=./",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
changeBg:WebGalEnter.webp -next;
2+
changeFigure:stand.webp -id=figure01 -transform={"position":{"x":1000,"y":720}};
3+
;演示setAnimation平行执行
4+
setAnimation:shockwaveIn -target=figure01 -next
5+
setAnimation:move-front-and-back -target=figure01 -parallel
6+
;演示通过-continue接续执行两个常规setTransform正常运作、不被打断
7+
setTransform:{"position":{"x":-1000}} -duration=5000 -target=figure01 -continue
8+
setTransform:{"position":{"x":1000}} -duration=5000 -target=figure01
9+
;演示setTransform平行执行
10+
setTransform:{"position":{"x":-1000},"scale":{"x":0.5},"contrast":0.5} -duration=5000 -target=figure01 -ease=easeOut -next -keep
11+
wait:2000
12+
setTransform:{"position":{"y":0},"scale":{"y":0.5},"saturation":0} -duration=5000 -target=figure01 -ease=linear -parallel -continue
13+
setTransform:{"position":{"y":-720},"scale":{"y":1},"saturation":1} -duration=5000 -target=figure01 -ease=linear -next
14+
setTransform:{"position":{"x":1000},"scale":{"x":1},"contrast":1} -duration=5000 -target=figure01 -ease=easeIn -parallel;
15+
;演示参数解耦改动后setTempAnimation普通运作是否正常
16+
setTempAnimation:[{"duration":0}, {"duration":500,"position":{"x":-1000}}, {"duration":500,"position":{"y":720},"scale":{"y":0.5},"saturation":0}, {"duration":500,"position":{"x":-1000, "y":720}}, {"duration":500}, {"duration":500,"position":{"x":-1000},"scale":{"x":0.5},"contrast":0.5}] -target=figure01
17+
setTempAnimation:[{"duration":0}, {"duration":500,"position":{"x":1000}}, {"duration":500,"position":{"y":720}}, {"duration":500,"position":{"x":1000, "y":720}}, {"duration":500}, {"duration":500,"position":{"x":1000}}] -target=figure01
18+
;演示参数解耦改动后setTransform的-writeDefault参数是否运作正常
19+
setTransform:{} -writeDefault -target=figure01 -duration=500
20+
setTransform:{"position":{"x":1000,"y":720}} -target=figure01 -next;
21+
setAnimation:shockwaveOut -target=figure01 -parallel
22+
;演示setTempAnimation平行执行
23+
setTempAnimation:[{"duration":0},{"position":{"x":-1000},"scale":{"x":0.5},"contrast":0.5,"duration":5000,"ease":"easeOut"},{"position":{"x":-1000},"scale":{"x":0.5},"contrast":0.5,"duration":2000},{"position":{"x":600},"scale":{"x":1},"contrast":1,"duration":5000,"ease":"easeIn"},{"duration":2000}] -target=figure01 -next;
24+
setTempAnimation:[{"duration":2000},{"position":{"y":0},"scale":{"y":0.5},"saturation":0,"duration":5000,"ease":"linear"},{"position":{"y":-720},"scale":{"y":1},"saturation":1,"duration":5000,"ease":"linear"},{"duration":2000}] -target=figure01 -parallel -continue;
25+
;演示并行执行多条终止时间点不一致的setTransform
26+
setTransform:{"position":{"x":-1000}} -duration=5000 -next -target=figure01;
27+
setTransform:{"position":{"y":0}} -duration=3000 -parallel -target=figure01;
28+
setTransform:{"position":{"x":1000}} -duration=3000 -next -target=figure01;
29+
setTransform:{"position":{"y":-720}} -duration=5000 -parallel -target=figure01;
30+
changeBg: -next;
31+
changeFigure: -id=figure01

packages/webgal/public/game/template/Stage/TextBox/textbox.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,7 @@
176176
.text {
177177
overflow: hidden;
178178
}
179+
180+
.read {
181+
color: #C0C0C0;
182+
}

0 commit comments

Comments
 (0)