diff --git a/Assets/Scripts/Editor/DatabaseView.cs b/Assets/Scripts/Editor/DatabaseView.cs index 8f74d557a..bfea28ead 100644 --- a/Assets/Scripts/Editor/DatabaseView.cs +++ b/Assets/Scripts/Editor/DatabaseView.cs @@ -20,7 +20,7 @@ public class DatabaseListView : EditorWindow public static RethinkDB R = RethinkDB.R; private DatabaseCache _databaseCache; - private bool[] _gearFoldouts; + private bool[] _itemTypeFoldouts; private bool _itemsFoldout; private bool _compoundFoldout; private bool _simpleFoldout; @@ -39,6 +39,7 @@ public class DatabaseListView : EditorWindow private RethinkQueryStatus _queryStatus; private Dictionary> _itemBlueprints = new Dictionary>(); private HashSet _itemBlueprintFoldouts = new HashSet(); + private HashSet _itemGroupFoldouts = new HashSet(); public Color LabelColor => EditorGUIUtility.isProSkin ? Color.white : Color.black; @@ -106,7 +107,11 @@ public class DatabaseListView : EditorWindow _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; _inspector = DatabaseInspector.ShowWindow(); @@ -116,7 +121,7 @@ public class DatabaseListView : EditorWindow _entryTypes = typeof(DatabaseEntry).GetAllChildClasses() .Where(t => t.GetCustomAttribute() != null && !typeof(ItemData).IsAssignableFrom(t)).ToArray(); - _gearFoldouts = new bool[_itemTypes.Length]; + _itemTypeFoldouts = new bool[_itemTypes.Length]; _entryFoldouts = new bool[_entryTypes.Length]; if (EditorPrefs.HasKey("RethinkDB.URL")) @@ -221,102 +226,131 @@ public class DatabaseListView : EditorWindow using (var h = new HorizontalScope(ListItemStyle)) { GUILayout.Space(10); - _gearFoldouts[i] = Foldout(_gearFoldouts[i], + _itemTypeFoldouts[i] = Foldout(_itemTypeFoldouts[i], ((NameAttribute) _itemTypes[i].GetCustomAttribute(typeof(NameAttribute)))?.Name ?? FormatTypeName(_itemTypes[i].Name), true); } - if (_gearFoldouts[i]) + if (_itemTypeFoldouts[i]) { + 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(GearData)) + itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(HardpointType), (item as GearData).Hardpoint)); + else if(_itemTypes[i] == typeof(HullData)) + itemGroups = typedItems.GroupBy(item => Enum.GetName(typeof(HullType), (item as HullData).HullType)); + + 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); + } + + using (var h = new HorizontalScope(GUILayout.Width(15))) + { + if (GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) + { + if(_itemBlueprintFoldouts.Contains(item.ID)) + _itemBlueprintFoldouts.Remove(item.ID); + else + _itemBlueprintFoldouts.Add(item.ID); + } + GUILayout.Label(_itemBlueprints[item.ID].Count.ToString()); + var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); + if (Event.current.type == EventType.Repaint) + { + var controlId = GUIUtility.GetControlID(1337, FocusType.Keyboard, position); + EditorStyles.foldout.Draw(rect, GUIContent.none, controlId, _itemBlueprintFoldouts.Contains(item.ID)); + } + } + } + + if (_itemBlueprintFoldouts.Contains(item.ID)) + { + foreach (var blueprintData in _itemBlueprints[item.ID] + .Select(id => _databaseCache.Get(id)) + .OrderBy(bp => bp.Quality)) + { + var blueprintStyle = ListItemStyle; + var blueprintSelected = SelectedItem == blueprintData.ID; + using (var h = new HorizontalScope(blueprintSelected ? SelectedStyle : blueprintStyle)) + { + if (h.rect.Contains(currentEvent.mousePosition)) + { + if (currentEventType == EventType.MouseDrag) + { + DragAndDrop.PrepareStartDrag(); + DragAndDrop.SetGenericData("Item", blueprintData.ID); + DragAndDrop.StartDrag("Database Item"); + } + else if (currentEventType == EventType.MouseUp) + Select(blueprintData); + } + + GUILayout.Space(40); + GUILayout.Label(blueprintData.Name, + blueprintSelected ? EditorStyles.whiteLabel : GUI.skin.label); + } + } + + using (var h = new HorizontalScope(ListItemStyle)) + { + if (GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) + { + var blueprint = new BlueprintData + { + Item = item.ID, + Name = item.Name + }; + _databaseCache.Add(blueprint); + Select(blueprint); + } + GUILayout.Space(30); + GUILayout.Label("New Blueprint"); + var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); + GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, + 0, 0); + } + } + } + } + } + foreach (var item in items.Where(e=>e.GetType()==_itemTypes[i]).OrderBy(item=>item.Name)) { - 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(20); - GUILayout.Label(item.Name, selected ? EditorStyles.whiteLabel : GUI.skin.label); - } - - using (var h = new HorizontalScope(GUILayout.Width(15))) - { - if (GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) - { - if(_itemBlueprintFoldouts.Contains(item.ID)) - _itemBlueprintFoldouts.Remove(item.ID); - else - _itemBlueprintFoldouts.Add(item.ID); - } - GUILayout.Label(_itemBlueprints[item.ID].Count.ToString()); - var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); - if (Event.current.type == EventType.Repaint) - { - var controlId = GUIUtility.GetControlID(1337, FocusType.Keyboard, position); - EditorStyles.foldout.Draw(rect, GUIContent.none, controlId, _itemBlueprintFoldouts.Contains(item.ID)); - } - } - } - - if(_itemBlueprintFoldouts.Contains(item.ID)) - { - foreach (var blueprintData in _itemBlueprints[item.ID] - .Select(id => _databaseCache.Get(id)) - .OrderBy(bp => bp.Quality)) - { - var blueprintStyle = ListItemStyle; - var blueprintSelected = SelectedItem == blueprintData.ID; - using (var h = new HorizontalScope(blueprintSelected ? SelectedStyle : blueprintStyle)) - { - if (h.rect.Contains(currentEvent.mousePosition)) - { - if (currentEventType == EventType.MouseDrag) - { - DragAndDrop.PrepareStartDrag(); - DragAndDrop.SetGenericData("Item", blueprintData.ID); - DragAndDrop.StartDrag("Database Item"); - } - else if (currentEventType == EventType.MouseUp) - Select(blueprintData); - } - - GUILayout.Space(30); - GUILayout.Label(blueprintData.Name, - blueprintSelected ? EditorStyles.whiteLabel : GUI.skin.label); - } - } - - using (var h = new HorizontalScope(ListItemStyle)) - { - if (GUI.Button(h.rect, GUIContent.none, GUIStyle.none)) - { - var blueprint = new BlueprintData - { - Item = item.ID, - Name = item.Name - }; - _databaseCache.Add(blueprint); - Select(blueprint); - } - GUILayout.Space(30); - GUILayout.Label("New Blueprint"); - var rect = GetControlRect(false, GUILayout.Width(EditorGUIUtility.singleLineHeight)); - GUI.DrawTexture(rect, Icons.Instance.plus, ScaleMode.StretchToFill, true, 1, LabelColor, - 0, 0); - } - } } using (var h = new HorizontalScope(ListItemStyle)) diff --git a/Assets/Scripts/ServerShared/Attributes.cs b/Assets/Scripts/ServerShared/Attributes.cs index 0ca583604..3cbe5830e 100644 --- a/Assets/Scripts/ServerShared/Attributes.cs +++ b/Assets/Scripts/ServerShared/Attributes.cs @@ -108,4 +108,14 @@ public class InspectableTypeAttribute : InspectableFieldAttribute } [AttributeUsage(AttributeTargets.Field)] -public class SimplePerformanceStatAttribute : Attribute { } \ No newline at end of file +public class SimplePerformanceStatAttribute : Attribute { } + +// public class CategoryAttribute : Attribute +// { +// public readonly Type Type; +// +// public CategoryAttribute(Type type) +// { +// Type = type; +// } +// } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/Enums.cs b/Assets/Scripts/ServerShared/Enums.cs index 9556f8315..d5257db15 100644 --- a/Assets/Scripts/ServerShared/Enums.cs +++ b/Assets/Scripts/ServerShared/Enums.cs @@ -60,4 +60,23 @@ public enum MegaPlacementType Resources = 2, Connected = 3, Isolated = 4 +} + +public enum SimpleCommodityCategory +{ + Minerals, + Metals, + Alloys, + Compounds, + Organics +} + +public enum CompoundCommodityCategory +{ + Wearables, + Consumables, + Luxuries, + Tools, + Manufacturing, + Assemblies } \ No newline at end of file diff --git a/Assets/Scripts/ServerShared/ItemData.cs b/Assets/Scripts/ServerShared/ItemData.cs index ba9b0bdb4..257317233 100644 --- a/Assets/Scripts/ServerShared/ItemData.cs +++ b/Assets/Scripts/ServerShared/ItemData.cs @@ -63,6 +63,9 @@ public class SimpleCommodityData : ItemData // Minimum amount of resources needed for presence to register [InspectableField, JsonProperty("floor"), Key(11)] public float Floor = 5f; + + [InspectableField, JsonProperty("category"), Key(12)] + public SimpleCommodityCategory Category; } [MessagePackObject, @@ -82,6 +85,9 @@ public class CompoundCommodityData : CraftedItemData { [InspectableDatabaseLink(typeof(PersonalityAttribute)), JsonProperty("demandProfile"), Key(7)] public Dictionary DemandProfile = new Dictionary(); + + [InspectableField, JsonProperty("category"), Key(8)] + public CompoundCommodityCategory Category; } [Union(0, typeof(GearData)), @@ -154,16 +160,16 @@ public class GearData : EquippableItemData [RethinkTable("Items"), Inspectable, MessagePackObject, JsonObject(MemberSerialization.OptIn)] public class HullData : EquippableItemData { - [InspectableField, JsonProperty("hullCapacity"), Key(13)] + [InspectableField, JsonProperty("hullCapacity"), Key(14)] public PerformanceStat Capacity = new PerformanceStat(); - [InspectableField, JsonProperty("hardpoints"), Key(14)] + [InspectableField, JsonProperty("hardpoints"), Key(15)] public List Hardpoints = new List(); - [InspectablePrefab, JsonProperty("prefab"), Key(15)] + [InspectablePrefab, JsonProperty("prefab"), Key(16)] public string Prefab; - [InspectableField, JsonProperty("hullType"), Key(16)] + [InspectableField, JsonProperty("hullType"), Key(17)] public HullType HullType; [IgnoreMember] public override HardpointType HardpointType => HardpointType.Hull; diff --git a/RethinkDB Queries.txt b/RethinkDB Queries.txt index 3d6e794f4..d4c33bf85 100644 --- a/RethinkDB Queries.txt +++ b/RethinkDB Queries.txt @@ -17,4 +17,7 @@ r.db('Aetheria').table('Items').filter({durabilityStat:{min:0}}).pluck('$type',' Find Galaxy Sectors With Long Names r.db('Aetheria').table('Galaxy').filter({$type:'ZoneData'}).filter(function (zone) { return zone("name").count().gt(8); -}) \ No newline at end of file +}) + +Find orphaned blueprints +r.db('Aetheria').table('Items').filter({$type:'BlueprintData'}).filter({item:'00000000-0000-0000-0000-000000000000'}) \ No newline at end of file