[REL] AlertsManager [61450]

Discussion in 'Released Mods' started by cola_colin, January 12, 2014.

  1. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    Install via pamm v3!

    For Players


    The alert manager changes a few things about alerts:
    • The alert filtering that was part of PA Stats is no longer part of PA Stats, instead it is part of this mod.
    • Left click still moves the camera to the position of the event
    • Left click + shift moves the camera and the chronocam to the event
    • Right click + ctrl removes the event
    • Events are not removed by leftclick anymore
    • When you press k your currently selected units will be marked as "interesting". You will see alerts for that specific unit, no matter your alert filter settings.
    • When you shift left clicked on an alert and the chrono cam opened you can press l to "get back". get back will move your camera to the position it had when you did the left click and deactivate the chronocam.
    So i.e. a scenario is at the start of the game:

    1. Build scout
    2. select scout, press k
    3. scout
    4. get alert "scout is dead"
    5. shift left click
    6. watch the poor scout die
    7. press l to get back to your base

    k and l can be configured in the options. They are bound using mousetrap, so you need to be careful not to conflict with other keys.

    For Modders

    PA currently has no own API to register a listener for alert-events. To prevent mods from conflicting this mod provides an API to register listeners. I.e. PA Stats uses it like this:
    Code:
    alertsManager.addListener(function(payload) {
        // handle the payload, that looks just like the watchlist.
    // note that the plain addListener registers all created and destroyed events.
        }
    });
    If you only want a filtered subset of events you can use addFilteredListener instead of addListener. Example that only gets events about the events that are visible per default:

    Code:
    var settings = alertsManager.makeEmptyFilterSettings();
    settings.selectedTypes[alertsManager.WATCH_TYPES.CREATED] = ['Factory'];
    settings.selectedTypes[alertsManager.WATCH_TYPES.DAMAGED] = ['Commander'];
    settings.selectedTypes[alertsManager.WATCH_TYPES.DESTROYED] = ['Structure'];
    // to be unit specific:
    settings.includedUnits[...watch_type as above...] = [/*Array with spec ids*/];
    settings.excludedUnits[...watch_type as above...] = [/*Array with spec ids*/];
    
    alertsManager.addFilteredListener(function(payload) {
        console.log("a visible event: ");
        console.log(payload);
    }, settings);
    Drawbacks
    • No support for damage alerts. Their behavior is unchanged (only commander). It would be trivial to add (if somebody wants to try, read the mod code, there are comments), but I am worried about "toooooo many". The mod internally has to deal with all events that occur, and damage-alerts look like they will be too many.
    • While you are using the chronocam PA Stats cannot gather data on army/resources values. This has always been the case, but until now the chronocam was rarely used while playing. So while you are watching the events in the past you wont collect data on your resources and army counter. The army composition data is uneffected. I think generally it is a good idea not to watch the past for too long of a time anyway ;)
    So I hope this does not have big bugs anymore :)

    Also: https://github.com/pamods/uimod-AlertsManager
    Last edited: January 12, 2014
  2. elitedanzel

    elitedanzel Active Member

    Messages:
    151
    Likes Received:
    137
    YEOS!!! Awesome, looking forwards to using this :)
  3. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    Same here!
  4. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Wow nice, what a lot of interesting code.
    For the k and l keys:
    I would add the keys to the normal action_sets and let the default system do the binding.
    So then you'll get a popup if there are conflicts with other keys.

    I use the action_sets['hotbuilds']

    But I guess we should start organizing things under an action_set['mods'] and move all keys to there.
    I'll check if I can change this in your code....
  5. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    I havent looked into how the default keybinding stuff works out all and I have not really used it either, so I had no idea that would be a good idea to do. Sounds good though. Feel free to fork it on github and push me a few nice changes :)
    or just commit directly into the pamod repository.
  6. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Yeah I'll do that but not today anymore :)

    basically the default system works like this

    set a default in the default_keybinds
    default_keybinds.gameplay['Mark Interesting Units'] = 'k';

    action_sets.gameplay['Mark Interesting Units'] = functionToRunOnKeypress();

    in settings it will add the key under the 'gameplay' title and will check if there is overlap on saving with this.

    in live_game it binds the keys using mousetrap based on the default_keybinds and action_sets.
    with apply_keybinds('gameplay');
    cola_colin likes this.
  7. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    Bug:
    You cannot press k on a factory while the factory is building a unit. Somehow something is weird about the selection API of PA:

    model.selection(); returns the current selection. Usually it has a property called "selectionResult". This lists the IDs of the units in the selection. I use these IDs. However while a factory is building a unit is does not have that property. Only while it is idle (even the idle between building 2 tanks is enough) it has that property.
    I am not sure what to do about it, apart from asking:
    "Uber this looks like an API bug that has no consequences for the game itself right now?"
  8. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    Is there a way to control how far back shift-click moves the chronocam? It seems like it could give us a couple more seconds of context before showing the actual event.
    totalannihilation likes this.
  9. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    currently it is a hard coded 0,5 seconds. You can change that value somewhere in the live_game.js file around line 30.
    Just do a -3 instead of -0.5s.
  10. Tontow

    Tontow Active Member

    Messages:
    459
    Likes Received:
    64
    Get this added to mod manager and I will definitely use it.
  11. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    This one broke a bit in 59549, because Uber improved the internal API.
    Updated for 59549, however it so far does not use the new API. Might change in the future.
    Note that if you use PA Stats, you HAVE to update this mod, too to get PA Stats to record all your units and stuff again.
  12. Xagar

    Xagar Active Member

    Messages:
    321
    Likes Received:
    117
    Is there some way to add a keybind for the chronocam jump feature? Shift-space seems logical but it doesn't work :(
  13. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    only via a bit of further coding.
  14. Xagar

    Xagar Active Member

    Messages:
    321
    Likes Received:
    117
    This mod conflicts with the Custom Unit Names mod. If you enable both, it will act as if you haven't set any filters and the options in the settings menu won't appear. However, the chronocam features still work, so it's some sort of ui integration bug, I would guess.

    Attached Files:

  15. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    Looks like a JavaScript error, probably. What errors are showing up in the coherent debugger?
    totalannihilation likes this.
  16. Xagar

    Xagar Active Member

    Messages:
    321
    Likes Received:
    117

    Attached Files:

  17. cptconundrum

    cptconundrum Post Master General

    Messages:
    4,186
    Likes Received:
    4,900
    Nothing unusual there. I wonder if it is more likely to be a bug with the unit names mod than this one.
    totalannihilation likes this.
  18. LavaSnake

    LavaSnake Post Master General

    Messages:
    1,620
    Likes Received:
    691
    I'm really confused about that. I've hidden all my variables and used unique names so I have no clue how or why they're conflicting. Maybe @cola_colin could figure it out?
  19. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    In the settings the issue is that you are replacing more html than you should:

    Code:
        //Enlarge the list
        $("body").html($("body").html().replace(
            "<select class=\"div_settings_control_select\" data-bind=\"options: LUnitNames_Rules_options, selectedOptions: LUnitNames_Rules\" size=\"10\"",
            "<select class=\"div_settings_control_select\" data-bind=\"options: LUnitNames_Rules_options, selectedOptions: LUnitNames_Rules\" size=\"10\" style='width: 100%;'"));
            
    That is executed after alertsManager, which deletes the html that was added by the alertsManager.

    Looking into the broken filtering now...

    EDIT:
    Filtering is not broken for me?
    From the code I don't see any issues as well.

    @LavaSnake: It might probably a good idea to not use a 500 ms interval that does what you are doing. A cleaner solution would be to intercept the unit definitions when they are given to PA and replace the names within them.
    Last edited: February 2, 2014
  20. wondible

    wondible Post Master General

    Messages:
    3,315
    Likes Received:
    2,089
    There might be some funny reason with CoherentUI to do the replacement, but normally this would be focused and far more efficient.

    HTML:
    $('.div_settings_control_select').css('width', '100%')
    There is a special case for width as well.

    HTML:
    $('.div_settings_control_select').width('100%')

Share This Page