Files
Ez2Lazer/osu.Game/LAsEzExtensions/EzLocalTextureFactory.Preload.cs
LA 0b9f9f70d6 主要为代码质量更新
1. 匹配新版按钮控件的自动宽度写法

2. 统一Ez日志写入方向

3.移除历史修改:缓存启用mod列表,切换mod时保持通用mod开启状态

4.代码格式化、

5.修改文件名称表意,更直观
2026-03-12 19:29:55 +08:00

124 lines
4.6 KiB
C#

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Threading.Tasks;
using osu.Framework.Logging;
using osu.Game.LAsEzExtensions.Analysis;
using osu.Game.LAsEzExtensions.Configuration;
namespace osu.Game.LAsEzExtensions
{
public partial class EzLocalTextureFactory
{
#region
private static readonly string[] preload_components =
{
"whitenote", "bluenote", "greennote",
"noteflare", "noteflaregood", "longnoteflare",
};
private static volatile bool isPreloading;
private static volatile bool preloadCompleted;
public async Task PreloadGameTextures()
{
if (preloadCompleted || isPreloading) return;
isPreloading = true;
try
{
string currentNoteSetName = noteSetName.Value;
Logger.Log($"[EzLocalTextureFactory] Starting preload for note set: {currentNoteSetName}", Ez2ConfigManager.LOGGER_NAME, LogLevel.Debug);
foreach (string component in preload_components)
preloadComponent(component, currentNoteSetName);
await Task.CompletedTask.ConfigureAwait(false);
preloadCompleted = true;
Logger.Log($"[EzLocalTextureFactory] Preload completed for {preload_components.Length} components", Ez2ConfigManager.LOGGER_NAME, LogLevel.Debug);
Logger.Log($"[EzLocalTextureFactory] Cache stats after preload: {global_cache.Count} frame sets", Ez2ConfigManager.LOGGER_NAME, LogLevel.Debug);
}
catch (Exception ex)
{
Logger.Log($"[EzLocalTextureFactory] Preload failed: {ex.Message}", Ez2ConfigManager.LOGGER_NAME, LogLevel.Error);
}
finally
{
isPreloading = false;
}
}
private void preloadComponent(string component, string noteSetName)
{
try
{
string cacheKey = $"{noteSetName}_{component}";
if (global_cache.ContainsKey(cacheKey)) return;
var frames = loadNotesFrames(component, noteSetName);
if (frames.Count > 0)
{
var newEntry = new CacheEntry(frames, true);
global_cache.TryAdd(cacheKey, newEntry);
}
}
catch (Exception ex)
{
Logger.Log($"[EzLocalTextureFactory] Failed to preload {component}: {ex.Message}", Ez2ConfigManager.LOGGER_NAME, LogLevel.Error);
}
}
// private async Task preloadStageTextures()
// {
// try
// {
// string currentStageName = stageName.Value;
// Logger.Log($"[EzLocalTextureFactory] Preloading stage textures for: {currentStageName}",
// LoggingTarget.Runtime, LogLevel.Debug);
//
// var stagePaths = new List<string>
// {
// $"Stage/{currentStageName}/Stage/fivekey/Body",
// $"Stage/{currentStageName}/Stage/GrooveLight",
// $"Stage/{currentStageName}/Stage/eightkey/keybase/KeyBase",
// $"Stage/{currentStageName}/Stage/eightkey/keypress/KeyBase",
// $"Stage/{currentStageName}/Stage/eightkey/keypress/KeyPress",
// };
//
// foreach (string path in stagePaths)
// {
// // For stage textures, skip preloading to avoid conflicts with runtime loading
// // var texture = largeTextureStore.Get($"{path}.png");
// // if (texture != null)
// // loadedCount++;
//
// Logger.Log($"[EzLocalTextureFactory] Skipping preload for stage texture {path}",
// LoggingTarget.Runtime, LogLevel.Debug);
//
// // Simulate loading delay if needed
// // await Task.Delay(10).ConfigureAwait(false);
// }
// }
// catch (Exception ex)
// {
// Logger.Log($"[EzLocalTextureFactory] Stage texture preload failed: {ex.Message}",
// LoggingTarget.Runtime, LogLevel.Error);
// }
// }
private void resetPreloadState()
{
preloadCompleted = false;
isPreloading = false;
}
#endregion
}
}