diff --git a/rollnw-py/wrapper_objects.cpp b/rollnw-py/wrapper_objects.cpp index 97cdf11f0..27e2aee71 100644 --- a/rollnw-py/wrapper_objects.cpp +++ b/rollnw-py/wrapper_objects.cpp @@ -47,7 +47,7 @@ nlohmann::json to_json_helper_player(const nw::Player* self) template T* create_object_from_json_helper(const nlohmann::json& j) { - auto obj = new T; + auto obj = nw::kernel::objects().make(); if constexpr (!std::is_same_v) { T::deserialize(obj, j, nw::SerializationProfile::blueprint); } else { @@ -239,8 +239,8 @@ void init_objects_creature(py::module& nw) py::class_(nw, "Creature") .def(py::init<>()) - .def_static("from_dict", &create_object_from_json_helper) - .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference_internal) + .def_static("from_dict", &create_object_from_json_helper, py::return_value_policy::reference) + .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference) .def("to_dict", &to_json_helper) .def("handle", &nw::Creature::handle) @@ -324,8 +324,8 @@ void init_objects_door(py::module& nw) .def_readonly_static("json_archive_version", &nw::Door::json_archive_version) .def_readonly_static("object_type", &nw::Door::object_type) - .def_static("from_dict", &create_object_from_json_helper) - .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference_internal) + .def_static("from_dict", &create_object_from_json_helper, py::return_value_policy::reference) + .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference) .def_readwrite("common", &nw::Door::common) .def_readwrite("conversation", &nw::Door::conversation) @@ -378,8 +378,8 @@ void init_objects_encounter(py::module& nw) .def_readonly_static("json_archive_version", &nw::Encounter::json_archive_version) .def_readonly_static("object_type", &nw::Encounter::object_type) - .def_static("from_dict", &create_object_from_json_helper) - .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference_internal) + .def_static("from_dict", &create_object_from_json_helper, py::return_value_policy::reference) + .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference) .def_readwrite("common", &nw::Encounter::common) .def_readwrite("creatures", &nw::Encounter::creatures) @@ -460,8 +460,8 @@ void init_objects_item(py::module& nw) .def_readonly_static("json_archive_version", &nw::Item::json_archive_version) .def_readonly_static("object_type", &nw::Item::object_type) - .def_static("from_dict", &create_object_from_json_helper) - .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference_internal) + .def_static("from_dict", &create_object_from_json_helper, py::return_value_policy::reference) + .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference) .def_readwrite("common", &nw::Item::common) @@ -594,8 +594,8 @@ void init_objects_placeable(py::module& nw) .def_readonly_static("json_archive_version", &nw::Placeable::json_archive_version) .def_readonly_static("object_type", &nw::Placeable::object_type) - .def_static("from_dict", &create_object_from_json_helper) - .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference_internal) + .def_static("from_dict", &create_object_from_json_helper, py::return_value_policy::reference) + .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference) .def_readwrite("common", &nw::Placeable::common) .def_readwrite("conversation", &nw::Placeable::conversation) @@ -632,8 +632,8 @@ void init_objects_player(py::module& nw) .def("to_dict", &to_json_helper_player) - .def_static("from_dict", &create_object_from_json_helper) - .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference_internal); + .def_static("from_dict", &create_object_from_json_helper, py::return_value_policy::reference) + .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference); } void init_objects_sound(py::module& nw) @@ -646,8 +646,8 @@ void init_objects_sound(py::module& nw) .def_readonly_static("json_archive_version", &nw::Sound::json_archive_version) .def_readonly_static("object_type", &nw::Sound::object_type) - .def_static("from_dict", &create_object_from_json_helper) - .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference_internal) + .def_static("from_dict", &create_object_from_json_helper, py::return_value_policy::reference) + .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference) .def_readwrite("common", &nw::Sound::common) .def_readwrite("sounds", &nw::Sound::sounds) @@ -688,8 +688,8 @@ void init_objects_store(py::module& nw) .def_readonly_static("json_archive_version", &nw::Store::json_archive_version) .def_readonly_static("object_type", &nw::Store::object_type) - .def_static("from_dict", &create_object_from_json_helper) - .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference_internal) + .def_static("from_dict", &create_object_from_json_helper, py::return_value_policy::reference) + .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference) .def_readwrite("common", &nw::Store::common) @@ -735,8 +735,8 @@ void init_object_trigger(pybind11::module& nw) .def_readonly_static("json_archive_version", &nw::Trigger::json_archive_version) .def_readonly_static("object_type", &nw::Trigger::object_type) - .def_static("from_dict", &create_object_from_json_helper) - .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference_internal) + .def_static("from_dict", &create_object_from_json_helper, py::return_value_policy::reference) + .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference) .def_readwrite("common", &nw::Trigger::common) .def_readwrite("geometry", &nw::Trigger::geometry) @@ -763,8 +763,8 @@ void init_object_waypoint(pybind11::module& nw) .def_readonly_static("json_archive_version", &nw::Waypoint::json_archive_version) .def_readonly_static("object_type", &nw::Waypoint::object_type) - .def_static("from_dict", &create_object_from_json_helper) - .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference_internal) + .def_static("from_dict", &create_object_from_json_helper, py::return_value_policy::reference) + .def_static("from_file", &create_object_from_file_helper, py::return_value_policy::reference) .def("to_dict", &to_json_helper)