|
| 1 | +/***************************************************************************** |
| 2 | + * |
| 3 | + * PROJECT: Multi Theft Auto |
| 4 | + * LICENSE: See LICENSE in the top level directory |
| 5 | + * FILE: mods/shared_logic/luadefs/CLuaModelDefs.cpp |
| 6 | + * PURPOSE: Lua model definitions class |
| 7 | + * |
| 8 | + * Multi Theft Auto is available from http://www.multitheftauto.com/ |
| 9 | + * |
| 10 | + *****************************************************************************/ |
| 11 | + |
| 12 | +#include "StdInc.h" |
| 13 | +#include <lua/CLuaFunctionParser.h> |
| 14 | +#include "CLodModels.h" |
| 15 | +#include "CClientObjectManager.h" |
| 16 | +#include "CClientBuildingManager.h" |
| 17 | + |
| 18 | +void CLuaModelDefs::LoadFunctions() |
| 19 | +{ |
| 20 | + constexpr static const std::pair<const char*, lua_CFunction> functions[]{ |
| 21 | + // Util func |
| 22 | + {"IsValidModel", ArgumentParser<IsValidModel>}, |
| 23 | + |
| 24 | + // LOD funcs |
| 25 | + {"getLowLODModel", ArgumentParser<GetLowLODModel>}, |
| 26 | + {"getHighLODModel", ArgumentParser<GetHighLODModel>}, |
| 27 | + {"setLowLODModel", ArgumentParser<SetLowLODModel>}, |
| 28 | + {"resetLowLODModel", ArgumentParser<ResetLowLODModel>}, |
| 29 | + {"resetLowLODModels", ArgumentParser<ResetLowLODModels>}, |
| 30 | + }; |
| 31 | + |
| 32 | + // Add functions |
| 33 | + for (const auto& [name, func] : functions) |
| 34 | + CLuaCFunctions::AddFunction(name, func); |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +bool CLuaModelDefs::IsValidModel(std::string modelPurpose, std::uint32_t id) |
| 39 | +{ |
| 40 | + if (modelPurpose == "object") |
| 41 | + return CClientObjectManager::IsValidModel(id); |
| 42 | + else if (modelPurpose == "building") |
| 43 | + return CClientBuildingManager::IsValidModel(id); |
| 44 | + |
| 45 | + throw std::invalid_argument("Invalid model purpose passed, expected 'object' or 'building'"); |
| 46 | +} |
| 47 | + |
| 48 | +std::variant<bool, std::uint32_t> CLuaModelDefs::GetLowLODModel(std::uint32_t hLODModel) noexcept |
| 49 | +{ |
| 50 | + return CLodModels::GetLowLODModel(hLODModel); |
| 51 | +} |
| 52 | + |
| 53 | +std::variant<bool, std::uint32_t> CLuaModelDefs::GetHighLODModel(std::uint32_t lLODModel) noexcept |
| 54 | +{ |
| 55 | + return CLodModels::GetHighLODModel(lLODModel); |
| 56 | +} |
| 57 | + |
| 58 | +bool CLuaModelDefs::SetLowLODModel(std::string modelPurpose, std::uint32_t hLODModel, std::uint32_t lLODModel) |
| 59 | +{ |
| 60 | + if (!IsValidModel(modelPurpose, hLODModel)) |
| 61 | + throw std::invalid_argument("Invalid model ID passed for High-LOD argument"); |
| 62 | + |
| 63 | + if (!IsValidModel(modelPurpose, lLODModel)) |
| 64 | + throw std::invalid_argument("Invalid model ID passed for Low-LOD argument"); |
| 65 | + |
| 66 | + return CLodModels::SetLowLODModel(hLODModel, lLODModel); |
| 67 | +} |
| 68 | + |
| 69 | +bool CLuaModelDefs::ResetLowLODModel(std::uint32_t hLODModel) noexcept |
| 70 | +{ |
| 71 | + return CLodModels::ResetLowLODModel(hLODModel); |
| 72 | +} |
| 73 | + |
| 74 | +void CLuaModelDefs::ResetLowLODModels() noexcept |
| 75 | +{ |
| 76 | + CLodModels::ResetLowLODModels(); |
| 77 | +} |
0 commit comments