From 218ca538b0175ecd41588acff1c6bf2407c9bcb7 Mon Sep 17 00:00:00 2001 From: Stijn Wopereis Date: Fri, 22 Jun 2018 19:52:37 +0200 Subject: [PATCH] Unregister extension spec on delete --- src/ManualAttaching.lua | 1 + src/ManualAttachingRegistrationHelper.lua | 31 ++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/ManualAttaching.lua b/src/ManualAttaching.lua index 974b872..29dd427 100644 --- a/src/ManualAttaching.lua +++ b/src/ManualAttaching.lua @@ -107,6 +107,7 @@ end --- -- function ManualAttaching:deleteMap() + g_currentMission.dynamicHoseIsManual = false g_currentMission.callbackManualAttaching = nil end diff --git a/src/ManualAttachingRegistrationHelper.lua b/src/ManualAttachingRegistrationHelper.lua index 190400e..ad97d08 100644 --- a/src/ManualAttachingRegistrationHelper.lua +++ b/src/ManualAttachingRegistrationHelper.lua @@ -28,7 +28,6 @@ end function ManualAttachingRegistrationHelper:loadMap(name) if not g_currentMission.manualAttachingRegistrationHelperIsLoaded then self:register() - g_currentMission.manualAttachingRegistrationHelperIsLoaded = true else print("ManualAttaching - error: The ManualAttachingRegistrationHelper have been loaded already! Remove one of the copy's!") @@ -38,7 +37,10 @@ end --- -- function ManualAttachingRegistrationHelper:deleteMap() - g_currentMission.manualAttachingRegistrationHelperIsLoaded = nil + if g_currentMission.manualAttachingRegistrationHelperIsLoaded then + self:unregister() + g_currentMission.manualAttachingRegistrationHelperIsLoaded = false + end end --- @@ -67,9 +69,30 @@ end --- -- function ManualAttachingRegistrationHelper:register() + local extensionSpec = SpecializationUtil.getSpecialization('manualAttachingExtension') + + for _, vehicleType in pairs(VehicleTypeUtil.vehicleTypes) do + if vehicleType ~= nil + and SpecializationUtil.hasSpecialization(Attachable, vehicleType.specializations) + or SpecializationUtil.hasSpecialization(AttacherJoints, vehicleType.specializations) then + table.insert(vehicleType.specializations, extensionSpec) + end + end +end + +--- +-- +function ManualAttachingRegistrationHelper:unregister() + local extensionSpec = SpecializationUtil.getSpecialization('manualAttachingExtension') + for _, vehicleType in pairs(VehicleTypeUtil.vehicleTypes) do - if vehicleType ~= nil and SpecializationUtil.hasSpecialization(Attachable, vehicleType.specializations) or SpecializationUtil.hasSpecialization(AttacherJoints, vehicleType.specializations) then - table.insert(vehicleType.specializations, SpecializationUtil.getSpecialization('manualAttachingExtension')) + if vehicleType ~= nil then + for i, spec in ipairs(vehicleType.specializations) do + if spec == extensionSpec then + table.remove(vehicleType.specializations, i) + break + end + end end end end