Conversation
- 新增 webgal-engine.json 引擎描述文件,包含引擎元数据 - 新增 update-engine-version.js 脚本,自动同步版本号 - 修改构建流程,在构建前自动更新引擎描述文件版本 - 为第三方工具提供标准化的引擎识别和版本管理支持
fix: supplement transform interface
fix: remove animation before set effect
Fix safari problem
fix: fast button state error
feat: 添加 WebGAL 引擎描述文件规范实现
Refresh UI
feat: add rules argument for getUserInput
fix: add skin support
…est-v3 Chore/align webgal engine manifest v3
Deploying webgal-dev with
|
| Latest commit: |
9df6af2
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a71da497.webgal-dev.pages.dev |
There was a problem hiding this comment.
Code Review
This pull request updates the WebGAL engine to version 4.5.19, introducing significant UI refinements, improved iOS/Safari support, and a refactored Service Worker for better asset caching. New features include regex validation for user input, Spine skin support, and additional visual filters. The code review identifies opportunities to improve event handling by using addEventListener instead of onkeydown, optimize animation removal logic to avoid O(n^2) complexity, and prevent potential string replacement bugs in user input dialogs by using a function-based replacement in replaceAll.
| document.onkeydown = (e) => { | ||
| if (e && e.key === 'F11') { | ||
| setTimeout(() => { | ||
| scheduleResize(); | ||
| }, 100); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Assigning to document.onkeydown overwrites any existing keydown handlers. It is generally better practice to use addEventListener to allow multiple listeners to coexist without interference.
| document.onkeydown = (e) => { | |
| if (e && e.key === 'F11') { | |
| setTimeout(() => { | |
| scheduleResize(); | |
| }, 100); | |
| } | |
| }; | |
| document.addEventListener('keydown', (e) => { | |
| if (e && e.key === 'F11') { | |
| setTimeout(() => { | |
| scheduleResize(); | |
| }, 100); | |
| } | |
| }); |
| public removeAnimationByTargetKey(targetKey: string) { | ||
| let index = this.stageAnimations.findIndex((e) => e.targetKey === targetKey); | ||
| while (index !== -1) { | ||
| this.removeAnimationByIndex(index); | ||
| index = this.stageAnimations.findIndex((e) => e.targetKey === targetKey); | ||
| } | ||
| } |
There was a problem hiding this comment.
The current implementation of removeAnimationByTargetKey is inefficient because it repeatedly calls findIndex from the start of the array within a while loop, resulting in removeAnimationByIndex) is performed.
| public removeAnimationByTargetKey(targetKey: string) { | |
| let index = this.stageAnimations.findIndex((e) => e.targetKey === targetKey); | |
| while (index !== -1) { | |
| this.removeAnimationByIndex(index); | |
| index = this.stageAnimations.findIndex((e) => e.targetKey === targetKey); | |
| } | |
| } | |
| public removeAnimationByTargetKey(targetKey: string) { | |
| for (let i = this.stageAnimations.length - 1; i >= 0; i--) { | |
| if (this.stageAnimations[i].targetKey === targetKey) { | |
| this.removeAnimationByIndex(i); | |
| } | |
| } | |
| } |
| if (reg && !reg.test(userInput.value)) { | ||
| if (ruleText) | ||
| showGlogalDialog({ | ||
| title: ruleText.replaceAll(/\$0/g, userInput.value), |
There was a problem hiding this comment.
Using a string as the second argument to replaceAll can lead to unexpected behavior if the user input contains special replacement patterns (e.g., $&, $$, $1). For example, if a user enters $&, it might result in the literal $0 being inserted instead of the user's actual input. Using a function as the second argument ensures the input is treated as a literal string.
| title: ruleText.replaceAll(/\$0/g, userInput.value), | |
| title: ruleText.replaceAll(/\$0/g, () => userInput.value), |
No description provided.