activity_catalog_build.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "activity_catalog_build.h"
  2. #include "../../../middleware/content/packages/tables/activity_table.h"
  3. #include "../items/packages/internal.h"
  4. #include "activity_presentation_build.h"
  5. namespace sunrise::client::content::activity {
  6. namespace packages = middleware::content::packages;
  7. bool build_catalog(const packages::reader::Source& source,
  8. packages::reader::Scratch& scratch) noexcept {
  9. namespace catalog = state::build_data::activities;
  10. namespace tables = packages::tables;
  11. if (catalog::ready()) {
  12. return true;
  13. }
  14. if (catalog::extraction_failed()) {
  15. return false;
  16. }
  17. std::array<std::uint32_t, items::packages::kContainerCandidates> candidates{};
  18. std::size_t candidateCount{};
  19. if (!items::packages::investment_globals_tags(candidates, candidateCount)) {
  20. catalog::note_extraction_failure();
  21. return false;
  22. }
  23. std::vector<std::byte> globals, root, table;
  24. static std::array<catalog::Definition, catalog::kCapacity> rows{};
  25. for (std::size_t i = 0; i < candidateCount; ++i) {
  26. std::uint32_t rootTag{}, tableTag{}, rootClass{};
  27. std::size_t count{};
  28. if (packages::reader::read_tag(source, scratch, candidates[i], globals)
  29. && tables::child_tag(globals, tables::kInvestmentRootChild, rootTag)
  30. && packages::reader::read_tag(source, scratch, rootTag, root, rootClass)
  31. && rootClass == tables::kInvestmentRootClass
  32. && tables::slot_tag(root, tables::activities::kRootSlot, tableTag)
  33. && packages::reader::read_tag(source, scratch, tableTag, table)
  34. && tables::activities::decode(table, rows, count)) {
  35. const auto found = std::span(rows).first(count);
  36. build_presentations(source, scratch, globals, found);
  37. build_artwork(source, scratch);
  38. return catalog::publish(found);
  39. }
  40. }
  41. catalog::note_extraction_failure();
  42. return false;
  43. }
  44. } // namespace sunrise::client::content::activity