Skip to content

重构修复谱面的逻辑,支持绿黄谱大号TouchSize#51

Merged
clansty merged 4 commits intoMuNET-OSS:mainfrom
Starrah:fix-chart
Mar 23, 2026
Merged

重构修复谱面的逻辑,支持绿黄谱大号TouchSize#51
clansty merged 4 commits intoMuNET-OSS:mainfrom
Starrah:fix-chart

Conversation

@Starrah
Copy link
Copy Markdown
Contributor

@Starrah Starrah commented Mar 23, 2026

  1. 对“修复不严格符合Simai标准、MaiLib无法解析的谱面”的逻辑进行了重构。
  • 增加了对于Ch[2:1]f或是1h[2:1]xb这种情况的修复支持(之前只能修复1h[2:1]b`,其他字母未支持)。
  • 之前的逻辑存在明显问题,FixChartSimaiSharp中会删除所有的换行符\r和\n,如果在这之后再尝试删除注释的话,由于没有了行尾、注释匹配的区间就会一直延申到谱面末尾。
一个例子:
(120){1}1,1,
// 这是一个注释
2,3,4,5,6,

按之前的逻辑,FixChartSimaiSharp后会变成一行:

(120){1}1,1,// 这是一个注释2,3,4,5,6,

再尝试去除注释的话,就变成了

(120){1}1,1,

注释后面的notes2,3,4,5,6也一块全被干掉了。

  1. 支持对绿谱和黄谱使用大号touchsize L1。
  2. MaiLib有一个转谱bug,对类似1p2p3p4p5p6这种一串p或一串q的星星会触发。那边已经PR了,这里bump MaiLib的版本到我修复后的版本上来。

Summary by Sourcery

优化 Simai 谱面导入与解析逻辑,更好地处理非标准记谱、注释以及触摸大小设置,同时将 MaiLib 更新到固定版本。

New Features:

  • 支持解析并自动修复更多非标准的 Simai 记谱模式,尤其是带方括号节奏并在末尾附带修饰字母的情况。
  • 在导入时,当条件合适时,自动为绿色和黄色的触摸与长按音符应用大型触摸尺寸 L1。

Bug Fixes:

  • 通过在移除注释之前先应用 Simai 修复,并避免不必要的文本规范化,防止注释清理错误地删除有效音符。
  • 通过在 Simai 修复流程中更早地规范化模式,纠正对非飞星记谱的处理。
  • 将 0 级谱面纳入通用导入循环,而不是单独处理,确保各个等级的一致解析行为。

Enhancements:

  • 通过将方括号与修饰符的规范化移动到专门的基于正则表达式的修复步骤中,简化 Simai 记号的后处理过程。
  • 使用单一循环遍历所有难度等级并对被忽略的等级进行显式跳过,从而统一谱面导入过程。
  • 在生成最终谱面输出之前,直接将触摸尺寸调整应用到已解析的 MaiLib 音符上。

Build:

  • 将 MaiLib 子模块/引用升级到一个修复了连续 p/q 模式星星音符转换问题的版本。
Original summary in English

Summary by Sourcery

Refine Simai chart import and parsing to better handle non-standard notation, comments, and touch sizes, while updating MaiLib to a fixed version.

New Features:

  • Support parsing and auto-fixing additional non-standard Simai patterns involving bracketed timing with trailing modifier letters.
  • Automatically apply large touch size L1 to green and yellow touch and hold notes during import when appropriate.

Bug Fixes:

  • Prevent comment removal from stripping valid notes by applying Simai fixes before comment-stripping and avoiding unnecessary text normalization.
  • Correct handling of non-flying star notation by normalizing the pattern earlier in the Simai fix pipeline.
  • Include level-0 charts in the generic import loop instead of handling them separately, ensuring consistent parsing behavior across levels.

Enhancements:

  • Simplify the Simai token post-processing by moving bracket and modifier normalization into a dedicated regex-based fix.
  • Unify chart import iteration over difficulty levels with a single loop and explicit skip for the ignored level.
  • Propagate touch size adjustments directly onto parsed MaiLib notes before composing the final chart output.

Build:

  • Bump the MaiLib submodule/reference to a version that fixes star-note conversion issues for consecutive p/q patterns.

Starrah added 3 commits March 23, 2026 20:14
…没有了行尾、注释匹配的区间就会一直延申到谱面末尾。

例子:
```
(120){1}1,1,
// 这是一个注释
2,3,4,5,6,
```
按之前的逻辑,FixChartSimaiSharp后会变成一行:
```
(120){1}1,1,// 这是一个注释2,3,4,5,6,
```
再尝试去除注释的话,就变成了
```
(120){1}1,1,
```
注释后面的notes`2,3,4,5,6`也一块全被干掉了。
增加了对于`Ch[2:1]f`或是`1h[2:1]xb`这种情况的支持(之前只支持`1h[2:1]b`)。并整合谱面修复的逻辑到一处。另有其他小优化去除冗余代码。
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Mar 23, 2026

审阅者指南

重构 Simai 谱面修复与解析逻辑,以正确处理非标准音符模式和注释,扩展对更多畸形模式和非飞星的支持,在绿/黄谱面上启用大触摸尺寸,调整谱面导入的难度(level) 处理,并将 MaiLib 固定到包含已知转换 bug 修复的版本。

更新后的 Simai 谱面解析与修复顺序图

sequenceDiagram
    actor User
    participant MaidataImportService
    participant SimaiTokenizer
    participant SimaiParser

    User->>MaidataImportService: TryParseChartSimaiSharp(chartText, level, errors)
    activate MaidataImportService

    note over MaidataImportService: 第一轮尝试:仅移除注释后解析
    MaidataImportService->>MaidataImportService: SimaiCommentRegex().Replace(chartText, "")
    MaidataImportService->>MaidataImportService: SimaiCommentRegex2().Replace(chartText, "")
    MaidataImportService->>SimaiTokenizer: TokensFromText(chartText_without_comments)
    SimaiTokenizer-->>MaidataImportService: tokens1
    MaidataImportService->>SimaiParser: ChartOfToken(tokens1)
    SimaiParser-->>MaidataImportService: maiLibChart1
    MaidataImportService-->>User: maiLibChart1
    deactivate MaidataImportService

    rect rgb(235, 235, 235)
    note over MaidataImportService,SimaiParser: 如果第一次解析抛出异常,则运行回退修复逻辑
    end

    User->>MaidataImportService: TryParseChartSimaiSharp(chartText, level, errors) fallback
    activate MaidataImportService
    MaidataImportService->>MaidataImportService: FixChartSimaiSharp(chartText)
    note over MaidataImportService: 应用 SimaiError1-6 正则修复
    MaidataImportService->>SimaiTokenizer: TokensFromText(fixed_chart)
    SimaiTokenizer-->>MaidataImportService: tokens2
    MaidataImportService->>SimaiParser: ChartOfToken(tokens2)
    SimaiParser-->>MaidataImportService: maiLibChart2
    MaidataImportService->>MaidataImportService: errors.Add(ImportChartMessage)
    MaidataImportService-->>User: maiLibChart2
    deactivate MaidataImportService
Loading

更新后的 MaidataImportService 及相关类型类图

classDiagram
    class MaidataImportService {
        +ImportChartResult ImportMaidata(Dictionary~string,string~ maiData, bool isUtage, bool debug)
        -MaiChart TryParseChartSimaiSharp(string chartText, int level, List~ImportChartMessage~ errors)
        -string FixChartSimaiSharp(string chart)
        -static string Add1Bar(string maidata, float bpm)
        -static Dictionary~int,AllChartsEntry~ allCharts
        -GeneratedRegex SimaiCommentRegex()
        -GeneratedRegex SimaiCommentRegex2()
        -GeneratedRegex SimaiError1()
        -GeneratedRegex SimaiError2()
        -GeneratedRegex SimaiError3()
        -GeneratedRegex SimaiError4()
        -GeneratedRegex SimaiError5()
        -GeneratedRegex SimaiError6()
    }

    class AllChartsEntry {
        +string originalText
        +MaiChart simaiSharpChart
        +AllChartsEntry(string originalText, MaiChart simaiSharpChart)
    }

    class MaiChart {
        +List~Note~ Notes
        +string Compose(ChartEnum_ChartVersion version)
    }

    class Note {
        +NoteEnum_NoteType NoteType
        +string TouchSize
    }

    class ImportChartResult {
        +List~ImportChartMessage~ messages
        +bool success
    }

    class ImportChartMessage {
        +string message
        +MessageLevel level
    }

    class SimaiTokenizer {
        +string[] TokensFromText(string text)
    }

    class SimaiParser {
        +MaiChart ChartOfToken(string[] tokens)
    }

    class ChartEnum_ChartVersion {
    }

    class NoteEnum_NoteType {
        <<enumeration>>
        TTP
        THO
    }

    MaidataImportService --> AllChartsEntry : uses
    MaidataImportService --> SimaiTokenizer : tokenizes
    MaidataImportService --> SimaiParser : parses
    MaidataImportService --> ImportChartResult : returns
    MaiChart "1" --> "*" Note : contains
    ImportChartResult "1" --> "*" ImportChartMessage : aggregates
    Note --> NoteEnum_NoteType : typed
    MaiChart --> ChartEnum_ChartVersion : composes with version
Loading

更新后的 MaidataImportService.ImportMaidata 流程图

flowchart TD
    A[Start ImportMaidata] --> B[构建 allCharts 字典
针对关卡 level i=0..8
跳过 i==1]
    B --> C[对每个非空 inote_i
调用 TryParseChartSimaiSharp]
    C --> D[计算谱面补白
并在需要时调用 Add1Bar]
    D --> E[遍历 allCharts 中的谱面]
    E --> F[判定 isUtage]
    F --> G[从 targetLevelMap
查找 targetLevel]
    G --> H{isUtage?}
    H -- yes --> I[将 targetLevel 设为 0]
    H -- no --> J[保持映射后的 targetLevel]
    I --> K[计算 touchSizeBig = !isUtage 且 level 在 2,3]
    J --> K
    K --> L[加载对应 level 的 maiLibChart]
    L --> M{touchSizeBig?}
    M -- yes --> N[遍历 maiLibChart.Notes
若 NoteType 为 TTP 或 THO
则设 TouchSize = L1]
    M -- no --> O[保持音符不变]
    N --> P[以 Ma2_104 版本输出谱面]
    O --> P
    P --> Q[写入谱面文件和元数据]
    Q --> R[完成所有 level]
    R --> S[返回 ImportChartResult]
Loading

文件级改动

Change Details Files
重构 Simai 注释剥离与错误修复流水线,避免误删合法音符,并支持更多畸形模式。
  • 新增 SimaiError6 正则,用于规范修正规则字母出现在带括号节奏块之后的模式,将其转换为标准顺序
  • 在 FixChartSimaiSharp 内部应用 SimaiError6 替换和非飞星规范化,而不是在分词之后再处理
  • 修改 TryParseChartSimaiSharp,使其在第一次解析尝试时对原始谱面文本进行注释剥离,同时保留换行
  • 移除第二轮注释剥离和对 "]b" 模式的手动分词修补,改为完全依赖 FixChartSimaiSharp 的转换
MaiChartManager/Services/MaidataImportService.cs
调整谱面导入映射,并为特定难度启用大触摸尺寸。
  • 将 inote 遍历改为通过单一循环覆盖 level 0–8,并显式跳过 level 1,而不是单独处理 level 0
  • 引入 touchSizeBig 标志,对绿谱和黄谱(非 Utage 时的 level 2 和 3)启用,并在开启时对 TTP 和 THO 音符设置 TouchSize="L1"
  • 确保 targetLevel 映射在应用触摸尺寸变更前,正确处理被忽略的等级和 Utage 映射
MaiChartManager/Services/MaidataImportService.cs
更新 MaiLib 依赖以包含上游的 p/q 星转换 bug 修复。
  • 将 MaiLib 子模块或引用升级到包含连续 p/q 星模式(如 "1p2p3p4p5p6")修复的版本
MaiLib

技巧与命令

与 Sourcery 交互

  • 触发新的代码审查: 在 Pull Request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub Issue: 在审查评论下回复,要求 Sourcery 用该评论创建 issue。你也可以直接回复 @sourcery-ai issue 来从该评论创建 issue。
  • 生成 Pull Request 标题: 在 PR 标题的任意位置写上 @sourcery-ai 以随时生成标题。也可以在 PR 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 摘要: 在 PR 描述正文的任意位置写上 @sourcery-ai summary,在你需要的位置生成 PR 摘要。也可以在 PR 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 Pull Request 中评论 @sourcery-ai guide 来(重新)生成审阅者指南。
  • 批量解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,以标记所有 Sourcery 评论为已解决。如果你已经处理完所有评论且不希望再看到它们,这会很方便。
  • 撤销所有 Sourcery 审查: 在 Pull Request 中评论 @sourcery-ai dismiss 以撤销所有现有的 Sourcery 审查。若你希望从一次全新的审查开始特别有用——别忘了随后再评论 @sourcery-ai review 触发新的审查!

自定义你的体验

访问你的 控制面板 以:

  • 启用或禁用审查功能,例如 Sourcery 生成的 PR 摘要、审阅者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查指令。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

Refactors Simai chart fixing and parsing to correctly handle non-standard note patterns and comments, expands support for additional malformed patterns and non-flying stars, enables large touch size on green/yellow charts, adjusts chart import level handling, and bumps MaiLib to a fixed version for a known conversion bug.

Sequence diagram for updated Simai chart parsing and fixing

sequenceDiagram
    actor User
    participant MaidataImportService
    participant SimaiTokenizer
    participant SimaiParser

    User->>MaidataImportService: TryParseChartSimaiSharp(chartText, level, errors)
    activate MaidataImportService

    note over MaidataImportService: First attempt: parse after removing comments only
    MaidataImportService->>MaidataImportService: SimaiCommentRegex().Replace(chartText, "")
    MaidataImportService->>MaidataImportService: SimaiCommentRegex2().Replace(chartText, "")
    MaidataImportService->>SimaiTokenizer: TokensFromText(chartText_without_comments)
    SimaiTokenizer-->>MaidataImportService: tokens1
    MaidataImportService->>SimaiParser: ChartOfToken(tokens1)
    SimaiParser-->>MaidataImportService: maiLibChart1
    MaidataImportService-->>User: maiLibChart1
    deactivate MaidataImportService

    rect rgb(235, 235, 235)
    note over MaidataImportService,SimaiParser: If first parse throws exception, run fallback fix logic
    end

    User->>MaidataImportService: TryParseChartSimaiSharp(chartText, level, errors) fallback
    activate MaidataImportService
    MaidataImportService->>MaidataImportService: FixChartSimaiSharp(chartText)
    note over MaidataImportService: Applies SimaiError1-6 regex fixes
    MaidataImportService->>SimaiTokenizer: TokensFromText(fixed_chart)
    SimaiTokenizer-->>MaidataImportService: tokens2
    MaidataImportService->>SimaiParser: ChartOfToken(tokens2)
    SimaiParser-->>MaidataImportService: maiLibChart2
    MaidataImportService->>MaidataImportService: errors.Add(ImportChartMessage)
    MaidataImportService-->>User: maiLibChart2
    deactivate MaidataImportService
Loading

Updated class diagram for MaidataImportService and related types

classDiagram
    class MaidataImportService {
        +ImportChartResult ImportMaidata(Dictionary~string,string~ maiData, bool isUtage, bool debug)
        -MaiChart TryParseChartSimaiSharp(string chartText, int level, List~ImportChartMessage~ errors)
        -string FixChartSimaiSharp(string chart)
        -static string Add1Bar(string maidata, float bpm)
        -static Dictionary~int,AllChartsEntry~ allCharts
        -GeneratedRegex SimaiCommentRegex()
        -GeneratedRegex SimaiCommentRegex2()
        -GeneratedRegex SimaiError1()
        -GeneratedRegex SimaiError2()
        -GeneratedRegex SimaiError3()
        -GeneratedRegex SimaiError4()
        -GeneratedRegex SimaiError5()
        -GeneratedRegex SimaiError6()
    }

    class AllChartsEntry {
        +string originalText
        +MaiChart simaiSharpChart
        +AllChartsEntry(string originalText, MaiChart simaiSharpChart)
    }

    class MaiChart {
        +List~Note~ Notes
        +string Compose(ChartEnum_ChartVersion version)
    }

    class Note {
        +NoteEnum_NoteType NoteType
        +string TouchSize
    }

    class ImportChartResult {
        +List~ImportChartMessage~ messages
        +bool success
    }

    class ImportChartMessage {
        +string message
        +MessageLevel level
    }

    class SimaiTokenizer {
        +string[] TokensFromText(string text)
    }

    class SimaiParser {
        +MaiChart ChartOfToken(string[] tokens)
    }

    class ChartEnum_ChartVersion {
    }

    class NoteEnum_NoteType {
        <<enumeration>>
        TTP
        THO
    }

    MaidataImportService --> AllChartsEntry : uses
    MaidataImportService --> SimaiTokenizer : tokenizes
    MaidataImportService --> SimaiParser : parses
    MaidataImportService --> ImportChartResult : returns
    MaiChart "1" --> "*" Note : contains
    ImportChartResult "1" --> "*" ImportChartMessage : aggregates
    Note --> NoteEnum_NoteType : typed
    MaiChart --> ChartEnum_ChartVersion : composes with version
Loading

Flow diagram for updated MaidataImportService.ImportMaidata logic

flowchart TD
    A[Start ImportMaidata] --> B[Build allCharts dictionary
for levels i=0..8
skip i==1]
    B --> C[TryParseChartSimaiSharp for each
non empty inote_i]
    C --> D[CalcChartPadding and
Add1Bar if needed]
    D --> E[Iterate charts in allCharts]
    E --> F[Determine isUtage]
    F --> G[Lookup targetLevel from
targetLevelMap]
    G --> H{isUtage?}
    H -- yes --> I[Set targetLevel = 0]
    H -- no --> J[Keep mapped targetLevel]
    I --> K[Compute touchSizeBig = !isUtage and level in 2,3]
    J --> K
    K --> L[Load maiLibChart for level]
    L --> M{touchSizeBig?}
    M -- yes --> N[For each note in maiLibChart.Notes
if NoteType is TTP or THO
set TouchSize = L1]
    M -- no --> O[Leave notes unchanged]
    N --> P[Compose chart to Ma2_104]
    O --> P
    P --> Q[Write chart file and metadata]
    Q --> R[Finish all levels]
    R --> S[Return ImportChartResult]
Loading

File-Level Changes

Change Details Files
Refactor Simai comment stripping and error-fix pipeline to avoid removing legitimate notes and support more malformed patterns.
  • Add SimaiError6 regex to normalize patterns where the modifier letters follow the bracketed timing block, converting them into standard order
  • Apply SimaiError6 replacement and non-flying star normalization inside FixChartSimaiSharp instead of after tokenization
  • Change TryParseChartSimaiSharp to strip comments on the raw chart text in the first parse attempt, leaving newlines intact
  • Remove secondary pass comment stripping and manual token fix-up for "]b" patterns, relying instead on FixChartSimaiSharp transformations
MaiChartManager/Services/MaidataImportService.cs
Adjust chart import mapping and enable large touch size for specific difficulties.
  • Change inote iteration to cover levels 0–8 in a single loop while explicitly skipping level 1 instead of handling level 0 separately
  • Introduce touchSizeBig flag for green and yellow charts (levels 2 and 3 when not Utage) and set TouchSize="L1" for TTP and THO notes when enabled
  • Ensure targetLevel mapping respects ignored levels and Utage mapping before applying touch size changes
MaiChartManager/Services/MaidataImportService.cs
Update MaiLib dependency to include upstream fix for p/q star conversion bug.
  • Bump MaiLib submodule or reference to a version that contains the fix for continuous p/q star patterns like "1p2p3p4p5p6"
MaiLib

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

本次拉取请求主要致力于提升Simai谱面解析和修复的健壮性与准确性。通过重构核心修复逻辑,解决了多种不标准格式的兼容性问题以及因注释处理不当导致的数据丢失风险。此外,还引入了针对特定难度谱面的视觉优化,并更新了关键依赖库以修复已知的解析缺陷,从而全面提升了谱面导入和处理的质量。

Highlights

  • Simai谱面修复逻辑重构: 重构了Simai谱面修复逻辑,增强了对不符合Simai标准格式的谱面(如Ch[2:1]f或1h[2:1]xb)的兼容性,并解决了之前注释删除逻辑导致的谱面数据丢失问题。
  • 绿谱和黄谱支持大号触摸区域: 为绿谱和黄谱增加了使用大号触摸区域(L1)的支持,优化了特定难度谱面的视觉表现。
  • MaiLib版本更新: 更新了MaiLib子项目版本,以包含对星形音符(如1p2p3p4p5p6)解析错误的修复。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@Starrah Starrah changed the title Fix chart 重构修复谱面的逻辑,支持绿黄谱大号TouchSize Mar 23, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次拉取请求对Simai谱面解析逻辑进行了重构和修复,解决了非标准格式的解析问题,并优化了注释处理逻辑。同时,增加了对绿谱和黄谱使用大号touchsize L1的支持,并更新了MaiLib子模块以修复已知bug。这些改进提高了谱面导入的兼容性和准确性。

Comment thread MaiChartManager/Services/MaidataImportService.cs
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了 1 个问题,并提供了一些整体性的反馈:

  • TryParseChartSimaiSharp 中,你在第一次解析前通过去除注释来修改了 chartText,因此后备调用 FixChartSimaiSharp(chartText) 时已经拿不到原始的原始文本;建议使用一个单独的局部变量(例如 var normalizedText = ...),这样第二次尝试就能按照预期基于未修改的输入运行。
  • 在对绿谱/黄谱应用 TouchSize = "L1" 时,你现在会覆盖 TTP/THO 音符上已有的触碰大小;如果谱面本身可以指定触碰大小,那么只在 TouchSize 为 null/空时才设置为 L1 可能会更安全。
  • ImportMaidata 中的循环 for (var i = 0; i < 9; i++) { if (i == 1) continue; ... } 略微不直观;可以考虑改为遍历一个明确列出的支持等级列表(例如 new[]{0,2,3,4,5,6,7,8}),让预期范围更加清晰。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `TryParseChartSimaiSharp`, you mutate `chartText` when stripping comments before the first parse, so the fallback `FixChartSimaiSharp(chartText)` no longer sees the original raw text; consider using a separate local (e.g. `var normalizedText = ...`) so the second attempt operates on the unmodified input as intended.
- When applying `TouchSize = "L1"` for green/yellow charts, you currently overwrite any existing touch size on TTP/THO notes; if charts can specify explicit touch sizes, it might be safer to only set `L1` when `TouchSize` is null/empty.
- The loop `for (var i = 0; i < 9; i++) { if (i == 1) continue; ... }` in `ImportMaidata` is a bit non-obvious; consider iterating over an explicit list of supported levels (e.g. `new[]{0,2,3,4,5,6,7,8}`) to make the intended range clearer.

## Individual Comments

### Comment 1
<location path="MaiChartManager/Services/MaidataImportService.cs" line_range="329-331" />
<code_context>

         var allCharts = new Dictionary<int, AllChartsEntry>();
-        for (var i = 2; i < 9; i++)
+        for (var i = 0; i < 9; i++)
         {
+            if (i == 1) continue;
             if (!string.IsNullOrWhiteSpace(maiData.GetValueOrDefault($"inote_{i}")))
             {
</code_context>
<issue_to_address>
**question (bug_risk):** Changing the inote iteration range changes insertion order in `allCharts`, which may affect downstream logic relying on dictionary iteration order.

Previously `allCharts` inserted `inote_2..8` first and `inote_0` last; now it inserts `0..8` (skipping `1`) in numeric order. Since .NET `Dictionary` preserves insertion order when iterating `Values`, this will change the sequence passed into `CalcChartPadding(allCharts.Values.Select(...))`. Please confirm that `CalcChartPadding` (and any callers) are order‑independent; if not, consider explicitly sorting by level at the call site or enforcing the required order when building `allCharts`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据这些反馈改进后续的审查。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • In TryParseChartSimaiSharp, you mutate chartText when stripping comments before the first parse, so the fallback FixChartSimaiSharp(chartText) no longer sees the original raw text; consider using a separate local (e.g. var normalizedText = ...) so the second attempt operates on the unmodified input as intended.
  • When applying TouchSize = "L1" for green/yellow charts, you currently overwrite any existing touch size on TTP/THO notes; if charts can specify explicit touch sizes, it might be safer to only set L1 when TouchSize is null/empty.
  • The loop for (var i = 0; i < 9; i++) { if (i == 1) continue; ... } in ImportMaidata is a bit non-obvious; consider iterating over an explicit list of supported levels (e.g. new[]{0,2,3,4,5,6,7,8}) to make the intended range clearer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `TryParseChartSimaiSharp`, you mutate `chartText` when stripping comments before the first parse, so the fallback `FixChartSimaiSharp(chartText)` no longer sees the original raw text; consider using a separate local (e.g. `var normalizedText = ...`) so the second attempt operates on the unmodified input as intended.
- When applying `TouchSize = "L1"` for green/yellow charts, you currently overwrite any existing touch size on TTP/THO notes; if charts can specify explicit touch sizes, it might be safer to only set `L1` when `TouchSize` is null/empty.
- The loop `for (var i = 0; i < 9; i++) { if (i == 1) continue; ... }` in `ImportMaidata` is a bit non-obvious; consider iterating over an explicit list of supported levels (e.g. `new[]{0,2,3,4,5,6,7,8}`) to make the intended range clearer.

## Individual Comments

### Comment 1
<location path="MaiChartManager/Services/MaidataImportService.cs" line_range="329-331" />
<code_context>

         var allCharts = new Dictionary<int, AllChartsEntry>();
-        for (var i = 2; i < 9; i++)
+        for (var i = 0; i < 9; i++)
         {
+            if (i == 1) continue;
             if (!string.IsNullOrWhiteSpace(maiData.GetValueOrDefault($"inote_{i}")))
             {
</code_context>
<issue_to_address>
**question (bug_risk):** Changing the inote iteration range changes insertion order in `allCharts`, which may affect downstream logic relying on dictionary iteration order.

Previously `allCharts` inserted `inote_2..8` first and `inote_0` last; now it inserts `0..8` (skipping `1`) in numeric order. Since .NET `Dictionary` preserves insertion order when iterating `Values`, this will change the sequence passed into `CalcChartPadding(allCharts.Values.Select(...))`. Please confirm that `CalcChartPadding` (and any callers) are order‑independent; if not, consider explicitly sorting by level at the call site or enforcing the required order when building `allCharts`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread MaiChartManager/Services/MaidataImportService.cs
Comment thread MaiChartManager/Services/MaidataImportService.cs Outdated
@clansty clansty merged commit dff96cb into MuNET-OSS:main Mar 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants