Aetheria/Assets/Scripts/ServerShared/AetheriaRuntimeItemReference.cs
2026-06-14 22:58:02 +01:00

60 lines
1.7 KiB
C#

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using Unity.Mathematics;
public interface INamedEntry
{
string EntryName { get; set; }
}
public class AetheriaRuntimeItemReference
{
private const string ItemDefinitionPrefix = "aetheria.item_definition:";
private const string LegacyItemDefinitionPrefix = "aetheria.item_definition:legacy:";
public string ItemKey;
public AetheriaRuntimeItemReference()
{
}
public AetheriaRuntimeItemReference(string itemKey)
{
ItemKey = itemKey;
}
public AetheriaRuntimeItemReference(Guid legacyItemId)
: this(FromLegacyId(legacyItemId))
{
}
public Guid LegacyItemId => TryParseLegacyId(ItemKey, out var itemId) ? itemId : Guid.Empty;
public static string FromLegacyId(Guid legacyItemId)
{
return legacyItemId == Guid.Empty ? "" : $"{LegacyItemDefinitionPrefix}{legacyItemId:D}";
}
private static bool TryParseLegacyId(string itemKey, out Guid itemId)
{
itemId = Guid.Empty;
if (string.IsNullOrWhiteSpace(itemKey))
return false;
var legacyId = itemKey.StartsWith(LegacyItemDefinitionPrefix, StringComparison.OrdinalIgnoreCase)
? itemKey.Substring(LegacyItemDefinitionPrefix.Length)
: itemKey.StartsWith(ItemDefinitionPrefix, StringComparison.OrdinalIgnoreCase)
? itemKey.Substring(ItemDefinitionPrefix.Length)
: itemKey;
return Guid.TryParse(legacyId, out itemId);
}
}
public interface ITintInspector
{
float3 TintColor { get; }
}