Persist action bar bindings in run checkpoints

This commit is contained in:
Meta Vens 2026-06-14 11:53:55 +01:00
commit 0115d8048a
9 changed files with 154 additions and 12 deletions

View file

@ -17,6 +17,7 @@ public class ActionBarSlot : MonoBehaviour
public ObservablePointerEnterTrigger PointerEnterTrigger;
public ObservablePointerExitTrigger PointerExitTrigger;
private ActionBarBinding binding;
public string ControlPath { get; set; }
public ActionBarBinding Binding
{
@ -96,6 +97,8 @@ public class ActionBarConsumableBinding : ActionBarBinding
private Guid TargetLegacyId =>
Guid.TryParse(Target.LegacyId, out var legacyId) ? legacyId : Guid.Empty;
public string TargetItemDefinitionLegacyId => Target?.LegacyId ?? "";
}
public class ActionBarGearBinding : ActionBarBinding
@ -105,6 +108,19 @@ public class ActionBarGearBinding : ActionBarBinding
public bool Active;
public int EquipmentIndex => Entity?.Equipment?.IndexOf(Item) ?? -1;
public int BehaviorIndex => Item?.Behaviors == null ? -1 : Array.IndexOf(Item.Behaviors, Behavior);
public string TargetItemDefinitionLegacyId
{
get
{
var itemId = Item?.EquippableItem?.ItemId ?? Guid.Empty;
return itemId == Guid.Empty ? "" : itemId.ToString("D");
}
}
public ActionBarGearBinding(Entity entity, ActionBarSlot slot, EquippedItem item, IActivatedBehavior behavior) : base(entity, slot)
{
Item = item;

View file

@ -422,10 +422,51 @@ public class ActionGameManager : MonoBehaviour
.Where(index => index >= 0)
.OrderBy(index => index)
.ToArray() ?? Array.Empty<int>(),
ActionBarBindings = ProjectActionBarBindings(),
Zones = Zone == null ? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>() : new[] { ProjectZoneSnapshot(Zone) }
};
}
private AetheriaRuntimeActionBarBindingCommit[] ProjectActionBarBindings()
{
return _actionBarSlots?
.Select(ProjectActionBarBinding)
.Where(binding => binding != null)
.ToArray() ?? Array.Empty<AetheriaRuntimeActionBarBindingCommit>();
}
private static AetheriaRuntimeActionBarBindingCommit ProjectActionBarBinding(ActionBarSlot slot)
{
switch (slot?.Binding)
{
case ActionBarConsumableBinding consumable:
return new AetheriaRuntimeActionBarBindingCommit
{
ControlPath = slot.ControlPath ?? "",
Kind = "consumable",
ItemDefinitionLegacyId = consumable.TargetItemDefinitionLegacyId
};
case ActionBarGearBinding gear:
return new AetheriaRuntimeActionBarBindingCommit
{
ControlPath = slot.ControlPath ?? "",
Kind = "gear",
ItemDefinitionLegacyId = gear.TargetItemDefinitionLegacyId,
EquipmentIndex = gear.EquipmentIndex,
BehaviorIndex = gear.BehaviorIndex
};
case ActionBarWeaponGroupBinding weaponGroup:
return new AetheriaRuntimeActionBarBindingCommit
{
ControlPath = slot.ControlPath ?? "",
Kind = "weapon_group",
WeaponGroup = weaponGroup.Group
};
default:
return null;
}
}
private AetheriaRuntimeZoneSnapshotCommit ProjectZoneSnapshot(Zone zone)
{
var galaxyZone = zone.GalaxyZone;
@ -718,6 +759,7 @@ public class ActionGameManager : MonoBehaviour
var action = new InputAction(binding: controlPath);
_actionBarActions.Add(action);
var slot = Instantiate(ActionBarSlot, ActionBar);
slot.ControlPath = controlPath;
slot.Binding = null;
_actionBarSlots.Add(slot);
action.started += context => slot.Binding?.Activate();