'use strict';

var vc;

module.exports = function(v4) {
    v4.version = 4;
    vc = v4.constants;
    v4.layers.forEach(convertLayer);
    return v4;
};

function convertLayer(layer) {
    // convert linear/exponential functions to stop functions
    // decrement zoom level of functions by 1 for map tileSize (512) change
    for (var classname in layer) {
        if (classname.indexOf('style') === -1) continue;
        var style = layer[classname];
        for (var propname in style) {
            if (!style[propname].fn) continue;
            var oldfn = style[propname];
            var newfn;
            if (oldfn.fn === 'stops') {
                newfn = { stops: oldfn.stops };
            // @TODO convert linear/exponential functions into stops functions.
            } else if (oldfn.fn === 'linear') {
                newfn = { stops: [] };
            } else if (oldfn.fn === 'exponential') {
                newfn = { stops: [] };
            }
            // Decrement zoom levels by 1.
            newfn.stops = newfn.stops.map(deczoom);
            style[propname] = newfn;
        }
    }

    function deczoom(pair) {
        return [Math.max(0, pair[0] - 1), pair[1]];
    }
}


@@ -348,24 +348,206 @@
 in layer) %7B%0A
+        if (layer%5Bclassname%5D%5B'text-max-angle'%5D) %7B%0A            layer%5Bclassname%5D%5B'text-max-angle'%5D = Number((layer%5Bclassname%5D%5B'text-max-angle'%5D * 180 / Math.PI).toFixed(2));%0A        %7D%0A
         if (
@@ -1377,9 +1377,8 @@
     %7D%0A%7D%0A
-%0A

convert text-max-angle radians to degrees