Skip to content

Commit

Permalink
Merge pull request #19 from CarterGames/release
Browse files Browse the repository at this point in the history
🚧 0.7.2 update
  • Loading branch information
JonathanMCarter authored Jul 20, 2024
2 parents 84a0c4d + 175b65f commit ae3103a
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,8 @@ public sealed class DataAssetIndexHandler : IPreprocessBuildWithReport
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

internal static readonly string DataAssetIndexPath = $"{ScriptableRef.AssetBasePath}/Carter Games/The Cart/Resources/Data Asset Index.asset";
private static DataAssetIndex dataAssetIndexCache;
private static readonly string DataAssetIndexFilter = $"t:{typeof(DataAssetIndex).FullName}";
private const string AssetFilter = "t:dataasset";

/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Properties
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

/// <summary>
/// The data asset index for the asset.
/// </summary>
public static DataAssetIndex DataAssetIndex =>
FileEditorUtil.CreateSoGetOrAssignAssetCache(ref dataAssetIndexCache, DataAssetIndexFilter, DataAssetIndexPath, "The Cart", $"The Cart/Resources/Data Asset Index.asset");
private static readonly string AssetFilter = typeof(DataAsset).FullName;

/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| IPreprocessBuildWithReport Implementation
Expand Down Expand Up @@ -96,24 +85,7 @@ private static void OnEditorUpdate()
if (!EditorApplication.isPlayingOrWillChangePlaymode || EditorApplication.isPlaying) return;
UpdateIndex();
}


/// <summary>
/// Tries to make the asset index if it doesn't exist yet.
/// </summary>
internal static void TryMakeIndex()
{
if (dataAssetIndexCache == null)
{
FileEditorUtil.CreateSoGetOrAssignAssetCache(
ref dataAssetIndexCache,
DataAssetIndexFilter,
DataAssetIndexPath,
"The Cart", "The Cart/Resources/Data Asset Index.asset");

}
}



/// <summary>
/// Updates the index with all the save manager asset scriptable objects in the project.
Expand All @@ -122,7 +94,7 @@ internal static void TryMakeIndex()
public static void UpdateIndex()
{
var foundAssets = new List<DataAsset>();
var asset = AssetDatabase.FindAssets(AssetFilter, null);
var asset = AssetDatabase.FindAssets($"t:{AssetFilter}", null);

if (asset == null || asset.Length <= 0) return;

Expand All @@ -137,50 +109,27 @@ public static void UpdateIndex()

foundAssets.Add((DataAsset) AssetDatabase.LoadAssetAtPath(assetPath, typeof(DataAsset)));
}

var indexProp = new SerializedObject(DataAssetIndex);

RemoveNullReferences(indexProp);
UpdateIndexReferences(foundAssets ,indexProp);
UpdateIndexReferences(foundAssets);

indexProp.ApplyModifiedProperties();
indexProp.Update();
}


/// <summary>
/// Removes any null references from the index when called.
/// </summary>
/// <param name="indexProp">The property to base off.</param>
private static void RemoveNullReferences(SerializedObject indexProp)
{
for (var i = 0; i < indexProp.Fp("assets").Fpr("list").arraySize; i++)
{
var entry = indexProp.Fp("assets").Fpr("list").GetIndex(i);
var jIndexAdjustment = 0;

for (var j = 0; j < entry.Fpr("value").arraySize; j++)
{
if (entry.Fpr("value").GetIndex(j - jIndexAdjustment).objectReferenceValue != null) continue;
entry.Fpr("value").DeleteIndex(j);
jIndexAdjustment++;
}
}
ScriptableRef.DataAssetIndexObject.ApplyModifiedProperties();
ScriptableRef.DataAssetIndexObject.Update();
}


/// <summary>
/// Updates any references when called with the latest in the project.
/// </summary>
/// <param name="foundAssets">The found assets to update.</param>
/// <param name="indexProp">The property to base off.</param>
private static void UpdateIndexReferences(IReadOnlyList<DataAsset> foundAssets, SerializedObject indexProp)
private static void UpdateIndexReferences(IReadOnlyList<DataAsset> foundAssets)
{
ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").ClearArray();

for (var i = 0; i < foundAssets.Count; i++)
{
for (var j = 0; j < indexProp.Fp("assets").Fpr("list").arraySize; j++)
for (var j = 0; j < ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").arraySize; j++)
{
var entry = indexProp.Fp("assets").Fpr("list").GetIndex(j);
var entry = ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").GetIndex(j);

if (entry.Fpr("key").stringValue.Equals(foundAssets[i].GetType().ToString()))
{
Expand All @@ -195,21 +144,21 @@ private static void UpdateIndexReferences(IReadOnlyList<DataAsset> foundAssets,
}
}

indexProp.Fp("assets").Fpr("list").InsertIndex(indexProp.Fp("assets").Fpr("list").arraySize);
indexProp.Fp("assets").Fpr("list").GetIndex(indexProp.Fp("assets").Fpr("list").arraySize - 1).Fpr("key").stringValue = foundAssets[i].GetType().ToString();
ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").InsertIndex(ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").arraySize);
ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").GetIndex(ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").arraySize - 1).Fpr("key").stringValue = foundAssets[i].GetType().ToString();

if (indexProp.Fp("assets").Fpr("list").GetIndex(indexProp.Fp("assets").Fpr("list").arraySize - 1).Fpr("value").arraySize > 0)
if (ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").GetIndex(ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").arraySize - 1).Fpr("value").arraySize > 0)
{
indexProp.Fp("assets").Fpr("list").GetIndex(indexProp.Fp("assets").Fpr("list").arraySize - 1)
ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").GetIndex(ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").arraySize - 1)
.Fpr("value").ClearArray();
}

indexProp.Fp("assets").Fpr("list").GetIndex(indexProp.Fp("assets").Fpr("list").arraySize - 1).Fpr("value").InsertIndex(0);
indexProp.Fp("assets").Fpr("list").GetIndex(indexProp.Fp("assets").Fpr("list").arraySize - 1)
ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").GetIndex(ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").arraySize - 1).Fpr("value").InsertIndex(0);
ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").GetIndex(ScriptableRef.DataAssetIndexObject.Fp("assets").Fpr("list").arraySize - 1)
.Fpr("value").GetIndex(0).objectReferenceValue = foundAssets[i];

AlreadyExists: ;
}
}
}
}
}
3 changes: 0 additions & 3 deletions Carter Games/The Cart/Code/Editor/Core/Data/Initialize.meta

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,20 @@ public override void OnInspectorGUI()
{
GUILayout.Space(4f);
GeneralUtilEditor.DrawSoScriptSection((DataAssetCartGlobalRuntimeSettings)target);
GUILayout.Space(2f);
GUILayout.Space(10f);

EditorGUILayout.LabelField("Core", EditorStyles.boldLabel);
GeneralUtilEditor.DrawHorizontalGUILine();

RngSettingsDrawer.DrawInspector(serializedObject);
GUILayout.Space(2f);
LoggingSettingsDrawer.DrawInspector(serializedObject);
GUILayout.Space(2f);
GUILayout.Space(12.5f);

if (SettingsProviderHandler.Providers.Count <= 0) return;

EditorGUILayout.LabelField("Modules", EditorStyles.boldLabel);
GeneralUtilEditor.DrawHorizontalGUILine();

foreach (var providerKvp in SettingsProviderHandler.Providers)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* THE SOFTWARE.
*/

using System.Collections.Generic;
using CarterGames.Cart.Core.Data;
using CarterGames.Cart.Core.Management.Editor;
using UnityEditor;
using UnityEngine;
Expand Down Expand Up @@ -76,22 +78,37 @@ private void DrawModulesRevisions()
{
EditorGUILayout.BeginVertical("HelpBox");
EditorGUILayout.Space(1f);

EditorGUILayout.BeginHorizontal();

EditorGUILayout.LabelField("Installed Modules", EditorStyles.boldLabel);

GUI.backgroundColor = Color.yellow;
if (GUILayout.Button("Refresh", GUILayout.Width(75)))
{
ScanAndApplyReceipts();
}
GUI.backgroundColor = Color.white;

EditorGUILayout.EndHorizontal();

GeneralUtilEditor.DrawHorizontalGUILine();

if (serializedObject.Fp("installedModuleReceipts").Fpr("list").arraySize > 0)
{
for (var i = 0; i < serializedObject.Fp("installedModuleReceipts").Fpr("list").arraySize; i++)
{
if (serializedObject.Fp("installedModuleReceipts").Fpr("list").GetIndex(i).Fpr("value").objectReferenceValue == null) continue;

EditorGUILayout.BeginHorizontal();
EditorGUI.BeginDisabledGroup(true);

EditorGUILayout.LabelField(serializedObject.Fp("installedModuleReceipts").Fpr("list").GetIndex(i)
.Fpr("key").stringValue);
EditorGUILayout.IntField(
serializedObject.Fp("installedModuleReceipts").Fpr("list").GetIndex(i).Fpr("value")
.Fpr("revision").intValue, GUILayout.Width(50));

var textAsset = (TextAsset) serializedObject.Fp("installedModuleReceipts").Fpr("list").GetIndex(i).Fpr("value").objectReferenceValue;

EditorGUILayout.IntField((JsonUtility.FromJson<ModuleInstallWrapper>(textAsset.text)).Revision, GUILayout.Width(50));

EditorGUI.EndDisabledGroup();
EditorGUILayout.EndHorizontal();
Expand Down Expand Up @@ -120,5 +137,43 @@ private void DrawManifest()
EditorGUILayout.Space(1.5f);
EditorGUILayout.EndVertical();
}


private void ScanAndApplyReceipts()
{
serializedObject.Fp("installedModuleReceipts").Fpr("list").ClearArray();

var pathToSearch = $"{ScriptableRef.AssetBasePath}/Carter Games/The Cart/Modules";
var assets = AssetDatabase.FindAssets("Installation", new string[] { pathToSearch });

if (assets.Length <= 0)
{
serializedObject.ApplyModifiedProperties();
serializedObject.Update();
return;
}

for (var i = 0; i < assets.Length; i++)
{
var path = AssetDatabase.GUIDToAssetPath(assets[i]);
var instance = AssetDatabase.LoadAssetAtPath<TextAsset>(path);

var moduleName = path
.Replace($"{ScriptableRef.AssetBasePath}/Carter Games/The Cart/Modules/", string.Empty)
.Replace("/Installation.json", string.Empty)
.Replace(" ", string.Empty)
.Trim();

var key = $"CarterGames.Cart.Modules.{moduleName}";

serializedObject.Fp("installedModuleReceipts").Fpr("list").InsertIndex(i);

serializedObject.Fp("installedModuleReceipts").Fpr("list").GetIndex(i).Fpr("key").stringValue = key;
serializedObject.Fp("installedModuleReceipts").Fpr("list").GetIndex(i).Fpr("value").objectReferenceValue = instance;
}

serializedObject.ApplyModifiedProperties();
serializedObject.Update();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ public static int InstalledRevisionNumber(IModule module)
return -1;
}

return DataAccess.GetAsset<ModuleCache>().InstalledModulesInfo[module.Namespace].Revision;
return JsonUtility.FromJson<ModuleInstallWrapper>(DataAccess.GetAsset<ModuleCache>().InstalledModulesInfo[module.Namespace].text).Revision;
}
else
{
DataAccess.GetAsset<ModuleCache>().AddInstalledModuleInfo(module, AssetDatabase.LoadAssetAtPath<TextAsset>(module.ModuleInstallPath + "/Installation.json"));
return DataAccess.GetAsset<ModuleCache>().InstalledModulesInfo[module.Namespace].Revision;
return JsonUtility.FromJson<ModuleInstallWrapper>(DataAccess.GetAsset<ModuleCache>().InstalledModulesInfo[module.Namespace].text).Revision;
}
}

Expand Down
Loading

0 comments on commit ae3103a

Please sign in to comment.