Prefer typed item keys in runtime commits
This commit is contained in:
parent
95bd76ee91
commit
d2996bc072
8 changed files with 90 additions and 33 deletions
|
|
@ -94,8 +94,8 @@ public class ActionBarConsumableBinding : ActionBarBinding
|
|||
else Slot.Fill.fillAmount = instance.RemainingDuration / instance.Duration;
|
||||
}
|
||||
|
||||
private string TargetItemKey =>
|
||||
Guid.TryParse(Target.LegacyId, out var legacyId) ? AetheriaRuntimeItemReference.FromLegacyId(legacyId) : "";
|
||||
public string TargetItemKey =>
|
||||
Guid.TryParse(Target?.LegacyId, out var legacyId) ? AetheriaRuntimeItemReference.FromLegacyId(legacyId) : "";
|
||||
|
||||
public string TargetItemDefinitionLegacyId => Target?.LegacyId ?? "";
|
||||
|
||||
|
|
@ -116,14 +116,14 @@ public class ActionBarGearBinding : ActionBarBinding
|
|||
{
|
||||
get
|
||||
{
|
||||
var itemKey = Item?.EquippableItem?.ItemKey ?? "";
|
||||
const string legacyPrefix = "aetheria.item_definition:legacy:";
|
||||
return itemKey.StartsWith(legacyPrefix, StringComparison.OrdinalIgnoreCase)
|
||||
? itemKey.Substring(legacyPrefix.Length)
|
||||
return AetheriaRuntimeItemReference.ToLegacyId(TargetItemKey) is var legacyId && legacyId != Guid.Empty
|
||||
? legacyId.ToString("D")
|
||||
: "";
|
||||
}
|
||||
}
|
||||
|
||||
public string TargetItemKey => Item?.EquippableItem?.ItemKey ?? "";
|
||||
|
||||
public ActionBarGearBinding(Entity entity, ActionBarSlot slot, EquippedItem item, IActivatedBehavior behavior) : base(entity, slot)
|
||||
{
|
||||
Item = item;
|
||||
|
|
|
|||
|
|
@ -523,6 +523,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
return new AetheriaRuntimeLoadoutItemCommit
|
||||
{
|
||||
ItemDefinitionLegacyId = item.ItemId == Guid.Empty ? "" : item.ItemId.ToString("D"),
|
||||
ItemKey = item.ItemKey,
|
||||
Quality = item is CraftedItemInstance crafted ? crafted.Quality : 1.0,
|
||||
Durability = item is EquippableItem equippable ? equippable.Durability : 1.0,
|
||||
Quantity = item is SimpleCommodity commodity ? commodity.Quantity : 1,
|
||||
|
|
@ -569,7 +570,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
ControlPath = slot.ControlPath ?? "",
|
||||
Kind = "consumable",
|
||||
ItemDefinitionLegacyId = consumable.TargetItemDefinitionLegacyId
|
||||
ItemDefinitionLegacyId = consumable.TargetItemDefinitionLegacyId,
|
||||
ItemKey = consumable.TargetItemKey
|
||||
};
|
||||
case ActionBarGearBinding gear:
|
||||
return new AetheriaRuntimeActionBarBindingCommit
|
||||
|
|
@ -577,6 +579,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
ControlPath = slot.ControlPath ?? "",
|
||||
Kind = "gear",
|
||||
ItemDefinitionLegacyId = gear.TargetItemDefinitionLegacyId,
|
||||
ItemKey = gear.TargetItemKey,
|
||||
EquipmentIndex = gear.EquipmentIndex,
|
||||
BehaviorIndex = gear.BehaviorIndex
|
||||
};
|
||||
|
|
@ -676,6 +679,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
.Select(pair => new AetheriaRuntimeBodyResourceCommit
|
||||
{
|
||||
ItemDefinitionLegacyId = LegacyId(pair.Key),
|
||||
ItemKey = AetheriaRuntimeItemReference.FromLegacyId(pair.Key),
|
||||
Amount = pair.Value
|
||||
})
|
||||
.ToArray() ?? Array.Empty<AetheriaRuntimeBodyResourceCommit>(),
|
||||
|
|
@ -707,6 +711,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
.Select(pair => new AetheriaRuntimeBodyResourceCommit
|
||||
{
|
||||
ItemDefinitionLegacyId = LegacyId(pair.Key),
|
||||
ItemKey = AetheriaRuntimeItemReference.FromLegacyId(pair.Key),
|
||||
Amount = pair.Value
|
||||
})
|
||||
.ToArray() ?? Array.Empty<AetheriaRuntimeBodyResourceCommit>(),
|
||||
|
|
@ -821,6 +826,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
Hypothermia = entity.Hypothermia,
|
||||
CorporationLegacyId = entity.Faction?.ID.ToString("D") ?? "",
|
||||
HullItemDefinitionLegacyId = entity.Hull?.ItemId == Guid.Empty ? "" : entity.Hull.ItemId.ToString("D"),
|
||||
HullItemKey = entity.Hull?.ItemKey ?? "",
|
||||
Equipment = ProjectEquippedSlots(entity.Equipment),
|
||||
CargoBays = ProjectEquippedSlots(entity.CargoBays),
|
||||
DockingBays = ProjectEquippedSlots(entity.DockingBays),
|
||||
|
|
@ -1183,6 +1189,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
.Select(effect => new AetheriaRuntimeActiveConsumableCommit
|
||||
{
|
||||
ItemDefinitionLegacyId = effect.Item?.ItemId == Guid.Empty ? "" : effect.Item.ItemId.ToString("D"),
|
||||
ItemKey = effect.Item?.ItemKey ?? "",
|
||||
Quality = effect.Item?.Quality ?? 1.0,
|
||||
RemainingDuration = effect.RemainingDuration,
|
||||
Duration = effect.Duration
|
||||
|
|
@ -1334,7 +1341,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
item ??= new AetheriaRuntimeLoadoutItemCommit();
|
||||
return new AetheriaRuntimeLoadoutItemSnapshot(
|
||||
ReferenceKey("aetheria.item_definition", item.ItemDefinitionLegacyId ?? ""),
|
||||
ReferenceKey(item.ItemKey, "aetheria.item_definition", item.ItemDefinitionLegacyId ?? ""),
|
||||
item.Quality,
|
||||
item.Durability,
|
||||
item.Quantity,
|
||||
|
|
@ -1366,6 +1373,13 @@ public class ActionGameManager : MonoBehaviour
|
|||
return string.IsNullOrWhiteSpace(legacyId) ? "" : $"{prefix}:{legacyId}";
|
||||
}
|
||||
|
||||
private static string ReferenceKey(string typedKey, string prefix, string legacyId)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(typedKey)
|
||||
? typedKey
|
||||
: ReferenceKey(prefix, legacyId);
|
||||
}
|
||||
|
||||
private void OnApplicationQuit() => QueueRunCheckpoint("application-quit");
|
||||
|
||||
private void QueueRunCheckpoint(string reason)
|
||||
|
|
|
|||
Loading…
Reference in a new issue