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() - .OrderBy(o => o.GetType().GetCustomAttribute()?.Order ?? 0); - list = (IList) Activator.CreateInstance(type); - foreach (var o in sortedList) - list.Add(o); - field.SetValue(obj, list); - GUI.changed = true; - } - } - foreach (var o in list) - { - if (o == null) - { - list.Remove(o); - break; - } - bool _tinted = false; - var originalColor = GUI.backgroundColor; - if (o is ITintInspector tint) - { - _tinted = true; - GUI.backgroundColor = tint.TintColor.ToColor(); - } - - using (new VerticalScope(_list.ListItemStyle)) - { - using (new HorizontalScope()) - { - //if (listType.IsInterface) - if(Foldout(_listItemFoldouts.Contains(o.GetHashCode()), o.ToString(), true)) - _listItemFoldouts.Add(o.GetHashCode()); - else - _listItemFoldouts.Remove(o.GetHashCode()); - - - // var rect = GetControlRect(false, - // GUILayout.Width(EditorGUIUtility.singleLineHeight)); - // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, - // LabelColor, 0, 0); - if (GUILayout.Button("-")) - { - list.Remove(o); - break; - } - } - if(_listItemFoldouts.Contains(o.GetHashCode())) - { - Space(); - - Inspect(o, inspectablesOnly); - } - } - - if(_tinted) - GUI.backgroundColor = originalColor; - } - using (new HorizontalScope(_list.ListItemStyle)) - { - GUILayout.Label($"Add new {listType.Name}", GUILayout.ExpandWidth(true)); - // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); - // GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); - if (GUILayout.Button("+")) - { - if (listType.IsInterface) - { - var menu = new GenericMenu(); - foreach (var behaviorType in listType.GetAllInterfaceClasses()) - { - menu.AddItem(new GUIContent(behaviorType.Name), false, () => - { - list.Add(Activator.CreateInstance(behaviorType)); - DatabaseCache.Add(entry); - }); - } - menu.ShowAsContext(); - } - else if (listType.IsAbstract) - { - var menu = new GenericMenu(); - foreach (var behaviorType in listType.GetAllChildClasses().Where(t=>!t.IsAbstract)) - { - menu.AddItem(new GUIContent(behaviorType.Name), false, () => - { - list.Add(Activator.CreateInstance(behaviorType)); - DatabaseCache.Add(entry); - }); - } - menu.ShowAsContext(); - } - else - { - list.Add(Activator.CreateInstance(listType)); - } - } - } - } - } - else if (typeof(Object).IsAssignableFrom(listType)) - { - Space(); - using (var v = new VerticalScope(GUI.skin.box)) - { - var list = (IList) field.GetValue(obj); - if (list == null) - { - list = (IList) Activator.CreateInstance(type); - field.SetValue(obj, list); - } - - if(list.Count==0) - using (new HorizontalScope(_list.ListItemStyle)) - GUILayout.Label($"Add a {listType.Name} by dragging from the project hierarchy."); - - foreach (var oo in list) - { - var o = (Object) oo; - using (new HorizontalScope(_list.ListItemStyle)) - { - GUILayout.Label(o.name.SplitCamelCase(), EditorStyles.boldLabel, GUILayout.ExpandWidth(true)); - - // var rect = GetControlRect(false, - // GUILayout.Width(EditorGUIUtility.singleLineHeight)); - // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, - // LabelColor, 0, 0); - if (GUILayout.Button("-")) - { - list.Remove(o); - break; - } - } - } - - if (v.rect.Contains(Event.current.mousePosition) && (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)) - { - var dragObj = DragAndDrop.objectReferences.FirstOrDefault(); - //var dragEntry = Database.Get(guid); - if(Event.current.type == EventType.DragUpdated) - DragAndDrop.visualMode = dragObj?.GetType() == listType ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; - else if(Event.current.type == EventType.DragPerform) - { - if (dragObj?.GetType() == listType) - { - DragAndDrop.AcceptDrag(); - GUI.changed = true; - list.Add(dragObj); - } - } - } - } - } - else Debug.Log($"Field \"{field.Name}\" is a list of non-Inspectable type {listType.Name}. No inspector was generated."); - } - else if (typeof(Object).IsAssignableFrom(type)) - { - using (new HorizontalScope()) - { - GUILayout.Label(field.Name.SplitCamelCase(), GUILayout.Width(width)); - field.SetValue(obj, ObjectField((Object)field.GetValue(obj),type,false)); - } - } -// else if (type == typeof(AudioClip)) -// { -// using (new EditorGUILayout.HorizontalScope()) -// { -// GUILayout.Label(field.Name.SplitCamelCase(), GUILayout.Width(width)); -// field.SetValue(obj, EditorGUILayout.ObjectField((AudioClip)field.GetValue(obj),typeof(AudioClip),false)); -// } -// } else Debug.Log($"Field \"{field.Name}\" has unknown type {field.FieldType.Name}. No inspector was generated."); } - public bool Inspect(string label, bool value) - { - using (var h = new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - return Toggle(value); - } - } - - public float Inspect(string label, float value) - { - using (var h = new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - return DelayedFloatField(value); - } - } - - public string Inspect(string label, string value, bool area = false) - { - using (var h = new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - if (area) - { - EditorStyles.textArea.wordWrap = true; - return DelayedTextField(value, EditorStyles.textArea, /*GUILayout.Width(EditorGUIUtility.currentViewWidth-width-10), */GUILayout.Height(100)); - } - return DelayedTextField(value); - } - } - - public float InspectTemperature(string label, float value) - { - using (var h = new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - GUILayout.Label("°K", _labelStyle, GUILayout.Width(labelWidth)); - value = DelayedFloatField(value);//, GUILayout.ExpandWidth(false) - GUILayout.Label("°C", _labelStyle, GUILayout.Width(labelWidth)); - value = DelayedFloatField(value - 273.15f) + 273.15f; - GUILayout.Label("°F", _labelStyle, GUILayout.Width(labelWidth)); - value = (DelayedFloatField((value - 273.15f) * 1.8f + 32) - 32) / 1.8f + 273.15f; - - return value; - } - } - - public float Inspect(string label, float value, float min, float max) - { - using (var h = new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - return Slider(value, min, max); - } - } - - public int Inspect(string label, int value) - { - using (var h = new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - return DelayedIntField(value); - } - } - - public int2 Inspect(string label, int2 value) - { - using (var h = new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - GUILayout.Label("X", GUILayout.Width(labelWidth)); - value.x = DelayedIntField(value.x); - GUILayout.Label("Y", GUILayout.Width(labelWidth)); - value.y = DelayedIntField(value.y); - if (GUILayout.Button("\u2190", GUILayout.Width(arrowWidth))) - value.x--; - if (GUILayout.Button("\u2192", GUILayout.Width(arrowWidth))) - value.x++; - if (GUILayout.Button("\u2191", GUILayout.Width(arrowWidth))) - value.y++; - if (GUILayout.Button("\u2193", GUILayout.Width(arrowWidth))) - value.y--; - return value; - } - } - - public int Inspect(string label, int value, int min, int max) - { - using (var h = new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - return IntSlider(value, min, max); - } - } - - public int Inspect(string label, int value, string[] enumOptions, bool flags) + public int InspectEnum(string label, int value, string[] enumOptions, bool flags) { if (flags) { @@ -580,538 +189,11 @@ public class DatabaseInspector : EditorWindow } } - public Type Inspect(string label, Type value, Type parentType) - { - var types = parentType.GetAllChildClasses(); - var enumOptions = new[] {"None"}.Concat(types.Select(t => t.Name)).ToArray(); - var index = Array.IndexOf(types, value) + 1; - - using (var h = new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - index = Popup(index, enumOptions); - } - - return index == 0 ? null : types[index - 1]; - } - - public string InspectUnityObject(string label, string value) where T : Object - { - using (var h = new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - return AssetDatabase.GetAssetPath(ObjectField(AssetDatabase.LoadAssetAtPath(value), typeof(T), false)); - } - } - - public GameObject Inspect(string label, GameObject value) - { - using (var h = new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - return (GameObject) ObjectField(value, typeof(GameObject), false); - } - } - - public float4[] InspectAnimationCurve(string label, float4[] value) - { - var val = value != null && value.Length > 0 - ? value.ToCurve() - : new AnimationCurve(); - using (var h = new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - val = CurveField(val, Color.yellow, new Rect(0, 0, 1, 1)); - } - - return val.keys.Select(k => float4(k.time, k.value, k.inTangent, k.outTangent)).ToArray(); - } - - public AnimationCurve Inspect(string label, AnimationCurve value) - { - using (var h = new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - if (value == null) - value = new AnimationCurve(); - value = CurveField(value, Color.yellow, new Rect(0, 0, 1, 1)); - } - - return value; - } - - public Guid Inspect(string label, Guid value, Type entryType) - { - LabelField(label, EditorStyles.boldLabel); - var valueEntry = DatabaseCache.Get(value); - using (var h = new HorizontalScope(GUI.skin.box)) - { - GUILayout.Label((valueEntry as INamedEntry)?.EntryName ?? valueEntry?.ID.ToString() ?? $"Assign a {entryType.Name} by dragging from the list panel."); - - if (h.rect.Contains(Event.current.mousePosition) && (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)) - { - var guid = (Guid) DragAndDrop.GetGenericData("Item"); - var dragEntry = DatabaseCache.Get(guid); - var dragValid = dragEntry != null && entryType.IsInstanceOfType(dragEntry) && dragEntry != entry; - if(Event.current.type == EventType.DragUpdated) - DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; - else if(Event.current.type == EventType.DragPerform) - { - if (dragValid) - { - DragAndDrop.AcceptDrag(); - GUI.changed = true; - return guid; - } - } - } - // var rect = GetControlRect(false, - // GUILayout.Width(EditorGUIUtility.singleLineHeight)); - // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, - // LabelColor, 0, 0); - if (GUILayout.Button("-")) - { - return Guid.Empty; - } - } - - return value; - } - - public void Inspect(string label, ref Dictionary value, Type referenceType) - { - Space(); - LabelField(label, EditorStyles.boldLabel); - - using (var v = new VerticalScope(GUI.skin.box)) - { - if (value.Count == 0) - { - using (var h = new HorizontalScope(_list.ListItemStyle)) - { - GUILayout.Label("Drag from list to add item"); - } - } - foreach (var ingredient in value.ToArray()) - { - using (var h = new HorizontalScope(_list.ListItemStyle)) - { - var entry = DatabaseCache.Get(ingredient.Key); - if (entry == null) - { - value.Remove(ingredient.Key); - GUI.changed = true; - return; - } - if(entry is INamedEntry named) - GUILayout.Label(named.EntryName); - else GUILayout.Label(entry.ID.ToString()); - - value[ingredient.Key] = DelayedIntField(value[ingredient.Key], GUILayout.Width(50)); - - // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); - // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); - if (GUILayout.Button("-") || value[ingredient.Key]==0) - value.Remove(ingredient.Key); - } - } - - if (v.rect.Contains(Event.current.mousePosition)) - { - var dragData = DragAndDrop.GetGenericData("Item"); - var isId = dragData is Guid guid; - var dragEntry = isId ? DatabaseCache.Get(guid) : null; - var correctType = referenceType.IsInstanceOfType(dragEntry); - if(Event.current.type == EventType.DragUpdated) - DragAndDrop.visualMode = correctType ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; - else if(Event.current.type == EventType.DragPerform) - { - if (isId && correctType) - { - DragAndDrop.AcceptDrag(); - value[guid] = 1; - GUI.changed = true; - } - } - } - } - } - - public void Inspect(string label, ref Dictionary value, Type referenceType) - { - Space(); - LabelField(label, EditorStyles.boldLabel); - - using (var v = new VerticalScope(GUI.skin.box)) - { - if (value.Count == 0) - { - using (var h = new HorizontalScope(_list.ListItemStyle)) - { - GUILayout.Label("Drag from list to add item"); - } - } - foreach (var ingredient in value.ToArray()) - { - using (var h = new HorizontalScope(_list.ListItemStyle)) - { - var entry = DatabaseCache.Get(ingredient.Key); - if (entry == null) - { - value.Remove(ingredient.Key); - GUI.changed = true; - return; - } - - if(entry is INamedEntry named) - GUILayout.Label(named.EntryName); - else GUILayout.Label(entry.ID.ToString()); - value[ingredient.Key] = DelayedFloatField(value[ingredient.Key], GUILayout.Width(50)); - - // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); - // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); - if (GUILayout.Button("-")) - value.Remove(ingredient.Key); - } - } - - if (v.rect.Contains(Event.current.mousePosition)) - { - var dragData = DragAndDrop.GetGenericData("Item"); - var isId = dragData is Guid guid; - var dragEntry = isId ? DatabaseCache.Get(guid) : null; - var correctType = referenceType.IsInstanceOfType(dragEntry); - if(Event.current.type == EventType.DragUpdated) - DragAndDrop.visualMode = correctType ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; - else if(Event.current.type == EventType.DragPerform) - { - if (isId && correctType) - { - DragAndDrop.AcceptDrag(); - value[guid] = 1; - GUI.changed = true; - } - } - } - } - } - - public void Inspect(string label, ref Dictionary value, Type referenceType, float min, float max) - { - Space(); - LabelField(label, EditorStyles.boldLabel); - - using (var v = new VerticalScope(GUI.skin.box)) - { - if (value.Count == 0) - { - using (var h = new HorizontalScope(_list.ListItemStyle)) - { - GUILayout.Label("Drag from list to add item"); - } - } - foreach (var ingredient in value.ToArray()) - { - using (var h = new HorizontalScope(_list.ListItemStyle)) - { - var entry = DatabaseCache.Get(ingredient.Key); - if (entry == null) - { - value.Remove(ingredient.Key); - GUI.changed = true; - return; - } - - if(entry is INamedEntry named) - GUILayout.Label(named.EntryName); - else GUILayout.Label(entry.ID.ToString()); - value[ingredient.Key] = Slider(value[ingredient.Key], min, max); - - // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); - // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); - if (GUILayout.Button("-")) - value.Remove(ingredient.Key); - } - } - - if (v.rect.Contains(Event.current.mousePosition)) - { - var dragData = DragAndDrop.GetGenericData("Item"); - var isId = dragData is Guid guid; - var dragEntry = isId ? DatabaseCache.Get(guid) : null; - var correctType = referenceType.IsInstanceOfType(dragEntry); - if(Event.current.type == EventType.DragUpdated) - DragAndDrop.visualMode = correctType ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; - else if(Event.current.type == EventType.DragPerform) - { - if (isId && correctType) - { - DragAndDrop.AcceptDrag(); - value[guid] = max; - GUI.changed = true; - } - } - } - } - } - - public void Inspect(string label, ref List value, Type entryType) - { - Space(); - LabelField(label, EditorStyles.boldLabel); - - using (var v = new VerticalScope(GUI.skin.box)) - { - if (value.Count == 0) - { - using (var h = new HorizontalScope(_list.ListItemStyle)) - { - GUILayout.Label($"Drag from list to add {entryType.Name}"); - } - } - foreach (var guid in value.ToArray()) - { - using (var h = new HorizontalScope(_list.ListItemStyle)) - { - var entry = DatabaseCache.Get(guid); - if (entry == null) - { - value.Remove(guid); - GUI.changed = true; - } - else - { - GUILayout.Label((entry as INamedEntry)?.EntryName ?? entry.ID.ToString()); - - // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); - // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); - if (GUILayout.Button("-")) - { - value.Remove(guid); - } - } - } - } - - if (v.rect.Contains(Event.current.mousePosition)) - { - var guid = DragAndDrop.GetGenericData("Item"); - var dragObj = DragAndDrop.GetGenericData("Item") is Guid ? DatabaseCache.Get((Guid) guid) : null; - var dragValid = entryType.IsInstanceOfType(dragObj) && dragObj != entry; - if(Event.current.type == EventType.DragUpdated) - DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; - else if(Event.current.type == EventType.DragPerform) - { - if (dragValid) - { - DragAndDrop.AcceptDrag(); - value.Add((Guid) guid); - GUI.changed = true; - } - } - } - } - } - - public Shape Inspect(string label, Shape value, HullData hull = null) - { - if(value == null) - { - value = new Shape(1, 1); - value[int2.zero] = true; - } - using (new VerticalScope()) - { - Texture2D schematic = null; - if(hull != null && !string.IsNullOrEmpty(hull.Schematic)) - schematic = AssetDatabase.LoadAssetAtPath(hull.Schematic); - using (new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - GUILayout.Label("Size", GUILayout.ExpandWidth(false)); - if(schematic == null) - { - GUILayout.Label("X", GUILayout.Width(labelWidth)); - value.Width = DelayedIntField(value.Width); - GUILayout.Label("Y", GUILayout.Width(labelWidth)); - value.Height = DelayedIntField(value.Height); - } - else - { - GUILayout.Label("X", GUILayout.Width(labelWidth)); - value.Width = DelayedIntField(value.Width); - value.Height = Mathf.RoundToInt(value.Width * ((float)schematic.height / schematic.width)); - GUILayout.Label("Y", GUILayout.Width(labelWidth)); - LabelField($"{value.Height}"); - } - } - - using (new HorizontalScope()) - { - GUILayout.Label("", GUILayout.Width(width)); - using (var a = new VerticalScope()) - { - if(schematic != null) - { - EditorGUI.DrawPreviewTexture(a.rect, schematic, _schematicMat); - } - for (var y = value.Height - 1; y >= 0; y--) - { - using (new HorizontalScope()) - { - for (var x = 0; x < value.Width; x++) - { - var oldColor = GUI.backgroundColor; - if(hull != null) - { - var hardpoint = hull.Hardpoints - .FirstOrDefault(hp => - hp.Shape.Coordinates - .Select(v => v + hp.Position) - .Any(v => v.x == x && v.y == y)); - if (hardpoint != null) - GUI.backgroundColor = hardpoint.TintColor.ToColor(); - } - value[int2(x, y)] = Toggle(value[int2(x, y)], GUILayout.Width(toggleWidth)); - GUI.backgroundColor = oldColor; - } - } - } - } - GUILayout.FlexibleSpace(); - } - } - - return value; - } - - public void Inspect(string label, ref StatReference effect) - { - using (new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - - using (new VerticalScope()) - { - var targetObjects = typeof(BehaviorData).GetAllChildClasses() - .Concat(typeof(EquippableItemData).GetAllChildClasses()).ToArray(); - var objectNames = targetObjects.Select(b => b.Name).ToArray(); - var selectedIndex = Array.IndexOf(objectNames, effect.Target); - if (selectedIndex == -1) - { - selectedIndex = 0; - GUI.changed = true; - } - using (new HorizontalScope()) - { - GUILayout.Label("Target", GUILayout.Width(width)); - var newSelection = Popup(selectedIndex, objectNames); - if (newSelection != selectedIndex) - GUI.changed = true; - effect.Target = objectNames[newSelection]; - } - - using (new HorizontalScope()) - { - GUILayout.Label("Stat", GUILayout.Width(width)); - var stats = targetObjects[selectedIndex].GetFields() - .Where(f => f.FieldType == typeof(PerformanceStat)).ToArray(); - if(stats.Length==0) - GUILayout.Label("No Stats!"); - else - { - var statNames = stats.Select(s => s.Name).ToArray(); - var selectedStatIndex = Array.IndexOf(statNames, effect.Stat); - if (selectedStatIndex == -1) - { - selectedStatIndex = 0; - GUI.changed = true; - } - var newSelection = Popup(selectedStatIndex, statNames); - if (newSelection != selectedStatIndex) - GUI.changed = true; - effect.Stat = statNames[newSelection]; - } - } - } - } - } - - public PerformanceStat Inspect(string label, PerformanceStat value, bool isSimple = false) - { - if(value == null) - value = new PerformanceStat(); - using (new VerticalScope()) - { - using (new HorizontalScope()) - { - GUILayout.Label(label, GUILayout.Width(width)); - GUILayout.Label("Min", _labelStyle, GUILayout.Width(labelWidth)); - value.Min = DelayedFloatField(value.Min); - GUILayout.Label("Max", _labelStyle, GUILayout.Width(labelWidth + 5)); - value.Max = DelayedFloatField(value.Max); - } - - // Only display heat, durability and quality effects if the stat actually varies - if (Math.Abs(value.Min - value.Max) > .0001f) - { - using (new HorizontalScope()) - { - GUILayout.Label("", GUILayout.Width(width)); - if (!isSimple) - { - GUILayout.Label("H", _labelStyle, GUILayout.Width(labelWidth)); - value.HeatExponentMultiplier = DelayedFloatField(value.HeatExponentMultiplier); - - GUILayout.Label("D", _labelStyle, GUILayout.Width(labelWidth)); - value.DurabilityExponentMultiplier = DelayedFloatField(value.DurabilityExponentMultiplier); - - GUILayout.Label("Q", _labelStyle, GUILayout.Width(labelWidth)); - value.QualityExponent = DelayedFloatField(value.QualityExponent); - } - else - { - GUILayout.Label("Quality Exponent", _labelStyle); - value.QualityExponent = DelayedFloatField(value.QualityExponent); - } - } - } - - - // using (new HorizontalScope()) - // { - // GUILayout.Label("", GUILayout.Width(width)); - // GUILayout.Label("Ingredient", GUILayout.ExpandWidth(false)); - // var ingredients = crafted.Ingredients.Keys.Select(DatabaseCache.Get).Where(i => i is CraftedItemData).Cast().ToList(); - // var ingredient = value.Ingredient != null ? DatabaseCache.Get(value.Ingredient.Value) as CraftedItemData : null; - // var names = ingredients.Select(i => i.Name).Append("None").ToArray(); - // var selected = value.Ingredient == null || !crafted.Ingredients.ContainsKey(value.Ingredient.Value) - // ? names.Length - 1 - // : ingredients.IndexOf(ingredient); - // var selection = Popup(selected, names); - // value.Ingredient = selection == names.Length - 1 ? (Guid?) null : ingredients[selection].ID; - // } - - Space(); - } - - return value; - } - public void OnGUI() { - _labelStyle = new GUIStyle(EditorStyles.centeredGreyMiniLabel) {normal = {textColor = LabelColor}}; - - Event current = Event.current; - EventType currentEventType = current.type; - if (currentEventType == EventType.KeyDown && current.keyCode == KeyCode.LeftControl) - _ctrlDown = true; - if (currentEventType == EventType.KeyUp && current.keyCode == KeyCode.LeftControl) - _ctrlDown = false; - if (entry==null) { - LabelField($"{(_list.SelectedItem==Guid.Empty?"No Entry Selected":"Selected Entry Not Found in Database")}\n{_list.SelectedItem}"); + LabelField("No Entry Selected!"); return; } @@ -1140,22 +222,18 @@ public class DatabaseInspector : EditorWindow { // if(GUILayout.Button("Print JSON")) // Debug.Log(entry.ToJson()); - // if (GUILayout.Button("Duplicate")) - // { - // DatabaseCache.Duplicate(entry); - // } if (GUILayout.Button("Delete Entry")) { - DatabaseCache.Delete(entry); + CultCache.Delete(entry); entry = null; return; } if (GUILayout.Button("Clone Entry")) { - var copy = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(entry)); + var copy = MessagePackSerializer.Deserialize(previousBytes); copy.ID = Guid.NewGuid(); - DatabaseCache.Add(copy); + CultCache.Add(copy); } } @@ -1166,25 +244,13 @@ public class DatabaseInspector : EditorWindow } Inspect(entry, true); - - #region Hull - var hull = entry as HullData; - if (hull != null) - { - Space(); - - // TODO: Hull Hardpoints Inspector - - } - #endregion if (EditorGUI.EndChangeCheck()) { if(!previousBytes.ByteEquals(MessagePackSerializer.Serialize(entry))) - DatabaseCache.Add(entry); + CultCache.Add(entry); } EndScrollView(); - } } diff --git a/Assets/Scripts/CultCache/Editor/DatabaseView.cs b/Assets/Scripts/CultCache/Editor/DatabaseView.cs index 59d449790..3cd2db9b4 100644 --- a/Assets/Scripts/CultCache/Editor/DatabaseView.cs +++ b/Assets/Scripts/CultCache/Editor/DatabaseView.cs @@ -14,89 +14,119 @@ using UnityEditor; using UnityEngine; using static UnityEditor.EditorGUILayout; -public class DatabaseListView : EditorWindow +public abstract class DatabaseListView : EditorWindow { - // Singleton to avoid multiple instances of window. - private static DatabaseListView _instance; - public static DatabaseListView Instance => _instance ? _instance : GetWindow(); - [MenuItem("Window/GameCult/Database Tools")] - static void Init() => Instance.Show(); - private void Awake() - { - _instance = this; - } + public static GUIStyle ListStyleOdd; + public static GUIStyle ListStyleEven; public Guid SelectedItem; public GUIStyle SelectedStyle; public static RethinkDB R = RethinkDB.R; - private DatabaseCache _databaseCache; - private bool[] _itemTypeFoldouts; - private bool _itemsFoldout; - private bool _compoundFoldout; - private bool _simpleFoldout; - private bool _commoditiesFoldout; - //private bool _consumablesFoldout; - private Type[] _itemTypes; - private bool _listItemStyle; - private GUIStyle _listStyleOdd; - private GUIStyle _listStyleEven; + protected CultCache cultCache; private static DatabaseInspector _inspector; private Type[] _entryTypes; - private bool[] _entryFoldouts; + private bool[] _typeFoldouts; private string _connectionString; - private const float LineHeight = 20; private Vector2 _view; private RethinkQueryStatus _queryStatus; - private HashSet _itemGroupFoldouts = new HashSet(); - private HashSet _itemManufacturerFoldouts = new HashSet(); - private HashSet<(Guid, HardpointType)> _itemManufacturerTypeFoldouts = new HashSet<(Guid, HardpointType)>(); - private string _filePath => Path.Combine(new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData").FullName, _fileName); - private string _fileName = "AetherDB.msgpack"; + + private HashSet _groupFoldouts = new HashSet(); + + protected abstract string DatabaseName { get; } + protected abstract string FilePath { get; } + protected virtual DatabaseEntryGroup[] Groupers => new DatabaseEntryGroup[] { }; + + protected class DatabaseEntryGroup : DatabaseEntryGroup where T : DatabaseEntry + { + public Func GroupSelector { get; } + public Func GroupLabel { get; } + public Action Activator { get; } + + public DatabaseEntryGroup(Func groupSelector, Func groupLabel, Action activator) + { + GroupSelector = groupSelector; + GroupLabel = groupLabel; + Activator = activator; + } + + public override bool CanGroup(Type type) + { + return typeof(T) == type; + } + + public override object SelectGroup(DatabaseEntry o) + { + if (o is T t) return GroupSelector(t); + return null; + } + + public override string GetGroupName(object o) + { + if (o is K k) return GroupLabel(k); + return "ERROR"; + } + + public override int HashGroup(object o) + { + if (o is K k) return k.GetHashCode(); + return 0; + } + + public override void Activate(DatabaseEntry o, object g) + { + if(o is T t && g is K k) Activator(t, k); + throw new ArgumentException( + $"Entry group activation failed! Expected: object type {typeof(T)}, group type {typeof(K)}; received: object type {o.GetType()}, group type {g.GetType()}"); + } + } + + protected abstract class DatabaseEntryGroup + { + public abstract bool CanGroup(Type type); + public abstract object SelectGroup(DatabaseEntry o); + public abstract string GetGroupName(object o); + public abstract int HashGroup(object o); + public abstract void Activate(DatabaseEntry o, object g); + } public Color LabelColor => EditorGUIUtility.isProSkin ? Color.white : Color.black; + private bool _listItemStyle; public GUIStyle ListItemStyle => - (_listItemStyle = !_listItemStyle) ? _listStyleEven : _listStyleOdd; + (_listItemStyle = !_listItemStyle) ? ListStyleEven : ListStyleOdd; void OnEnable() { + ListStyleOdd = new GUIStyle + { + normal = {background = EditorGUIUtility.isProSkin ? XKCDColors.DarkGrey.ToTexture() : XKCDColors.LightGrey.ToTexture()}, + margin = new RectOffset(0, 0, 0, 0) + }; + ListStyleEven = new GUIStyle + { + normal = {background = EditorGUIUtility.isProSkin ? Color.Lerp(XKCDColors.DarkGrey,Color.black,.5f).ToTexture() : Color.Lerp(XKCDColors.LightGrey,Color.white,.5f).ToTexture()}, + margin = new RectOffset(0, 0, 0, 0) + }; - //_filePath = ; - // Create database cache - _databaseCache = new DatabaseCache(_filePath); + cultCache = new CultCache(FilePath); - // var onInsert = new Action(entry => - // { - // }); - // _databaseCache.OnDataInsertLocal += onInsert; - // _databaseCache.OnDataInsertRemote += onInsert; + cultCache.OnDataUpdateLocal += _ => Repaint(); + cultCache.OnDataInsertLocal += _ => Repaint(); + cultCache.OnDataDeleteLocal += _ => Repaint(); + cultCache.OnDataUpdateRemote += _ => EditorDispatcher.Dispatch(Repaint); + cultCache.OnDataInsertRemote += _ => EditorDispatcher.Dispatch(Repaint); + cultCache.OnDataDeleteRemote += _ => EditorDispatcher.Dispatch(Repaint); - // var onDelete = new Action(entry => - // { - // }); - // _databaseCache.OnDataDeleteLocal += onDelete; - // _databaseCache.OnDataDeleteRemote += onDelete; - - _databaseCache.OnDataUpdateLocal += _ => Repaint(); - _databaseCache.OnDataInsertLocal += _ => Repaint(); - _databaseCache.OnDataDeleteLocal += _ => Repaint(); - _databaseCache.OnDataUpdateRemote += _ => EditorDispatcher.Dispatch(Repaint); - _databaseCache.OnDataInsertRemote += _ => EditorDispatcher.Dispatch(Repaint); - _databaseCache.OnDataDeleteRemote += _ => EditorDispatcher.Dispatch(Repaint); - - DatabaseInspector.DatabaseCache = _databaseCache; + DatabaseInspector.CultCache = cultCache; _inspector = DatabaseInspector.Instance; _inspector.Show(); - _itemTypes = typeof(ItemData).GetAllChildClasses() - .Where(t => t.GetCustomAttribute() != null).ToArray(); _entryTypes = typeof(DatabaseEntry).GetAllChildClasses() - .Where(t => t.GetCustomAttribute() != null && !typeof(ItemData).IsAssignableFrom(t)).ToArray(); + .Where(t => t.GetCustomAttribute() != null).ToArray(); - _itemTypeFoldouts = new bool[_itemTypes.Length]; - _entryFoldouts = new bool[_entryTypes.Length]; + _typeFoldouts = new bool[_entryTypes.Length]; if (EditorPrefs.HasKey("RethinkDB.URL")) _connectionString = EditorPrefs.GetString("RethinkDB.URL"); @@ -108,20 +138,9 @@ public class DatabaseListView : EditorWindow private void InitStyles() { - var isDark = EditorGUIUtility.isProSkin; - _listStyleOdd = new GUIStyle - { - normal = {background = isDark ? XKCDColors.DarkGrey.ToTexture() : XKCDColors.LightGrey.ToTexture()}, - margin = new RectOffset(0, 0, 0, 0) - }; - _listStyleEven = new GUIStyle - { - normal = {background = isDark ? Color.Lerp(XKCDColors.DarkGrey,Color.black,.5f).ToTexture() : Color.Lerp(XKCDColors.LightGrey,Color.white,.5f).ToTexture()}, - margin = new RectOffset(0, 0, 0, 0) - }; SelectedStyle = new GUIStyle { - normal = {background = isDark ? XKCDColors.DarkGreyBlue.ToTexture() : XKCDColors.Greyblue.ToTexture()}, + normal = {background = EditorGUIUtility.isProSkin ? XKCDColors.DarkGreyBlue.ToTexture() : XKCDColors.Greyblue.ToTexture()}, margin = new RectOffset(0, 0, 0, 0) }; } @@ -142,7 +161,7 @@ public class DatabaseListView : EditorWindow { EditorPrefs.SetString("RethinkDB.URL", _connectionString); JsonKnownTypesSettingsManager.RegisterTypeAssembly(); - _queryStatus = RethinkConnection.RethinkConnect(_databaseCache, _connectionString); + _queryStatus = RethinkConnection.RethinkConnect(cultCache, _connectionString, DatabaseName); } // if (GUILayout.Button("Connect All")) // { @@ -155,21 +174,21 @@ public class DatabaseListView : EditorWindow //_fileName = TextField(_fileName); if (GUILayout.Button("Save")) { - _databaseCache.Save(); + cultCache.Save(); Debug.Log("Local DB Cache Saved!"); } if (GUILayout.Button("Load")) { - _databaseCache.Load(); + cultCache.Load(); Debug.Log("Loaded DB From Local Cache!"); } } - if (_queryStatus != null && _queryStatus.RetrievedItems < _queryStatus.GalaxyEntries + _queryStatus.ItemsEntries) + if (_queryStatus != null && _queryStatus.RetrievedEntries < _queryStatus.TotalEntries) { var progressRect = GetControlRect(false, 20); - EditorGUI.ProgressBar(progressRect, (float)_queryStatus.RetrievedItems/(_queryStatus.GalaxyEntries + _queryStatus.ItemsEntries), "Sync Progress"); + EditorGUI.ProgressBar(progressRect, (float)_queryStatus.RetrievedEntries/_queryStatus.TotalEntries, "Sync Progress"); } GUILayout.Space(5); @@ -183,228 +202,100 @@ public class DatabaseListView : EditorWindow GUILayout.Width(EditorGUIUtility.currentViewWidth), GUILayout.ExpandHeight(true)); - // if(GUILayout.Button("Log Cache Count")) - // Debug.Log($"Cache contains {_databaseCache.AllEntries.Count()} elements"); - - using (var h = new HorizontalScope(ListItemStyle)) - { - _itemsFoldout = Foldout(_itemsFoldout, "Items", true); - } - if (_itemsFoldout) - { - var items = _databaseCache.AllEntries.Where(item => item is ItemData).Cast().ToArray(); - for (var i = 0; i < _itemTypes.Length; i++) - { - using (var h = new HorizontalScope(ListItemStyle)) - { - GUILayout.Space(10); - _itemTypeFoldouts[i] = Foldout(_itemTypeFoldouts[i], - ((NameAttribute) _itemTypes[i].GetCustomAttribute(typeof(NameAttribute)))?.Name ?? FormatTypeName(_itemTypes[i].Name), - true); - } - if (_itemTypeFoldouts[i]) - { - if (_itemTypes[i] == typeof(SimpleCommodityData) || - _itemTypes[i] == typeof(CompoundCommodityData) || - _itemTypes[i] == typeof(HullData)) - { - var typedItems = items - .Where(e => e.GetType() == _itemTypes[i]) - .OrderBy(item => item.Name); - IEnumerable> itemGroups = new List>(); - if(_itemTypes[i] == typeof(SimpleCommodityData)) - itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(SimpleCommodityCategory), (item as SimpleCommodityData).Category)); - else if(_itemTypes[i] == typeof(CompoundCommodityData)) - itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(CompoundCommodityCategory), (item as CompoundCommodityData).Category)); - else if (_itemTypes[i] == typeof(HullData)) - itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(HullType), (item as HullData).HullType)); - else itemGroups = typedItems.GroupBy(item => "All"); - - foreach (var itemGroup in itemGroups) - { - using (var h = new HorizontalScope(ListItemStyle)) - { - GUILayout.Space(20); - if (Foldout(_itemGroupFoldouts.Contains(itemGroup.Key), FormatTypeName(itemGroup.Key), true)) - _itemGroupFoldouts.Add(itemGroup.Key); - else _itemGroupFoldouts.Remove(itemGroup.Key); - } - - if (_itemGroupFoldouts.Contains(itemGroup.Key)) - { - foreach (var item in itemGroup) - { - var style = ListItemStyle; - var selected = SelectedItem == item.ID; - using (new HorizontalScope(selected?SelectedStyle:style)) - { - using (var h = new HorizontalScope()) - { - if (h.rect.Contains(currentEvent.mousePosition)) - { - if (currentEventType == EventType.MouseDrag) - { - DragAndDrop.PrepareStartDrag(); - DragAndDrop.SetGenericData("Item", item.ID); - DragAndDrop.StartDrag("Database Item"); - } - else if (currentEventType == EventType.MouseUp) - Select(item); - } - - GUILayout.Space(30); - GUILayout.Label(item.Name, selected ? EditorStyles.whiteLabel : GUI.skin.label); - } - } - } - } - } - } - else - { - if (!typeof(EquippableItemData).IsAssignableFrom(_itemTypes[i])) - throw new InvalidCastException($"Type {_itemTypes[i].Name} is invalid! Expected equippable item."); - var typedItems = items - .Where(e => e.GetType() == _itemTypes[i]) - .Cast() - .OrderBy(item => item.Name); - var manufacturerGroups = typedItems.GroupBy(item => item.Manufacturer); - foreach (var manufacturerGroup in manufacturerGroups) - { - var manufacturer = _databaseCache.Get(manufacturerGroup.Key); - var manufacturerName = manufacturer?.Name ?? "None"; - using (var h = new HorizontalScope(ListItemStyle)) - { - GUILayout.Space(20); - if (Foldout(_itemManufacturerFoldouts.Contains(manufacturerGroup.Key), manufacturerName, true)) - _itemManufacturerFoldouts.Add(manufacturerGroup.Key); - else _itemManufacturerFoldouts.Remove(manufacturerGroup.Key); - } - - if (_itemManufacturerFoldouts.Contains(manufacturerGroup.Key)) - { - if (_itemTypes[i] == typeof(GearData) || _itemTypes[i] == typeof(WeaponItemData)) - { - var itemGroups = manufacturerGroup.GroupBy(item => item.HardpointType); - - foreach (var itemGroup in itemGroups) - { - using (var h = new HorizontalScope(ListItemStyle)) - { - GUILayout.Space(30); - if (Foldout(_itemManufacturerTypeFoldouts.Contains((manufacturerGroup.Key, itemGroup.Key)), Enum.GetName(typeof(HardpointType), itemGroup.Key), true)) - _itemManufacturerTypeFoldouts.Add((manufacturerGroup.Key, itemGroup.Key)); - else _itemManufacturerTypeFoldouts.Remove((manufacturerGroup.Key, itemGroup.Key)); - } - - if (_itemManufacturerTypeFoldouts.Contains((manufacturerGroup.Key, itemGroup.Key))) - { - foreach (var item in itemGroup) - { - var style = ListItemStyle; - var selected = SelectedItem == item.ID; - using (new HorizontalScope(selected?SelectedStyle:style)) - { - using (var h = new HorizontalScope()) - { - if (h.rect.Contains(currentEvent.mousePosition)) - { - if (currentEventType == EventType.MouseDrag) - { - DragAndDrop.PrepareStartDrag(); - DragAndDrop.SetGenericData("Item", item.ID); - DragAndDrop.StartDrag("Database Item"); - } - else if (currentEventType == EventType.MouseUp) - Select(item); - } - - GUILayout.Space(40); - GUILayout.Label(item.Name, selected ? EditorStyles.whiteLabel : GUI.skin.label); - } - } - } - } - } - } - else - { - foreach (var item in manufacturerGroup) - { - var style = ListItemStyle; - var selected = SelectedItem == item.ID; - using (new HorizontalScope(selected?SelectedStyle:style)) - { - using (var h = new HorizontalScope()) - { - if (h.rect.Contains(currentEvent.mousePosition)) - { - if (currentEventType == EventType.MouseDrag) - { - DragAndDrop.PrepareStartDrag(); - DragAndDrop.SetGenericData("Item", item.ID); - DragAndDrop.StartDrag("Database Item"); - } - else if (currentEventType == EventType.MouseUp) - Select(item); - } - - GUILayout.Space(30); - GUILayout.Label(item.Name, selected ? EditorStyles.whiteLabel : GUI.skin.label); - } - } - } - } - } - } - } - - using (var h = new HorizontalScope(ListItemStyle)) - { - if(GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) - CreateItem(_itemTypes[i]); - GUILayout.Space(20); - GUILayout.Label("New " + FormatTypeName(_itemTypes[i].Name)); - // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); - // GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); - } - } - } - } - - //var entries = _databaseCache.AllEntries.Where(item => !(item is ItemData)).ToArray(); for (var i = 0; i < _entryTypes.Length; i++) { using (var h = new HorizontalScope(ListItemStyle)) { - _entryFoldouts[i] = Foldout(_entryFoldouts[i], + _typeFoldouts[i] = Foldout(_typeFoldouts[i], ((NameAttribute) _entryTypes[i].GetCustomAttribute(typeof(NameAttribute)))?.Name ?? FormatTypeName(_entryTypes[i].Name), true); } - if (_entryFoldouts[i]) + if (_typeFoldouts[i]) { - int index = 0; - foreach (var entry in _databaseCache.GetAll(_entryTypes[i]).OrderBy(entry=>entry is INamedEntry namedEntry ? namedEntry.EntryName : entry.ID.ToString())) + // TODO: NESTED GROUPS! + var entries = cultCache.GetAll(_entryTypes[i]) + .OrderBy(entry => entry is INamedEntry namedEntry ? namedEntry.EntryName : entry.ID.ToString()); + var grouper = Groupers.FirstOrDefault(g => g.CanGroup(_entryTypes[i])); + if (grouper != null) { - index++; - var style = ListItemStyle; - var selected = SelectedItem == entry.ID; - using (var h = new HorizontalScope(selected?SelectedStyle:style)) + var groups = entries.GroupBy(o => grouper.SelectGroup(o)); + foreach (var group in groups) { - if (h.rect.Contains(currentEvent.mousePosition)) + var groupHash = grouper.HashGroup(group.Key); + var groupName = grouper.GetGroupName(group.Key); + using (var h = new HorizontalScope(ListItemStyle)) { - if (currentEventType == EventType.MouseDrag) - { - DragAndDrop.PrepareStartDrag(); - DragAndDrop.SetGenericData("Item", entry.ID); - DragAndDrop.StartDrag("Database Item"); - } - else if (currentEventType == EventType.MouseUp) - Select(entry); + GUILayout.Space(10); + if (Foldout(_groupFoldouts.Contains(groupHash), FormatTypeName(groupName), true)) + _groupFoldouts.Add(groupHash); + else _groupFoldouts.Remove(groupHash); + } + + if (_groupFoldouts.Contains(groupHash)) + { + int index = 0; + foreach (var entry in group) + { + index++; + var style = ListItemStyle; + var selected = SelectedItem == entry.ID; + using (new HorizontalScope(selected?SelectedStyle:style)) + { + using (var h = new HorizontalScope()) + { + if (h.rect.Contains(currentEvent.mousePosition)) + { + if (currentEventType == EventType.MouseDrag) + { + DragAndDrop.PrepareStartDrag(); + DragAndDrop.SetGenericData("Item", entry.ID); + DragAndDrop.StartDrag("Database Item"); + } + else if (currentEventType == EventType.MouseUp) + Select(entry); + } + + GUILayout.Space(20); + GUILayout.Label((entry as INamedEntry)?.EntryName ?? index.ToString(), selected ? EditorStyles.whiteLabel : GUI.skin.label); + } + } + } + + using (var h = new HorizontalScope(ListItemStyle)) + { + if(GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) + CreateItem(_entryTypes[i], entry => grouper.Activate(entry, group.Key)); + GUILayout.Space(20); + GUILayout.Label($"New {groupName}"); + } + } + } + } + else + { + int index = 0; + foreach (var entry in entries) + { + index++; + var style = ListItemStyle; + var selected = SelectedItem == entry.ID; + using (var h = new HorizontalScope(selected?SelectedStyle:style)) + { + if (h.rect.Contains(currentEvent.mousePosition)) + { + if (currentEventType == EventType.MouseDrag) + { + DragAndDrop.PrepareStartDrag(); + DragAndDrop.SetGenericData("Item", entry.ID); + DragAndDrop.StartDrag("Database Item"); + } + else if (currentEventType == EventType.MouseUp) + Select(entry); + } + GUILayout.Space(10); + GUILayout.Label((entry as INamedEntry)?.EntryName ?? index.ToString(), selected ? EditorStyles.whiteLabel : GUI.skin.label); } - GUILayout.Space(10); - GUILayout.Label((entry as INamedEntry)?.EntryName ?? index.ToString(), selected ? EditorStyles.whiteLabel : GUI.skin.label); } } @@ -413,9 +304,7 @@ public class DatabaseListView : EditorWindow if(GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) CreateItem(_entryTypes[i]); GUILayout.Space(10); - GUILayout.Label("New " + _entryTypes[i].Name); - // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); - // GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); + GUILayout.Label($"New {_entryTypes[i].Name}"); } } } @@ -434,7 +323,7 @@ public class DatabaseListView : EditorWindow { SelectedItem = item.ID; Repaint(); - _inspector.entry = _databaseCache.Get(SelectedItem); + _inspector.entry = cultCache.Get(SelectedItem); _inspector.Repaint(); } @@ -444,7 +333,7 @@ public class DatabaseListView : EditorWindow if(newEntry is INamedEntry entry) entry.EntryName = $"New {FormatTypeName(type.Name)}"; onCreate?.Invoke(newEntry); - _databaseCache.Add(newEntry); + cultCache.Add(newEntry); Select(newEntry); return newEntry; } diff --git a/Assets/Scripts/CultCache/Editor/InspectorBase.cs b/Assets/Scripts/CultCache/Editor/InspectorBase.cs deleted file mode 100644 index 85a51b513..000000000 --- a/Assets/Scripts/CultCache/Editor/InspectorBase.cs +++ /dev/null @@ -1,9 +0,0 @@ -public abstract class InspectorBase -{ - 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); -} \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/AetheriaInspectors.cs b/Assets/Scripts/CultCache/Editor/Inspectors/AetheriaInspectors.cs new file mode 100644 index 000000000..7223c59ce --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/AetheriaInspectors.cs @@ -0,0 +1,183 @@ +using System; +using System.Linq; +using Unity.Mathematics; +using UnityEditor; +using UnityEngine; +using static UnityEditor.EditorGUILayout; +using static Unity.Mathematics.math; + +public class StatReferenceInspector : BaseInspector +{ + public override StatReference Inspect(string label, StatReference value, object parent, DatabaseInspector inspectorWindow) + { + using (new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + + using (new VerticalScope()) + { + var targetObjects = typeof(BehaviorData).GetAllChildClasses() + .Concat(typeof(EquippableItemData).GetAllChildClasses()).ToArray(); + var objectNames = targetObjects.Select(b => b.Name).ToArray(); + var selectedIndex = Array.IndexOf(objectNames, value.Target); + if (selectedIndex == -1) + { + selectedIndex = 0; + GUI.changed = true; + } + using (new HorizontalScope()) + { + GUILayout.Label("Target", GUILayout.Width(width)); + var newSelection = Popup(selectedIndex, objectNames); + if (newSelection != selectedIndex) + GUI.changed = true; + value.Target = objectNames[newSelection]; + } + + using (new HorizontalScope()) + { + GUILayout.Label("Stat", GUILayout.Width(width)); + var stats = targetObjects[selectedIndex].GetFields() + .Where(f => f.FieldType == typeof(PerformanceStat)).ToArray(); + if(stats.Length==0) + GUILayout.Label("No Stats!"); + else + { + var statNames = stats.Select(s => s.Name).ToArray(); + var selectedStatIndex = Array.IndexOf(statNames, value.Stat); + if (selectedStatIndex == -1) + { + selectedStatIndex = 0; + GUI.changed = true; + } + var newSelection = Popup(selectedStatIndex, statNames); + if (newSelection != selectedStatIndex) + GUI.changed = true; + value.Stat = statNames[newSelection]; + } + } + } + } + + return value; + } +} + +public class PerformanceStatInspector : BaseInspector +{ + public override PerformanceStat Inspect(string label, PerformanceStat value, object parent, DatabaseInspector inspectorWindow) + { + if(value == null) + value = new PerformanceStat(); + using (new VerticalScope()) + { + using (new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + GUILayout.Label("Min", EditorStyles.miniLabel, GUILayout.Width(labelWidth)); + value.Min = DelayedFloatField(value.Min); + GUILayout.Label("Max", EditorStyles.miniLabel, GUILayout.Width(labelWidth + 5)); + value.Max = DelayedFloatField(value.Max); + } + + // Only display heat, durability and quality effects if the stat actually varies + if (Math.Abs(value.Min - value.Max) > .0001f) + { + using (new HorizontalScope()) + { + GUILayout.Label("", GUILayout.Width(width)); + GUILayout.Label("H", EditorStyles.miniLabel, GUILayout.Width(labelWidth)); + value.HeatExponentMultiplier = DelayedFloatField(value.HeatExponentMultiplier); + + GUILayout.Label("D", EditorStyles.miniLabel, GUILayout.Width(labelWidth)); + value.DurabilityExponentMultiplier = DelayedFloatField(value.DurabilityExponentMultiplier); + + GUILayout.Label("Q", EditorStyles.miniLabel, GUILayout.Width(labelWidth)); + value.QualityExponent = DelayedFloatField(value.QualityExponent); + } + } + + Space(); + } + + return value; + } +} + +public class ShapeInspector : BaseInspector +{ + private Material _schematicMat = new Material(Shader.Find("Legacy Shaders/Particles/Additive")); + + public override Shape Inspect(string label, Shape value, object parent, DatabaseInspector inspectorWindow) + { + var hull = parent as HullData; + if(value == null) + { + value = new Shape(1, 1); + value[int2(0)] = true; + } + using (new VerticalScope()) + { + Texture2D schematic = null; + if(hull != null && !string.IsNullOrEmpty(hull.Schematic)) + schematic = AssetDatabase.LoadAssetAtPath(hull.Schematic); + using (new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + GUILayout.Label("Size", GUILayout.ExpandWidth(false)); + if(schematic == null) + { + GUILayout.Label("X", GUILayout.Width(labelWidth)); + value.Width = DelayedIntField(value.Width); + GUILayout.Label("Y", GUILayout.Width(labelWidth)); + value.Height = DelayedIntField(value.Height); + } + else + { + GUILayout.Label("X", GUILayout.Width(labelWidth)); + value.Width = DelayedIntField(value.Width); + value.Height = Mathf.RoundToInt(value.Width * ((float)schematic.height / schematic.width)); + GUILayout.Label("Y", GUILayout.Width(labelWidth)); + LabelField($"{value.Height}"); + } + } + + using (new HorizontalScope()) + { + GUILayout.Label("", GUILayout.Width(width)); + using (var a = new VerticalScope()) + { + if(schematic != null) + { + EditorGUI.DrawPreviewTexture(a.rect, schematic, _schematicMat); + } + for (var y = value.Height - 1; y >= 0; y--) + { + using (new HorizontalScope()) + { + for (var x = 0; x < value.Width; x++) + { + var oldColor = GUI.backgroundColor; + if(hull != null) + { + var hardpoint = hull.Hardpoints + .FirstOrDefault(hp => + hp.Shape.Coordinates + .Select(v => v + hp.Position) + .Any(v => v.x == x && v.y == y)); + if (hardpoint != null) + GUI.backgroundColor = hardpoint.TintColor.ToColor(); + } + value[int2(x, y)] = Toggle(value[int2(x, y)], GUILayout.Width(toggleWidth)); + GUI.backgroundColor = oldColor; + } + } + } + } + GUILayout.FlexibleSpace(); + } + } + + return value; + } +} \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/AetheriaInspectors.cs.meta b/Assets/Scripts/CultCache/Editor/Inspectors/AetheriaInspectors.cs.meta new file mode 100644 index 000000000..d04e230b0 --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/AetheriaInspectors.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 57d0bc090768458b9428efd7a8a33741 +timeCreated: 1617069994 \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/AnimationCurveInspector.cs b/Assets/Scripts/CultCache/Editor/Inspectors/AnimationCurveInspector.cs new file mode 100644 index 000000000..ceaf74bea --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/AnimationCurveInspector.cs @@ -0,0 +1,39 @@ +using System.Linq; +using Unity.Mathematics; +using UnityEditor; +using UnityEngine; +using static UnityEditor.EditorGUILayout; +using static Unity.Mathematics.math; + +public class AnimationCurveFloat4Inspector : BaseInspector +{ + public override float4[] Inspect(string label, float4[] value, object parent, DatabaseInspector inspectorWindow) + { + var val = value != null && value.Length > 0 + ? value.ToCurve() + : new AnimationCurve(); + using (var h = new EditorGUILayout.HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + val = CurveField(val, Color.yellow, new Rect(0, 0, 1, 1)); + } + + return val.keys.Select(k => float4(k.time, k.value, k.inTangent, k.outTangent)).ToArray(); + } +} + +public class AnimationCurveInspect : BaseInspector +{ + public override AnimationCurve Inspect(string label, AnimationCurve value, object parent, DatabaseInspector inspectorWindow) + { + using (var h = new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + if (value == null) + value = new AnimationCurve(); + value = CurveField(value, Color.yellow, new Rect(0, 0, 1, 1)); + } + + return value; + } +} \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/AnimationCurveInspector.cs.meta b/Assets/Scripts/CultCache/Editor/Inspectors/AnimationCurveInspector.cs.meta new file mode 100644 index 000000000..fffa738ed --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/AnimationCurveInspector.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c89e0e7eb9f243cbbce28df59f6fb1c9 +timeCreated: 1617066399 \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/DatabaseLinkInspector.cs b/Assets/Scripts/CultCache/Editor/Inspectors/DatabaseLinkInspector.cs new file mode 100644 index 000000000..acccbeeb8 --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/DatabaseLinkInspector.cs @@ -0,0 +1,152 @@ +using System; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; +using static UnityEditor.EditorGUILayout; + +public class DatabaseLinkInspector : BaseInspector +{ + public override Guid Inspect(string label, Guid value, object parent, DatabaseInspector inspectorWindow, InspectableDatabaseLinkAttribute link) + { + LabelField(label, EditorStyles.boldLabel); + var valueEntry = DatabaseInspector.CultCache.Get(value); + using (var h = new HorizontalScope(GUI.skin.box)) + { + GUILayout.Label((valueEntry as INamedEntry)?.EntryName ?? valueEntry?.ID.ToString() ?? $"Assign a {link.EntryType.Name} by dragging from the list panel."); + + if (h.rect.Contains(Event.current.mousePosition) && (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)) + { + var guid = (Guid) DragAndDrop.GetGenericData("Item"); + var dragEntry = DatabaseInspector.CultCache.Get(guid); + var dragValid = dragEntry != null && link.EntryType.IsInstanceOfType(dragEntry) && dragEntry != valueEntry; + if(Event.current.type == EventType.DragUpdated) + DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; + else if(Event.current.type == EventType.DragPerform) + { + if (dragValid) + { + DragAndDrop.AcceptDrag(); + GUI.changed = true; + return guid; + } + } + } + if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3))) + { + return Guid.Empty; + } + } + + return value; + } +} + +public class DatabaseLinkObjectInspector : BaseInspector> where T : DatabaseEntry +{ + public override DatabaseLink Inspect(string label, DatabaseLink value, object parent, DatabaseInspector inspectorWindow) + { + if (value == null) + value = new DatabaseLink{Cache = DatabaseInspector.CultCache}; + LabelField(label, EditorStyles.boldLabel); + var valueEntry = value.Value; + using (var h = new HorizontalScope(GUI.skin.box)) + { + GUILayout.Label((valueEntry as INamedEntry)?.EntryName ?? valueEntry?.ID.ToString() ?? $"Assign a {typeof(T).Name} by dragging from the list panel."); + + if (h.rect.Contains(Event.current.mousePosition) && (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform)) + { + var guid = (Guid) DragAndDrop.GetGenericData("Item"); + var dragEntry = DatabaseInspector.CultCache.Get(guid); + var dragValid = dragEntry is T && dragEntry != valueEntry; + if(Event.current.type == EventType.DragUpdated) + DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; + else if(Event.current.type == EventType.DragPerform) + { + if (dragValid) + { + DragAndDrop.AcceptDrag(); + value.LinkID = guid; + return value; + } + } + } + if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3))) + { + value.LinkID = Guid.Empty; + } + } + + return value; + } +} + +public class DatabaseLinkListInspector : BaseInspector, InspectableDatabaseLinkAttribute> +{ + private bool _listItemStyle; + public GUIStyle ListItemStyle => + (_listItemStyle = !_listItemStyle) ? DatabaseListView.ListStyleEven : DatabaseListView.ListStyleOdd; + + public override List Inspect(string label, + List value, + object parent, + DatabaseInspector inspectorWindow, + InspectableDatabaseLinkAttribute link) + { + Space(); + LabelField(label, EditorStyles.boldLabel); + + using (var v = new VerticalScope(GUI.skin.box)) + { + if (value.Count == 0) + { + using (new HorizontalScope(ListItemStyle)) + { + GUILayout.Label($"Drag from list to add {link.EntryType.Name}"); + } + } + foreach (var guid in value.ToArray()) + { + using (new HorizontalScope(ListItemStyle)) + { + var entry = DatabaseInspector.CultCache.Get(guid); + if (entry == null) + { + value.Remove(guid); + GUI.changed = true; + } + else + { + GUILayout.Label((entry as INamedEntry)?.EntryName ?? entry.ID.ToString()); + + // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); + // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); + if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3))) + { + value.Remove(guid); + } + } + } + } + + if (v.rect.Contains(Event.current.mousePosition)) + { + var guid = DragAndDrop.GetGenericData("Item"); + var dragObj = DragAndDrop.GetGenericData("Item") is Guid ? DatabaseInspector.CultCache.Get((Guid) guid) : null; + var dragValid = dragObj != null && link.EntryType.IsInstanceOfType(dragObj) && !value.Contains(dragObj.ID); + if(Event.current.type == EventType.DragUpdated) + DragAndDrop.visualMode = dragValid ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; + else if(Event.current.type == EventType.DragPerform) + { + if (dragValid) + { + DragAndDrop.AcceptDrag(); + value.Add((Guid) guid); + GUI.changed = true; + } + } + } + } + + return value; + } +} \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/DatabaseLinkInspector.cs.meta b/Assets/Scripts/CultCache/Editor/Inspectors/DatabaseLinkInspector.cs.meta new file mode 100644 index 000000000..42978a734 --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/DatabaseLinkInspector.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5e08712ea4854536b130f82ad61db7a8 +timeCreated: 1617069551 \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/DictionaryInspector.cs b/Assets/Scripts/CultCache/Editor/Inspectors/DictionaryInspector.cs new file mode 100644 index 000000000..0c04b95b8 --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/DictionaryInspector.cs @@ -0,0 +1,223 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEditor; +using UnityEngine; +using static UnityEditor.EditorGUILayout; + +public class FloatDictionaryInspector : BaseInspector, InspectableDatabaseLinkAttribute> +{ + private bool _listItemStyle; + public GUIStyle ListItemStyle => + (_listItemStyle = !_listItemStyle) ? DatabaseListView.ListStyleEven : DatabaseListView.ListStyleOdd; + + public override Dictionary Inspect(string label, + Dictionary value, + object parent, + DatabaseInspector inspectorWindow, + InspectableDatabaseLinkAttribute attribute) + { + Space(); + LabelField(label, EditorStyles.boldLabel); + + using (var v = new VerticalScope(GUI.skin.box)) + { + if (value.Count == 0) + { + using (new HorizontalScope(ListItemStyle)) + { + GUILayout.Label("Drag from list to add item"); + } + } + foreach (var ingredient in value.ToArray()) + { + using (new HorizontalScope(ListItemStyle)) + { + var entry = DatabaseInspector.CultCache.Get(ingredient.Key); + if (entry == null) + { + value.Remove(ingredient.Key); + GUI.changed = true; + return value; + } + + if(entry is INamedEntry named) + GUILayout.Label(named.EntryName); + else GUILayout.Label(entry.ID.ToString()); + value[ingredient.Key] = DelayedFloatField(value[ingredient.Key], GUILayout.Width(50)); + + // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); + // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); + if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3))) + value.Remove(ingredient.Key); + } + } + + if (v.rect.Contains(Event.current.mousePosition)) + { + var dragData = DragAndDrop.GetGenericData("Item"); + var isId = dragData is Guid guid; + var dragEntry = isId ? DatabaseInspector.CultCache.Get(guid) : null; + var correctType = attribute.EntryType.IsInstanceOfType(dragEntry); + if(Event.current.type == EventType.DragUpdated) + DragAndDrop.visualMode = correctType ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; + else if(Event.current.type == EventType.DragPerform) + { + if (isId && correctType) + { + DragAndDrop.AcceptDrag(); + value[guid] = 1; + GUI.changed = true; + } + } + } + } + + return value; + } +} + +public class RangedFloatDictionaryInspector : BaseInspector, InspectableDatabaseLinkAttribute, RangedFloatAttribute> +{ + private bool _listItemStyle; + public GUIStyle ListItemStyle => + (_listItemStyle = !_listItemStyle) ? DatabaseListView.ListStyleEven : DatabaseListView.ListStyleOdd; + + public override Dictionary Inspect(string label, + Dictionary value, + object parent, + DatabaseInspector inspectorWindow, + InspectableDatabaseLinkAttribute link, + RangedFloatAttribute range) + { + Space(); + LabelField(label, EditorStyles.boldLabel); + + using (var v = new VerticalScope(GUI.skin.box)) + { + if (value.Count == 0) + { + using (new HorizontalScope(ListItemStyle)) + { + GUILayout.Label("Drag from list to add item"); + } + } + foreach (var ingredient in value.ToArray()) + { + using (new HorizontalScope(ListItemStyle)) + { + var entry = DatabaseInspector.CultCache.Get(ingredient.Key); + if (entry == null) + { + value.Remove(ingredient.Key); + GUI.changed = true; + return value; + } + + if(entry is INamedEntry named) + GUILayout.Label(named.EntryName); + else GUILayout.Label(entry.ID.ToString()); + value[ingredient.Key] = Slider(value[ingredient.Key], range.Min, range.Max); + + // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); + // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); + if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3))) + value.Remove(ingredient.Key); + } + } + + if (v.rect.Contains(Event.current.mousePosition)) + { + var dragData = DragAndDrop.GetGenericData("Item"); + var isId = dragData is Guid guid; + var dragEntry = isId ? DatabaseInspector.CultCache.Get(guid) : null; + var correctType = link.EntryType.IsInstanceOfType(dragEntry); + if(Event.current.type == EventType.DragUpdated) + DragAndDrop.visualMode = correctType ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; + else if(Event.current.type == EventType.DragPerform) + { + if (isId && correctType) + { + DragAndDrop.AcceptDrag(); + value[guid] = range.Max; + GUI.changed = true; + } + } + } + } + + return value; + } +} + +public class IntDictionaryInspector : BaseInspector, InspectableDatabaseLinkAttribute> +{ + private bool _listItemStyle; + public GUIStyle ListItemStyle => + (_listItemStyle = !_listItemStyle) ? DatabaseListView.ListStyleEven : DatabaseListView.ListStyleOdd; + + public override Dictionary Inspect(string label, + Dictionary value, + object parent, + DatabaseInspector inspectorWindow, + InspectableDatabaseLinkAttribute attribute) + { + Space(); + LabelField(label, EditorStyles.boldLabel); + + using (var v = new VerticalScope(GUI.skin.box)) + { + if (value.Count == 0) + { + using (var h = new HorizontalScope(ListItemStyle)) + { + GUILayout.Label("Drag from list to add item"); + } + } + foreach (var ingredient in value.ToArray()) + { + using (var h = new HorizontalScope(ListItemStyle)) + { + var entry = DatabaseInspector.CultCache.Get(ingredient.Key); + if (entry == null) + { + value.Remove(ingredient.Key); + GUI.changed = true; + return value; + } + if(entry is INamedEntry named) + GUILayout.Label(named.EntryName); + else GUILayout.Label(entry.ID.ToString()); + + value[ingredient.Key] = DelayedIntField(value[ingredient.Key], GUILayout.Width(50)); + + // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); + // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); + if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3)) || value[ingredient.Key]==0) + value.Remove(ingredient.Key); + } + } + + if (v.rect.Contains(Event.current.mousePosition)) + { + var dragData = DragAndDrop.GetGenericData("Item"); + var isId = dragData is Guid guid; + var dragEntry = isId ? DatabaseInspector.CultCache.Get(guid) : null; + var correctType = attribute.EntryType.IsInstanceOfType(dragEntry); + if(Event.current.type == EventType.DragUpdated) + DragAndDrop.visualMode = correctType ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.Rejected; + else if(Event.current.type == EventType.DragPerform) + { + if (isId && correctType) + { + DragAndDrop.AcceptDrag(); + value[guid] = 1; + GUI.changed = true; + } + } + } + } + + return value; + } +} \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/DictionaryInspector.cs.meta b/Assets/Scripts/CultCache/Editor/Inspectors/DictionaryInspector.cs.meta new file mode 100644 index 000000000..08a3ac73a --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/DictionaryInspector.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a42620fd406045889578e2ad8d5fd8de +timeCreated: 1617067689 \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/FloatInspector.cs b/Assets/Scripts/CultCache/Editor/Inspectors/FloatInspector.cs new file mode 100644 index 000000000..9b4c58864 --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/FloatInspector.cs @@ -0,0 +1,54 @@ +using UnityEditor; +using UnityEngine; +using static UnityEditor.EditorGUILayout; + +public class FloatInspector : BaseInspector +{ + public override float Inspect(string label, float value, object parent, DatabaseInspector inspectorWindow) + { + using (new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + return DelayedFloatField(value); + } + } +} + +public class RangedFloatInspector : BaseInspector +{ + public override float Inspect(string label, + float value, + object parent, + DatabaseInspector inspectorWindow, + RangedFloatInspectableAttribute attribute) + { + using (new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + return Slider(value, attribute.Min, attribute.Max); + } + } +} + +public class TemperatureFloatInspector : BaseInspector +{ + public override float Inspect(string label, + float value, + object parent, + DatabaseInspector inspectorWindow, + InspectableTemperatureAttribute attribute) + { + using (var h = new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + GUILayout.Label("°K", EditorStyles.miniLabel, GUILayout.Width(labelWidth)); + value = DelayedFloatField(value); + GUILayout.Label("°C", EditorStyles.miniLabel, GUILayout.Width(labelWidth)); + value = DelayedFloatField(value - 273.15f) + 273.15f; + GUILayout.Label("°F", EditorStyles.miniLabel, GUILayout.Width(labelWidth)); + value = (DelayedFloatField((value - 273.15f) * 1.8f + 32) - 32) / 1.8f + 273.15f; + + return value; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/FloatInspector.cs.meta b/Assets/Scripts/CultCache/Editor/Inspectors/FloatInspector.cs.meta new file mode 100644 index 000000000..17a7c71fc --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/FloatInspector.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 47b8e5bc90714055881eb31baf2ab879 +timeCreated: 1617065074 \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/IntInspector.cs b/Assets/Scripts/CultCache/Editor/Inspectors/IntInspector.cs new file mode 100644 index 000000000..ae5a34812 --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/IntInspector.cs @@ -0,0 +1,27 @@ +using UnityEditor; +using UnityEngine; +using static UnityEditor.EditorGUILayout; + +public class IntInspector : BaseInspector +{ + public override int Inspect(string label, int value, object parent, DatabaseInspector inspectorWindow) + { + using (new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + return DelayedIntField(value); + } + } +} + +public class RangedIntInspector : BaseInspector +{ + public override int Inspect(string label, int value, object parent, DatabaseInspector inspectorWindow, RangedIntInspectableAttribute attribute) + { + using (new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + return IntSlider(value, attribute.Min, attribute.Max); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/IntInspector.cs.meta b/Assets/Scripts/CultCache/Editor/Inspectors/IntInspector.cs.meta new file mode 100644 index 000000000..969165fd1 --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/IntInspector.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ac7d3b8651964ce1a732a002447d6f69 +timeCreated: 1617065365 \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/ListInspector.cs b/Assets/Scripts/CultCache/Editor/Inspectors/ListInspector.cs new file mode 100644 index 000000000..345ba30b3 --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/ListInspector.cs @@ -0,0 +1,142 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using UnityEditor; +using UnityEngine; +using static UnityEditor.EditorGUILayout; + +public class ListInspector : BaseInspector> +{ + private bool _listItemStyle; + private static HashSet _listItemFoldouts = new HashSet(); + public GUIStyle ListItemStyle => + (_listItemStyle = !_listItemStyle) ? DatabaseListView.ListStyleEven : DatabaseListView.ListStyleOdd; + + public override List Inspect(string label, List list, object parent, DatabaseInspector inspectorWindow) + { + var listType = typeof(T); + if (listType.GetCustomAttribute() != null) + { + Space(); + using (new VerticalScope(GUI.skin.box)) + { + if (list == null) + { + list = new List(); + } + else + { + var sorted = true; + var order = int.MinValue; + foreach(var element in list) + { + if (element == null) + { + list.Remove(element); + return list; + } + var elementType = element.GetType(); + var elementOrder = elementType.GetCustomAttribute()?.Order ?? 0; + if (elementOrder < order) + sorted = false; + order = elementOrder; + } + + if (!sorted) + { + list.Sort((x, y) => (x.GetType().GetCustomAttribute()?.Order ?? 0).CompareTo(y.GetType().GetCustomAttribute()?.Order ?? 0)); + } + } + foreach (var o in list) + { + if (o == null) + { + list.Remove(o); + break; + } + bool _tinted = false; + var originalColor = GUI.backgroundColor; + if (o is ITintInspector tint) + { + _tinted = true; + GUI.backgroundColor = tint.TintColor.ToColor(); + } + + using (new VerticalScope(ListItemStyle)) + { + using (new HorizontalScope()) + { + //if (listType.IsInterface) + if(Foldout(_listItemFoldouts.Contains(o.GetHashCode()), o.ToString(), true)) + _listItemFoldouts.Add(o.GetHashCode()); + else + _listItemFoldouts.Remove(o.GetHashCode()); + + + // var rect = GetControlRect(false, + // GUILayout.Width(EditorGUIUtility.singleLineHeight)); + // GUI.DrawTexture(rect, Icons.Instance.minus, ScaleMode.StretchToFill, true, 1, + // LabelColor, 0, 0); + if (GUILayout.Button("-", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3))) + { + list.Remove(o); + break; + } + } + if(_listItemFoldouts.Contains(o.GetHashCode())) + { + Space(); + + inspectorWindow.Inspect(o, true); + } + } + + if(_tinted) + GUI.backgroundColor = originalColor; + } + using (new HorizontalScope(ListItemStyle)) + { + GUILayout.Label($"Add new {listType.Name}", GUILayout.ExpandWidth(true)); + // var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); + // GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, 0, 0); + if (GUILayout.Button("+", GUILayout.Width((EditorGUIUtility.singleLineHeight - 3)*2), GUILayout.Height(EditorGUIUtility.singleLineHeight-3))) + { + if (listType.IsInterface) + { + var menu = new GenericMenu(); + foreach (var childType in listType.GetAllInterfaceClasses()) + { + menu.AddItem(new GUIContent(childType.Name), false, () => + { + list.Add((T)Activator.CreateInstance(childType)); + }); + } + menu.ShowAsContext(); + } + else if (listType.IsAbstract) + { + var menu = new GenericMenu(); + foreach (var childType in listType.GetAllChildClasses().Where(t=>!t.IsAbstract)) + { + menu.AddItem(new GUIContent(childType.Name), false, () => + { + list.Add((T)Activator.CreateInstance(childType)); + }); + } + menu.ShowAsContext(); + } + else + { + list.Add(Activator.CreateInstance()); + } + } + } + } + } + else Debug.Log($"Field \"{label}\" is a list of non-Inspectable type {listType.Name}. No inspector was generated."); + + return list; + } +} \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/ListInspector.cs.meta b/Assets/Scripts/CultCache/Editor/Inspectors/ListInspector.cs.meta new file mode 100644 index 000000000..c9e68d5d1 --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/ListInspector.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 551335721057411d942b3317ae028546 +timeCreated: 1617145746 \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/MathematicsInspector.cs b/Assets/Scripts/CultCache/Editor/Inspectors/MathematicsInspector.cs index 7bc6b82e3..48b4de130 100644 --- a/Assets/Scripts/CultCache/Editor/Inspectors/MathematicsInspector.cs +++ b/Assets/Scripts/CultCache/Editor/Inspectors/MathematicsInspector.cs @@ -3,11 +3,12 @@ using UnityEditor; using UnityEngine; using static UnityEditor.EditorGUILayout; -public class Float2Inspector : InspectorBase + +public class Float2Inspector : BaseInspector { - public override float2 Inspect(string label, float2 value) + public override float2 Inspect(string label, float2 value, object parent, DatabaseInspector inspectorWindow) { - using (var h = new EditorGUILayout.HorizontalScope()) + using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label(label, GUILayout.Width(width)); GUILayout.Label("X", GUILayout.Width(labelWidth)); @@ -19,27 +20,49 @@ public class Float2Inspector : InspectorBase } } -public class Float3Inspector : InspectorBase +public class Float3Inspector : BaseInspector { - public override float3 Inspect(string label, float3 value) + public override float3 Inspect(string label, float3 value, object parent, DatabaseInspector inspectorWindow) { - using (var h = new EditorGUILayout.HorizontalScope()) + using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label(label, GUILayout.Width(width)); GUILayout.Label("X", GUILayout.Width(labelWidth)); value.x = DelayedFloatField(value.x); GUILayout.Label("Y", GUILayout.Width(labelWidth)); value.y = DelayedFloatField(value.y); + GUILayout.Label("Z", GUILayout.Width(labelWidth)); + value.z = DelayedFloatField(value.z); return value; } } } -public class Int2Inspector : InspectorBase +public class Float4Inspector : BaseInspector { - public override int2 Inspect(string label, int2 value) + public override float4 Inspect(string label, float4 value, object parent, DatabaseInspector inspectorWindow) { - using (var h = new EditorGUILayout.HorizontalScope()) + using (new EditorGUILayout.HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + GUILayout.Label("X", GUILayout.Width(labelWidth)); + value.x = DelayedFloatField(value.x); + GUILayout.Label("Y", GUILayout.Width(labelWidth)); + value.y = DelayedFloatField(value.y); + GUILayout.Label("Z", GUILayout.Width(labelWidth)); + value.z = DelayedFloatField(value.z); + GUILayout.Label("W", GUILayout.Width(labelWidth)); + value.w = DelayedFloatField(value.w); + return value; + } + } +} + +public class Int2Inspector : BaseInspector +{ + public override int2 Inspect(string label, int2 value, object parent, DatabaseInspector inspectorWindow) + { + using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label(label, GUILayout.Width(width)); GUILayout.Label("X", GUILayout.Width(labelWidth)); @@ -57,4 +80,42 @@ public class Int2Inspector : InspectorBase return value; } } +} + +public class Int3Inspector : BaseInspector +{ + public override int3 Inspect(string label, int3 value, object parent, DatabaseInspector inspectorWindow) + { + using (new EditorGUILayout.HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + GUILayout.Label("X", GUILayout.Width(labelWidth)); + value.x = DelayedIntField(value.x); + GUILayout.Label("Y", GUILayout.Width(labelWidth)); + value.y = DelayedIntField(value.y); + GUILayout.Label("Z", GUILayout.Width(labelWidth)); + value.z = DelayedIntField(value.z); + return value; + } + } +} + +public class Int4Inspector : BaseInspector +{ + public override int4 Inspect(string label, int4 value, object parent, DatabaseInspector inspectorWindow) + { + using (new EditorGUILayout.HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + GUILayout.Label("X", GUILayout.Width(labelWidth)); + value.x = DelayedIntField(value.x); + GUILayout.Label("Y", GUILayout.Width(labelWidth)); + value.y = DelayedIntField(value.y); + GUILayout.Label("Z", GUILayout.Width(labelWidth)); + value.z = DelayedIntField(value.z); + GUILayout.Label("W", GUILayout.Width(labelWidth)); + value.w = DelayedIntField(value.w); + return value; + } + } } \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/PrimitiveInspector.cs b/Assets/Scripts/CultCache/Editor/Inspectors/PrimitiveInspector.cs new file mode 100644 index 000000000..b2c4b99ac --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/PrimitiveInspector.cs @@ -0,0 +1,40 @@ +using UnityEditor; +using UnityEngine; +using static UnityEditor.EditorGUILayout; + +public class BoolInspector : BaseInspector +{ + public override bool Inspect(string label, bool value, object parent, DatabaseInspector inspectorWindow) + { + using (var h = new EditorGUILayout.HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + return Toggle(value); + } + } +} + +public class StringInspector : BaseInspector +{ + public override string Inspect(string label, string value, object parent, DatabaseInspector inspectorWindow) + { + using (var h = new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + return DelayedTextField(value); + } + } +} + +public class StringAreaInspector : BaseInspector +{ + public override string Inspect(string label, string value, object parent, DatabaseInspector inspectorWindow, InspectableTextAttribute attribute) + { + using (new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + EditorStyles.textArea.wordWrap = true; + return DelayedTextField(value, EditorStyles.textArea, GUILayout.Height(100)); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/PrimitiveInspector.cs.meta b/Assets/Scripts/CultCache/Editor/Inspectors/PrimitiveInspector.cs.meta new file mode 100644 index 000000000..fc3143b8b --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/PrimitiveInspector.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 91dcbfa1679e4be1944d6856ca63bf13 +timeCreated: 1617065181 \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/TypeInspector.cs b/Assets/Scripts/CultCache/Editor/Inspectors/TypeInspector.cs new file mode 100644 index 000000000..19a4138b0 --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/TypeInspector.cs @@ -0,0 +1,23 @@ +using System; +using System.Linq; +using UnityEditor; +using UnityEngine; +using static UnityEditor.EditorGUILayout; + +public class TypeInspector : BaseInspector +{ + public override Type Inspect(string label, Type value, object parent, DatabaseInspector inspectorWindow, InspectableTypeAttribute attribute) + { + var types = attribute.Type.GetAllChildClasses(); + var enumOptions = new[] {"None"}.Concat(types.Select(t => t.Name)).ToArray(); + var index = Array.IndexOf(types, value) + 1; + + using (new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + index = Popup(index, enumOptions); + } + + return index == 0 ? null : types[index - 1]; + } +} \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/TypeInspector.cs.meta b/Assets/Scripts/CultCache/Editor/Inspectors/TypeInspector.cs.meta new file mode 100644 index 000000000..005fcd819 --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/TypeInspector.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4762384a61dc4d08a1ba4e7564a20081 +timeCreated: 1617066802 \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/UnityObjectInspector.cs b/Assets/Scripts/CultCache/Editor/Inspectors/UnityObjectInspector.cs new file mode 100644 index 000000000..cf0c872ae --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/UnityObjectInspector.cs @@ -0,0 +1,47 @@ +using UnityEditor; +using UnityEngine; +using static UnityEditor.EditorGUILayout; + +public class TextureInspector : BaseInspector +{ + public override string Inspect(string label, + string value, + object parent, + DatabaseInspector inspectorWindow, + InspectableTextureAttribute attribute) + { + using (new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + return AssetDatabase.GetAssetPath(ObjectField(AssetDatabase.LoadAssetAtPath(value), typeof(Texture2D), false)); + } + } +} + +public class GameObjectInspector : BaseInspector +{ + public override string Inspect(string label, string value, object parent, DatabaseInspector inspectorWindow, InspectablePrefabAttribute attribute) + { + using (new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + return AssetDatabase.GetAssetPath(ObjectField(AssetDatabase.LoadAssetAtPath(value), typeof(GameObject), false)); + } + } +} + +public class TextAssetInspector : BaseInspector +{ + public override string Inspect(string label, + string value, + object parent, + DatabaseInspector inspectorWindow, + InspectableTextAssetAttribute attribute) + { + using (new HorizontalScope()) + { + GUILayout.Label(label, GUILayout.Width(width)); + return AssetDatabase.GetAssetPath(ObjectField(AssetDatabase.LoadAssetAtPath(value), typeof(TextAsset), false)); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/Inspectors/UnityObjectInspector.cs.meta b/Assets/Scripts/CultCache/Editor/Inspectors/UnityObjectInspector.cs.meta new file mode 100644 index 000000000..1990fc264 --- /dev/null +++ b/Assets/Scripts/CultCache/Editor/Inspectors/UnityObjectInspector.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8519fa7d4f06468bb9be151f053d1fcb +timeCreated: 1617067005 \ No newline at end of file diff --git a/Assets/Scripts/CultCache/Editor/RethinkConnection.cs b/Assets/Scripts/CultCache/Editor/RethinkConnection.cs index 247ac8e05..5845a08a8 100644 --- a/Assets/Scripts/CultCache/Editor/RethinkConnection.cs +++ b/Assets/Scripts/CultCache/Editor/RethinkConnection.cs @@ -5,6 +5,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Threading.Tasks; using Newtonsoft.Json; @@ -17,10 +18,9 @@ public static class RethinkConnection { public static RethinkDB R = RethinkDB.R; - public static RethinkQueryStatus RethinkConnect(DatabaseCache cache, string connectionString, bool syncLocalChanges = true) + public static RethinkQueryStatus RethinkConnect(CultCache cache, string connectionString, string dbName, bool syncLocalChanges = true) { // Add Unity.Mathematics serialization support to RethinkDB Driver - //Converter.Serializer.Converters.Add(new MathJsonConverter()); JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Converters = new List @@ -32,10 +32,28 @@ public static class RethinkConnection Converter.PocoExprConverter } }; + + var syncTables = typeof(DatabaseEntry).GetAllChildClasses() + .Select(t => t.GetCustomAttribute()?.TableName ?? "Default").Distinct(); + + var connectionStringDomainLength = connectionString.IndexOf(':'); + if (connectionStringDomainLength < 1) + throw new ArgumentException("Illegal Connection String: must include port!"); - var connection = R.Connection().Hostname(connectionString).Port(RethinkDBConstants.DefaultPort+1).Timeout(60).Connect(); + var portString = connectionString.Substring(connectionStringDomainLength + 1); + if (!int.TryParse(portString, out var port)) + throw new ArgumentException($"Illegal connection string! \"{portString}\" is not a valid port number!"); + + var connection = R.Connection() + .Hostname(connectionString.Substring(0,connectionStringDomainLength)) + .Port(port).Timeout(60).Connect(); Debug.Log("Connected to RethinkDB"); + var tables = R.Db(dbName).TableList().RunAtom(connection); + + foreach (var st in syncTables.Where(st => !tables.Contains(st))) + R.Db(dbName).TableCreate(st).RunNoReply(connection); + if (syncLocalChanges) { // When entries are changed locally, push the changes to RethinkDB @@ -77,66 +95,51 @@ public static class RethinkConnection var status = new RethinkQueryStatus(); - // Get all item data from RethinkDB - Task.Run(async () => + foreach (var table in syncTables) { - status.ItemsEntries = R - .Db("Aetheria") - .Table("Items") - .Count().RunAtom(connection); + // Get entries from RethinkDB + Task.Run(async () => + { + status.TotalEntries += R + .Db("Aetheria") + .Table(table) + .Count().RunAtom(connection); - var result = await R - .Db("Aetheria") - .Table("Items") - .RunCursorAsync(connection); - while (await result.MoveNextAsync()) - { - var entry = result.Current; - //Debug.Log($"Received Items entry from RethinkDB: {entry.GetType()} {(entry as INamedEntry)?.EntryName ?? ""}:{entry.ID}"); - cache.Add(entry, true); - status.RetrievedItems++; - } - }).WrapAwait(); - - // Get globaldata and all galaxy map layer data from RethinkDB - Task.Run(async () => - { - ReqlAst operation = R - .Db("Aetheria") - .Table("Galaxy"); - status.GalaxyEntries = ((Table) operation).Count().RunAtom(connection); + var result = await R + .Db("Aetheria") + .Table(table) + .RunCursorAsync(connection); + while (await result.MoveNextAsync()) + { + var entry = result.Current; + //Debug.Log($"Received Items entry from RethinkDB: {entry.GetType()} {(entry as INamedEntry)?.EntryName ?? ""}:{entry.ID}"); + cache.Add(entry, true); + status.RetrievedEntries++; + } + }).WrapAwait(); - var result = await operation - .RunCursorAsync(connection); - while (await result.MoveNextAsync()) + // Subscribe to changes from RethinkDB + Task.Run(async () => { - var entry = result.Current; - //Debug.Log($"Received Galaxy entry from RethinkDB: {entry.GetType()} {(entry as INamedEntry)?.EntryName ?? ""}:{entry.ID}"); - cache.Add(entry, true); - status.RetrievedItems++; - } - }).WrapAwait(); + var result = await R + .Db("Aetheria") + .Table(table) + .Changes() + .RunChangesAsync(connection); + while (await result.MoveNextAsync()) + { + var change = result.Current; + if(change.OldValue == null) + Debug.Log($"Received change from RethinkDB (Entry Created): {change.NewValue.ID}"); + else if(change.NewValue == null) + Debug.Log($"Received change from RethinkDB (Entry Deleted): {change.OldValue.ID}"); + else + Debug.Log($"Received change from RethinkDB: {change.NewValue.ID}"); + cache.Add(change.NewValue, true); + } + }).WrapAwait(); + } - // Subscribe to changes from RethinkDB - Task.Run(async () => - { - var result = await R - .Db("Aetheria") - .Table("Items") - .Changes() - .RunChangesAsync(connection); - while (await result.MoveNextAsync()) - { - var change = result.Current; - if(change.OldValue == null) - Debug.Log($"Received change from RethinkDB (Entry Created): {change.NewValue.ID}"); - else if(change.NewValue == null) - Debug.Log($"Received change from RethinkDB (Entry Deleted): {change.OldValue.ID}"); - else - Debug.Log($"Received change from RethinkDB: {change.NewValue.ID}"); - cache.Add(change.NewValue, true); - } - }).WrapAwait(); // Observable.Timer(DateTimeOffset.Now, TimeSpan.FromSeconds(60)).Subscribe(_ => // { @@ -149,7 +152,6 @@ public static class RethinkConnection public class RethinkQueryStatus { - public int RetrievedItems; - public int GalaxyEntries; - public int ItemsEntries; + public int RetrievedEntries; + public int TotalEntries; } \ No newline at end of file diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index 378d7b305..a3e587e35 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -31,18 +31,18 @@ public class ActionGameManager : MonoBehaviour get => _gameDataDirectory ??= new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData"); } - private static DatabaseCache _database; + private static CultCache _cultCache; - public static DatabaseCache Database + public static CultCache CultCache { get { - if (_database != null) return _database; + if (_cultCache != null) return _cultCache; - _database = new DatabaseCache(Path.Combine(GameDataDirectory.FullName, "AetherDB.msgpack")); - _database.Load(); + _cultCache = new CultCache(Path.Combine(GameDataDirectory.FullName, "AetherDB.msgpack")); + _cultCache.Load(); - return _database; + return _cultCache; } } @@ -173,7 +173,7 @@ public class ActionGameManager : MonoBehaviour AkSoundEngine.RegisterGameObj(gameObject); ConsoleController.MessageReceiver = this; - ItemManager = new ItemManager(Database, Settings.GameplaySettings, Debug.Log); + ItemManager = new ItemManager(CultCache, Settings.GameplaySettings, Debug.Log); ZoneRenderer.ItemManager = ItemManager; // _loadoutPath = GameDataDirectory.CreateSubdirectory("Loadouts"); diff --git a/Assets/Scripts/MainMenu.cs b/Assets/Scripts/MainMenu.cs index 9fa499de6..6e0a3f846 100644 --- a/Assets/Scripts/MainMenu.cs +++ b/Assets/Scripts/MainMenu.cs @@ -96,7 +96,7 @@ public class MainMenu : MonoBehaviour _nextMenu.panel.AddButton("Continue", () => { - ActionGameManager.CurrentSector = new Sector(ActionGameManager.Database, ActionGameManager.PlayerSettings.CurrentRun); + ActionGameManager.CurrentSector = new Sector(ActionGameManager.CultCache, ActionGameManager.PlayerSettings.CurrentRun); SceneManager.LoadScene("ARPG"); }); else @@ -116,7 +116,7 @@ public class MainMenu : MonoBehaviour Dialog.Show(); Settings.SectorGenerationSettings.NoisePosition = Random.value * 100; - var task = Task.Run(() => new Sector(Settings.SectorGenerationSettings, ActionGameManager.Database, 0, setState)); + var task = Task.Run(() => new Sector(Settings.SectorGenerationSettings, ActionGameManager.CultCache, 0, setState)); task.ContinueWith(task => Observable.NextFrame().Subscribe(_ => { ActionGameManager.PlayerSettings.CurrentRun = null; diff --git a/Assets/Scripts/ServerShared/Behaviors/AutoWeapon.cs b/Assets/Scripts/ServerShared/Behaviors/AutoWeapon.cs index a0519af40..99ecf3097 100644 --- a/Assets/Scripts/ServerShared/Behaviors/AutoWeapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/AutoWeapon.cs @@ -6,7 +6,7 @@ using Newtonsoft.Json; using Unity.Mathematics; using static Unity.Mathematics.math; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class AutoWeaponData : InstantWeaponData { public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Behaviors.cs b/Assets/Scripts/ServerShared/Behaviors/Behaviors.cs index dc296844a..225a9e0d1 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Behaviors.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Behaviors.cs @@ -83,7 +83,7 @@ public abstract class PersistentBehaviorData { } -[InspectableField, +[Inspectable, Union(0, typeof(GuidedWeaponData)), Union(1, typeof(LauncherData)), Union(2, typeof(ReactorData)), @@ -125,7 +125,7 @@ public abstract class PersistentBehaviorData JsonConverter(typeof(JsonKnownTypesConverter)), JsonObject(MemberSerialization.OptIn)] public abstract class BehaviorData { - [InspectableField, JsonProperty("group"), Key(0)] + [Inspectable, JsonProperty("group"), Key(0)] public int Group; public abstract IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item); diff --git a/Assets/Scripts/ServerShared/Behaviors/Capacitor.cs b/Assets/Scripts/ServerShared/Behaviors/Capacitor.cs index 6017711be..71effc7b1 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Capacitor.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Capacitor.cs @@ -11,10 +11,10 @@ using static Unity.Mathematics.math; [MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class CapacitorData : BehaviorData { - [InspectableField, JsonProperty("capacity"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("capacity"), Key(1), RuntimeInspectable] public PerformanceStat Capacity = new PerformanceStat(); - [InspectableField, JsonProperty("efficiency"), Key(2), RuntimeInspectable] + [Inspectable, JsonProperty("efficiency"), Key(2), RuntimeInspectable] public PerformanceStat Efficiency = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs b/Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs index b5170658f..912e20053 100644 --- a/Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/ChargedWeapon.cs @@ -6,43 +6,43 @@ using Newtonsoft.Json; using Unity.Mathematics; using static Unity.Mathematics.math; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class ChargedWeaponData : InstantWeaponData { - [InspectableField, JsonProperty("chargeTime"), Key(21), RuntimeInspectable] + [Inspectable, JsonProperty("chargeTime"), Key(21), RuntimeInspectable] public PerformanceStat ChargeTime = new PerformanceStat(); - [InspectableField, JsonProperty("chargeEnergy"), Key(22), RuntimeInspectable] + [Inspectable, JsonProperty("chargeEnergy"), Key(22), RuntimeInspectable] public PerformanceStat ChargeEnergy = new PerformanceStat(); - [InspectableField, JsonProperty("chargeHeat"), Key(23), RuntimeInspectable] + [Inspectable, JsonProperty("chargeHeat"), Key(23), RuntimeInspectable] public PerformanceStat ChargeHeat = new PerformanceStat(); - [InspectableField, JsonProperty("canFireEarly"), Key(24)] + [Inspectable, JsonProperty("canFireEarly"), Key(24)] public bool CanFireEarly; - [InspectableField, JsonProperty("failureCharge"), Key(25)] + [Inspectable, JsonProperty("failureCharge"), Key(25)] public float FailureCharge; - [InspectableField, JsonProperty("failureDamage"), Key(26)] + [Inspectable, JsonProperty("failureDamage"), Key(26)] public float FailureDamage = 1; - [InspectableField, JsonProperty("chargeDamage"), Key(27)] + [Inspectable, JsonProperty("chargeDamage"), Key(27)] public float ChargeFiringDamageMultiplier = 1; - [InspectableField, JsonProperty("chargeSpread"), Key(28)] + [Inspectable, JsonProperty("chargeSpread"), Key(28)] public float ChargeFiringSpreadMultiplier = 1; - [InspectableField, JsonProperty("chargeBurstCount"), Key(29)] + [Inspectable, JsonProperty("chargeBurstCount"), Key(29)] public float ChargeFiringBurstCountMultiplier = 1; - [InspectableField, JsonProperty("chargeVisibility"), Key(30)] + [Inspectable, JsonProperty("chargeVisibility"), Key(30)] public float ChargeFiringVisibilityMultiplier = 1; - [InspectableField, JsonProperty("chargeVelocity"), Key(31)] + [Inspectable, JsonProperty("chargeVelocity"), Key(31)] public float ChargeFiringVelocityMultiplier = 1; - [InspectableField, JsonProperty("chargeHeatMul"), Key(32)] + [Inspectable, JsonProperty("chargeHeatMul"), Key(32)] public float ChargeFiringHeatMultiplier = 1; public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs b/Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs index 2ffc9ec88..b80be7845 100644 --- a/Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/ConstantWeapon.cs @@ -8,7 +8,7 @@ using Newtonsoft.Json; using Unity.Mathematics; using static Unity.Mathematics.math; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class ConstantWeaponData : WeaponData { [InspectablePrefab, JsonProperty("ammoInterval"), Key(17)] diff --git a/Assets/Scripts/ServerShared/Behaviors/Cooldown.cs b/Assets/Scripts/ServerShared/Behaviors/Cooldown.cs index 36c63226b..6b82be8b5 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Cooldown.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Cooldown.cs @@ -9,10 +9,10 @@ using Newtonsoft.Json; using Unity.Mathematics; using static Unity.Mathematics.math; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-10), RuntimeInspectable] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-10), RuntimeInspectable] public class CooldownData : BehaviorData { - [InspectableField, JsonProperty("cooldown"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("cooldown"), Key(1), RuntimeInspectable] public PerformanceStat Cooldown = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/EnergyDraw.cs b/Assets/Scripts/ServerShared/Behaviors/EnergyDraw.cs index dc5094d08..ea70804c9 100644 --- a/Assets/Scripts/ServerShared/Behaviors/EnergyDraw.cs +++ b/Assets/Scripts/ServerShared/Behaviors/EnergyDraw.cs @@ -7,13 +7,13 @@ using System.Linq; using MessagePack; using Newtonsoft.Json; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-20), RuntimeInspectable] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-20), RuntimeInspectable] public class EnergyDrawData : BehaviorData { - [InspectableField, JsonProperty("draw"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("draw"), Key(1), RuntimeInspectable] public PerformanceStat EnergyDraw = new PerformanceStat(); - [InspectableField, JsonProperty("perSecond"), Key(2)] + [Inspectable, JsonProperty("perSecond"), Key(2)] public bool PerSecond; public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Heat.cs b/Assets/Scripts/ServerShared/Behaviors/Heat.cs index b135c32fd..2d4478434 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Heat.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Heat.cs @@ -7,13 +7,13 @@ using System.Linq; using MessagePack; using Newtonsoft.Json; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(10), Inspectable] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(10)] public class HeatData : BehaviorData { - [InspectableField, JsonProperty("heat"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("heat"), Key(1), RuntimeInspectable] public PerformanceStat Heat = new PerformanceStat(); - [InspectableField, JsonProperty("perSecond"), Key(2)] + [Inspectable, JsonProperty("perSecond"), Key(2)] public bool PerSecond; public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs b/Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs index 2b727458c..af3eb8e4c 100644 --- a/Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/InstantWeapon.cs @@ -6,16 +6,16 @@ using Newtonsoft.Json; using Unity.Mathematics; using static Unity.Mathematics.math; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class InstantWeaponData : WeaponData { - [InspectableField, JsonProperty("count"), Key(17)] + [Inspectable, JsonProperty("count"), Key(17)] public PerformanceStat Count = new PerformanceStat(); - [InspectableField, JsonProperty("burstTime"), Key(18)] + [Inspectable, JsonProperty("burstTime"), Key(18)] public PerformanceStat BurstTime = new PerformanceStat(); - [InspectableField, JsonProperty("cooldown"), Key(19), RuntimeInspectable] + [Inspectable, JsonProperty("cooldown"), Key(19), RuntimeInspectable] public PerformanceStat Cooldown = new PerformanceStat(); [InspectablePrefab, JsonProperty("ammoInterval"), Key(20)] diff --git a/Assets/Scripts/ServerShared/Behaviors/ItemUsage.cs b/Assets/Scripts/ServerShared/Behaviors/ItemUsage.cs index b50768765..7087f3241 100644 --- a/Assets/Scripts/ServerShared/Behaviors/ItemUsage.cs +++ b/Assets/Scripts/ServerShared/Behaviors/ItemUsage.cs @@ -7,7 +7,7 @@ using System.Linq; using MessagePack; using Newtonsoft.Json; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-5), RuntimeInspectable] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-5), RuntimeInspectable] public class ItemUsageData : BehaviorData { [InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("item"), Key(1), RuntimeInspectable] diff --git a/Assets/Scripts/ServerShared/Behaviors/Launcher.cs b/Assets/Scripts/ServerShared/Behaviors/Launcher.cs index 17cb72e19..557b94507 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Launcher.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Launcher.cs @@ -6,7 +6,7 @@ using MessagePack; using Newtonsoft.Json; using Unity.Mathematics; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class LauncherData : LockWeaponData { [InspectableAnimationCurve, JsonProperty("guidance"), Key(26)] @@ -18,13 +18,13 @@ public class LauncherData : LockWeaponData [InspectableAnimationCurve, JsonProperty("liftCurve"), Key(28)] public float4[] LiftCurve; - [InspectableField, JsonProperty("thrust"), Key(29)] + [Inspectable, JsonProperty("thrust"), Key(29)] public PerformanceStat Thrust = new PerformanceStat(); - [InspectableField, JsonProperty("frequency"), Key(30)] + [Inspectable, JsonProperty("frequency"), Key(30)] public float DodgeFrequency; - [InspectableField, JsonProperty("missileSpeed"), Key(31), RuntimeInspectable] + [Inspectable, JsonProperty("missileSpeed"), Key(31), RuntimeInspectable] public PerformanceStat MissileVelocity = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) @@ -33,7 +33,7 @@ public class LauncherData : LockWeaponData } } -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class GuidedWeaponData : InstantWeaponData { [InspectableAnimationCurve, JsonProperty("guidance"), Key(21)] @@ -45,13 +45,13 @@ public class GuidedWeaponData : InstantWeaponData [InspectableAnimationCurve, JsonProperty("liftCurve"), Key(23)] public float4[] LiftCurve; - [InspectableField, JsonProperty("thrust"), Key(24)] + [Inspectable, JsonProperty("thrust"), Key(24)] public PerformanceStat Thrust = new PerformanceStat(); - [InspectableField, JsonProperty("frequency"), Key(25)] + [Inspectable, JsonProperty("frequency"), Key(25)] public float DodgeFrequency; - [InspectableField, JsonProperty("missileSpeed"), Key(26), RuntimeInspectable] + [Inspectable, JsonProperty("missileSpeed"), Key(26), RuntimeInspectable] public PerformanceStat MissileVelocity = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs b/Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs index d105c2418..c20f94c78 100644 --- a/Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/LockWeapon.cs @@ -6,22 +6,22 @@ using Newtonsoft.Json; using Unity.Mathematics; using static Unity.Mathematics.math; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class LockWeaponData : InstantWeaponData { - [InspectableField, JsonProperty("speed"), Key(21), RuntimeInspectable] + [Inspectable, JsonProperty("speed"), Key(21), RuntimeInspectable] public PerformanceStat LockSpeed = new PerformanceStat(); - [InspectableField, JsonProperty("sensorImpact"), Key(22)] + [Inspectable, JsonProperty("sensorImpact"), Key(22)] public PerformanceStat SensorImpact = new PerformanceStat(); - [InspectableField, JsonProperty("threshold"), Key(23), RuntimeInspectable] + [Inspectable, JsonProperty("threshold"), Key(23), RuntimeInspectable] public PerformanceStat LockAngle = new PerformanceStat(); - [InspectableField, JsonProperty("directionImpact"), Key(24)] + [Inspectable, JsonProperty("directionImpact"), Key(24)] public PerformanceStat DirectionImpact = new PerformanceStat(); - [InspectableField, JsonProperty("decay"), Key(25)] + [Inspectable, JsonProperty("decay"), Key(25)] public PerformanceStat Decay = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/MiningTool.cs b/Assets/Scripts/ServerShared/Behaviors/MiningTool.cs index 5c71e2d16..9bfc3eaf4 100644 --- a/Assets/Scripts/ServerShared/Behaviors/MiningTool.cs +++ b/Assets/Scripts/ServerShared/Behaviors/MiningTool.cs @@ -9,19 +9,19 @@ using Newtonsoft.Json; using Unity.Mathematics; using static Unity.Mathematics.math; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(10)] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(10)] public class MiningToolData : BehaviorData { - [InspectableField, JsonProperty("dps"), Key(1)] + [Inspectable, JsonProperty("dps"), Key(1)] public PerformanceStat DamagePerSecond = new PerformanceStat(); - [InspectableField, JsonProperty("efficiency"), Key(2)] + [Inspectable, JsonProperty("efficiency"), Key(2)] public PerformanceStat Efficiency = new PerformanceStat(); - [InspectableField, JsonProperty("penetration"), Key(3)] + [Inspectable, JsonProperty("penetration"), Key(3)] public PerformanceStat Penetration = new PerformanceStat(); - [InspectableField, JsonProperty("range"), Key(4)] + [Inspectable, JsonProperty("range"), Key(4)] public PerformanceStat Range = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Radiance.cs b/Assets/Scripts/ServerShared/Behaviors/Radiance.cs index b85a671cd..b3113d670 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Radiance.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Radiance.cs @@ -7,10 +7,10 @@ using System.Linq; using MessagePack; using Newtonsoft.Json; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class RadianceData : BehaviorData { - [InspectableField, JsonProperty("radiance"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("radiance"), Key(1), RuntimeInspectable] public PerformanceStat Radiance = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Radiator.cs b/Assets/Scripts/ServerShared/Behaviors/Radiator.cs index 3806ff2e2..9a6eb45af 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Radiator.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Radiator.cs @@ -10,19 +10,19 @@ using static Unity.Mathematics.math; [MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class RadiatorData : BehaviorData { - [InspectableField, JsonProperty("emissivity"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("emissivity"), Key(1), RuntimeInspectable] public PerformanceStat Emissivity = new PerformanceStat(); - [InspectableField, JsonProperty("pumpedHeat"), Key(2), RuntimeInspectable] + [Inspectable, JsonProperty("pumpedHeat"), Key(2), RuntimeInspectable] public PerformanceStat PumpedHeat = new PerformanceStat(); [InspectableTemperature, JsonProperty("temperatureFloor"), Key(3), RuntimeInspectable] public float TemperatureFloor; - [InspectableField, JsonProperty("wasteHeat"), Key(4), RuntimeInspectable] + [Inspectable, JsonProperty("wasteHeat"), Key(4), RuntimeInspectable] public PerformanceStat WasteHeat = new PerformanceStat(); - [InspectableField, JsonProperty("energyUsage"), Key(5), RuntimeInspectable] + [Inspectable, JsonProperty("energyUsage"), Key(5), RuntimeInspectable] public PerformanceStat EnergyUsage = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Reactor.cs b/Assets/Scripts/ServerShared/Behaviors/Reactor.cs index 81fbc69d0..68a350b4b 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Reactor.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Reactor.cs @@ -13,16 +13,16 @@ using static Unity.Mathematics.math; [MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class ReactorData : BehaviorData { - [InspectableField, JsonProperty("charge"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("charge"), Key(1), RuntimeInspectable] public PerformanceStat Charge = new PerformanceStat(); - [InspectableField, JsonProperty("efficiency"), Key(2), RuntimeInspectable] + [Inspectable, JsonProperty("efficiency"), Key(2), RuntimeInspectable] public PerformanceStat Efficiency = new PerformanceStat(); - [InspectableField, JsonProperty("overload"), Key(3), RuntimeInspectable] + [Inspectable, JsonProperty("overload"), Key(3), RuntimeInspectable] public PerformanceStat OverloadEfficiency = new PerformanceStat(); - [InspectableField, JsonProperty("underload"), Key(4), RuntimeInspectable] + [Inspectable, JsonProperty("underload"), Key(4), RuntimeInspectable] public PerformanceStat ThrottlingFactor = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Reflector.cs b/Assets/Scripts/ServerShared/Behaviors/Reflector.cs index fa5d2e730..35a1689e4 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Reflector.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Reflector.cs @@ -10,7 +10,7 @@ using static Unity.Mathematics.math; [MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class ReflectorData : BehaviorData { - [InspectableField, JsonProperty("crossSection"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("crossSection"), Key(1), RuntimeInspectable] public PerformanceStat CrossSection = new PerformanceStat(); // [InspectableAnimationCurve, JsonProperty("visibility"), Key(1)] diff --git a/Assets/Scripts/ServerShared/Behaviors/ResourceScanner.cs b/Assets/Scripts/ServerShared/Behaviors/ResourceScanner.cs index fa20a6b97..29dbde551 100644 --- a/Assets/Scripts/ServerShared/Behaviors/ResourceScanner.cs +++ b/Assets/Scripts/ServerShared/Behaviors/ResourceScanner.cs @@ -9,16 +9,16 @@ using Newtonsoft.Json; using Unity.Mathematics; using static Unity.Mathematics.math; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class ResourceScannerData : BehaviorData { - [InspectableField, JsonProperty("range"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("range"), Key(1), RuntimeInspectable] public PerformanceStat Range = new PerformanceStat(); - [InspectableField, JsonProperty("minDensity"), Key(2), RuntimeInspectable] + [Inspectable, JsonProperty("minDensity"), Key(2), RuntimeInspectable] public PerformanceStat MinimumDensity = new PerformanceStat(); - [InspectableField, JsonProperty("scanDuration"), Key(3), RuntimeInspectable] + [Inspectable, JsonProperty("scanDuration"), Key(3), RuntimeInspectable] public PerformanceStat ScanDuration = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Sensor.cs b/Assets/Scripts/ServerShared/Behaviors/Sensor.cs index 869dd6ac5..6aa65e326 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Sensor.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Sensor.cs @@ -9,34 +9,34 @@ using Newtonsoft.Json; using Unity.Mathematics; using static Unity.Mathematics.math; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class SensorData : BehaviorData { - [InspectableField, JsonProperty("sensitivity"), Key(3), RuntimeInspectable] + [Inspectable, JsonProperty("sensitivity"), Key(3), RuntimeInspectable] public PerformanceStat Sensitivity = new PerformanceStat(); [InspectableAnimationCurve, JsonProperty("sensitivityCurve"), Key(4), RuntimeInspectable] public float4[] SensitivityCurve; - [InspectableField, JsonProperty("pingBoost"), Key(5), RuntimeInspectable] + [Inspectable, JsonProperty("pingBoost"), Key(5), RuntimeInspectable] public PerformanceStat PingBoost; - [InspectableField, JsonProperty("pingEnergy"), Key(6), RuntimeInspectable] + [Inspectable, JsonProperty("pingEnergy"), Key(6), RuntimeInspectable] public PerformanceStat PingEnergy; - [InspectableField, JsonProperty("pingVisibility"), Key(7), RuntimeInspectable] + [Inspectable, JsonProperty("pingVisibility"), Key(7), RuntimeInspectable] public PerformanceStat PingVisibility; - [InspectableField, JsonProperty("pingRange"), Key(8), RuntimeInspectable] + [Inspectable, JsonProperty("pingRange"), Key(8), RuntimeInspectable] public PerformanceStat PingRange; - [InspectableField, JsonProperty("pingCooldown"), Key(9), RuntimeInspectable] + [Inspectable, JsonProperty("pingCooldown"), Key(9), RuntimeInspectable] public PerformanceStat PingCooldown; - [InspectableField, JsonProperty("pingDuration"), Key(10)] + [Inspectable, JsonProperty("pingDuration"), Key(10)] public float PingDuration = 2; - [InspectableField, JsonProperty("pingRadiusExponent"), Key(11)] + [Inspectable, JsonProperty("pingRadiusExponent"), Key(11)] public float PingRadiusExponent = .5f; public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Shield.cs b/Assets/Scripts/ServerShared/Behaviors/Shield.cs index e27fafe46..caf390e44 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Shield.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Shield.cs @@ -10,10 +10,10 @@ using static Unity.Mathematics.math; [MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class ShieldData : BehaviorData { - [InspectableField, JsonProperty("efficiency"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("efficiency"), Key(1), RuntimeInspectable] public PerformanceStat Efficiency = new PerformanceStat(); - [InspectableField, JsonProperty("energy"), Key(2), RuntimeInspectable] + [Inspectable, JsonProperty("energy"), Key(2), RuntimeInspectable] public PerformanceStat EnergyUsage = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/StatModifier.cs b/Assets/Scripts/ServerShared/Behaviors/StatModifier.cs index a43133345..35e0115d8 100644 --- a/Assets/Scripts/ServerShared/Behaviors/StatModifier.cs +++ b/Assets/Scripts/ServerShared/Behaviors/StatModifier.cs @@ -7,16 +7,16 @@ using System.Linq; using MessagePack; using Newtonsoft.Json; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class StatModifierData : BehaviorData { - [InspectableField, JsonProperty("stat"), Key(1)] + [Inspectable, JsonProperty("stat"), Key(1)] public StatReference Stat = new StatReference(); - [InspectableField, JsonProperty("modifier"), Key(2)] + [Inspectable, JsonProperty("modifier"), Key(2)] public PerformanceStat Modifier = new PerformanceStat(); - [InspectableField, JsonProperty("type"), Key(3)] + [Inspectable, JsonProperty("type"), Key(3)] public StatModifierType Type; [InspectableType(typeof(BehaviorData)), JsonProperty("requireBehavior"), Key(4)] @@ -103,12 +103,12 @@ public enum StatModifierType Multiplier } -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class StatReference { [InspectableType(typeof(BehaviorData)), JsonProperty("behavior"), Key(1)] public string Target; - [InspectableField, JsonProperty("stat"), Key(2)] + [Inspectable, JsonProperty("stat"), Key(2)] public string Stat; } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Behaviors/Switch.cs b/Assets/Scripts/ServerShared/Behaviors/Switch.cs index 5c4a5e5c7..ccf07bb7d 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Switch.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Switch.cs @@ -7,7 +7,7 @@ using System.Linq; using MessagePack; using Newtonsoft.Json; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-25)] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-25)] public class SwitchData : BehaviorData { public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Thermotoggle.cs b/Assets/Scripts/ServerShared/Behaviors/Thermotoggle.cs index af8d03f55..4df055a9c 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Thermotoggle.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Thermotoggle.cs @@ -7,13 +7,13 @@ using System.Linq; using MessagePack; using Newtonsoft.Json; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-22)] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-22)] public class ThermotoggleData : BehaviorData { [InspectableTemperature, JsonProperty("targetTemp"), Key(1)] public float TargetTemperature; - [InspectableField, JsonProperty("highPass"), Key(2)] + [Inspectable, JsonProperty("highPass"), Key(2)] public bool HighPass; public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Thruster.cs b/Assets/Scripts/ServerShared/Behaviors/Thruster.cs index 43948eb89..b61b90b66 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Thruster.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Thruster.cs @@ -10,16 +10,16 @@ using static Unity.Mathematics.math; [MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship), RuntimeInspectable] public class ThrusterData : BehaviorData { - [InspectableField, JsonProperty("thrust"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("thrust"), Key(1), RuntimeInspectable] public PerformanceStat Thrust = new PerformanceStat(); - [InspectableField, JsonProperty("visibility"), Key(2), RuntimeInspectable] + [Inspectable, JsonProperty("visibility"), Key(2), RuntimeInspectable] public PerformanceStat Visibility = new PerformanceStat(); - [InspectableField, JsonProperty("heat"), Key(3), RuntimeInspectable] + [Inspectable, JsonProperty("heat"), Key(3), RuntimeInspectable] public PerformanceStat Heat = new PerformanceStat(); - [InspectableField, JsonProperty("energy"), Key(4), RuntimeInspectable] + [Inspectable, JsonProperty("energy"), Key(4), RuntimeInspectable] public PerformanceStat EnergyUsage = new PerformanceStat(); [InspectablePrefab, JsonProperty("Particles"), Key(5)] diff --git a/Assets/Scripts/ServerShared/Behaviors/Trigger.cs b/Assets/Scripts/ServerShared/Behaviors/Trigger.cs index f54c34358..10c30163d 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Trigger.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Trigger.cs @@ -7,7 +7,7 @@ using System.Linq; using MessagePack; using Newtonsoft.Json; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-20)] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-20)] public class TriggerData : BehaviorData { public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/VelocityConversion.cs b/Assets/Scripts/ServerShared/Behaviors/VelocityConversion.cs index 1f5d9cec0..fef52068f 100644 --- a/Assets/Scripts/ServerShared/Behaviors/VelocityConversion.cs +++ b/Assets/Scripts/ServerShared/Behaviors/VelocityConversion.cs @@ -10,7 +10,7 @@ using static Unity.Mathematics.math; [MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class VelocityConversionData : BehaviorData { - [InspectableField, JsonProperty("traction"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("traction"), Key(1), RuntimeInspectable] public PerformanceStat Traction = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/VelocityLimit.cs b/Assets/Scripts/ServerShared/Behaviors/VelocityLimit.cs index f0e6701d1..09b948e75 100644 --- a/Assets/Scripts/ServerShared/Behaviors/VelocityLimit.cs +++ b/Assets/Scripts/ServerShared/Behaviors/VelocityLimit.cs @@ -10,7 +10,7 @@ using static Unity.Mathematics.math; [MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class VelocityLimitData : BehaviorData { - [InspectableField, JsonProperty("topSpeed"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("topSpeed"), Key(1), RuntimeInspectable] public PerformanceStat TopSpeed = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Visibility.cs b/Assets/Scripts/ServerShared/Behaviors/Visibility.cs index 735bf5040..1e5359869 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Visibility.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Visibility.cs @@ -7,13 +7,13 @@ using System.Linq; using MessagePack; using Newtonsoft.Json; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn), RuntimeInspectable] public class VisibilityData : BehaviorData { - [InspectableField, JsonProperty("visibility"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("visibility"), Key(1), RuntimeInspectable] public PerformanceStat Visibility = new PerformanceStat(); - [InspectableField, JsonProperty("visibilityDecay"), Key(2)] + [Inspectable, JsonProperty("visibilityDecay"), Key(2)] public PerformanceStat VisibilityDecay = new PerformanceStat(); public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item) diff --git a/Assets/Scripts/ServerShared/Behaviors/Weapon.cs b/Assets/Scripts/ServerShared/Behaviors/Weapon.cs index 0640d19dc..d060057d6 100644 --- a/Assets/Scripts/ServerShared/Behaviors/Weapon.cs +++ b/Assets/Scripts/ServerShared/Behaviors/Weapon.cs @@ -17,10 +17,10 @@ using static Unity.Mathematics.math; RuntimeInspectable] public abstract class WeaponData : BehaviorData { - [InspectableField, JsonProperty("damageType"), Key(1), RuntimeInspectable] + [Inspectable, JsonProperty("damageType"), Key(1), RuntimeInspectable] public DamageType DamageType; - [InspectableField, JsonProperty("damage"), Key(2), RuntimeInspectable] + [Inspectable, JsonProperty("damage"), Key(2), RuntimeInspectable] public PerformanceStat Damage = new PerformanceStat(); [RangedFloatInspectable(0,1), JsonProperty("penetration"), Key(3), RuntimeInspectable] @@ -29,10 +29,10 @@ public abstract class WeaponData : BehaviorData [RangedFloatInspectable(0,1), JsonProperty("damageSpread"), Key(4)] public PerformanceStat DamageSpread = new PerformanceStat(); - [InspectableField, JsonProperty("minRange"), Key(5), RuntimeInspectable] + [Inspectable, JsonProperty("minRange"), Key(5), RuntimeInspectable] public PerformanceStat MinRange = new PerformanceStat(); - [InspectableField, JsonProperty("range"), Key(6), RuntimeInspectable] + [Inspectable, JsonProperty("range"), Key(6), RuntimeInspectable] public PerformanceStat Range = new PerformanceStat(); [InspectableAnimationCurve, JsonProperty("damageRange"), Key(7), RuntimeInspectable] @@ -62,7 +62,7 @@ public abstract class WeaponData : BehaviorData [InspectablePrefab, JsonProperty("spread"), Key(15)] public PerformanceStat Spread = new PerformanceStat(); - [InspectableField, JsonProperty("velocity"), Key(16)] + [Inspectable, JsonProperty("velocity"), Key(16)] public PerformanceStat Velocity = new PerformanceStat(); } diff --git a/Assets/Scripts/ServerShared/Corporations.cs b/Assets/Scripts/ServerShared/Corporations.cs index 45f7aa609..79bc3736d 100644 --- a/Assets/Scripts/ServerShared/Corporations.cs +++ b/Assets/Scripts/ServerShared/Corporations.cs @@ -9,39 +9,13 @@ using MessagePack; using Newtonsoft.Json; using Unity.Mathematics; - -[RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)] -public class Corporation : DatabaseEntry, INamedEntry -{ - [JsonProperty("name"), Key(1)] - public string Name; - - [JsonProperty("parent"), Key(2)] - public Guid Parent; - - [JsonProperty("tasks"), Key(3)] - public List Tasks = new List(); - - [JsonProperty("planetSurveyFloor"), Key(4)] - public Dictionary PlanetSurveyFloor = new Dictionary(); - - [JsonProperty("unlockedBlueprints"), Key(5)] - public List UnlockedBlueprints = new List(); - - [IgnoreMember] public string EntryName - { - get => Name; - set => Name = value; - } -} - [RethinkTable("Galaxy"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class Faction : DatabaseEntry, INamedEntry { - [InspectableField, JsonProperty("name"), Key(1)] + [Inspectable, JsonProperty("name"), Key(1)] public string Name; - [InspectableField, JsonProperty("shortName"), Key(2)] + [Inspectable, JsonProperty("shortName"), Key(2)] public string ShortName; [InspectableText, JsonProperty("description"), Key(3)] @@ -53,7 +27,7 @@ public class Faction : DatabaseEntry, INamedEntry [InspectableDatabaseLink(typeof(PersonalityAttribute)), JsonProperty("personality"), Key(5)] public Dictionary Personality = new Dictionary(); - [InspectableField, JsonProperty("hostile"), Key(6)] + [Inspectable, JsonProperty("hostile"), Key(6)] public bool PlayerHostile; [InspectableColor, JsonProperty("primaryColor"), Key(7)] @@ -68,7 +42,7 @@ public class Faction : DatabaseEntry, INamedEntry [InspectableDatabaseLink(typeof(HullData)), JsonProperty("bossHull"), Key(10)] public Guid BossHull; - [InspectableField, JsonProperty("influence"), Key(11)] + [Inspectable, JsonProperty("influence"), Key(11)] public int InfluenceDistance = 4; [InspectableDatabaseLink(typeof(Faction)), RangedFloat(0, 1), JsonProperty("allegiance"), Key(12)] diff --git a/Assets/Scripts/ServerShared/CultCache/Attributes.cs b/Assets/Scripts/ServerShared/CultCache/Attributes.cs index 800cf2bed..574ec07b8 100644 --- a/Assets/Scripts/ServerShared/CultCache/Attributes.cs +++ b/Assets/Scripts/ServerShared/CultCache/Attributes.cs @@ -1,28 +1,14 @@ using System; -[AttributeUsage(AttributeTargets.Class)] -public class InspectableAttribute : Attribute { } - -public abstract class PreferredInspectorAttribute : InspectableAttribute -{ - public Type TargetType; - - public PreferredInspectorAttribute(Type targetType) - { - TargetType = targetType; - } -} - [AttributeUsage(AttributeTargets.Class)] public class ExternalEntryAttribute : Attribute { } -public class InspectableFieldAttribute : Attribute { } +public class InspectableAttribute : Attribute { } [AttributeUsage(AttributeTargets.Field)] -public class InspectableTextAttribute : InspectableFieldAttribute { } +public abstract class PreferredInspectorAttribute : InspectableAttribute { } -[AttributeUsage(AttributeTargets.Field)] -public class InspectableUnityObjectAttribute : InspectableFieldAttribute +public class InspectableUnityObjectAttribute : PreferredInspectorAttribute { public Type ObjectType; @@ -31,27 +17,15 @@ public class InspectableUnityObjectAttribute : InspectableFieldAttribute ObjectType = type; } } +public class InspectableTextAttribute : PreferredInspectorAttribute { } +public class InspectablePrefabAttribute : PreferredInspectorAttribute { } +public class InspectableTextureAttribute : PreferredInspectorAttribute { } +public class InspectableTextAssetAttribute : PreferredInspectorAttribute { } +public class InspectableTemperatureAttribute : PreferredInspectorAttribute { } +public class InspectableAnimationCurveAttribute : PreferredInspectorAttribute { } +public class InspectableColorAttribute : PreferredInspectorAttribute { } -[AttributeUsage(AttributeTargets.Field)] -public class InspectablePrefabAttribute : InspectableFieldAttribute { } - -[AttributeUsage(AttributeTargets.Field)] -public class InspectableTextureAttribute : InspectableFieldAttribute { } - -[AttributeUsage(AttributeTargets.Field)] -public class InspectableTextAssetAttribute : InspectableFieldAttribute { } - -[AttributeUsage(AttributeTargets.Field)] -public class InspectableTemperatureAttribute : InspectableFieldAttribute { } - -[AttributeUsage(AttributeTargets.Field)] -public class InspectableAnimationCurveAttribute : InspectableFieldAttribute { } - -[AttributeUsage(AttributeTargets.Field)] -public class InspectableColorAttribute : InspectableFieldAttribute { } - -[AttributeUsage(AttributeTargets.Field)] -public class InspectableDatabaseLinkAttribute : InspectableFieldAttribute +public class InspectableDatabaseLinkAttribute : PreferredInspectorAttribute { public readonly Type EntryType; @@ -61,8 +35,7 @@ public class InspectableDatabaseLinkAttribute : InspectableFieldAttribute } } -[AttributeUsage(AttributeTargets.Field)] -public class RangedFloatInspectableAttribute : InspectableFieldAttribute +public class RangedFloatInspectableAttribute : PreferredInspectorAttribute { public readonly float Min, Max; @@ -73,6 +46,27 @@ public class RangedFloatInspectableAttribute : InspectableFieldAttribute } } +public class RangedIntInspectableAttribute : PreferredInspectorAttribute +{ + public readonly int Min, Max; + + public RangedIntInspectableAttribute(int min, int max) + { + Min = min; + Max = max; + } +} + +public class InspectableTypeAttribute : PreferredInspectorAttribute +{ + public readonly Type Type; + + public InspectableTypeAttribute(Type type) + { + Type = type; + } +} + [AttributeUsage(AttributeTargets.Field)] public class RangedFloatAttribute : Attribute { @@ -85,30 +79,6 @@ public class RangedFloatAttribute : Attribute } } -[AttributeUsage(AttributeTargets.Field)] -public class RangedIntInspectableAttribute : InspectableFieldAttribute -{ - public readonly int Min, Max; - - public RangedIntInspectableAttribute(int min, int max) - { - Min = min; - Max = max; - } -} - -public class InspectableTypeAttribute : InspectableFieldAttribute -{ - public readonly Type Type; - - public InspectableTypeAttribute(Type type) - { - Type = type; - } -} - -[AttributeUsage(AttributeTargets.Field)] -public class SimplePerformanceStatAttribute : Attribute { } /// /// Specify a tooltip for a field in the Inspector window. diff --git a/Assets/Scripts/ServerShared/CultCache/DatabaseCache.cs b/Assets/Scripts/ServerShared/CultCache/CultCache.cs similarity index 90% rename from Assets/Scripts/ServerShared/CultCache/DatabaseCache.cs rename to Assets/Scripts/ServerShared/CultCache/CultCache.cs index 1fc2355b0..3cefd8bda 100644 --- a/Assets/Scripts/ServerShared/CultCache/DatabaseCache.cs +++ b/Assets/Scripts/ServerShared/CultCache/CultCache.cs @@ -10,7 +10,7 @@ using System.Linq; using System.Reflection; using MessagePack; -public class DatabaseCache +public class CultCache { public event Action OnDataInsertLocal; public event Action OnDataUpdateLocal; @@ -42,10 +42,11 @@ public class DatabaseCache } } private readonly Dictionary _externalEntries = new Dictionary(); + private readonly Dictionary _linkFields = new Dictionary(); public IEnumerable AllEntries => _entries.Values; - public DatabaseCache(string filePath) + public CultCache(string filePath) { RegisterResolver.Register(); _filePath = filePath; @@ -57,6 +58,9 @@ public class DatabaseCache // This is mainly to accomodate large files like datasets foreach (var type in typeof(DatabaseEntry).GetAllChildClasses()) { + var linkFields = type.GetFields().Where(f => f.FieldType.IsAssignableToGenericType(typeof(DatabaseLink<>))).ToArray(); + if(linkFields.Length > 0) + _linkFields[type] = linkFields; if (type.GetCustomAttribute() != null) { var typeDirectory = dataDirectory.CreateSubdirectory(type.Name); @@ -88,6 +92,17 @@ public class DatabaseCache // If an external entry is added, store it separately var type = entry.GetType(); + if (_linkFields.ContainsKey(type)) + { + foreach (var linkField in _linkFields[type]) + { + var link = (DatabaseLinkBase) linkField.GetValue(entry); + if (link != null) + { + link.Cache = this; + } + } + } if (_externalTypes.ContainsKey(type)) { if (_externalEntries.ContainsKey(entry.ID)) diff --git a/Assets/Scripts/ServerShared/CultCache/DatabaseCache.cs.meta b/Assets/Scripts/ServerShared/CultCache/CultCache.cs.meta similarity index 100% rename from Assets/Scripts/ServerShared/CultCache/DatabaseCache.cs.meta rename to Assets/Scripts/ServerShared/CultCache/CultCache.cs.meta diff --git a/Assets/Scripts/ServerShared/CultCache/DatabaseEntry.cs b/Assets/Scripts/ServerShared/CultCache/DatabaseEntry.cs index ff3ab368e..84c971591 100644 --- a/Assets/Scripts/ServerShared/CultCache/DatabaseEntry.cs +++ b/Assets/Scripts/ServerShared/CultCache/DatabaseEntry.cs @@ -17,9 +17,7 @@ public interface INamedEntry string EntryName { get; set; } } -[InspectableField, - MessagePackObject, - //MessagePackFormatter(typeof(TypelessFormatter)), +[MessagePackObject, JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter)), Union(0, typeof(SimpleCommodityData)), @@ -33,7 +31,7 @@ public interface INamedEntry Union(9, typeof(NameFile)), //Union(10, typeof(ZoneData)), Union(11, typeof(PlayerData)), - Union(12, typeof(Corporation)), + // Union(12, typeof(Corporation)), Union(13, typeof(Faction)), Union(14, typeof(OrbitalEntity)), Union(15, typeof(OrbitData)), @@ -41,8 +39,8 @@ public interface INamedEntry Union(17, typeof(PersonalityAttribute)), Union(18, typeof(AgentTask)), // Union(19, typeof(LoadoutData)), - Union(20, typeof(Ship)), - Union(21, typeof(Mining)), + Union(20, typeof(Ship)), + Union(21, typeof(Mining)), Union(22, typeof(StationTowing)), Union(23, typeof(Survey)), Union(24, typeof(HaulingTask)), @@ -57,6 +55,21 @@ public abstract class DatabaseEntry { [JsonProperty("id"), Key(0)] public Guid ID = Guid.NewGuid(); +} + +[MessagePackObject, JsonObject(MemberSerialization.OptIn)] +public class DatabaseLink : DatabaseLinkBase where T : DatabaseEntry +{ + [IgnoreMember] + public T Value => Cache.Get(LinkID); +} + +[MessagePackObject, JsonObject(MemberSerialization.OptIn)] +public class DatabaseLinkBase +{ + [Key(0), JsonProperty("linkID")] + public Guid LinkID; - public DatabaseEntry(){} + [IgnoreMember] + public CultCache Cache; } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/CultCache/Extensions.cs b/Assets/Scripts/ServerShared/CultCache/Extensions.cs index ccfc2086f..1e80feb8f 100644 --- a/Assets/Scripts/ServerShared/CultCache/Extensions.cs +++ b/Assets/Scripts/ServerShared/CultCache/Extensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Threading.Tasks; public static class CultCacheExtensions @@ -56,7 +57,35 @@ public static class CultCacheExtensions return ChildClasses[type] = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(ass => ass.GetTypes()).Where(type.IsAssignableFrom).ToArray(); } + + private static Dictionary GenericChildClasses = new Dictionary(); + public static Type[] GetAllGenericChildClasses(this Type genericType) + { + if (GenericChildClasses.ContainsKey(genericType)) + return ChildClasses[genericType]; + return ChildClasses[genericType] = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(ass => ass.GetTypes()).Where(type=>type.IsAssignableToGenericType(genericType)).ToArray(); + } + public static bool IsAssignableToGenericType(this Type givenType, Type genericType) + { + var interfaceTypes = givenType.GetInterfaces(); + + foreach (var it in interfaceTypes) + { + if (it.IsGenericType && it.GetGenericTypeDefinition() == genericType) + return true; + } + + if (givenType.IsGenericType && givenType.GetGenericTypeDefinition() == genericType) + return true; + + Type baseType = givenType.BaseType; + if (baseType == null) return false; + + return IsAssignableToGenericType(baseType, genericType); + } + public static async void WrapAwait(this Task task) { await task; diff --git a/Assets/Scripts/ServerShared/GlobalData.cs b/Assets/Scripts/ServerShared/GlobalData.cs index b6ceb1e87..71c477fb4 100644 --- a/Assets/Scripts/ServerShared/GlobalData.cs +++ b/Assets/Scripts/ServerShared/GlobalData.cs @@ -15,46 +15,46 @@ using static NoiseFbm; [Inspectable, Serializable, RethinkTable("Galaxy"), MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class GalaxyMapLayerData : DatabaseEntry, INamedEntry { - [InspectableField, JsonProperty("coreBoost"), Key(1)] + [Inspectable, JsonProperty("coreBoost"), Key(1)] public float CoreBoost = 1.05f; - [InspectableField, JsonProperty("coreBoostOffset"), Key(2)] + [Inspectable, JsonProperty("coreBoostOffset"), Key(2)] public float CoreBoostOffset = .1f; - [InspectableField, JsonProperty("coreBoostPower"), Key(3)] + [Inspectable, JsonProperty("coreBoostPower"), Key(3)] public float CoreBoostPower = 2.25f; - [InspectableField, JsonProperty("spokeScale"), Key(4)] + [Inspectable, JsonProperty("spokeScale"), Key(4)] public float SpokeScale = 1; - [InspectableField, JsonProperty("spokeOffset"), Key(5)] + [Inspectable, JsonProperty("spokeOffset"), Key(5)] public float SpokeOffset = 0; - [InspectableField, JsonProperty("edgeReduction"), Key(6)] + [Inspectable, JsonProperty("edgeReduction"), Key(6)] public float EdgeReduction = 3; - [InspectableField, JsonProperty("noiseOffset"), Key(7)] + [Inspectable, JsonProperty("noiseOffset"), Key(7)] public float NoiseOffset = 0; - [InspectableField, JsonProperty("noiseAmplitude"), Key(8)] + [Inspectable, JsonProperty("noiseAmplitude"), Key(8)] public float NoiseAmplitude = 1.5f; - [InspectableField, JsonProperty("noiseGain"), Key(9)] + [Inspectable, JsonProperty("noiseGain"), Key(9)] public float NoiseGain = .7f; - [InspectableField, JsonProperty("noiseLacunarity"), Key(10)] + [Inspectable, JsonProperty("noiseLacunarity"), Key(10)] public float NoiseLacunarity = 2; - [InspectableField, JsonProperty("noiseOctaves"), Key(11)] + [Inspectable, JsonProperty("noiseOctaves"), Key(11)] public int NoiseOctaves = 7; - [InspectableField, JsonProperty("noiseFrequency"), Key(12)] + [Inspectable, JsonProperty("noiseFrequency"), Key(12)] public float NoiseFrequency = 1; - [InspectableField, JsonProperty("noisePosition"), Key(13)] + [Inspectable, JsonProperty("noisePosition"), Key(13)] public float NoisePosition = 1337; - [InspectableField, JsonProperty("name"), Key(14)] + [Inspectable, JsonProperty("name"), Key(14)] public string Name; public float Evaluate(float2 uv, GalaxyShapeSettings settings) diff --git a/Assets/Scripts/ServerShared/ItemData.cs b/Assets/Scripts/ServerShared/ItemData.cs index 2437045d4..b0e50a2c2 100644 --- a/Assets/Scripts/ServerShared/ItemData.cs +++ b/Assets/Scripts/ServerShared/ItemData.cs @@ -14,7 +14,7 @@ using static Unity.Mathematics.math; using float2 = Unity.Mathematics.float2; using int2 = Unity.Mathematics.int2; -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class Shape { [JsonProperty("name"), Key(0)] public bool[,] Cells; @@ -222,7 +222,7 @@ public class Shape [MessagePackObject, JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter))] public abstract class ItemData : DatabaseEntry, INamedEntry { - [InspectableField, JsonProperty("name"), Key(1)] + [Inspectable, JsonProperty("name"), Key(1)] public string Name; [InspectableText, JsonProperty("description"), Key(2)] @@ -231,20 +231,20 @@ public abstract class ItemData : DatabaseEntry, INamedEntry [InspectableDatabaseLink(typeof(Faction)), JsonProperty("creator"), Key(3)] public Guid Manufacturer; - [InspectableField, JsonProperty("mass"), Key(4)] + [Inspectable, JsonProperty("mass"), Key(4)] public float Mass; - [InspectableField, JsonProperty("shape"), Key(5)] + [Inspectable, JsonProperty("shape"), Key(5)] public Shape Shape; // Heat needed to change temperature of 1 gram by 1 degree - [InspectableField, JsonProperty("specificHeat"), Key(6)] + [Inspectable, JsonProperty("specificHeat"), Key(6)] public float SpecificHeat = 1; - [InspectableField, JsonProperty("conductivity"), Key(7)] + [Inspectable, JsonProperty("conductivity"), Key(7)] public float Conductivity = 1; - [InspectableField, JsonProperty("price"), Key(8)] + [Inspectable, JsonProperty("price"), Key(8)] public int Price = 0; [IgnoreMember] public string EntryName @@ -274,17 +274,17 @@ public class SimpleCommodityData : ItemData // [InspectableField, JsonProperty("floor"), Key(11)] // public float Floor = 5f; - [InspectableField, JsonProperty("maxStackSize"), Key(9)] + [Inspectable, JsonProperty("maxStackSize"), Key(9)] public int MaxStack = 10; - [InspectableField, JsonProperty("category"), Key(10)] + [Inspectable, JsonProperty("category"), Key(10)] public SimpleCommodityCategory Category; } [MessagePackObject, JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter))] public abstract class CraftedItemData : ItemData { - [InspectableField, JsonProperty("ingredientQualityWeight"), Key(9)] + [Inspectable, JsonProperty("ingredientQualityWeight"), Key(9)] public float IngredientQualityWeight = .5f; } @@ -294,7 +294,7 @@ public class CompoundCommodityData : CraftedItemData [InspectableDatabaseLink(typeof(PersonalityAttribute)), JsonProperty("demandProfile"), Key(10)] public Dictionary DemandProfile = new Dictionary(); - [InspectableField, JsonProperty("category"), Key(11)] + [Inspectable, JsonProperty("category"), Key(11)] public CompoundCommodityCategory Category; } @@ -304,10 +304,10 @@ public abstract class EquippableItemData : CraftedItemData [InspectableTexture, JsonProperty("schematic"), Key(10)] public string Schematic; - [InspectableField, JsonProperty("behaviors"), Key(11)] + [Inspectable, JsonProperty("behaviors"), Key(11)] public List Behaviors = new List(); - [InspectableField, JsonProperty("durability"), Key(12)] + [Inspectable, JsonProperty("durability"), Key(12)] public float Durability; [InspectableTemperature, JsonProperty("minTemp"), Key(13)] @@ -325,10 +325,10 @@ public abstract class EquippableItemData : CraftedItemData [InspectableAnimationCurve, JsonProperty("performanceCurve"), Key(17)] public float4[] HeatPerformanceCurve; - [InspectableField, JsonProperty("resilience"), Key(18)] + [Inspectable, JsonProperty("resilience"), Key(18)] public float ThermalResilience = 1; - [InspectableField, JsonProperty("sfx"), Key(19)] + [Inspectable, JsonProperty("sfx"), Key(19)] public string SoundEffectTrigger; [IgnoreMember] @@ -372,7 +372,7 @@ public abstract class EquippableItemData : CraftedItemData [RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class GearData : EquippableItemData { - [InspectableField, JsonProperty("hardpointType"), Key(20)] + [Inspectable, JsonProperty("hardpointType"), Key(20)] public HardpointType Hardpoint; [IgnoreMember] public override HardpointType HardpointType => Hardpoint; @@ -381,7 +381,7 @@ public class GearData : EquippableItemData [RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class CargoBayData : EquippableItemData { - [InspectableField, JsonProperty("interiorShape"), Key(20)] + [Inspectable, JsonProperty("interiorShape"), Key(20)] public Shape InteriorShape; [IgnoreMember] public override HardpointType HardpointType => HardpointType.Tool; } @@ -389,45 +389,45 @@ public class CargoBayData : EquippableItemData [RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class DockingBayData : CargoBayData { - [InspectableField, JsonProperty("maxSize"), Key(21)] + [Inspectable, JsonProperty("maxSize"), Key(21)] public int2 MaxSize; } [RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class WeaponItemData : GearData { - [InspectableField, JsonProperty("range"), Key(21)] + [Inspectable, JsonProperty("range"), Key(21)] public WeaponRange WeaponRange; - [InspectableField, JsonProperty("caliber"), Key(22)] + [Inspectable, JsonProperty("caliber"), Key(22)] public WeaponCaliber WeaponCaliber; - [InspectableField, JsonProperty("weaponType"), Key(23)] + [Inspectable, JsonProperty("weaponType"), Key(23)] public WeaponType WeaponType; - [InspectableField, JsonProperty("fireTypes"), Key(24)] + [Inspectable, JsonProperty("fireTypes"), Key(24)] public WeaponFireType WeaponFireTypes; - [InspectableField, JsonProperty("modifiers"), Key(25)] + [Inspectable, JsonProperty("modifiers"), Key(25)] public WeaponModifiers WeaponModifiers; } [RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class HullData : EquippableItemData { - [InspectableField, JsonProperty("hardpoints"), Key(20)] + [Inspectable, JsonProperty("hardpoints"), Key(20)] public List Hardpoints = new List(); [InspectablePrefab, JsonProperty("prefab"), Key(21)] public string Prefab; - [InspectableField, JsonProperty("hullType"), Key(22)] + [Inspectable, JsonProperty("hullType"), Key(22)] public HullType HullType; - [InspectableField, JsonProperty("gridOffset"), Key(23)] + [Inspectable, JsonProperty("gridOffset"), Key(23)] public float GridOffset; - [InspectableField, JsonProperty("armor"), Key(24)] + [Inspectable, JsonProperty("armor"), Key(24)] public float Armor; [IgnoreMember] @@ -449,15 +449,15 @@ public class HullData : EquippableItemData [IgnoreMember] public override HardpointType HardpointType => HardpointType.Hull; } -[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)] +[Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class HardpointData : ITintInspector { - [InspectableField, JsonProperty("type"), Key(0)] public HardpointType Type; - [InspectableField, JsonProperty("position"), Key(1)] public int2 Position; - [InspectableField, JsonProperty("shape"), Key(2)] public Shape Shape = new Shape(); - [InspectableField, JsonProperty("transform"), Key(3)] public string Transform; - [InspectableField, JsonProperty("rotation"), Key(4)] public ItemRotation Rotation; - [InspectableField, JsonProperty("armor"), Key(5)] public float Armor; + [Inspectable, JsonProperty("type"), Key(0)] public HardpointType Type; + [Inspectable, JsonProperty("position"), Key(1)] public int2 Position; + [Inspectable, JsonProperty("shape"), Key(2)] public Shape Shape = new Shape(); + [Inspectable, JsonProperty("transform"), Key(3)] public string Transform; + [Inspectable, JsonProperty("rotation"), Key(4)] public ItemRotation Rotation; + [Inspectable, JsonProperty("armor"), Key(5)] public float Armor; public override string ToString() { @@ -539,13 +539,13 @@ public class PerformanceStat [RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class PersonalityAttribute : DatabaseEntry, INamedEntry { - [InspectableField, JsonProperty("name"), Key(1)] + [Inspectable, JsonProperty("name"), Key(1)] public string Name; - [InspectableField, JsonProperty("low"), Key(2)] + [Inspectable, JsonProperty("low"), Key(2)] public string LowName; - [InspectableField, JsonProperty("high"), Key(3)] + [Inspectable, JsonProperty("high"), Key(3)] public string HighName; [IgnoreMember] public string EntryName diff --git a/Assets/Scripts/ServerShared/ItemManager.cs b/Assets/Scripts/ServerShared/ItemManager.cs index cb09b4f50..b40bb215d 100644 --- a/Assets/Scripts/ServerShared/ItemManager.cs +++ b/Assets/Scripts/ServerShared/ItemManager.cs @@ -31,7 +31,7 @@ public class ItemManager // private Guid _forceLoadZone; // public GlobalData GlobalData => _globalData ?? (_globalData = ItemData.GetAll().FirstOrDefault()); - public DatabaseCache ItemData { get; } + public CultCache ItemData { get; } public GameplaySettings GameplaySettings { get; } public double Time @@ -47,7 +47,7 @@ public class ItemManager // private readonly Dictionary Tier = new Dictionary(); - public ItemManager(DatabaseCache itemData, GameplaySettings settings, Action logger) + public ItemManager(CultCache itemData, GameplaySettings settings, Action logger) { ItemData = itemData; GameplaySettings = settings; diff --git a/Assets/Scripts/ServerShared/Sector.cs b/Assets/Scripts/ServerShared/Sector.cs index a44940737..077f50941 100644 --- a/Assets/Scripts/ServerShared/Sector.cs +++ b/Assets/Scripts/ServerShared/Sector.cs @@ -33,10 +33,10 @@ public class Sector } } - public Sector(DatabaseCache database, SavedGame savedGame) + public Sector(CultCache cultCache, SavedGame savedGame) { Settings = savedGame.Settings; - Factions = savedGame.Factions.Select(database.Get).ToArray(); + Factions = savedGame.Factions.Select(cultCache.Get).ToArray(); Zones = savedGame.Zones.Select(zone => { return new SectorZone @@ -67,10 +67,10 @@ public class Sector CalculateDistanceMatrix(); } - public Sector(SectorGenerationSettings settings, DatabaseCache database, uint seed = 0, Action progressCallback = null, float minLineSeparation = .01f) + public Sector(SectorGenerationSettings settings, CultCache cultCache, uint seed = 0, Action progressCallback = null, float minLineSeparation = .01f) { Settings = settings; - var megas = database.GetAll(); + var megas = cultCache.GetAll(); var random = new Random(seed == 0 ? (uint) (DateTime.Now.Ticks % uint.MaxValue) : seed); Factions = megas.OrderBy(x => random.NextFloat()).Take(settings.MegaCount).ToArray(); @@ -229,7 +229,7 @@ public class Sector progressCallback?.Invoke($"Feeding Markov Chains: {i+1} / {Factions.Length}"); //if(progressCallback!=null) Thread.Sleep(250); // Inserting Delay to make it seem like it's doing more work lmao var faction = Factions[i]; - _nameGenerators[faction] = new MarkovNameGenerator(ref random, database.Get(faction.GeonameFile).Names, settings); + _nameGenerators[faction] = new MarkovNameGenerator(ref random, cultCache.Get(faction.GeonameFile).Names, settings); } // Generate zone name using the owner's name generator, otherwise assign catalogue ID