Split AssetBrowser supported formats
Splitting them from one array into separate allows us to then reliably pick how each asset should be presented. Also lets us unhardcode some checks like "if file is .vxl ... else is sprite".
This commit is contained in:
committed by
Matthias Mailänder
parent
8ac2815c9e
commit
a058b1f5bd
@@ -15,7 +15,8 @@ namespace OpenRA
|
||||
{
|
||||
public class AssetBrowser : IGlobalModData
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
public readonly string[] SupportedExtensions = Array.Empty<string>();
|
||||
public readonly string[] SpriteExtensions = Array.Empty<string>();
|
||||
public readonly string[] ModelExtensions = Array.Empty<string>();
|
||||
public readonly string[] VideoExtensions = Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
public class AssetBrowserLogic : ChromeLogic
|
||||
{
|
||||
readonly string[] allowedExtensions;
|
||||
readonly string[] allowedSpriteExtensions;
|
||||
readonly string[] allowedModelExtensions;
|
||||
readonly string[] allowedVideoExtensions;
|
||||
readonly IEnumerable<IReadOnlyPackage> acceptablePackages;
|
||||
readonly string[] palettes;
|
||||
readonly World world;
|
||||
@@ -283,7 +286,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
|
||||
var assetBrowserModData = modData.Manifest.Get<AssetBrowser>();
|
||||
allowedExtensions = assetBrowserModData.SupportedExtensions;
|
||||
allowedSpriteExtensions = assetBrowserModData.SpriteExtensions;
|
||||
allowedModelExtensions = assetBrowserModData.ModelExtensions;
|
||||
allowedVideoExtensions = assetBrowserModData.VideoExtensions;
|
||||
allowedExtensions = allowedSpriteExtensions
|
||||
.Union(allowedModelExtensions)
|
||||
.Union(allowedVideoExtensions)
|
||||
.ToArray();
|
||||
|
||||
acceptablePackages = modData.ModFiles.MountedPackages.Where(p =>
|
||||
p.Contents.Any(c => allowedExtensions.Contains(Path.GetExtension(c).ToLowerInvariant())));
|
||||
@@ -397,30 +406,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
prefix += "|";
|
||||
}
|
||||
|
||||
var video = VideoLoader.GetVideo(Game.ModData.DefaultFileSystem.Open(filename), Game.ModData.VideoLoaders);
|
||||
if (video != null)
|
||||
{
|
||||
player = panel.Get<VideoPlayerWidget>("PLAYER");
|
||||
player.Load(prefix + filename);
|
||||
player.DrawOverlay = false;
|
||||
isVideoLoaded = true;
|
||||
|
||||
if (frameSlider != null)
|
||||
{
|
||||
frameSlider.MaximumValue = (float)player.Video.Frames - 1;
|
||||
frameSlider.Ticks = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Path.GetExtension(filename.ToLowerInvariant()) == ".vxl")
|
||||
{
|
||||
var voxelName = Path.GetFileNameWithoutExtension(filename);
|
||||
currentVoxel = world.ModelCache.GetModel(voxelName);
|
||||
currentSprites = null;
|
||||
}
|
||||
else
|
||||
var fileExtension = Path.GetExtension(filename.ToLowerInvariant());
|
||||
if (allowedSpriteExtensions.Contains(fileExtension))
|
||||
{
|
||||
currentSprites = world.Map.Rules.Sequences.SpriteCache[prefix + filename];
|
||||
currentFrame = 0;
|
||||
@@ -433,6 +420,32 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
currentVoxel = null;
|
||||
}
|
||||
else if (allowedModelExtensions.Contains(fileExtension))
|
||||
{
|
||||
var voxelName = Path.GetFileNameWithoutExtension(filename);
|
||||
currentVoxel = world.ModelCache.GetModel(voxelName);
|
||||
currentSprites = null;
|
||||
}
|
||||
else if (allowedVideoExtensions.Contains(fileExtension))
|
||||
{
|
||||
var video = VideoLoader.GetVideo(Game.ModData.DefaultFileSystem.Open(filename), Game.ModData.VideoLoaders);
|
||||
if (video != null)
|
||||
{
|
||||
|
||||
player = panel.Get<VideoPlayerWidget>("PLAYER");
|
||||
player.Load(prefix + filename);
|
||||
player.DrawOverlay = false;
|
||||
isVideoLoaded = true;
|
||||
|
||||
if (frameSlider != null)
|
||||
{
|
||||
frameSlider.MaximumValue = (float)player.Video.Frames - 1;
|
||||
frameSlider.Ticks = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -239,7 +239,8 @@ SpriteSequenceFormat: ClassicTilesetSpecificSpriteSequence
|
||||
ModelSequenceFormat: PlaceholderModelSequence
|
||||
|
||||
AssetBrowser:
|
||||
SupportedExtensions: .shp, .tem, .des, .sno, .jun, .vqa, .wsa
|
||||
SpriteExtensions: .shp, .tem, .des, .sno, .jun
|
||||
VideoExtensions: .vqa, .wsa
|
||||
|
||||
GameSpeeds:
|
||||
DefaultSpeed: default
|
||||
|
||||
@@ -214,7 +214,8 @@ SpriteSequenceFormat: DefaultSpriteSequence
|
||||
ModelSequenceFormat: PlaceholderModelSequence
|
||||
|
||||
AssetBrowser:
|
||||
SupportedExtensions: .shp, .r8, .vqa
|
||||
SpriteExtensions: .shp, .r8
|
||||
VideoExtensions: .vqa
|
||||
|
||||
GameSpeeds:
|
||||
DefaultSpeed: default
|
||||
|
||||
@@ -244,7 +244,8 @@ SpriteSequenceFormat: ClassicTilesetSpecificSpriteSequence
|
||||
ModelSequenceFormat: PlaceholderModelSequence
|
||||
|
||||
AssetBrowser:
|
||||
SupportedExtensions: .shp, .tmp, .tem, .des, .sno, .int, .vqa, .wsa
|
||||
SpriteExtensions: .shp, .tmp, .tem, .des, .sno, .int
|
||||
VideoExtensions: .vqa, .wsa
|
||||
|
||||
GameSpeeds:
|
||||
DefaultSpeed: default
|
||||
|
||||
@@ -272,7 +272,9 @@ SpriteSequenceFormat: TilesetSpecificSpriteSequence
|
||||
ModelSequenceFormat: VoxelModelSequence
|
||||
|
||||
AssetBrowser:
|
||||
SupportedExtensions: .shp, .tem, .sno, .vqa, .vxl
|
||||
SpriteExtensions: .shp, .tem, .sno
|
||||
ModelExtensions: .vxl
|
||||
VideoExtensions: .vqa
|
||||
|
||||
GameSpeeds:
|
||||
DefaultSpeed: default
|
||||
|
||||
Reference in New Issue
Block a user