MOD!
This commit is contained in:
102
Assets/Scripts/Mod/Manifests/ModManifest.cs
Normal file
102
Assets/Scripts/Mod/Manifests/ModManifest.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using Continentis.MainGame;
|
||||
using Continentis.MainGame.Card;
|
||||
using Continentis.MainGame.Character;
|
||||
using Continentis.MainGame.Equipment;
|
||||
using Continentis.MainGame.UI;
|
||||
using NaughtyAttributes;
|
||||
using SLSFramework.UModAssistance;
|
||||
using UMod;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace Continentis.Mods
|
||||
{
|
||||
[CreateAssetMenu(fileName = "ModManifest", menuName = "Continentis/Mod/Manifest", order = 1)]
|
||||
public partial class ModManifest : ScriptableObject
|
||||
{
|
||||
public string inEditorModFolder;
|
||||
|
||||
public List<string> keywordDataIDList = new List<string>();
|
||||
public List<string> cardDataIDList = new List<string>();
|
||||
public List<string> characterDataIDList = new List<string>();
|
||||
public List<string> equipmentDataIDList = new List<string>();
|
||||
public List<string> hudDataIDList = new List<string>();
|
||||
|
||||
public List<TextAsset> localizationFiles = new List<TextAsset>();
|
||||
|
||||
public void SaveToDatabase(ModHost host)
|
||||
{
|
||||
SaveIDListToDatabase<KeywordData>(host, keywordDataIDList);
|
||||
SaveIDListToDatabase<CardData>(host, cardDataIDList);
|
||||
SaveIDListToDatabase<CharacterData>(host, characterDataIDList);
|
||||
SaveIDListToDatabase<EquipmentData>(host, equipmentDataIDList);
|
||||
SaveIDListToDatabase<HUDData>(host, hudDataIDList);
|
||||
}
|
||||
|
||||
private void SaveIDListToDatabase<T>(ModHost host, List<string> idList) where T : ScriptableObject
|
||||
{
|
||||
ModManager.Database.TryAdd(typeof(T), new Dictionary<string, ScriptableObject>());
|
||||
|
||||
foreach (var assetName in idList)
|
||||
{
|
||||
T data = host.Assets.Load<T>(assetName);
|
||||
if (!ModManager.Database[typeof(T)].TryAdd(assetName, data))
|
||||
{
|
||||
Debug.LogWarning($"Asset '{assetName}' already exists in the database. Skipping addition.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
public partial class ModManifest
|
||||
{
|
||||
[Button]
|
||||
private void CollectAllKeywordData() => keywordDataIDList = CollectData<KeywordData>();
|
||||
|
||||
[Button]
|
||||
private void CollectAllCardData() => cardDataIDList = CollectData<CardData>();
|
||||
|
||||
[Button]
|
||||
private void CollectAllCharacterData() => characterDataIDList = CollectData<CharacterData>();
|
||||
|
||||
[Button]
|
||||
private void CollectAllEquipmentData() => equipmentDataIDList = CollectData<EquipmentData>();
|
||||
|
||||
[Button]
|
||||
private void CollectAllHUDData() => hudDataIDList = CollectData<HUDData>();
|
||||
}
|
||||
|
||||
public partial class ModManifest
|
||||
{
|
||||
private List<string> CollectData<T>() where T : ScriptableObject
|
||||
{
|
||||
string inEditorModPath = "Assets/Mods/" + inEditorModFolder;
|
||||
string dataTypeName = typeof(T).Name;
|
||||
string[] guids = UnityEditor.AssetDatabase.FindAssets($"t:{dataTypeName}", new[] { inEditorModPath });
|
||||
List<string> collectedDataIDList = new List<string>();
|
||||
|
||||
foreach (string guid in guids)
|
||||
{
|
||||
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(guid);
|
||||
T data = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
|
||||
string assetFileName = System.IO.Path.GetFileNameWithoutExtension(path);
|
||||
if (!Regex.IsMatch(assetFileName, @"^\w+_\w+_.+$"))
|
||||
{
|
||||
Debug.LogWarning("Asset name does not follow the 'Type_ModName_AssetName' format: " + assetFileName);
|
||||
}
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
collectedDataIDList.Add(assetFileName);
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log($"Collected {collectedDataIDList.Count} CardData assets.");
|
||||
return collectedDataIDList;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user