collectible_catalog.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #include <array>
  3. #include <cstddef>
  4. #include <cstdint>
  5. #include <span>
  6. namespace sunrise::state::build_data::collectibles {
  7. /** The Collections protocol carries a present bit followed by a 15-bit native row index. */
  8. inline constexpr std::size_t kDefinitionCapacity = 1U << 15U;
  9. /** Some collectible rows deliberately do not resolve to an inventory item. */
  10. inline constexpr std::uint16_t kUnavailableItemDefinitionIndex = 0xFFFFU;
  11. /** A collectible with no acquisition charge carries this native requirement-set sentinel. */
  12. inline constexpr std::uint16_t kUnavailableMaterialRequirementSetIndex = 0xFFFFU;
  13. /** A collectible that unlocks no lore carries this instead of a row. */
  14. inline constexpr std::uint16_t kUnavailableLoreRow = 0xFFFFU;
  15. /** Installed requirement sets contain at most six material rows. */
  16. inline constexpr std::size_t kMaterialRequirementCapacity = 6;
  17. /** One native material row attached to a Collections acquisition. */
  18. struct MaterialRequirement {
  19. std::uint32_t quantity{};
  20. std::uint16_t itemDefinitionIndex{kUnavailableItemDefinitionIndex};
  21. bool deleteOnAction{};
  22. bool omitFromRequirements{};
  23. };
  24. /** One installed-build collectible row and the item-definition row it grants. */
  25. struct Definition {
  26. std::uint32_t collectibleHash{};
  27. std::uint32_t materialRequirementSetHash{};
  28. std::uint16_t collectibleIndex{};
  29. std::uint16_t itemDefinitionIndex{kUnavailableItemDefinitionIndex};
  30. std::uint16_t materialRequirementSetIndex{kUnavailableMaterialRequirementSetIndex};
  31. /**
  32. * Lore row this collectible unlocks, or kUnavailableLoreRow when it unlocks none.
  33. *
  34. * The record that displays the same row is the chapter this collectible completes, so the pair
  35. * joins on the row rather than on any hash.
  36. */
  37. std::uint16_t loreRow{kUnavailableLoreRow};
  38. std::uint8_t materialRequirementCount{};
  39. std::array<MaterialRequirement, kMaterialRequirementCapacity> materialRequirements{};
  40. };
  41. /** Clears every generated collectible mapping. */
  42. void clear() noexcept;
  43. /** @return True when every native collectible index appears exactly once. */
  44. [[nodiscard]] bool valid(std::span<const Definition> definitions) noexcept;
  45. /** Replaces the complete dense collectible table in one publication. */
  46. [[nodiscard]] bool replace(std::span<const Definition> definitions) noexcept;
  47. /** Finds one collectible by the native 15-bit index carried by the request. */
  48. [[nodiscard]] bool find(std::uint16_t collectibleIndex, Definition& definition) noexcept;
  49. /**
  50. * Answers whether any collectible grants one installed item row.
  51. * @param itemDefinitionIndex Installed item-definition row.
  52. * @return True when Collections can grant that item, so an account can come to own it.
  53. */
  54. [[nodiscard]] bool grants_item(std::uint16_t itemDefinitionIndex) noexcept;
  55. /** Copies every row in native collectible-index order. */
  56. [[nodiscard]] bool snapshot(std::span<Definition> output, std::size_t& count) noexcept;
  57. /** @return Number of installed-build collectible mappings. */
  58. [[nodiscard]] std::size_t count() noexcept;
  59. } // namespace sunrise::state::build_data::collectibles