---@class Motorized_spec
---@field effects? ParticleEffect[]

---@class MotorizedEffectsExtension : Vehicle, Motorized
---@field spec_motorized Motorized_spec
MotorizedEffectsExtension = {}

function MotorizedEffectsExtension.prerequisitesPresent(specializations)
    return SpecializationUtil.hasSpecialization(Motorized, specializations)
end

function MotorizedEffectsExtension.registerEventListeners(vehicleType)
    SpecializationUtil.registerEventListener(vehicleType, 'onLoad', MotorizedEffectsExtension)
end

function MotorizedEffectsExtension:onLoad()
    local spec = self.spec_motorized

    ---@type XMLFile
    local xmlFile = self.xmlFile

    if spec.effects ~= nil then
        for i, effect in ipairs(spec.effects) do
            if effect.setColor ~= nil then
                local key = string.format('vehicle.motorized.effects.effectNode(%d)#color', i - 1)

                if hasXMLProperty(xmlFile.handle, key) then
                    local color = string.getVector(xmlFile:getString(key), 4)

                    if color ~= nil then
                        effect:setColor(color[1], color[2], color[3], color[4])
                    end
                end
            end
        end
    end
end
