mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Start of asset management 2.0
This commit is contained in:
@@ -3,6 +3,8 @@ using GlitchyEngine;
|
||||
using System.IO;
|
||||
using Bon;
|
||||
using GlitchyEngine.Content;
|
||||
using GlitchyEditor.Assets;
|
||||
using GlitchyEditor.Assets.Importers;
|
||||
|
||||
namespace GlitchyEditor;
|
||||
|
||||
@@ -18,28 +20,39 @@ class AssetConfig
|
||||
[BonInclude]
|
||||
public AssetLoaderConfig Config ~ delete _;
|
||||
|
||||
[BonInclude]
|
||||
public String Importer ~ delete _;
|
||||
[BonInclude]
|
||||
public AssetImporterConfig ImporterConfig ~ delete _;
|
||||
[BonInclude]
|
||||
public String Processor ~ delete _;
|
||||
[BonInclude]
|
||||
public AssetProcessorConfig ProcessorConfig ~ delete _;
|
||||
[BonInclude]
|
||||
public String Exporter ~ delete _;
|
||||
[BonInclude]
|
||||
public AssetExporterConfig ExporterConfig ~ delete _;
|
||||
|
||||
[BonInclude]
|
||||
public AssetHandle AssetHandle = .Invalid;
|
||||
}
|
||||
|
||||
/// Represents an unprocessed asset as it lies in the asset hierarchy.
|
||||
class AssetFile
|
||||
{
|
||||
private EditorContentManager _contentManager;
|
||||
|
||||
private String _path ~ delete:append _;
|
||||
private String _identifier ~ delete:append _;
|
||||
private String _assetConfigPath ~ delete:append _;
|
||||
private AssetNode _assetFile;
|
||||
|
||||
private AssetConfig _assetConfig ~ delete _;
|
||||
|
||||
private bool _isDirectory;
|
||||
|
||||
private Asset _loadedAsset;
|
||||
|
||||
public bool IsDirectory => _isDirectory;
|
||||
private DateTime _lastAssetEditTime;
|
||||
private DateTime _lastConfigEditTime;
|
||||
|
||||
public StringView FilePath => _path;
|
||||
public StringView Identifier => _identifier;
|
||||
public AssetNode AssetFile => _assetFile;
|
||||
public StringView AssetConfigPath => _assetConfigPath;
|
||||
|
||||
public const String ConfigFileExtension = ".ass";
|
||||
@@ -48,30 +61,47 @@ class AssetFile
|
||||
|
||||
public Asset LoadedAsset => _loadedAsset;
|
||||
|
||||
public EditorContentManager ContentManager => _contentManager;
|
||||
|
||||
[AllowAppend]
|
||||
public this(EditorContentManager contentManager, StringView identifier, StringView path, bool isDirectory)
|
||||
public this(EditorContentManager contentManager, AssetNode assetNode)
|
||||
{
|
||||
String identifierBuffer = append String(identifier);
|
||||
String pathBuffer = append String(path);
|
||||
String configPathBuffer = append String(path.Length + ConfigFileExtension.Length);
|
||||
String configPathBuffer = append String(assetNode.Path.Length + ConfigFileExtension.Length);
|
||||
|
||||
_identifier = identifierBuffer;
|
||||
_path = pathBuffer;
|
||||
|
||||
configPathBuffer..Append(path).Append(ConfigFileExtension);
|
||||
configPathBuffer..Append(assetNode.Path).Append(ConfigFileExtension);
|
||||
_assetConfigPath = configPathBuffer;
|
||||
|
||||
_contentManager = contentManager;
|
||||
|
||||
_isDirectory = isDirectory;
|
||||
_assetFile = assetNode;
|
||||
|
||||
Log.EngineLogger.AssertDebug(File.Exists(_path), "File doesn't exist.");
|
||||
|
||||
FindAssetConfig();
|
||||
_lastAssetEditTime = File.GetLastWriteTimeUtc(_assetFile.Path);
|
||||
}
|
||||
|
||||
// Loads the asset config (.ass) file or creates it.
|
||||
private void FindAssetConfig()
|
||||
public static AssetFile LoadOrCreateAssetFile(EditorContentManager contentManager, AssetNode assetNode)
|
||||
{
|
||||
AssetFile assetFile = new AssetFile(contentManager, assetNode);
|
||||
|
||||
assetFile.LoadOrCreateAssetConfig();
|
||||
|
||||
// TODO: Remove this check once we only use the new processing pipeline
|
||||
if (assetFile._assetConfig.ImporterConfig != null)
|
||||
{
|
||||
CachedAsset cacheEntry = assetFile._contentManager.AssetCache.GetCacheEntry(assetFile._assetConfig.AssetHandle);
|
||||
|
||||
if (cacheEntry == null ||
|
||||
cacheEntry.CreationTimestamp < assetFile._lastAssetEditTime ||
|
||||
cacheEntry.CreationTimestamp < assetFile._lastConfigEditTime)
|
||||
{
|
||||
assetFile._contentManager.AssetConverter.QueueForProcessing(assetFile);
|
||||
}
|
||||
}
|
||||
|
||||
return assetFile;
|
||||
}
|
||||
|
||||
/// Loads the asset config (.ass) file or creates it.
|
||||
private void LoadOrCreateAssetConfig()
|
||||
{
|
||||
if (File.Exists(_assetConfigPath))
|
||||
{
|
||||
@@ -81,6 +111,8 @@ class AssetFile
|
||||
{
|
||||
CreateDefaultAssetLoader();
|
||||
}
|
||||
|
||||
_lastAssetEditTime = File.GetLastWriteTimeUtc(_assetConfigPath);
|
||||
}
|
||||
|
||||
private void GenerateAssetHandle()
|
||||
@@ -90,12 +122,18 @@ class AssetFile
|
||||
|
||||
private void CreateDefaultAssetLoader()
|
||||
{
|
||||
String fileExtension = Path.GetExtension(_path, .. scope .());
|
||||
String fileExtension = Path.GetExtension(_assetFile.Path, .. scope .());
|
||||
|
||||
_assetConfig = new AssetConfig();
|
||||
|
||||
GenerateAssetHandle();
|
||||
|
||||
var assetPipeline = _contentManager.GetDefaultProcessors(fileExtension);
|
||||
|
||||
// TODO!
|
||||
//if (assetPipeline case .Err)
|
||||
// return;
|
||||
|
||||
var assetLoader = _contentManager.GetDefaultAssetLoader(fileExtension);
|
||||
|
||||
// We don't have a loader -> we don't need a config
|
||||
@@ -108,6 +146,17 @@ class AssetFile
|
||||
_assetConfig.Config = assetLoader?.GetDefaultConfig();
|
||||
_assetConfig.Config?.[Friend]_changed = true;
|
||||
|
||||
_assetConfig.Importer = new String();
|
||||
assetPipeline?.Importer?.GetType()?.GetName(_assetConfig.Importer);
|
||||
_assetConfig.ImporterConfig = assetPipeline?.Importer.CreateDefaultConfig();
|
||||
|
||||
_assetConfig.Processor = new String();
|
||||
assetPipeline?.Processor?.GetType()?.GetName(_assetConfig.Processor);
|
||||
_assetConfig.ProcessorConfig = assetPipeline?.Processor.CreateDefaultConfig();
|
||||
|
||||
_assetConfig.Exporter = new String();
|
||||
assetPipeline?.Exporter?.GetType()?.GetName(_assetConfig.Exporter);
|
||||
_assetConfig.ExporterConfig = assetPipeline?.Exporter.CreateDefaultConfig();
|
||||
|
||||
SaveAssetConfig();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user