247 lines
12 KiB
C#
247 lines
12 KiB
C#
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Xml.Linq;
|
|
using System.Xml.XPath;
|
|
using JD.Collections.Extensions;
|
|
using JD.LogService;
|
|
using TeaBox.Macros;
|
|
using File = System.IO.File;
|
|
|
|
namespace JDSongConverter.Tasks
|
|
{
|
|
class CreateOnlineCoverTask : Task
|
|
{
|
|
public override string Name
|
|
{
|
|
get { return "Create Online Cover"; }
|
|
set {}
|
|
}
|
|
|
|
public override string ProgressText
|
|
{
|
|
get { return "Creating Online Cover"; }
|
|
}
|
|
|
|
private string CoverGenericActorFile { get { return Path.Combine(Context.OutputMap.MenuArtFolder, "Actors", Context.OutputMap.Name + "_Cover_Generic.act"); } }
|
|
private string CoverGenericAtlasFile { get { return Path.Combine(Context.OutputMap.MenuArtFolder, "Textures", Context.OutputMap.Name + "_Cover_Generic.atl"); } }
|
|
private string CoverGenericTextureFile { get { return Path.Combine(Context.OutputMap.MenuArtFolder, "Textures", Context.OutputMap.Name + "_Cover_Generic.tga"); } }
|
|
private string CoverGenericTextureInfoFile { get { return Path.Combine(Context.OutputMap.MenuArtFolder, "Textures", Context.OutputMap.Name + "_Cover_Generic.tga.tfi"); } }
|
|
|
|
private string CoverOnlineActorFile { get { return Path.Combine(Context.OutputMap.MenuArtFolder, "Actors", Context.OutputMap.Name + "_Cover_Online.act"); } }
|
|
private string CoverOnlineActorRelativePath { get { return Path.Combine(Context.OutputMap.MenuArtFolder.Relative, "Actors", Context.OutputMap.Name + "_Cover_Online.act").Replace("\\", "/"); } }
|
|
private string CoverOnlineAtlasFile { get { return Path.Combine(Context.OutputMap.MenuArtFolder, "Textures", Context.OutputMap.Name + "_Cover_Online.atl"); } }
|
|
private string CoverOnlineTextureFile { get { return Path.Combine(Context.OutputMap.MenuArtFolder, "Textures", Context.OutputMap.Name + "_Cover_Online.tga"); } }
|
|
private string CoverOnlineTextureInfoFile { get { return Path.Combine(Context.OutputMap.MenuArtFolder, "Textures", Context.OutputMap.Name + "_Cover_Online.tga.tfi"); } }
|
|
|
|
private string MenuArtSceneFile { get { return Path.Combine(Context.OutputMap.MenuArtFolder, Context.OutputMap.Name + "_MENUART.isc"); } }
|
|
|
|
private string OnlineCoversPackageSkuScene { get { return Path.Combine(Context.OutputMap.Folder.Parent.Parent, "SkuScenes" , "Packages", "covers", "onlineCovers.isc"); } }
|
|
|
|
public override TaskResult Process(IExecutionContext executionContext)
|
|
{
|
|
|
|
File.Copy(CoverGenericTextureFile, CoverOnlineTextureFile, true);
|
|
|
|
UpdateActorFile();
|
|
UpdateTextureInfoFile();
|
|
UpdateAtlasFile();
|
|
UpdateMenuArtIsc(executionContext);
|
|
UpdateOnlineCoversSkuScene(executionContext);
|
|
|
|
return TaskResult.Ok;
|
|
}
|
|
|
|
private void UpdateActorFile()
|
|
{
|
|
File.Copy(CoverGenericActorFile, CoverOnlineActorFile, true);
|
|
File.SetAttributes(CoverOnlineActorFile, FileAttributes.Normal);
|
|
var content = File.ReadAllText(CoverOnlineActorFile);
|
|
content = content.Replace("cover_generic", "cover_online");
|
|
content = content.Replace(" RELATIVEZ = 0,00000,\n", "");
|
|
File.WriteAllText(CoverOnlineActorFile, content);
|
|
}
|
|
|
|
private void UpdateTextureInfoFile()
|
|
{
|
|
XDocument document = XDocument.Load(CoverGenericTextureInfoFile);
|
|
var configurations = document.XPathSelectElements("/root/TextureConfiguration").ToList();
|
|
foreach (var configuration in configurations)
|
|
{
|
|
configuration.SetAttributeValue("MipmapLevelStart", "2");
|
|
}
|
|
configurations.First().AddBeforeSelf(configurations.First());
|
|
configurations.First().SetAttributeValue("TargetName", "DURANGO");
|
|
configurations.First().AddBeforeSelf(configurations.First());
|
|
configurations.First().SetAttributeValue("TargetName", "ORBIS");
|
|
document.Save(CoverOnlineTextureInfoFile);
|
|
}
|
|
|
|
private void UpdateAtlasFile()
|
|
{
|
|
File.Copy(CoverGenericAtlasFile, CoverOnlineAtlasFile, true);
|
|
File.SetAttributes(CoverOnlineActorFile, FileAttributes.Normal);
|
|
var content = File.ReadAllText(CoverOnlineAtlasFile);
|
|
content = content.Replace("1024", "256");
|
|
File.WriteAllText(CoverOnlineAtlasFile, content);
|
|
}
|
|
|
|
private void UpdateMenuArtIsc(IExecutionContext executionContext)
|
|
{
|
|
File.SetAttributes(MenuArtSceneFile, FileAttributes.Normal);
|
|
XDocument document = XDocument.Load(MenuArtSceneFile);
|
|
|
|
// check for scene node
|
|
var scene = document.XPathSelectElements("/root/Scene").FirstOrDefault();
|
|
if (scene == null)
|
|
{
|
|
executionContext.LogError("Unable to find scene node in " + MenuArtSceneFile);
|
|
return;
|
|
}
|
|
|
|
// check the cover actor is not already registered in scene
|
|
var duplicateActors = document.XPathSelectElements("/root/Scene/ACTORS/Actor[@USERFRIENDLY='" + Context.OutputMap.Name + "_cover_online']/..").ToList();
|
|
if ( duplicateActors != null)
|
|
{
|
|
// cleanup!
|
|
duplicateActors.Remove();
|
|
}
|
|
|
|
// get an actor template
|
|
var genericActor = document.XPathSelectElements("/root/Scene/ACTORS").FirstOrDefault();
|
|
if (genericActor == null)
|
|
{
|
|
executionContext.LogError("Unable to find generic cover in " + MenuArtSceneFile);
|
|
return;
|
|
}
|
|
|
|
// create new cover actor from template
|
|
var onlineActor = new XElement(genericActor);
|
|
// replace generic cover related content in it
|
|
GetAllChildrenAttributes(onlineActor).ForEach(x => x.Value = x.Value.Replace("cover_generic", "cover_online"));
|
|
// append after template actor
|
|
genericActor.AddAfterSelf(onlineActor);
|
|
|
|
// remove previous platform filters
|
|
document.XPathSelectElements("/root/Scene/PLATFORM_FILTER").Remove();
|
|
|
|
// write platform filters
|
|
scene.AddFirst(CreatePlatformFilter("PS3", string.Format("{0}_cover_online", Context.Song.Name)));
|
|
scene.AddFirst(CreatePlatformFilter("X360", string.Format("{0}_cover_online", Context.Song.Name)));
|
|
scene.AddFirst(CreatePlatformFilter("WII", string.Format("{0}_cover_online", Context.Song.Name)));
|
|
|
|
// save menuart scene
|
|
document.Save(MenuArtSceneFile);
|
|
}
|
|
|
|
private XElement CreatePlatformFilter(string platform, string targetFriendlyName)
|
|
{
|
|
var filter = new XElement("PLATFORM_FILTER");
|
|
|
|
var targetFilterlistNode = new XElement("TargetFilterList");
|
|
targetFilterlistNode.SetAttributeValue("platform", platform);
|
|
filter.Add(targetFilterlistNode);
|
|
|
|
var objectsNode = new XElement("objects");
|
|
objectsNode.SetAttributeValue("VAL", targetFriendlyName);
|
|
targetFilterlistNode.Add(objectsNode);
|
|
|
|
return filter;
|
|
}
|
|
|
|
private void UpdateOnlineCoversSkuScene(IExecutionContext executionContext)
|
|
{
|
|
if ( !File.Exists(OnlineCoversPackageSkuScene))
|
|
{
|
|
executionContext.LogMessage("OnlineCoversSkuScene not found ! %s", OnlineCoversPackageSkuScene);
|
|
return;
|
|
}
|
|
|
|
File.SetAttributes(OnlineCoversPackageSkuScene, FileAttributes.Normal);
|
|
XDocument document = XDocument.Load(OnlineCoversPackageSkuScene);
|
|
|
|
// find scene node
|
|
var scene = document.XPathSelectElements("/root/Scene").FirstOrDefault();
|
|
if (scene == null)
|
|
{
|
|
executionContext.LogError("Unable to find scene node in " + OnlineCoversPackageSkuScene + ".");
|
|
return;
|
|
}
|
|
|
|
// find current song actor in scene
|
|
var onlineCoverActor = document.XPathSelectElements("/root/Scene/ACTORS/Actor[@USERFRIENDLY='" + Context.OutputMap.Name + "_cover_online']").FirstOrDefault();
|
|
|
|
// if not found, try to create it
|
|
if (onlineCoverActor == null)
|
|
{
|
|
var genericActor = document.XPathSelectElements("/root/Scene/ACTORS").FirstOrDefault();
|
|
// check theres a template actor to copy
|
|
if (genericActor == null)
|
|
{
|
|
executionContext.LogError("Unable to find actor node in " + OnlineCoversPackageSkuScene);
|
|
return;
|
|
}
|
|
// clone template actor
|
|
onlineCoverActor = new XElement(genericActor);
|
|
// replace map related values in actor
|
|
var onlineCoverActorContent = onlineCoverActor.XPathSelectElements("Actor").FirstOrDefault();
|
|
onlineCoverActorContent.SetAttributeValue("USERFRIENDLY", Context.OutputMap.Name + "_cover_online");
|
|
onlineCoverActorContent.SetAttributeValue("INSTANCEDATAFILE", CoverOnlineActorRelativePath);
|
|
|
|
// append the actor after template one
|
|
genericActor.AddAfterSelf(onlineCoverActor);
|
|
executionContext.LogMessage(Context.OutputMap.Name + "_cover_online added to Online SkuScene");
|
|
|
|
}
|
|
|
|
// find song descriptor node
|
|
var descriptorElement = document.XPathSelectElements("/root/Scene/sceneConfigs/SceneConfigs/sceneConfigs[@NAME='JD_CoversDlcDescriptorSceneConfig']/JD_CoversDlcDescriptorSceneConfig").FirstOrDefault();
|
|
if (descriptorElement == null)
|
|
{
|
|
executionContext.LogError("Unable to find JD_CoversDlcDescriptorSceneConfig node in " + OnlineCoversPackageSkuScene + ".");
|
|
return;
|
|
}
|
|
|
|
// find current song descriptor element
|
|
var onlineMenuArtDescriptorElement = descriptorElement.XPathSelectElements("allMapsWithSmallCover[contains(@VAL,'" + Context.OutputMap.Name + "')]").FirstOrDefault();
|
|
|
|
// if not found, try to create it
|
|
if (onlineMenuArtDescriptorElement == null)
|
|
{
|
|
var genericDescriptorElement = descriptorElement.XPathSelectElements("allMapsWithSmallCover").FirstOrDefault();
|
|
if (genericDescriptorElement == null)
|
|
{
|
|
executionContext.LogError("Unable to find a base allMapsWithSmallCover element in " + OnlineCoversPackageSkuScene + ".");
|
|
return;
|
|
}
|
|
// clone template descriptor element
|
|
onlineMenuArtDescriptorElement = new XElement(genericDescriptorElement);
|
|
// replace map related values
|
|
onlineMenuArtDescriptorElement.SetAttributeValue("VAL", Context.OutputMap.Name);
|
|
// append after template
|
|
genericDescriptorElement.AddAfterSelf(onlineMenuArtDescriptorElement);
|
|
|
|
executionContext.LogMessage(Context.OutputMap.Name + " descriptor added to Online Skuscene.");
|
|
}
|
|
|
|
// save skuscene
|
|
document.Save(OnlineCoversPackageSkuScene);
|
|
}
|
|
|
|
private IEnumerable<XAttribute> GetAllChildrenAttributes(XElement element)
|
|
{
|
|
foreach (var attribute in element.Attributes())
|
|
{
|
|
yield return attribute;
|
|
}
|
|
foreach (var node in element.Nodes().OfType<XElement>())
|
|
{
|
|
foreach (var attribute in GetAllChildrenAttributes(node))
|
|
{
|
|
yield return attribute;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|