Remove asset browser dependency on sequences.

This commit is contained in:
Paul Chote
2022-12-29 09:17:30 +13:00
committed by Gustas
parent b7cdcf419f
commit b69adb518a

View File

@@ -17,6 +17,7 @@ using System.Linq;
using OpenRA.FileSystem; using OpenRA.FileSystem;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Video; using OpenRA.Video;
using OpenRA.Widgets; using OpenRA.Widgets;
@@ -57,6 +58,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
readonly ScrollPanelWidget assetList; readonly ScrollPanelWidget assetList;
readonly ScrollItemWidget template; readonly ScrollItemWidget template;
readonly Cache<SheetType, SheetBuilder> sheetBuilders;
readonly Cache<string, Sprite[]> spriteCache;
IReadOnlyPackage assetSource = null; IReadOnlyPackage assetSource = null;
bool animateFrames = false; bool animateFrames = false;
@@ -82,6 +86,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public AssetBrowserLogic(Widget widget, Action onExit, ModData modData, WorldRenderer worldRenderer) public AssetBrowserLogic(Widget widget, Action onExit, ModData modData, WorldRenderer worldRenderer)
{ {
sheetBuilders = new Cache<SheetType, SheetBuilder>(t => new SheetBuilder(t));
spriteCache = new Cache<string, Sprite[]>(
filename => FrameLoader.GetFrames(modData.DefaultFileSystem, filename, modData.SpriteLoaders, out _)
.Select(f => sheetBuilders[SheetBuilder.FrameTypeToSheetType(f.Type)].Add(f))
.ToArray());
world = worldRenderer.World; world = worldRenderer.World;
this.modData = modData; this.modData = modData;
panel = widget; panel = widget;
@@ -505,7 +515,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var fileExtension = Path.GetExtension(filename.ToLowerInvariant()); var fileExtension = Path.GetExtension(filename.ToLowerInvariant());
if (allowedSpriteExtensions.Contains(fileExtension)) if (allowedSpriteExtensions.Contains(fileExtension))
{ {
currentSprites = world.Map.Sequences.SpriteCache[prefix + filename]; currentSprites = spriteCache[filename];
currentFrame = 0; currentFrame = 0;
if (frameSlider != null && currentSprites?.Length > 0) if (frameSlider != null && currentSprites?.Length > 0)