anx.framework/ANX.Framework.Content.Pipeline/Tasks/DefaultContentProcessorContext.cs
Konstantin Koch a8588a30a5 Update ContentCompiler, make Visual Studio Extension work without having Anx Framework installed.
Make ContentCompilerGui compatible to recent changes in pipeline and did
some usability changes.
Make the Visual Studio Extension work even if the ANX Framework is not
installed additionally..
Improve that the path for assembly refernces in a content project
doesn't get automatically updated, only if the reference is actually
saved, this is so you can specify a relative path yourself.
Fix missing icon for ContentProject when it was opened with Visual
Studio.
Made create_shaders.bat directly executable under windows by fixing the
directory separators.
2015-09-03 23:43:55 +02:00

154 lines
5.1 KiB
C#

using ANX.Framework.Content.Pipeline;
using ANX.Framework.Content.Pipeline.Tasks;
using ANX.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace ANX.Framework.Content.Pipeline.Tasks
{
public class DefaultContentProcessorContext : ContentProcessorContext
{
BuildContentTask task;
OpaqueDataDictionary parameters = new OpaqueDataDictionary();
string buildConfiguration;
string intermediateDirectory;
string outputFilename;
string outputDirectory;
public DefaultContentProcessorContext(BuildContentTask task, string buildConfiguration, string intermediateDirectory, string outputDirectory, string outputFilename)
{
this.task = task;
this.buildConfiguration = buildConfiguration;
this.intermediateDirectory = intermediateDirectory;
this.outputFilename = outputFilename;
this.outputDirectory = outputDirectory;
}
public override string BuildConfiguration
{
get { return buildConfiguration; }
}
public override string IntermediateDirectory
{
get { return intermediateDirectory; }
}
public override ContentBuildLogger Logger
{
get { return task.BuildLogger; }
}
public override string OutputDirectory
{
get { return outputDirectory; }
}
public override string OutputFilename
{
get { return outputFilename; }
}
public override OpaqueDataDictionary Parameters
{
get { return parameters; }
}
public override TargetPlatform TargetPlatform
{
get { return task.TargetPlatform; }
}
public override GraphicsProfile TargetProfile
{
get { return task.TargetProfile; }
}
public override void AddDependency(string filename)
{
throw new NotImplementedException();
}
public override void AddOutputFile(string filename)
{
throw new NotImplementedException();
}
public override TOutput BuildAndLoadAsset<TInput, TOutput>(ExternalReference<TInput> sourceAsset, string processorName, OpaqueDataDictionary processorParameters, string importerName)
{
if (sourceAsset == null)
throw new ArgumentNullException("sourceAsset");
var buildItem = new BuildItem()
{
AssetName = Path.GetFileNameWithoutExtension(sourceAsset.Filename),
ImporterName = importerName,
ProcessorName = processorName,
SourceFilename = sourceAsset.Filename
};
if (processorParameters != null)
{
foreach (var pair in processorParameters)
{
buildItem.ProcessorParameters.Add(pair.Key, pair.Value);
}
}
var result = task.Execute(buildItem);
if (!result.Successfull)
throw new InvalidOperationException(string.Format("Unable to build asset \"{0}\".", sourceAsset.Filename));
return (TOutput)result.Item;
}
public override ExternalReference<TOutput> BuildAsset<TInput, TOutput>(ExternalReference<TInput> sourceAsset, string processorName, OpaqueDataDictionary processorParameters, string importerName, string assetName)
{
if (sourceAsset == null)
throw new ArgumentNullException("sourceAsset");
var buildItem = new BuildItem()
{
AssetName = assetName,
ImporterName = importerName,
ProcessorName = processorName,
SourceFilename = sourceAsset.Filename
};
if (processorParameters != null)
{
foreach (var pair in processorParameters)
{
buildItem.ProcessorParameters.Add(pair.Key, pair.Value);
}
}
var result = task.Execute(buildItem);
if (!result.Successfull)
throw new InvalidOperationException(string.Format("Unable to build asset \"{0}\".", sourceAsset.Filename));
return new ExternalReference<TOutput>(result.OutputFile);
}
public override TOutput Convert<TInput, TOutput>(TInput input, string processorName, OpaqueDataDictionary processorParameters)
{
var processorManager = task.ProcessorManager;
if (string.IsNullOrWhiteSpace(processorName))
processorName = processorManager.GetProcessorForType(typeof(TInput), typeof(TOutput));
else
processorManager.ValidateProcessorTypes(processorName, typeof(TInput), typeof(TOutput));
var processor = processorManager.GetInstance(processorName);
if (processorParameters != null)
processorManager.SetProcessorParameters(processor, processorParameters);
return (TOutput)processor.Process(input, this);
}
}
}