Reads tapestry.json, creates or finds Fabrics by name, calls reconstruct(fabric, base_path) for each, then restores Tapestry-level named Expanses and registers them on the listed Fabrics.
681{
682 ReconstructionResult total;
683
684 const std::string tapestry_path = base_dir + "/tapestry.json";
685 IO::JSONSerializer ser;
686 auto schema_opt = ser.read<State::TapestrySchema>(tapestry_path);
687 if (!schema_opt) {
688 m_last_error =
"Failed to load tapestry schema: " + ser.last_error();
690 return total;
691 }
692 const auto& schema = *schema_opt;
693
694 for (const auto& ref : schema.fabrics) {
695 auto fabric = tapestry.get_fabric(ref.name);
696 if (!fabric) {
697 fabric = tapestry.create_fabric(ref.name);
698 }
700 total.constructed += result.constructed;
701 total.patched += result.patched;
702 total.skipped += result.skipped;
703 for (auto& w : result.warnings)
704 total.warnings.push_back(ref.name +
": " +
std::move(w));
705 }
706
707 for (const auto& xrec : schema.expanses) {
708 if (xrec.fn_name.empty()) {
709 total.warnings.push_back("TapestryExpanse '" + xrec.name + "': no fn_name, skipping");
710 continue;
711 }
715
716 for (const auto& fname : xrec.fabric_names) {
717 auto fabric = tapestry.get_fabric(fname);
718 if (!fabric)
719 continue;
720 if (!contains_fn) {
721 if (
auto ptr = fabric->resolve_expanse_fn(xrec.fn_name);
ptr && *
ptr)
723 }
724 if (!on_enter_fn && !xrec.on_enter_fn_name.empty()) {
725 if (
auto ptr = fabric->resolve_crossing_fn(xrec.on_enter_fn_name);
ptr && *
ptr)
727 }
728 if (!on_exit_fn && !xrec.on_exit_fn_name.empty()) {
729 if (
auto ptr = fabric->resolve_crossing_fn(xrec.on_exit_fn_name);
ptr && *
ptr)
731 }
732 }
733
734 if (!contains_fn) {
735 total.warnings.push_back("TapestryExpanse '" + xrec.name
736 + "': fn '" + xrec.fn_name + "' not resolved, skipping");
737 continue;
738 }
739
740 auto expanse = tapestry.create_expanse(
741 xrec.name,
742 std::move(contains_fn),
743 std::move(on_enter_fn),
744 std::move(on_exit_fn));
745
746 for (const auto& fname : xrec.fabric_names) {
747 if (auto fabric = tapestry.get_fabric(fname))
748 fabric->add_expanse(expanse);
749 }
750 ++total.constructed;
751 }
752
753 total.user_state = schema.user_state;
754
756 "StateDecoder::reconstruct(Tapestry): constructed={} patched={} skipped={} warnings={}",
757 total.constructed, total.patched, total.skipped, total.warnings.size());
758 return total;
759}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
std::function< void(uint32_t)> CrossingFn
std::function< bool(const glm::vec3 &)> ContainsFn
ReconstructionResult reconstruct(Fabric &fabric, const std::string &base_path)
Patch existing entities and construct missing ones from schema.
@ FileIO
Filesystem I/O operations.
@ Nexus
Spatial indexing and scheduling for user-defined behaviour.