Missing Database Reference Hotfix

Database inspector was crashing when selecting a blueprint with missing ingredients
This commit is contained in:
hyperion51 2020-04-29 23:36:00 +01:00
commit 8d1b7bed28
10 changed files with 115 additions and 29 deletions

View file

@ -1282,6 +1282,7 @@
<e p="AgentTask.cs" t="Include" />
<e p="EntityAgent.cs" t="Include" />
<e p="Locomotion.cs" t="Include" />
<e p="StationTowing.cs" t="Include" />
<e p="VelocityMatch.cs" t="Include" />
</e>
<e p="Attributes.cs" t="Include" />

View file

@ -8351,7 +8351,7 @@ MonoBehaviour:
m_HandleRect: {fileID: 1082785902}
m_Direction: 0
m_Value: 0
m_Size: 1
m_Size: 0.99999994
m_NumberOfSteps: 0
m_OnValueChanged:
m_PersistentCalls:
@ -24596,8 +24596,8 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 943.50006, y: 0}
m_SizeDelta: {x: 1887.0001, y: 0}
m_AnchoredPosition: {x: 943.5, y: 0}
m_SizeDelta: {x: 1887, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1101630447
MonoBehaviour:

View file

@ -642,6 +642,12 @@ public class DatabaseInspector : EditorWindow
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());

View file

@ -1,10 +1,13 @@
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class AgentTask
{
public abstract AgentJob JobType { get; }
public int Priority;
public Guid Zone;
}
public enum AgentJob
@ -13,5 +16,6 @@ public enum AgentJob
Haul,
Tow,
Defend,
Attack
Attack,
Explore
}

View file

@ -0,0 +1,19 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StationTowing : AgentTask
{
public override AgentJob JobType => AgentJob.Tow;
private Guid _entity;
private Guid _targetOrbit;
public StationTowing(Guid zone, Guid entity, Guid targetOrbit)
{
Zone = zone;
_entity = entity;
_targetOrbit = targetOrbit;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c8845fb5e89a4bf46abdf94517139172
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -3,31 +3,37 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using JsonKnownTypes;
using MessagePack;
using Newtonsoft.Json;
using Unity.Mathematics;
using static Unity.Mathematics.math;
public class Entity
[MessagePackObject,
JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter<Entity>))]
public class Entity : DatabaseEntry, IMessagePackSerializationCallbackReceiver
{
public Dictionary<IAnalogBehavior, float> AxisOverrides = new Dictionary<IAnalogBehavior, float>();
public readonly Dictionary<object, float> VisibilitySources = new Dictionary<object, float>();
[IgnoreMember] public Dictionary<IAnalogBehavior, float> AxisOverrides = new Dictionary<IAnalogBehavior, float>();
[IgnoreMember] public readonly Dictionary<object, float> VisibilitySources = new Dictionary<object, float>();
public float Temperature;
public float Energy;
public float2 Position;
public float2 Direction = float2(0,1);
public float2 Velocity;
public Dictionary<Guid, List<IActivatedBehavior>> Bindings;
public Dictionary<IAnalogBehavior, float> Axes;
public readonly GameContext Context;
[IgnoreMember] public Dictionary<Guid, List<IActivatedBehavior>> Bindings;
[IgnoreMember] public Dictionary<IAnalogBehavior, float> Axes;
public readonly List<ItemInstance> Cargo;
public readonly List<Gear> EquippedItems;
protected readonly List<IBehavior> Behaviors;
[IgnoreMember] protected List<IBehavior> Behaviors;
public Gear Hull { get; }
public float Mass { get; private set; }
public float SpecificHeat { get; private set; }
public float Visibility => VisibilitySources.Values.Sum();
[IgnoreMember] public float Mass { get; private set; }
[IgnoreMember] public float SpecificHeat { get; private set; }
[IgnoreMember] public float Visibility => VisibilitySources.Values.Sum();
public object[] PersistedBehaviors;
public Entity(GameContext context, Gear hull, IEnumerable<Gear> items, IEnumerable<ItemInstance> cargo)
{
@ -103,4 +109,39 @@ public class Entity
foreach (var item in EquippedItems.Where(item => item.ItemData.Performance(Temperature) < .01f))
item.Durability -= delta;
}
public void OnBeforeSerialize()
{
PersistedBehaviors = Behaviors
.Where(b => b is IPersistentBehavior)
.Cast<IPersistentBehavior>()
.Select(b => b.Store()).ToArray();
}
public void OnAfterDeserialize()
{
RecalculateMass();
var activeItems = Hull == null ? EquippedItems : EquippedItems.Append(Hull);
Behaviors = activeItems
.Where(i=>i.ItemData.Behaviors?.Any()??false)
.SelectMany(i => i.ItemData.Behaviors
.Select(bd => bd.CreateInstance(Context, this, i)))
.OrderBy(b => b.GetType().GetCustomAttribute<UpdateOrderAttribute>()?.Order ?? 0).ToList();
Bindings = Behaviors
.Where(b => b is IActivatedBehavior)
.GroupBy(b => b.Item.ID, (guid, behaviors) => new {guid, behaviors})
.ToDictionary(g => g.guid, g => g.behaviors.Cast<IActivatedBehavior>().ToList());
Axes = Behaviors
.Where(b => b is IAnalogBehavior)
.ToDictionary(b => b as IAnalogBehavior, b => 0f);
foreach (var behavior in Behaviors)
{
behavior.Initialize();
}
}
}

View file

@ -14,20 +14,20 @@ using Unity.Mathematics;
JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter<ItemData>))]
public abstract class ItemData : DatabaseEntry, INamedEntry
{
[InspectableField, JsonProperty("name"), Key(1)]
[InspectableField, JsonProperty("name"), Key(1)]
public string Name;
[InspectableText, JsonProperty("description"), Key(2)]
[InspectableText, JsonProperty("description"), Key(2)]
public string Description;
[InspectableField, JsonProperty("mass"), Key(3)]
[InspectableField, JsonProperty("mass"), Key(3)]
public float Mass;
[InspectableField, JsonProperty("size"), Key(4)]
[InspectableField, JsonProperty("size"), Key(4)]
public float Size;
// Heat needed to change temperature of 1 gram by 1 degree
[InspectableField, JsonProperty("specificHeat"), Key(5)]
[InspectableField, JsonProperty("specificHeat"), Key(5)]
public float SpecificHeat;
[IgnoreMember] public string EntryName
@ -75,25 +75,25 @@ public class CompoundCommodityData : CraftedItemData {}
JsonObject(MemberSerialization.OptIn), JsonConverter(typeof(JsonKnownTypesConverter<EquippableItemData>))]
public abstract class EquippableItemData : CraftedItemData
{
[InspectableField, JsonProperty("draw"), Key(6)]
[InspectableField, JsonProperty("draw"), Key(6)]
public PerformanceStat EnergyDraw = new PerformanceStat();
[InspectableAnimationCurve, JsonProperty("performanceCurve"), Key(7)]
[InspectableAnimationCurve, JsonProperty("performanceCurve"), Key(7)]
public float4[] HeatPerformanceCurve;
[TemperatureInspectable, JsonProperty("minTemp"), Key(8)]
[TemperatureInspectable, JsonProperty("minTemp"), Key(8)]
public float MinimumTemperature;
[TemperatureInspectable, JsonProperty("maxTemp"), Key(9)]
[TemperatureInspectable, JsonProperty("maxTemp"), Key(9)]
public float MaximumTemperature;
[InspectableField, JsonProperty("durabilityStat"), Key(10)]
[InspectableField, JsonProperty("durabilityStat"), Key(10)]
public PerformanceStat Durability = new PerformanceStat();
[InspectableField, JsonProperty("durabilityExponent"), Key(11)]
[InspectableField, JsonProperty("durabilityExponent"), Key(11)]
public PerformanceStat DurabilityExponent = new PerformanceStat();
[InspectableField, JsonProperty("heatExponent"), Key(12)]
[InspectableField, JsonProperty("heatExponent"), Key(12)]
public PerformanceStat HeatExponent = new PerformanceStat();
[InspectableField, JsonProperty("behaviors"), Key(13)]

View file

@ -126,9 +126,12 @@ public class StrategyGameManager : MonoBehaviour
if (_currentTab == ZoneTabButton)
{
if (_populatedZone != _selectedZone && _cache.Get<ZoneData>(_selectedZone) != null)
var zone = _cache.Get<ZoneData>(_selectedZone);
if (_populatedZone != _selectedZone && zone != null)
PopulateZone();
Camera.transform.position = -Vector3.forward;
if (zone != null)
Camera.orthographicSize = zone.Radius * ZoneSizeScale;
}
if (_currentTab == TechTabButton)

View file

@ -66,6 +66,7 @@
<Compile Include="Assets\Scripts\ServerShared\Agents\AgentTask.cs" />
<Compile Include="Assets\Scripts\ServerShared\Agents\EntityAgent.cs" />
<Compile Include="Assets\Scripts\ServerShared\Agents\Locomotion.cs" />
<Compile Include="Assets\Scripts\ServerShared\Agents\StationTowing.cs" />
<Compile Include="Assets\Scripts\ServerShared\Agents\VelocityMatch.cs" />
<Compile Include="Assets\Scripts\ServerShared\Attributes.cs" />
<Compile Include="Assets\Scripts\ServerShared\Behaviors\Afterburner.cs" />