Ticket #2087: Loading.js_cleanup.diff

File Loading.js_cleanup.diff, 4.5 KB (added by Stan, 8 years ago)

Early Return should remove trailing if any, replace var by let, use g_ instead of caps.

  • binaries/data/mods/public/gui/loading/loading.js

    diff --git a/binaries/data/mods/public/gui/loading/loading.js
    index 685ab89..e33cb66 100644
    a b  
    1 var g_Data;
    2 const END_PIECE_WIDTH = 16;
     1let g_Data;
     2const g_EndPieceWidth = 16;
    33
    44function init(data)
    55{
    66    g_Data = data;
    77
     8    if(!g_Data)
     9        return;
     10
    811    // Set to "hourglass" cursor.
    912    Engine.SetCursor("cursor-wait");
    1013
    1114    // Get tip image and corresponding tip text
    12     var tipTextLoadingArray = Engine.BuildDirEntList("gui/text/tips/", "*.txt", false);
     15    let tipTextLoadingArray = Engine.BuildDirEntList("gui/text/tips/", "*.txt", false);
    1316
    1417    if (tipTextLoadingArray.length > 0)
    1518    {
    1619        // Set tip text
    17         var tipTextFilePath = tipTextLoadingArray[getRandom (0, tipTextLoadingArray.length-1)];
    18         var tipText = Engine.TranslateLines(Engine.ReadFile(tipTextFilePath));
     20        let tipTextFilePath = tipTextLoadingArray[getRandom (0, tipTextLoadingArray.length-1)];
     21        let tipText = Engine.TranslateLines(Engine.ReadFile(tipTextFilePath));
    1922
    2023        if (tipText)
    2124        {
    22             var index = tipText.indexOf("\n");
    23             var tipTextTitle = tipText.substring(0, index);
    24             var tipTextMessage = tipText.substring(index);
     25            let index = tipText.indexOf("\n");
     26            let tipTextTitle = tipText.substring(0, index);
     27            let tipTextMessage = tipText.substring(index);
    2528            Engine.GetGUIObjectByName("tipTitle").caption = tipTextTitle? tipTextTitle : "";
    2629            Engine.GetGUIObjectByName("tipText").caption = tipTextMessage? tipTextMessage : "";
    2730        }
    2831
    2932        // Set tip image
    30         var fileName = tipTextFilePath.substring(tipTextFilePath.lastIndexOf("/")+1).replace(".txt", ".png");
    31         var tipImageFilePath = "loading/tips/" + fileName;
    32         var sprite = "stretched:" + tipImageFilePath;
     33        let fileName = tipTextFilePath.substring(tipTextFilePath.lastIndexOf("/")+1).replace(".txt", ".png");
     34        let tipImageFilePath = "loading/tips/" + fileName;
     35        let sprite = "stretched:" + tipImageFilePath;
    3336        Engine.GetGUIObjectByName("tipImage").sprite = sprite? sprite : "";
    3437    }
    3538    else
    function init(data)  
    3740
    3841    // janwas: main loop now sets progress / description, but that won't
    3942    // happen until the first timeslice completes, so set initial values.
    40     var loadingMapName = Engine.GetGUIObjectByName("loadingMapName");
     43    let loadingMapName = Engine.GetGUIObjectByName("loadingMapName");
    4144
    4245    if (data)
    4346    {
    44         var mapName = translate(data.attribs.settings.Name);
     47        let mapName = translate(data.attribs.settings.Name);
    4548        switch (data.attribs.mapType)
    4649        {
    4750        case "skirmish":
    function init(data)  
    6265    Engine.GetGUIObjectByName("progressbar").caption = 0;
    6366
    6467    // Pick a random quote of the day (each line is a separate tip).
    65     var quoteArray = Engine.ReadFileLines("gui/text/quotes.txt");
     68    let quoteArray = Engine.ReadFileLines("gui/text/quotes.txt");
    6669    Engine.GetGUIObjectByName("quoteText").caption = translate(quoteArray[getRandom(0, quoteArray.length-1)]);
    6770}
    6871
    function displayProgress()  
    7376        return;
    7477
    7578    // Show 100 when it is really 99
    76     var progress = g_Progress + 1;
     79    let progress = g_Progress + 1;
    7780
    7881    Engine.GetGUIObjectByName("progressbar").caption = progress; // display current progress
    7982    Engine.GetGUIObjectByName("progressText").caption = progress + "%";
    function displayProgress()  
    8285    // Engine.GetGUIObjectByName("progressText").caption = g_LoadDescription; // display current progess details
    8386
    8487    // Keep curved right edge of progress bar in sync with the rest of the progress bar
    85     var middle = Engine.GetGUIObjectByName("progressbar");
    86     var rightSide = Engine.GetGUIObjectByName("progressbar_right");
     88    let middle = Engine.GetGUIObjectByName("progressbar");
     89    let rightSide = Engine.GetGUIObjectByName("progressbar_right");
    8790
    88     var middleLength = (middle.size.right - middle.size.left) - (END_PIECE_WIDTH / 2);
    89     var increment = Math.round(progress * middleLength / 100);
     91    let middleLength = (middle.size.right - middle.size.left) - (g_EndPieceWidth / 2);
     92    let increment = Math.round(progress * middleLength / 100);
    9093
    91     var size = rightSide.size;
     94    let size = rightSide.size;
    9295    size.left = increment;
    93     size.right = increment + END_PIECE_WIDTH;
     96    size.right = increment + g_EndPieceWidth;
    9497    rightSide.size = size;
    9598}
    9699
    function reallyStartGame()  
    105108
    106109    // Restore default cursor.
    107110    Engine.SetCursor("arrow-default");
    108    
     111
    109112    // Notify the other clients that we have finished the loading screen
    110113    if (g_Data.isNetworked && g_Data.isRejoining)
    111114        Engine.SendNetworkRejoined();