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

add jacketAsMovie post process #33

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ck2739046
Copy link
Contributor

@ck2739046 ck2739046 commented Feb 11, 2025

Sourcery 总结

新功能:

  • 允许在使用外套作为背景电影之前对其进行后期处理。
Original summary in English

Summary by Sourcery

New Features:

  • Allow post-processing jackets before using them as background movies.

Copy link

sourcery-ai bot commented Feb 11, 2025

Sourcery 评审指南

此 Pull Request 通过引入异步封面后期处理和重构电影加载工作流程来增强 MovieLoader。它添加了新的配置条目、一个专用的异步后期处理方法,并更新了加载电影的逻辑,以处理各种来源(源电影、mp4 电影和封面),并具有适当的错误处理和回退机制。

封面后期处理流程时序图

sequenceDiagram
    participant GM as GetMovie (MovieLoader)
    participant JP as JacketPostProcess (MovieLoader)
    participant FS as FileSystem
    participant CMD as cmd.exe (run.bat process)

    GM->>GM: Check configuration & load jacket
    GM->>JP: Call JacketPostProcess(jacket)
    activate JP
    JP->>FS: Resolve PostProcessorDir
    JP->>FS: Delete old input.png and output.png (if exist)
    JP->>JP: Create render texture & copy jacket
    JP->>FS: Write input.png file
    JP->>FS: Check existence of run.bat
    JP->>CMD: Start process (cmd.exe /c run.bat)
    CMD-->>JP: Process completes (with exit code)
    alt Successful exit (exit code 0)
      JP->>FS: Read output.png
      JP->>JP: Create processed Texture2D
    else Failure
      JP->>JP: Log error and return null
    end
    JP->>FS: Delete input.png and output.png
    deactivate JP
    JP-->>GM: Return processed jacket texture
    GM->>GM: Update movieInfo with processed jacket
Loading

更新后的 MovieLoader 类图

classDiagram
    class MovieLoader {
      <<static>> bool jacketAsMovie
      <<static>> bool jacketPostProcess
      <<static>> readonly string PostProcessorDir
      <<static>> (string, string, Texture2D, string) movieInfo
      <<static>> VideoPlayer[] _videoPlayers

      +async void GetMovie()
      +static void LoadLocalBgaAwake(GameObject ____movieMaskObj, int ___monitorIndex)
      +async Task<Texture2D> JacketPostProcess(Texture2D jacket)
    }

    %% Note: GetMovie calls JacketPostProcess internally
    MovieLoader : +[HarmonyPatch] GetMovie()
    MovieLoader : +[HarmonyPatch] LoadLocalBgaAwake()
Loading

文件级别变更

变更 详情 文件
添加了封面后期处理的配置条目
  • 引入了一个新的配置条目,用于“封面后期处理”,具有双语支持和使用说明。
  • 添加了一个配置条目,用于指定后期处理器目录。
AquaMai.Mods/GameSystem/Assets/MovieLoader.cs
实现了异步封面后期处理
  • 创建了 JacketPostProcess 方法来异步执行图像处理。
  • 利用渲染纹理复制不可读的封面纹理,以便保存为 input.png。
  • 通过执行批处理文件 (run.bat) 触发后期处理,并将输出图像读取为处理后的封面。
  • 处理了文件清理和错误日志记录,以防处理失败或超时。
AquaMai.Mods/GameSystem/Assets/MovieLoader.cs
重构了电影加载工作流程
  • 用新的 GetMovie 方法替换了之前的电影加载逻辑,该方法已修补到 TrackStartProcess.OnStart。
  • 引入了一个 movieInfo 元组来管理不同的电影源状态(源电影、mp4Movie、封面、jacket_processing)。
  • 更新了日志消息和变量命名(使用 musicID 格式)以提高清晰度。
AquaMai.Mods/GameSystem/Assets/MovieLoader.cs
更新了 LoadLocalBgaAwake 中的 BGA 加载
  • 修改了后期处理分支,以处理封面处理失败时的回退。
  • 确保在没有有效的 mp4 或封面图像可用时,生成适当的日志消息。
AquaMai.Mods/GameSystem/Assets/MovieLoader.cs

提示和命令

与 Sourcery 互动

  • 触发新的审查: 在 Pull Request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub Issue: 通过回复审查评论,要求 Sourcery 从该评论创建一个 Issue。您也可以回复审查评论并使用 @sourcery-ai issue 从中创建一个 Issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题中的任何位置写入 @sourcery-ai 以随时生成标题。您也可以在 Pull Request 上评论 @sourcery-ai title 以随时(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 正文中的任何位置写入 @sourcery-ai summary 以随时在您想要的位置生成 PR 摘要。您也可以在 Pull Request 上评论 @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 以触发新的审查!
  • 为 Issue 生成行动计划: 在 Issue 上评论 @sourcery-ai plan 以为其生成行动计划。

自定义您的体验

访问您的 仪表板 以:

  • 启用或禁用审查功能,例如 Sourcery 生成的 Pull Request 摘要、评审指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This pull request enhances the MovieLoader by introducing asynchronous jacket post-processing and refactoring the movie loading workflow. It adds new configuration entries, a dedicated async method for post-processing, and updates the logic in loading movies to handle various sources (source movie, mp4 movie, and jacket) with proper error handling and fallback mechanisms.

Sequence Diagram for Jacket Post-Processing Flow

sequenceDiagram
    participant GM as GetMovie (MovieLoader)
    participant JP as JacketPostProcess (MovieLoader)
    participant FS as FileSystem
    participant CMD as cmd.exe (run.bat process)

    GM->>GM: Check configuration & load jacket
    GM->>JP: Call JacketPostProcess(jacket)
    activate JP
    JP->>FS: Resolve PostProcessorDir
    JP->>FS: Delete old input.png and output.png (if exist)
    JP->>JP: Create render texture & copy jacket
    JP->>FS: Write input.png file
    JP->>FS: Check existence of run.bat
    JP->>CMD: Start process (cmd.exe /c run.bat)
    CMD-->>JP: Process completes (with exit code)
    alt Successful exit (exit code 0)
      JP->>FS: Read output.png
      JP->>JP: Create processed Texture2D
    else Failure
      JP->>JP: Log error and return null
    end
    JP->>FS: Delete input.png and output.png
    deactivate JP
    JP-->>GM: Return processed jacket texture
    GM->>GM: Update movieInfo with processed jacket
Loading

Class Diagram for Updated MovieLoader

classDiagram
    class MovieLoader {
      <<static>> bool jacketAsMovie
      <<static>> bool jacketPostProcess
      <<static>> readonly string PostProcessorDir
      <<static>> (string, string, Texture2D, string) movieInfo
      <<static>> VideoPlayer[] _videoPlayers

      +async void GetMovie()
      +static void LoadLocalBgaAwake(GameObject ____movieMaskObj, int ___monitorIndex)
      +async Task<Texture2D> JacketPostProcess(Texture2D jacket)
    }

    %% Note: GetMovie calls JacketPostProcess internally
    MovieLoader : +[HarmonyPatch] GetMovie()
    MovieLoader : +[HarmonyPatch] LoadLocalBgaAwake()
Loading

File-Level Changes

Change Details Files
Added configuration entries for jacket post-processing
  • Introduced a new config entry for 'jacket post-process' with dual language support and instructions for usage.
  • Added a config entry for specifying the post-processor directory.
AquaMai.Mods/GameSystem/Assets/MovieLoader.cs
Implemented asynchronous jacket post-processing
  • Created the JacketPostProcess method to perform image processing asynchronously.
  • Utilized a render texture to copy non-readable jacket textures for saving as input.png.
  • Triggered the post-process by executing a batch file (run.bat) and read the output image as the processed jacket.
  • Handled file cleanup and error logging in case of processing failures or timeouts.
AquaMai.Mods/GameSystem/Assets/MovieLoader.cs
Refactored movie loading workflow
  • Replaced previous movie loading logic with the new GetMovie method patched to TrackStartProcess.OnStart.
  • Introduced a movieInfo tuple to manage different movie source states (source movie, mp4Movie, jacket, jacket_processing).
  • Updated log messages and variable naming (using musicID format) for clarity.
AquaMai.Mods/GameSystem/Assets/MovieLoader.cs
Updated BGA loading in LoadLocalBgaAwake
  • Modified the post-processing branch to handle fallback when jacket processing fails.
  • Ensured that if neither a valid mp4 nor jacket image is available, an appropriate log message is generated.
AquaMai.Mods/GameSystem/Assets/MovieLoader.cs

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

Copy link

@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 @ck2739046 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding error handling or logging for the case where Singleton<OptionDataManager>.Instance.GetMovieDataPath returns null or an empty string.
  • The movieInfo variable is being reset at the start of GetMovie and then potentially overwritten multiple times; consider simplifying this logic.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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.

public static void LoadLocalBgaAwake(GameObject ____movieMaskObj, int ___monitorIndex)
{
[HarmonyPatch(typeof(TrackStartProcess), "OnStart")]
public static async void GetMovie() {
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Use of async void could mask exceptions and complicate error handling.

Consider changing the signature to return a Task to propagate exceptions properly. If this method must be async void due to Harmony patch requirements, ensure that any exceptions are appropriately caught and handled to prevent unobserved exception issues.

Suggested implementation:

    [HarmonyPostfix]
    [HarmonyPatch(typeof(TrackStartProcess), "OnStart")]
    public static async Task GetMovie() {

Make sure the project has a reference to System.Threading.Tasks (or any equivalent Task framework library) if not already imported.
Also check that Harmony supports async Task for this patch. If Harmony requires an async void method, then consider wrapping the method body in a try-catch to log and handle exceptions.

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.

1 participant