Skip to content

Commit

Permalink
Dependencies are now stored in Meta Files
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsakharov committed Mar 23, 2024
1 parent fb37037 commit d03a8b8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
15 changes: 8 additions & 7 deletions Prowl.Editor/Assets/AssetDatabase.Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,20 @@ public static bool Reimport(FileInfo assetFile, bool disposeExisting = true)
return false; // Import failed no Main Object
}

// Update the meta file (LastModified is set by MetaFile.Load)
meta.assetTypes = new string[ctx.SubAssets.Count];
for (int i = 0; i < ctx.SubAssets.Count; i++)
meta.assetTypes[i] = ctx.SubAssets[i].GetType().FullName!;
meta.Save();

// Delete the old imported asset if it exists
var serialized = GetSerializedFile(meta.guid);
if (File.Exists(serialized.FullName))
serialized.Delete();

// Save the asset
ctx.SaveToFile(serialized);
ctx.SaveToFile(serialized, out var dependencies);

// Update the meta file (LastModified is set by MetaFile.Load)
meta.assetTypes = new string[ctx.SubAssets.Count];
for (int i = 0; i < ctx.SubAssets.Count; i++)
meta.assetTypes[i] = ctx.SubAssets[i].GetType().FullName!;
meta.dependencies = dependencies.ToList();
meta.Save();
return true;
}

Expand Down
1 change: 1 addition & 0 deletions Prowl.Editor/Assets/MetaFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class MetaFile

public DateTime lastModified;
public ScriptedImporter importer;
public List<Guid> dependencies;

/// <summary>Default constructor for MetaFile.</summary>
public MetaFile() { }
Expand Down
4 changes: 2 additions & 2 deletions Prowl.Runtime/Serializer/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ private static SerializedProperty SerializeObject(object? value, SerializationCo
compound["$id"] = new(PropertyType.Int, id);
compound["$type"] = new(PropertyType.String, type.FullName);
var dependencies = ctx.EndDependencies();
if(dependencies.Count > 0)
compound["$dependencies"] = new(PropertyType.List, dependencies.Select(d => new SerializedProperty(PropertyType.String, d.ToString())).ToList());
//if(dependencies.Count > 0)
// compound["$dependencies"] = new(PropertyType.List, dependencies.Select(d => new SerializedProperty(PropertyType.String, d.ToString())).ToList());

if (value is ISerializeCallbacks callback2)
callback2.PostSerialize();
Expand Down
11 changes: 5 additions & 6 deletions Prowl.Runtime/Utils/SerializedAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ public class SerializedAsset

public bool HasMain => Main != null;

public void SaveToFile(FileInfo file)
public void SaveToFile(FileInfo file, out HashSet<Guid>? dependencies)
{
if (Main == null) throw new Exception("Asset does not have a main object.");

#warning TODO: Somehow record Dependencies - reflection to find all AssetRef instances and store them in a list?
// We need a way for said Dependencies to be able to be loaded and references independently of the asset
// so like if we delete another asset we can let the user know its in use by X object are they sure?

file.Directory?.Create(); // Ensure the Directory exists
var tag = Serializer.Serialize(this);
Serializer.SerializationContext ctx = new();
var tag = Serializer.Serialize(this, ctx);
dependencies = ctx.dependencies;

using var stream = file.OpenWrite();
using BinaryWriter writer = new(stream);
BinaryTagConverter.WriteTo(tag, writer);
Expand Down

0 comments on commit d03a8b8

Please sign in to comment.