JD2022-TU1/main/tools/apps/Packager/Tasks/CookOnlineTexturesTask.cs

73 lines
No EOL
2.4 KiB
C#

using System;
using System.ComponentModel;
using System.IO;
using JD.Asset.Types.Map;
using JD.Core.ProjectManaging;
using Packager.Parameters;
namespace Packager.Tasks
{
[DisplayName("Cook Online Textures")]
[Description("Takes all the texture files in the Menu art folder and generate their equivalent .ckd files")]
public class CookOnlineTexturesTask : Task
{
[Input("Map List", IOCardinality.Multi, IOType.File)]
public ReferenceList FileList { get; set; }
[Output("Online textures", IOType.File)]
public ReferenceList Onlinetextures = new ReferenceList();
public CookOnlineTexturesTask()
{
FileList = new ReferenceList();
}
public override bool NeedCooker { get { return true; } }
protected override void StartInternal(BuildConfiguration profile, cookerWrapper cooker)
{
foreach (var file in FileList)
{
if (file.EndsWith(".tga", StringComparison.OrdinalIgnoreCase))
{
CookTexture(profile, cooker, file);
}
else
{
var map = Map.FromPath(file);
foreach (var texture in Directory.GetFiles(map.MenuArtTexturesFolder, "*.tga", SearchOption.AllDirectories))
{
CookTexture(profile, cooker, texture);
}
}
}
}
private void CookTexture(BuildConfiguration _profile, cookerWrapper _cooker, string texture)
{
var platform = _profile.GetPlatform();
var normalizedFilepath = DataPath.GetRelativePath(texture);
string cookedFileName = "";
_cooker.getCookedNamePlatform(normalizedFilepath, platform, ref cookedFileName);
cookedFileName = DataPath.GetAbsolutePath(cookedFileName);
// Force to recook the texture for now, .... this can be removed later.
if (File.Exists(cookedFileName))
{
File.Delete(cookedFileName);
}
// Use config means use temporary config.
if (!_cooker.cookTexture(platform, normalizedFilepath, useConfig: false))
{
LogMessage(true, $"Texture {texture} not Cooked Properly");
}
else
{
Onlinetextures.Add(cookedFileName);
}
}
}
}