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

[+] mp4 movie #3

Merged
merged 8 commits into from
Dec 2, 2024
Merged

[+] mp4 movie #3

merged 8 commits into from
Dec 2, 2024

Conversation

clansty
Copy link
Contributor

@clansty clansty commented Dec 2, 2024

Sourcery总结

引入一个MovieLoader类来管理MP4文件加载,并在找不到.dat文件时使用封面图像作为备用电影。重构IsSectionEnabled方法以改善代码结构,并添加一个新的配置迁移类以进行版本更新。

新功能:

  • 引入一个新的MovieLoader类来处理MP4文件的加载,并在找不到.dat文件时使用封面图像作为电影。

增强:

  • 将ConfigMigration_V2_0_V2_1中的IsSectionEnabled方法重构为ConfigView类的一部分,以更好地组织代码。

杂务:

  • 添加一个新的配置迁移类ConfigMigration_V2_1_V2_2,以处理从版本2.1到2.2的迁移。
Original summary in English

Summary by Sourcery

Introduce a MovieLoader class to manage MP4 file loading and use cover images as fallback movies. Refactor IsSectionEnabled method to improve code structure and add a new configuration migration class for version updates.

New Features:

  • Introduce a new MovieLoader class to handle loading of MP4 files and use cover images as movies when .dat files are not found.

Enhancements:

  • Refactor the IsSectionEnabled method from ConfigMigration_V2_0_V2_1 to be part of the ConfigView class for better code organization.

Chores:

  • Add a new configuration migration class ConfigMigration_V2_1_V2_2 to handle migration from version 2.1 to 2.2.

新功能:

  • 引入一个新的 MovieLoader 类来处理 MP4 文件的加载,并在找不到 .dat 文件时使用封面图像作为电影。

增强:

  • 将 IsSectionEnabled 方法从 ConfigMigration_V2_0_V2_1 重构为 ConfigView 类的一部分,以改善代码组织。

杂务:

  • 添加一个新的配置迁移类 ConfigMigration_V2_1_V2_2,以处理从版本 2.1 到 2.2 的迁移。
Original summary in English

Sourcery总结

引入一个MovieLoader类来管理MP4文件加载,并在找不到.dat文件时使用封面图像作为备用电影。重构IsSectionEnabled方法以改善代码结构,并添加一个新的配置迁移类以进行版本更新。

新功能:

  • 引入一个新的MovieLoader类来处理MP4文件的加载,并在找不到.dat文件时使用封面图像作为电影。

增强:

  • 将ConfigMigration_V2_0_V2_1中的IsSectionEnabled方法重构为ConfigView类的一部分,以更好地组织代码。

杂务:

  • 添加一个新的配置迁移类ConfigMigration_V2_1_V2_2,以处理从版本2.1到2.2的迁移。
Original summary in English

Summary by Sourcery

Introduce a MovieLoader class to manage MP4 file loading and use cover images as fallback movies. Refactor IsSectionEnabled method to improve code structure and add a new configuration migration class for version updates.

New Features:

  • Introduce a new MovieLoader class to handle loading of MP4 files and use cover images as movies when .dat files are not found.

Enhancements:

  • Refactor the IsSectionEnabled method from ConfigMigration_V2_0_V2_1 to be part of the ConfigView class for better code organization.

Chores:

  • Add a new configuration migration class ConfigMigration_V2_1_V2_2 to handle migration from version 2.1 to 2.2.

@clansty clansty requested a review from Menci December 2, 2024 02:40
Copy link

sourcery-ai bot commented Dec 2, 2024

审核者指南 by Sourcery

此 PR 增加了对 MP4 视频播放的支持,并在 .dat 文件不可用时引入了使用封面图像作为电影背景的功能。实现包括一个新的 MovieLoader 类、配置迁移更新和代码组织改进。

新的 MovieLoader 类的类图

Loading
classDiagram
    class MovieLoader {
        - static bool jacketAsMovie
        - static bool loadMp4Movie
        - static string movieAssetsDir
        - static Dictionary<string, string> optionFileMap
        - static VideoPlayer[] _videoPlayers
        + static void LoadMusicPostfix(List<string> ____targetDirs)
        + static void LoadLocalBgaAwake(GameObject ____movieMaskObj, int ___monitorIndex)
        + static void Play(int frame)
        + static void Pause(bool pauseFlag)
        + static void SetSpeed(float speed)
    }

更新后的 ConfigView 和 ConfigMigration 类图

Loading
classDiagram
    class ConfigView {
        + IConfigView Clone()
        + bool IsSectionEnabled(string path)
    }
    class ConfigMigration_V2_0_V2_1 {
        - bool IsSectionEnabled(IConfigView src, string path)
    }
    class ConfigMigration_V2_1_V2_2 {
        + IConfigView Migrate(IConfigView src)
    }
    ConfigMigration_V2_0_V2_1 --> ConfigView : 重构方法
    ConfigMigration_V2_1_V2_2 --> ConfigView : 使用
    ConfigMigration_V2_1_V2_2 --> IConfigView : 实现
    ConfigView --> IConfigView : 实现
    IConfigView : 接口
    IConfigView : + bool IsSectionEnabled(string path)
    IConfigView : + IConfigView Clone()

文件级更改

更改 详情 文件
添加了 MP4 视频播放和封面图像回退支持
  • 创建了 MovieLoader 类以处理 MP4 文件加载
  • 实现了视频播放器初始化和控制方法
  • 添加了 MP4 加载和封面图像回退的配置选项
  • 使用 MaterialOverride 模式设置视频渲染
  • 添加了基本视频控制支持(播放、暂停、速度)
AquaMai.Mods/GameSystem/Assets/MovieLoader.cs
AquaMai.Mods/GameSystem/Assets/UseJacketAsDummyMovie.cs
重构了配置处理并改进了代码组织
  • 将 IsSectionEnabled 方法从 ConfigMigration 移动到 ConfigView 类
  • 更新接口以包含 IsSectionEnabled 方法
  • 将 localAssetsDir 重命名为 imageAssetsDir 以提高清晰度
AquaMai.Config/ConfigView.cs
AquaMai.Config.Interfaces/IConfigView.cs
AquaMai.Config/Migration/ConfigMigration_V2_0_V2_1.cs
AquaMai.Mods/GameSystem/Assets/LoadLocalImages.cs
为版本 2.1 到 2.2 添加了新的配置迁移
  • 创建了 ConfigMigration_V2_1_V2_2 类
  • 为 UseJacketAsDummyMovie 设置添加了迁移逻辑
  • 更新了资产目录的配置路径
  • 将新迁移添加到 ConfigMigrationManager
AquaMai.Config/Migration/ConfigMigration_V2_1_V2_2.cs
AquaMai.Config/Migration/ConfigMigrationManager.cs

提示和命令

与 Sourcery 互动

  • 触发新审核: 在拉取请求上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审核评论。
  • 从审核评论生成 GitHub 问题: 通过回复审核评论请求 Sourcery 创建问题。
  • 生成拉取请求标题: 在拉取请求标题的任何地方写 @sourcery-ai 以随时生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任何地方写 @sourcery-ai summary 以随时生成 PR 摘要。您也可以使用此命令指定摘要应插入的位置。

自定义您的体验

访问您的仪表板以:

  • 启用或禁用审核功能,如 Sourcery 生成的拉取请求摘要、审核者指南等。
  • 更改审核语言。
  • 添加、删除或编辑自定义审核说明。
  • 调整其他审核设置。

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This PR adds support for MP4 video playback and introduces the ability to use jacket images as movie backgrounds when .dat files are not available. The implementation includes a new MovieLoader class, configuration migration updates, and code organization improvements.

Class diagram for the new MovieLoader class

Loading
classDiagram
    class MovieLoader {
        - static bool jacketAsMovie
        - static bool loadMp4Movie
        - static string movieAssetsDir
        - static Dictionary<string, string> optionFileMap
        - static VideoPlayer[] _videoPlayers
        + static void LoadMusicPostfix(List<string> ____targetDirs)
        + static void LoadLocalBgaAwake(GameObject ____movieMaskObj, int ___monitorIndex)
        + static void Play(int frame)
        + static void Pause(bool pauseFlag)
        + static void SetSpeed(float speed)
    }

Updated class diagram for ConfigView and ConfigMigration

Loading
classDiagram
    class ConfigView {
        + IConfigView Clone()
        + bool IsSectionEnabled(string path)
    }
    class ConfigMigration_V2_0_V2_1 {
        - bool IsSectionEnabled(IConfigView src, string path)
    }
    class ConfigMigration_V2_1_V2_2 {
        + IConfigView Migrate(IConfigView src)
    }
    ConfigMigration_V2_0_V2_1 --> ConfigView : refactored method
    ConfigMigration_V2_1_V2_2 --> ConfigView : uses
    ConfigMigration_V2_1_V2_2 --> IConfigView : implements
    ConfigView --> IConfigView : implements
    IConfigView : interface
    IConfigView : + bool IsSectionEnabled(string path)
    IConfigView : + IConfigView Clone()

File-Level Changes

Change Details Files
Added MP4 video playback and jacket image fallback support
  • Created MovieLoader class to handle MP4 file loading
  • Implemented video player initialization and control methods
  • Added configuration options for MP4 loading and jacket image fallback
  • Set up video rendering using MaterialOverride mode
  • Added support for basic video controls (play, pause, speed)
AquaMai.Mods/GameSystem/Assets/MovieLoader.cs
AquaMai.Mods/GameSystem/Assets/UseJacketAsDummyMovie.cs
Refactored configuration handling and improved code organization
  • Moved IsSectionEnabled method from ConfigMigration to ConfigView class
  • Updated interface to include IsSectionEnabled method
  • Renamed localAssetsDir to imageAssetsDir for clarity
AquaMai.Config/ConfigView.cs
AquaMai.Config.Interfaces/IConfigView.cs
AquaMai.Config/Migration/ConfigMigration_V2_0_V2_1.cs
AquaMai.Mods/GameSystem/Assets/LoadLocalImages.cs
Added new configuration migration for version 2.1 to 2.2
  • Created ConfigMigration_V2_1_V2_2 class
  • Added migration logic for UseJacketAsDummyMovie settings
  • Updated configuration paths for asset directories
  • Added new migration to ConfigMigrationManager
AquaMai.Config/Migration/ConfigMigration_V2_1_V2_2.cs
AquaMai.Config/Migration/ConfigMigrationManager.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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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.

@clansty - 我已经审查了你的更改,它们看起来很棒!

这是我在审查期间查看的内容
  • 🟡 一般问题:发现3个问题
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

Sourcery对开源项目免费 - 如果你喜欢我们的审查,请考虑分享它们 ✨
帮助我变得更有用!请在每条评论上点击👍或👎,我将使用反馈来改进你的审查。
Original comment in English

Hey @clansty - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 3 issues 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.

var sprite = movie.GetComponent<SpriteRenderer>();
if (mp4Exists)
{
sprite.material = new Material(Shader.Find("Sprites/Default"));
Copy link

Choose a reason for hiding this comment

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

suggestion (performance): 在每次Initialize调用时创建新的Material实例效率低下

考虑将材质实例缓存为静态字段以避免重复创建。

private static Material _defaultSpriteMaterial;

private void InitializeDefaultMaterial()
{
    if (_defaultSpriteMaterial == null)
    {
        _defaultSpriteMaterial = new Material(Shader.Find("Sprites/Default"));
    }
    sprite.material = _defaultSpriteMaterial;
}
Original comment in English

suggestion (performance): Creating new Material instances on every Initialize call is inefficient

Consider caching the material instance as a static field to avoid repeated creation.

private static Material _defaultSpriteMaterial;

private void InitializeDefaultMaterial()
{
    if (_defaultSpriteMaterial == null)
    {
        _defaultSpriteMaterial = new Material(Shader.Find("Sprites/Default"));
    }
    sprite.material = _defaultSpriteMaterial;
}

@clansty
Copy link
Contributor Author

clansty commented Dec 2, 2024

@sourcery-ai review

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.

@clansty - 我已经审查了你的更改,看起来很棒!

这是我在审查期间查看的内容
  • 🟢 一般问题:一切看起来都很好
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟡 复杂性:发现1个问题
  • 🟢 文档:一切看起来都很好

Sourcery 对开源项目免费 - 如果你喜欢我们的审查,请考虑分享它们 ✨
帮助我变得更有用!请在每条评论上点击 👍 或 👎,我将使用反馈来改进你的审查。
Original comment in English

Hey @clansty - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 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.

}
}

private static VideoPlayer[] _videoPlayers = new VideoPlayer[2];
Copy link

Choose a reason for hiding this comment

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

issue (complexity): 考虑将重复的视频播放器逻辑提取到专注的辅助方法和专用的管理类中

代码可以通过以下方式简化:

  1. 提取视频播放器初始化:

  2. 提取精灵设置:

  3. 用一个简单的管理类替换静态数组来处理播放器操作:

这简化了主流程,消除了重复的空检查,同时保持了所有功能。

Original comment in English

issue (complexity): Consider extracting repeated video player logic into focused helper methods and a dedicated manager class

The code could be simplified by:

  1. Extracting video player initialization:
private VideoPlayer InitializeVideoPlayer(GameObject movieMaskObj, string mp4Path, int monitorIndex) 
{
    if (_videoPlayers[monitorIndex] == null)
    {
        _videoPlayers[monitorIndex] = movieMaskObj.AddComponent<VideoPlayer>();
    }
    var player = _videoPlayers[monitorIndex];
    player.url = mp4Path;
    player.playOnAwake = false;
    player.renderMode = VideoRenderMode.MaterialOverride;
    player.audioOutputMode = VideoAudioOutputMode.None;
    return player;
}
  1. Extracting sprite setup:
private void SetupMovieSprite(Transform movie, VideoPlayer player, Texture2D jacket, bool useVideo)
{
    var sprite = movie.GetComponent<SpriteRenderer>();
    sprite.material = new Material(Shader.Find("Sprites/Default"));

    if (useVideo)
    {
        player.targetMaterialRenderer = sprite;
    }
    else 
    {
        sprite.sprite = Sprite.Create(jacket, new Rect(0, 0, jacket.width, jacket.height), new Vector2(0.5f, 0.5f));
    }
}
  1. Replace static array with a simple manager class to handle player operations:
private class VideoPlayerManager
{
    private readonly VideoPlayer[] _players = new VideoPlayer[2];

    public void SetPlayer(int index, VideoPlayer player) => _players[index] = player;

    public void PlayAll(int frame)
    {
        foreach (var player in _players.Where(p => p != null))
        {
            player.frame = frame;
            player.Play();
        }
    }
    // Similar methods for Pause and SetSpeed
}

This simplifies the main flow and eliminates repeated null checks while maintaining all functionality.

@clansty clansty merged commit 96995fc into main Dec 2, 2024
1 check passed
@clansty
Copy link
Contributor Author

clansty commented Dec 2, 2024

草了,merge commit 了

现在设置成只允许 squash 了

@clansty clansty deleted the feat/mp4-movie branch December 7, 2024 04:41
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.

None yet

1 participant