Skip to content

Commit

Permalink
Unregister extension spec on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnwop committed Jun 22, 2018
1 parent 85fb827 commit 218ca53
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/ManualAttaching.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ end
---
--
function ManualAttaching:deleteMap()
g_currentMission.dynamicHoseIsManual = false
g_currentMission.callbackManualAttaching = nil
end

Expand Down
31 changes: 27 additions & 4 deletions src/ManualAttachingRegistrationHelper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand All @@ -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

---
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 218ca53

Please sign in to comment.