Ticket #3222: t3222_handle_notifications_v4.patch

File t3222_handle_notifications_v4.patch, 2.9 KB (added by elexis, 9 years ago)

Same patch as above, but changed 'for(var i = 0; i < notifications.length; ++i)' to 'for(var notification of notifications)'.

  • binaries/data/mods/public/gui/session/messages.js

     
    136136};
    137137
    138138// Notifications
    139139function handleNotifications()
    140140{
    141     var notification = Engine.GuiInterfaceCall("GetNextNotification");
     141    var notifications = Engine.GuiInterfaceCall("GetNotifications");
    142142
    143     if (!notification)
    144         return;
    145     if (!notification.type)
     143    for(var notification of notifications)
    146144    {
    147         error("notification without type found.\n"+uneval(notification))
    148         return;
     145        if (!notification.type)
     146        {
     147            error("Notification without type found.\n"+uneval(notification))
     148            continue;
     149        }
     150       
     151        if (!notification.players)
     152        {
     153            error("Notification without players found.\n"+uneval(notification))
     154            continue;
     155        }
     156       
     157        var action = g_NotificationsTypes[notification.type];
     158        if (!action)
     159        {
     160            error("Unknown notification type '" + notification.type + "' found.");
     161            continue;
     162        }
     163       
     164        for (var player of notification.players)
     165            action(notification, player);
    149166    }
    150     if (!notification.players)
    151     {
    152         error("notification without players found.\n"+uneval(notification))
    153         return;
    154     }
    155     var action = g_NotificationsTypes[notification.type];
    156     if (!action)
    157     {
    158         error("unknown notification type '" + notification.type + "' found.");
    159         return;
    160     }
    161 
    162     for (var player of notification.players)
    163         action(notification, player);
    164167}
    165168
    166169function updateDiplomacy()
    167170{
    168171    g_Players = getPlayerData(g_PlayerAssignments);
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    732732        this.AddTimeNotification(notification);
    733733    else
    734734        this.notifications.push(notification);
    735735};
    736736
    737 GuiInterface.prototype.GetNextNotification = function()
     737GuiInterface.prototype.GetNotifications = function()
    738738{
    739     if (this.notifications.length)
    740         return this.notifications.pop();
    741     else
    742         return false;
     739    var n = this.notifications;
     740    this.notifications = [];
     741    return n;
    743742};
    744743
    745744GuiInterface.prototype.GetAvailableFormations = function(player, wantedPlayer)
    746745{
    747746    var cmpPlayerMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
     
    18751874    "CheckTechnologyRequirements": 1,
    18761875    "GetStartedResearch": 1,
    18771876    "GetBattleState": 1,
    18781877    "GetIncomingAttacks": 1,
    18791878    "GetNeededResources": 1,
    1880     "GetNextNotification": 1,
     1879    "GetNotifications": 1,
    18811880    "GetTimeNotifications": 1,
    18821881
    18831882    "GetAvailableFormations": 1,
    18841883    "GetFormationRequirements": 1,
    18851884    "CanMoveEntsIntoFormation": 1,