Visual Behavior Sorting
Behaviors in DB Inspector now visibly sort according to their execution order
This commit is contained in:
parent
8cd4ea3dc5
commit
3ffd88ade5
13 changed files with 45 additions and 27 deletions
|
|
@ -21,11 +21,11 @@ public class RethinkTableAttribute : Attribute
|
|||
}
|
||||
}
|
||||
|
||||
public class UpdateOrderAttribute : Attribute
|
||||
public class OrderAttribute : Attribute
|
||||
{
|
||||
public int Order;
|
||||
|
||||
public UpdateOrderAttribute(int order)
|
||||
public OrderAttribute(int order)
|
||||
{
|
||||
Order = order;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using System.Linq;
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-10)]
|
||||
public class CooldownData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("cooldown"), Key(1)]
|
||||
|
|
@ -15,7 +15,6 @@ public class CooldownData : BehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
[UpdateOrder(-10)]
|
||||
public class Cooldown : IBehavior, IAlwaysUpdatedBehavior
|
||||
{
|
||||
private CooldownData _data;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using System.Linq;
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(10)]
|
||||
public class HeatData : BehaviorData
|
||||
{
|
||||
[InspectableField, JsonProperty("heat"), Key(1)]
|
||||
|
|
@ -15,7 +15,6 @@ public class HeatData : BehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
[UpdateOrder(10)]
|
||||
public class Heat : IBehavior
|
||||
{
|
||||
private HeatData _data;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using System.Linq;
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-5)]
|
||||
public class ItemUsageData : BehaviorData
|
||||
{
|
||||
[InspectableDatabaseLink(typeof(SimpleCommodityData)), JsonProperty("item"), Key(1)]
|
||||
|
|
@ -16,7 +16,6 @@ public class ItemUsageData : BehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
[UpdateOrder(-5)]
|
||||
public class ItemUsage : IBehavior
|
||||
{
|
||||
private ItemUsageData _data;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using Newtonsoft.Json;
|
|||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship)]
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship), Order(-100)]
|
||||
public class PatrolControllerData : ControllerData
|
||||
{
|
||||
[InspectableField, JsonProperty("targetDistance"), Key(5)]
|
||||
|
|
@ -18,7 +18,6 @@ public class PatrolControllerData : ControllerData
|
|||
}
|
||||
}
|
||||
|
||||
[UpdateOrder(-100)]
|
||||
public class PatrolController : IBehavior, IController, IInitializableBehavior
|
||||
{
|
||||
public TaskType TaskType => TaskType.Tow;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class StatModifierData : BehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
[UpdateOrder(-4)]
|
||||
[Order(-4)]
|
||||
public class StatModifier : IBehavior, IInitializableBehavior, IDisposableBehavior
|
||||
{
|
||||
private StatModifierData _data;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using System.Linq;
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-25)]
|
||||
public class SwitchData : BehaviorData
|
||||
{
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -12,7 +12,6 @@ public class SwitchData : BehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
[UpdateOrder(-25)]
|
||||
public class Switch : IBehavior
|
||||
{
|
||||
private SwitchData _data;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using Newtonsoft.Json;
|
|||
using Unity.Mathematics;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship)]
|
||||
[MessagePackObject, JsonObject(MemberSerialization.OptIn), EntityTypeRestriction(HullType.Ship), Order(-100)]
|
||||
public class TowingControllerData : ControllerData
|
||||
{
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -16,7 +16,6 @@ public class TowingControllerData : ControllerData
|
|||
}
|
||||
}
|
||||
|
||||
[UpdateOrder(-100)]
|
||||
public class TowingController : IBehavior, IPersistentBehavior, IController, IInitializableBehavior
|
||||
{
|
||||
public TaskType TaskType => TaskType.Tow;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using System.Linq;
|
|||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn)]
|
||||
[InspectableField, MessagePackObject, JsonObject(MemberSerialization.OptIn), Order(-20)]
|
||||
public class TriggerData : BehaviorData
|
||||
{
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
|
|
@ -12,7 +12,6 @@ public class TriggerData : BehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
[UpdateOrder(-20)]
|
||||
public class Trigger : IBehavior
|
||||
{
|
||||
private TriggerData _data;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public class VelocityLimitData : BehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
[UpdateOrder(100)]
|
||||
[Order(100)]
|
||||
public class VelocityLimit : IBehavior
|
||||
{
|
||||
public Entity Entity { get; }
|
||||
|
|
|
|||
|
|
@ -70,14 +70,13 @@ public abstract class Entity : DatabaseEntry, IMessagePackSerializationCallbackR
|
|||
ItemBehaviors = gear
|
||||
.Where(i=> gearData[i].ItemData.Behaviors?.Any()??false)
|
||||
.ToDictionary(i=> gearData[i], i => gearData[i].ItemData.Behaviors
|
||||
.OrderBy(bd => bd.GetType().GetCustomAttribute<OrderAttribute>()?.Order ?? 0)
|
||||
.Select(bd => bd.CreateInstance(Context, this, gearData[i]))
|
||||
.OrderBy(b => b.GetType().GetCustomAttribute<UpdateOrderAttribute>()?.Order ?? 0)
|
||||
.ToList());
|
||||
|
||||
var behaviorGroups = ItemBehaviors
|
||||
.SelectMany(x => x.Value
|
||||
.Select(b => new {item = x.Key, behavior = b})
|
||||
.OrderBy(ib => ib.behavior.GetType().GetCustomAttribute<UpdateOrderAttribute>()?.Order ?? 0))
|
||||
.Select(b => new {item = x.Key, behavior = b}))
|
||||
.GroupBy(ib => new {ib.item, ib.behavior.Data.Group});
|
||||
|
||||
Behaviors = behaviorGroups
|
||||
|
|
|
|||
Loading…
Reference in a new issue