94 lines
No EOL
4.5 KiB
C#
94 lines
No EOL
4.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using JD.Core;
|
|
using Packager.Parameters;
|
|
|
|
namespace Packager.Tasks
|
|
{
|
|
// Find the ISC file of the map video previews (a feature that appeared in JD19)
|
|
// This class is part of the fix to Jira ticket 1197 ( https://mdc-tomcat-jira29.ubisoft.org/jira/browse/JDTOOLS-1197 )
|
|
public class FindVideoPreviewTask : Task
|
|
{
|
|
/// <summary>
|
|
/// Input: a collection of strings.
|
|
/// Example of input: ("Skibidi", "Airplanes").
|
|
/// </summary>
|
|
[Input(nameof(MapNames), IOCardinality.Multi, IOType.String)]
|
|
public ReferenceList MapNames { get; set; } = new ReferenceList();
|
|
|
|
/// <summary>
|
|
/// Output of the task: a collection of relative paths.
|
|
/// Example of output: "World\MAPS\Skibidi\VideosCoach\Skibidi_VIDEO_MAP_PREVIEW.isc\nWorld\MAPS\Airplanes\VideosCoach\Airplanes_VIDEO_MAP_PREVIEW.isc".
|
|
/// </summary>
|
|
[Output(nameof(VideoPreviewIscPaths), IOType.String)]
|
|
public ReferenceList VideoPreviewIscPaths = new ReferenceList();
|
|
|
|
/// <summary>
|
|
/// Output: the path to a file containing a collection of relative paths.
|
|
/// Example of output: "C:/output/videoPreviewsIscPaths.txt".
|
|
/// Example of content of the output file: "World\MAPS\Skibidi\VideosCoach\Skibidi_VIDEO_MAP_PREVIEW.isc\nWorld\MAPS\Airplanes\VideosCoach\Airplanes_VIDEO_MAP_PREVIEW.isc".
|
|
/// </summary>
|
|
[Output(nameof(VideoPreviewIscPaths), IOType.File)]
|
|
public SingleReference VideoPreviewIscPathsFile = new SingleReference();
|
|
|
|
protected override void StartInternal(BuildConfiguration profile, cookerWrapper cooker)
|
|
{
|
|
string dataRoot = DataRoot.Value;
|
|
ICollection<string> iscRelativePaths = new List<string>();
|
|
foreach (string mapName in MapNames)
|
|
{
|
|
string mapActualName;
|
|
if (mapName.Contains('_'))
|
|
{
|
|
// sometimes we get "happy_main_scene" as a 'map name', so we have to extract the real map name out of it :(
|
|
int indexOfUnderscore = mapName.IndexOf('_');
|
|
mapActualName = mapName.Substring(0, indexOfUnderscore);
|
|
}
|
|
else
|
|
{
|
|
mapActualName = mapName;
|
|
}
|
|
|
|
// We want to find World\MAPS\Skibidi\VideosCoach\Skibidi_VIDEO_MAP_PREVIEW.isc in order to get it built with the map
|
|
string iscFilename = mapActualName + "_VIDEO_MAP_PREVIEW.isc";
|
|
string iscRelativePath = Path.Combine("World", "MAPS", mapActualName, "VideosCoach", iscFilename);
|
|
|
|
string iscAbsolutePath = Path.Combine(dataRoot, iscRelativePath);
|
|
|
|
if (File.Exists(iscAbsolutePath))
|
|
{
|
|
iscRelativePaths.Add(iscRelativePath);
|
|
LogMessage(error: false, message: $"Added reference to {mapActualName} video previews with \'{iscRelativePath}\'.");
|
|
}
|
|
else
|
|
{
|
|
throw new FileNotFoundException($"The file \'{iscFilename}\' used to reference the previews of the map {mapActualName} was not found at \"{iscAbsolutePath}\". " +
|
|
$"Please make sure this file exists and is in the right folder. This file is supposed to exist for sku maps.");
|
|
}
|
|
}
|
|
|
|
// write the result to the output file
|
|
string outputFile = Path.Combine(TaskOutputFolder, "videoPreviewsIscPaths.txt");
|
|
string fileContent = string.Join(Environment.NewLine, iscRelativePaths);
|
|
File.WriteAllText(outputFile, fileContent);
|
|
|
|
// WARNING
|
|
// WRONG WAY of setting an output:
|
|
//
|
|
// VideoPreviewIscPaths = new SingleReference(outputFile);
|
|
//
|
|
// The ouput of the task will now be a new instance, so it will NOT be used by other task.
|
|
// The binding between input and outputs is done right after the constructor is called (in the TaskList)
|
|
|
|
// Good way of setting an output:
|
|
//
|
|
// VideoPreviewIscPaths.Value = outputFile;
|
|
//
|
|
// Updating the value in the Reference object allow other tasks to access it
|
|
VideoPreviewIscPathsFile.Value = outputFile;
|
|
VideoPreviewIscPaths.Add(iscRelativePaths.ToArray());
|
|
}
|
|
}
|
|
} |