activity_catalog_build.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. /** @return True once the first valid installed activity table has been published. */
  8. bool build_catalog(const packages::reader::Source& source,
  9. packages::reader::Scratch& scratch) noexcept {
  10. namespace catalog = state::build_data::activities;
  11. namespace tables = packages::tables;
  12. if (catalog::ready()) {
  13. return true;
  14. }
  15. if (catalog::extraction_failed()) {
  16. return false;
  17. }
  18. std::array<std::uint32_t, items::packages::kContainerCandidates> candidates{};
  19. std::size_t candidateCount{};
  20. if (!items::packages::investment_globals_tags(candidates, candidateCount)) {
  21. catalog::note_extraction_failure();
  22. return false;
  23. }
  24. std::vector<std::byte> globals, root, table;
  25. static std::array<catalog::Definition, catalog::kCapacity> rows{};
  26. for (std::size_t i = 0; i < candidateCount; ++i) {
  27. std::uint32_t rootTag{}, tableTag{}, rootClass{};
  28. std::size_t count{};
  29. if (packages::reader::read_tag(source, scratch, candidates[i], globals)
  30. && tables::child_tag(globals, tables::kInvestmentRootChild, rootTag)
  31. && packages::reader::read_tag(source, scratch, rootTag, root, rootClass)
  32. && rootClass == tables::kInvestmentRootClass
  33. && tables::slot_tag(root, tables::activities::kRootSlot, tableTag)
  34. && packages::reader::read_tag(source, scratch, tableTag, table)
  35. && tables::activities::decode(table, rows, count)) {
  36. const auto found = std::span(rows).first(count);
  37. build_presentations(source, scratch, globals, found);
  38. build_artwork(source, scratch);
  39. return catalog::publish(found);
  40. }
  41. }
  42. catalog::note_extraction_failure();
  43. return false;
  44. }
  45. } // namespace sunrise::client::content::activity