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.
674{
675 ReconstructionResult total;
676
677 const std::string tapestry_path = base_dir + "/tapestry.json";
678 IO::JSONSerializer ser;
679 auto schema_opt = ser.read<State::TapestrySchema>(tapestry_path);
680 if (!schema_opt) {
681 m_last_error =
"Failed to load tapestry schema: " + ser.last_error();
683 return total;
684 }
685 const auto& schema = *schema_opt;
686
687 for (const auto& ref : schema.fabrics) {
688 auto fabric = tapestry.get_fabric(ref.name);
689 if (!fabric) {
690 fabric = tapestry.create_fabric(ref.name);
691 }
693 total.constructed += result.constructed;
694 total.patched += result.patched;
695 total.skipped += result.skipped;
696 for (auto& w : result.warnings)
697 total.warnings.push_back(ref.name +
": " +
std::move(w));
698 }
699
700 for (const auto& xrec : schema.expanses) {
701 if (xrec.fn_name.empty()) {
702 total.warnings.push_back("TapestryExpanse '" + xrec.name + "': no fn_name, skipping");
703 continue;
704 }
708
709 for (const auto& fname : xrec.fabric_names) {
710 auto fabric = tapestry.get_fabric(fname);
711 if (!fabric)
712 continue;
713 if (!contains_fn) {
714 if (
auto ptr = fabric->resolve_expanse_fn(xrec.fn_name);
ptr && *
ptr)
716 }
717 if (!on_enter_fn && !xrec.on_enter_fn_name.empty()) {
718 if (
auto ptr = fabric->resolve_crossing_fn(xrec.on_enter_fn_name);
ptr && *
ptr)
720 }
721 if (!on_exit_fn && !xrec.on_exit_fn_name.empty()) {
722 if (
auto ptr = fabric->resolve_crossing_fn(xrec.on_exit_fn_name);
ptr && *
ptr)
724 }
725 }
726
727 if (!contains_fn) {
728 total.warnings.push_back("TapestryExpanse '" + xrec.name
729 + "': fn '" + xrec.fn_name + "' not resolved, skipping");
730 continue;
731 }
732
733 auto expanse = tapestry.create_expanse(
734 xrec.name,
735 std::move(contains_fn),
736 std::move(on_enter_fn),
737 std::move(on_exit_fn));
738
739 for (const auto& fname : xrec.fabric_names) {
740 if (auto fabric = tapestry.get_fabric(fname))
741 fabric->add_expanse(expanse);
742 }
743 ++total.constructed;
744 }
745
746 total.user_state = schema.user_state;
747
749 "StateDecoder::reconstruct(Tapestry): constructed={} patched={} skipped={} warnings={}",
750 total.constructed, total.patched, total.skipped, total.warnings.size());
751 return total;
752}
#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.