diff --git a/Aetheria.Shared.Unity.csproj b/Aetheria.Shared.Unity.csproj
index 8a9472fbb..8c7c16a4e 100644
--- a/Aetheria.Shared.Unity.csproj
+++ b/Aetheria.Shared.Unity.csproj
@@ -170,7 +170,7 @@
-
+
diff --git a/Assets/Materials/UI/Map Gravity Lines.mat b/Assets/Materials/UI/Map Gravity Lines.mat
index 13365b26e..d8a812926 100644
--- a/Assets/Materials/UI/Map Gravity Lines.mat
+++ b/Assets/Materials/UI/Map Gravity Lines.mat
@@ -86,7 +86,7 @@ Material:
- _Mode: 0
- _OcclusionStrength: 1
- _Parallax: 0.02
- - _Scale: 3.0991225
+ - _Scale: 2.049001
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
diff --git a/Assets/Scripts/CultCache/Editor/AetheriaDatabaseView.cs b/Assets/Scripts/CultCache/Editor/AetheriaDatabaseView.cs
new file mode 100644
index 000000000..a30834018
--- /dev/null
+++ b/Assets/Scripts/CultCache/Editor/AetheriaDatabaseView.cs
@@ -0,0 +1,46 @@
+using System;
+using System.IO;
+using UnityEditor;
+using UnityEngine;
+
+public class AetheriaDatabaseView : DatabaseListView
+{
+ // Singleton to avoid multiple instances of window.
+ private static DatabaseListView _instance;
+ private string tableName;
+ public static DatabaseListView Instance => _instance ? _instance : GetWindow();
+ [MenuItem("Window/Aetheria/Database Tools")]
+ static void Init() => Instance.Show();
+ private void Awake()
+ {
+ _instance = this;
+ }
+
+ protected override string DatabaseName => "Aetheria";
+
+ protected override string FilePath => Path.Combine(new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData").FullName, "AetherDB.msgpack");
+
+ protected override DatabaseEntryGroup[] Groupers => new DatabaseEntryGroup[]
+ {
+ new DatabaseEntryGroup(
+ data => data.Category,
+ category => Enum.GetName(typeof(SimpleCommodityCategory), category),
+ (data, category) => data.Category = category ),
+ new DatabaseEntryGroup(
+ data => data.Category,
+ category => Enum.GetName(typeof(CompoundCommodityCategory), category),
+ (data, category) => data.Category = category ),
+ new DatabaseEntryGroup(
+ data => data.HardpointType,
+ type => Enum.GetName(typeof(HardpointType), type),
+ (data, type) => data.Hardpoint = type),
+ // new DatabaseEntryGroup(
+ // data => data.Manufacturer,
+ // factionID => cultCache.Get(factionID).ShortName,
+ // (data, faction) => data.Manufacturer = faction),
+ new DatabaseEntryGroup(
+ data => data.HullType,
+ type => Enum.GetName(typeof(HullType), type),
+ (data, type) => data.HullType = type)
+ };
+}
\ No newline at end of file
diff --git a/Assets/Scripts/CultCache/Editor/AetheriaDatabaseView.cs.meta b/Assets/Scripts/CultCache/Editor/AetheriaDatabaseView.cs.meta
new file mode 100644
index 000000000..073e80c80
--- /dev/null
+++ b/Assets/Scripts/CultCache/Editor/AetheriaDatabaseView.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 4016d25951e246a184441b2aae75eba0
+timeCreated: 1617151686
\ No newline at end of file
diff --git a/Assets/Scripts/CultCache/Editor/BaseInspector.cs b/Assets/Scripts/CultCache/Editor/BaseInspector.cs
new file mode 100644
index 000000000..2c07b7e6e
--- /dev/null
+++ b/Assets/Scripts/CultCache/Editor/BaseInspector.cs
@@ -0,0 +1,31 @@
+using System;
+
+public abstract class BaseInspector
+{
+ protected const int width = 150;
+ protected const int labelWidth = 20;
+ protected const int toggleWidth = 18;
+ protected const int arrowWidth = 22;
+
+ public abstract T Inspect(string label, T value, object parent, DatabaseInspector inspectorWindow);
+}
+
+public abstract class BaseInspector where A : Attribute
+{
+ protected const int width = 150;
+ protected const int labelWidth = 20;
+ protected const int toggleWidth = 18;
+ protected const int arrowWidth = 22;
+
+ public abstract T Inspect(string label, T value, object parent, DatabaseInspector inspectorWindow, A attribute);
+}
+
+public abstract class BaseInspector where A : Attribute where B : Attribute
+{
+ protected const int width = 150;
+ protected const int labelWidth = 20;
+ protected const int toggleWidth = 18;
+ protected const int arrowWidth = 22;
+
+ public abstract T Inspect(string label, T value, object parent, DatabaseInspector inspectorWindow, A attributeA, B attributeB);
+}
\ No newline at end of file
diff --git a/Assets/Scripts/CultCache/Editor/InspectorBase.cs.meta b/Assets/Scripts/CultCache/Editor/BaseInspector.cs.meta
similarity index 100%
rename from Assets/Scripts/CultCache/Editor/InspectorBase.cs.meta
rename to Assets/Scripts/CultCache/Editor/BaseInspector.cs.meta
diff --git a/Assets/Scripts/CultCache/Editor/DatabaseInspector.cs b/Assets/Scripts/CultCache/Editor/DatabaseInspector.cs
index 95b276bda..048ee8153 100644
--- a/Assets/Scripts/CultCache/Editor/DatabaseInspector.cs
+++ b/Assets/Scripts/CultCache/Editor/DatabaseInspector.cs
@@ -19,49 +19,52 @@ using Object = UnityEngine.Object;
public class DatabaseInspector : EditorWindow
{
- public static DatabaseCache DatabaseCache;
+ public static CultCache CultCache;
public DatabaseEntry entry;
// Singleton to avoid multiple instances of window.
private static DatabaseInspector _instance;
public static DatabaseInspector Instance => _instance ? _instance : GetWindow();
- private DatabaseListView _list;
- private GUIStyle _labelStyle;
private Vector2 _view;
- private const float IconSize = 1.0f / 16;
- // private static HardpointData _hardpoint;
- private static float2 _dragOffset;
- private bool _ctrlDown;
- private string[] _hardpointTypes;
private const int width = 150;
- private const int labelWidth = 20;
- private const int toggleWidth = 18;
- private const int arrowWidth = 22;
- private Material _galaxyMat;
- private Texture2D _white;
private GUIStyle _warning;
private HashSet _listItemFoldouts = new HashSet();
private Material _schematicMat;
+ private Dictionary<(Type targetType, HashSet attributes), (object instance, Type type)> _inspectors =
+ new Dictionary<(Type targetType, HashSet attributes), (object instance, Type type)>();
+
+ private Dictionary _genericInspectors = new Dictionary();
public Color LabelColor => EditorGUIUtility.isProSkin ? Color.white : Color.black;
-
void OnEnable()
{
_instance = this;
- _list = DatabaseListView.Instance;
- _list.Show();
- DatabaseCache.OnDataUpdateLocal += _ => Repaint();
- DatabaseCache.OnDataUpdateRemote += _ => EditorDispatcher.Dispatch(Repaint);
+ CultCache.OnDataUpdateLocal += _ => Repaint();
+ CultCache.OnDataUpdateRemote += _ => EditorDispatcher.Dispatch(Repaint);
wantsMouseMove = true;
- _hardpointTypes = Enum.GetNames(typeof(HardpointType));
- _galaxyMat = new Material(Shader.Find("Unlit/GalaxyMap"));
- _schematicMat = new Material(Shader.Find("Legacy Shaders/Particles/Additive"));
- _white = Color.white.ToTexture();
_warning = new GUIStyle(EditorStyles.boldLabel);
_warning.normal.textColor = Color.red;
-
+
+ var inspectorTypes = typeof(BaseInspector<>).GetAllGenericChildClasses()
+ .Concat(typeof(BaseInspector<,>).GetAllGenericChildClasses())
+ .Concat(typeof(BaseInspector<,,>).GetAllGenericChildClasses());
+ foreach (var type in inspectorTypes)
+ {
+ var genericArguments = type.BaseType.GetGenericArguments();
+ if(genericArguments.Any())
+ {
+ if (genericArguments[0].ContainsGenericParameters)
+ {
+ _genericInspectors.Add(genericArguments[0].GetGenericTypeDefinition(), type);
+ }
+ else
+ {
+ _inspectors.Add((genericArguments[0], new HashSet(genericArguments.Skip(1))), (Activator.CreateInstance(type), type));
+ }
+ }
+ }
}
public void Inspect(object obj, bool inspectablesOnly = false)
@@ -71,148 +74,70 @@ public class DatabaseInspector : EditorWindow
Inspect(obj, field, inspectablesOnly);
}
- if (obj is EquippableItemData equippableItemData)
- {
- var restricted = false;
- var doubleRestricted = false;
- HullType type = HullType.Ship;
- foreach (var behavior in equippableItemData.Behaviors)
- {
- var restriction = behavior.GetType().GetCustomAttribute();
- if (restriction != null)
- {
- if (restricted && restriction.Type != type)
- doubleRestricted = true;
- restricted = true;
- type = restriction.Type;
- }
- }
- if(doubleRestricted)
- GUILayout.Label("ITEM UNEQUIPPABLE: BEHAVIOR HULL TYPE CONFLICT", _warning);
- else if (restricted)
- GUILayout.Label($"Item restricted by behavior to hull type {Enum.GetName(typeof(HullType), type)}", EditorStyles.boldLabel);
- }
+ // if (obj is EquippableItemData equippableItemData)
+ // {
+ // var restricted = false;
+ // var doubleRestricted = false;
+ // HullType type = HullType.Ship;
+ // foreach (var behavior in equippableItemData.Behaviors)
+ // {
+ // var restriction = behavior.GetType().GetCustomAttribute();
+ // if (restriction != null)
+ // {
+ // if (restricted && restriction.Type != type)
+ // doubleRestricted = true;
+ // restricted = true;
+ // type = restriction.Type;
+ // }
+ // }
+ // if(doubleRestricted)
+ // GUILayout.Label("ITEM UNEQUIPPABLE: BEHAVIOR HULL TYPE CONFLICT", _warning);
+ // else if (restricted)
+ // GUILayout.Label($"Item restricted by behavior to hull type {Enum.GetName(typeof(HullType), type)}", EditorStyles.boldLabel);
+ // }
}
public void Inspect(object obj, FieldInfo field, bool inspectablesOnly = false)
{
- var inspectable = field.GetCustomAttribute();
+ var inspectable = field.GetCustomAttribute();
if (inspectable == null && inspectablesOnly) return;
var type = field.FieldType;
var value = field.GetValue(obj);
- var link = inspectable as InspectableDatabaseLinkAttribute;
- if (type == typeof(float))
+ if (type.IsGenericType)
{
- if (inspectable is RangedFloatInspectableAttribute)
+ var genericTypeDefinition = type.GetGenericTypeDefinition();
+ if(_genericInspectors.ContainsKey(genericTypeDefinition))
{
- var range = inspectable as RangedFloatInspectableAttribute;
- field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (float) value, range.Min, range.Max));
+ var genericInspectorGenericType = _genericInspectors[genericTypeDefinition];
+ var genericInspectorType = genericInspectorGenericType.MakeGenericType(type.GenericTypeArguments[0]);
+ var genericInspector = Activator.CreateInstance(genericInspectorType);
+ var parameters = new[] {field.Name.SplitCamelCase(), field.GetValue(obj), obj, this};
+ field.SetValue(obj, genericInspectorType.GetMethod("Inspect").Invoke(genericInspector, parameters));
+ return;
}
- else if (inspectable is InspectableTemperatureAttribute)
- field.SetValue(obj, InspectTemperature(field.Name.SplitCamelCase(), (float) value));
- else
- field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (float) value));
}
- else if (type == typeof(float4[]) && inspectable is InspectableAnimationCurveAttribute)
+ var potentialInspectors = _inspectors.Keys
+ .Where(pi =>
+ pi.targetType == type &&
+ pi.attributes.All(attributeType => field.GetCustomAttribute(attributeType) != null));
+ if (potentialInspectors.Any())
{
- field.SetValue(obj, InspectAnimationCurve(field.Name.SplitCamelCase(), (float4[]) value));
- }
- else if (type == typeof(int))
- {
- if (inspectable is RangedIntInspectableAttribute)
- {
- var range = inspectable as RangedIntInspectableAttribute;
- field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (int) value, range.Min, range.Max));
- }
- else
- field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (int) value));
- }
- else if (type == typeof(int2))
- {
- field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (int2) field.GetValue(obj)));
- }
- else if (type == typeof(float3))
- {
- if (inspectable is InspectableColorAttribute)
- {
- field.SetValue(obj, ColorField(field.Name.SplitCamelCase(), ((float3)field.GetValue(obj)).ToColor()).ToFloat3());
- }
+ var preferredInspector = potentialInspectors.MaxBy(i => i.attributes.Count);
+ var parameters = new[] {field.Name.SplitCamelCase(), field.GetValue(obj), obj, this}
+ .Concat(preferredInspector.attributes.Select(attributeType => field.GetCustomAttribute(attributeType)))
+ .ToArray();
+ field.SetValue(obj, _inspectors[preferredInspector].type.GetMethod("Inspect").Invoke(_inspectors[preferredInspector].instance, parameters));
}
else if (type.IsEnum)
{
var isflags = type.GetCustomAttributes().Any();
var names = Enum.GetNames(field.FieldType);
field.SetValue(obj,
- Inspect(field.Name.SplitCamelCase(), (int) field.GetValue(obj), isflags ? names.Skip(1).ToArray() : names, isflags));
+ InspectEnum(field.Name.SplitCamelCase(), (int) field.GetValue(obj), isflags ? names.Skip(1).ToArray() : names, isflags));
}
- //else if (field.FieldType == typeof(Color)) Inspect(field.Name, () => (Color) field.GetValue(obj), c => field.SetValue(obj, c));
- else if (type == typeof(bool)) field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (bool) value));
- else if (type == typeof(string))
- {
- if (inspectable is InspectableUnityObjectAttribute unityObjectAttribute)
- {
- var inspectMethod = typeof(DatabaseInspector).GetMethod("InspectUnityObject");
- var generic = inspectMethod.MakeGenericMethod(unityObjectAttribute.ObjectType);
- field.SetValue(obj, generic.Invoke(this, new[] {value}));
- }
- if(inspectable is InspectablePrefabAttribute)
- field.SetValue(obj, InspectUnityObject(field.Name.SplitCamelCase(), (string) value));
- else if(inspectable is InspectableTextureAttribute)
- field.SetValue(obj, InspectUnityObject(field.Name.SplitCamelCase(), (string) value));
- else if(inspectable is InspectableTextAssetAttribute)
- field.SetValue(obj, InspectUnityObject(field.Name.SplitCamelCase(), (string) value));
- else
- field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (string) value, inspectable is InspectableTextAttribute));
- }
- else if (type == typeof(Type) && inspectable is InspectableTypeAttribute typeAttribute) field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (Type) value, typeAttribute.Type));
- else if (type == typeof(GameObject)) field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (GameObject) value));
- else if (type == typeof(AnimationCurve)) field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (AnimationCurve) value));
- else if (type == typeof(Shape)) field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (Shape) value, (obj is HullData hull) ? hull : null));
- else if (type == typeof(PerformanceStat)) field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (PerformanceStat) value, field.GetCustomAttribute() != null));
- else if (type == typeof(PerformanceStat[]))
- {
- LabelField(field.Name.SplitCamelCase(), EditorStyles.boldLabel);
- using (new VerticalScope(GUI.skin.box))
- {
- var stats = (PerformanceStat[]) value;
- var damageTypes = Enum.GetNames(typeof(DamageType));
- if(stats==null || stats.Length!=damageTypes.Length)
- stats = new PerformanceStat[damageTypes.Length];
- for (var i = 0; i < stats.Length; i++)
- {
- Inspect(damageTypes[i].SplitCamelCase(), stats[i]);
- }
- field.SetValue(obj, stats);
- }
- }
- else if (type == typeof(StatReference))
- {
- var statRef = (StatReference) field.GetValue(obj);
- Inspect(field.Name.SplitCamelCase(), ref statRef);
- }
- else if (type == typeof(Dictionary))
- {
- var dict = (Dictionary) field.GetValue(obj);
- Inspect(field.Name.SplitCamelCase(), ref dict, link.EntryType);
- }
- else if (type == typeof(Dictionary))
- {
- var dict = (Dictionary) field.GetValue(obj);
- var ranged = field.GetCustomAttribute();
- if(ranged != null)
- Inspect(field.Name.SplitCamelCase(), ref dict, link.EntryType, ranged.Min, ranged.Max);
- else Inspect(field.Name.SplitCamelCase(), ref dict, link.EntryType);
- }
- else if (type == typeof(List) && link != null)
- {
- var list = (List) field.GetValue(obj);
- if(list==null) field.SetValue(obj, list = new List());
- Inspect(field.Name.SplitCamelCase(), ref list, link.EntryType);
- }
- else if (type == typeof(Guid) && link != null) field.SetValue(obj, Inspect(field.Name.SplitCamelCase(), (Guid) value, link.EntryType));
- else if (type.GetCustomAttribute() != null)
+ else if (type.GetCustomAttribute() != null)
{
Space();
using (new HorizontalScope())
@@ -230,326 +155,10 @@ public class DatabaseInspector : EditorWindow
}
if(value != null) Inspect(field.GetValue(obj), inspectablesOnly);
}
- else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>))
- {
- var listType = field.FieldType.GenericTypeArguments[0];
- // if (listType.IsEnum)
- // {
- // Space();
- // using (new VerticalScope(GUI.skin.box))
- // {
- // var list = (IList) field.GetValue(obj);
- // if (list == null)
- // {
- // list = (IList) Activator.CreateInstance(type);
- // field.SetValue(obj, list);
- // GUI.changed = true;
- // }
- // var isflags = type.GetCustomAttributes().Any();
- // var names = Enum.GetNames(field.FieldType);
- //
- // for (var i = 0; i < list.Count; i++)
- // {
- // list[i] = Inspect(field.Name.SplitCamelCase(), (int) list[i], isflags ? names.Skip(1).ToArray() : names, isflags);
- // }
- // }
- // }
- if (listType.GetCustomAttribute() != null)
- {
- Space();
- using (new VerticalScope(GUI.skin.box))
- {
- var list = (IList) field.GetValue(obj);
- if (list == null)
- {
- list = (IList) Activator.CreateInstance(type);
- field.SetValue(obj, list);
- GUI.changed = true;
- }
- else
- {
- var sorted = true;
- var order = int.MinValue;
- foreach(var element in list)
- {
- var elementType = element.GetType();
- var elementOrder = elementType.GetCustomAttribute()?.Order ?? 0;
- if (elementOrder < order)
- sorted = false;
- order = elementOrder;
- }
-
- if (!sorted)
- {
- var sortedList = list
- .Cast