Suspected UI bug: Clicking units produces "selectionResult", "Select Idle Fabbers" does not

Discussion in 'Mod Support' started by coldboot, May 4, 2015.

  1. coldboot

    coldboot Active Member

    Messages:
    447
    Likes Received:
    112
    When I write this code in the live_game scene:
    Code:
    model.selection.subscribe(function (value) {
        if (value && value.selectionResult) {
            console.log('selectionResult exists');
        } else {
            console.log('selectionResult MISSING');
        }
    }
    
    Then when I click some unit(s), or click+drag select some unit(s), I get a selectionResult.

    However, while I'm dragging over some units, before releasing the mouse button, I get a new event for every new unit that enters the bandbox, all without a selectionResult. The selectionResult is only produced when I let go of the mouse button, and the selection is completed, which is expected given the name "selectionResult". However, I get the same "no selectionResult" event when I select any units with any key binding.

    I expect there to be a selectionResult whenever a bunch of units end up in the "selected" state.

    1. Is Uber aware of this bug, and do they plan to fix it?
    2. Is there another way to do this so I can get the same kind of event for mouse-selecting and keybinding-selecting?
  2. coldboot

    coldboot Active Member

    Messages:
    447
    Likes Received:
    112
    @cola_colin suggested using this code for attaching to selection events before I created this thread:
    Code:
    (function() {
        var oldSelectionHandler = handlers.selection;
        handlers.selection = function(payload) {
            console.log("The selection was changed, the new selection is");
            console.log(payload);
          
            if (oldSelectionHandler) {
                oldSelectionHandler(payload);
            }
        };
    }());
    
    It turns out that using handlers.selection produces events at the same times as model.selection.subscribe, but it never produces a selectionResult. Therefore it doesn't distinguish between a selection in progress and a completed selection, whether it's with the mouse or keybindings. This also seems like a bug.
  3. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    handlers.selection isn't buggy imho. It triggers whenever the selection is changed. A selection in progress is just a selection as well to it. I never used the model.selection observable and never even knew there is something like a selection result.
    Considering the handlers.selection function is the only source I know of that the UI has to get information on what is selected (model.selection is a result of that information that is computed as a result of the handler getting data) my guess would be the UI tries to guess if the selection is finished based on timing and that was forgotten or is not necessary for the idle fabber thing.

    Either way my recommendation still is to directly use the handler and do the "is the selection complete" tracking yourself via timings.
    Maybe first look up how the original selectionResult is determined.
  4. coldboot

    coldboot Active Member

    Messages:
    447
    Likes Received:
    112
    The selectionResult property isn't being populated by any JavaScript code, it comes from the game's C++ code. I grepped through everything and there are only references to selectionResult, nothing assigning it.

    Can you elaborate on what you mean by "timings" when determining whether a selection has been completed or not?

    Either way, what do you think the intent of selectionResult is?
  5. wondible

    wondible Post Master General

    Messages:
    3,315
    Likes Received:
    2,089
    The UI only uses it to determine when a single-click at a point selected something or not - that is about all we can say about it's purpose.

    You could use model.mode() == 'select' to determine when a drag box is in progress. The mode may not get reset until after the selection is completed, but you should have selectionResult in those cases.
    coldboot likes this.
  6. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    I have never seen "selectionResult" anywhere and never needed anything like it. If handlers.selection is not the one that passes it from C++ to javascript then through what handler does it go? Any information that goes from C++ to js has to move through some handler I think.
    With timing I meant you could tell if a selection is finished by assuming that if the selection has not changed for some time it is finished.
  7. coldboot

    coldboot Active Member

    Messages:
    447
    Likes Received:
    112
    Here are the grep results for selectionResult:
    Code:
    media/ui/main/game/live_game/live_game.js
    2604:                                    if (selection && selection.selectionResult) {
    2605:                                        holodeck.doubleClickId = selection.selectionResult[0];
    2607:                                        if (!selection.selectionResult.length)
    
    I don't see it being assigned there.

    I don't think you can use timings to determine if a selection is finished, because it won't work in the case where someone holds a bandbox over a bunch of units for a while without letting go of the mouse. You might be able to use a global state
  8. coldboot

    coldboot Active Member

    Messages:
    447
    Likes Received:
    112
    This sounds like it could work. Thanks.
  9. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    I guess if all else fails tracking the mouse plus timing would yield acceptable results.
  10. coldboot

    coldboot Active Member

    Messages:
    447
    Likes Received:
    112
    Thanks @cola_colin and @wondible. I updated Super Select and selection history is working perfectly now.

    I ended up verifying that model.mode() != 'select' to confirm that a selection was complete.

Share This Page