--
-- wheelDirtTwins
--
-- author: upsidedown
-- date: 26.12.2013

-- NO RELEASE CANDIDATE!


wheelDirtTwins = {};

function wheelDirtTwins.prerequisitesPresent(specializations)
    return true; --SpecializationUtil.hasSpecialization(Steerable, specializations);
end;

function wheelDirtTwins:load(savegame)
    --self.easyCylinders = {};
    local i=0;
    while true do
        local areaKey = string.format("vehicle.wheelDirtTwins.object(%d)", i);
        if not hasXMLProperty(xmlFile, areaKey) then
            break;
        end
        
        
        local object = Utils.indexToObject(self.components, getXMLString(xmlFile, areaKey .. "#index"));
        local wheelDirt = getXMLInt(xmlFile, areaKey .. "#dirtWheel");
        
        if self.DirtWheels ~= nil then
            if self.DirtWheels[wheelDirt] ~= nil then
                if self.DirtWheels[wheelDirt].twins == nil then
                    self.DirtWheels[wheelDirt].twins = {};
                end;
                table.insert(self.DirtWheels[wheelDirt].twins,object);                
            end;
        else
            print("Warning: wheelDirtTwins loaded before or without WheelDirtSpecialization!")
        end;
        i=i+1;
    end;
end;

function wheelDirtTwins:delete()
    
end;

function wheelDirtTwins:mouseEvent(posX, posY, isDown, isUp, button)
end;

function wheelDirtTwins:keyEvent(unicode, sym, modifier, isDown)
end;

function wheelDirtTwins:update(dt)
end;

function wheelDirtTwins:updateTick(dt)
    if self:getIsActive() then
        for k, dirtWheel in pairs(self.DirtWheels) do
            if dirtWheel.twins~=nil then
                local killDirt = false;
                for _,object in pairs(dirtWheel.twins) do
                    if not getVisibility(object) then
                        killDirt=true;
                    end;
                end;
                if killDirt then
                    dirtWheel.timeOnDirtGround = 0;
                end;
            end;
            -- local ratio = dirtWheel.timeOnDirtGround/8000;
            -- local scale = 0.9+ratio/10;
            -- if dirtWheel.scaleObjects ~= nil then
                -- for _,object in pairs(dirtWheel.scaleObjects) do
                    -- setScale(object,scale,scale,scale);
                -- end;
            -- end;
        end;
    end;
end;


function wheelDirtTwins:draw()
    
end;


function wheelDirtTwins:onDeactivate()
    
end;