| 695 | } |
| 696 | |
| 697 | LocalScripts* LuaManager::createLocalScripts( |
| 698 | const MWWorld::Ptr& ptr, std::optional<LuaUtil::ScriptIdsWithInitializationData> autoStartConf) |
| 699 | { |
| 700 | assert(mInitialized); |
| 701 | std::shared_ptr<LocalScripts> scripts; |
| 702 | const uint32_t type = getLiveCellRefType(ptr.mRef); |
| 703 | if (type == ESM::REC_STAT) |
| 704 | throw std::runtime_error("Lua scripts on static objects are not allowed"); |
| 705 | else if (type == ESM::REC_INTERNAL_PLAYER) |
| 706 | { |
| 707 | scripts = std::make_shared<PlayerScripts>(&mLua, LObject(getId(ptr))); |
| 708 | scripts->setAutoStartConf(mConfiguration.getPlayerConf()); |
| 709 | for (const auto& [name, package] : mPlayerPackages) |
| 710 | scripts->addPackage(name, package); |
| 711 | } |
| 712 | else |
| 713 | { |
| 714 | scripts = std::make_shared<LocalScripts>(&mLua, LObject(getId(ptr)), &mScriptTracker); |
| 715 | if (!autoStartConf.has_value()) |
| 716 | autoStartConf = mConfiguration.getLocalConf(type, ptr.getCellRef().getRefId(), getId(ptr)); |
| 717 | scripts->setAutoStartConf(std::move(*autoStartConf)); |
| 718 | for (const auto& [name, package] : mLocalPackages) |
| 719 | scripts->addPackage(name, package); |
| 720 | } |
| 721 | scripts->setSerializer(mLocalSerializer.get()); |
| 722 | |
| 723 | MWWorld::RefData& refData = ptr.getRefData(); |
| 724 | refData.setLuaScripts(std::move(scripts)); |
| 725 | return refData.getLuaScripts(); |
| 726 | } |
| 727 | |
| 728 | void LuaManager::write(ESM::ESMWriter& writer, Loading::Listener& progress) |
| 729 | { |
nothing calls this directly
no test coverage detected