ListingLocalisationHelpers.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Robust.Shared.Prototypes;
  2. namespace Content.Shared.Store;
  3. public static class ListingLocalisationHelpers
  4. {
  5. /// <summary>
  6. /// ListingData's Name field can be either a localisation string or the actual entity's name.
  7. /// This function gets a localised name from the localisation string if it exists, and if not, it gets the entity's name.
  8. /// If neither a localised string exists, or an associated entity name, it will return the value of the "Name" field.
  9. /// </summary>
  10. public static string GetLocalisedNameOrEntityName(ListingData listingData, IPrototypeManager prototypeManager)
  11. {
  12. var name = string.Empty;
  13. if (listingData.Name != null)
  14. name = Loc.GetString(listingData.Name);
  15. else if (listingData.ProductEntity != null)
  16. name = prototypeManager.Index(listingData.ProductEntity.Value).Name;
  17. return name;
  18. }
  19. /// <summary>
  20. /// ListingData's Description field can be either a localisation string or the actual entity's description.
  21. /// This function gets a localised description from the localisation string if it exists, and if not, it gets the entity's description.
  22. /// If neither a localised string exists, or an associated entity description, it will return the value of the "Description" field.
  23. /// </summary>
  24. public static string GetLocalisedDescriptionOrEntityDescription(ListingData listingData, IPrototypeManager prototypeManager)
  25. {
  26. var desc = string.Empty;
  27. if (listingData.Description != null)
  28. desc = Loc.GetString(listingData.Description);
  29. else if (listingData.ProductEntity != null)
  30. desc = prototypeManager.Index(listingData.ProductEntity.Value).Description;
  31. return desc;
  32. }
  33. }