<commit_before>function getMonsterDom(monster) {
    var name = monster.getName();
    var hp = monster.getCurrentHP();
    var hpPercentage = hp * 100 / hp;
    var baseHP = monster.getBaseHP();
    var mana = monster.getCurrentMana();
    var baseMana = monster.getBaseMana();
    var manaPercentage = mana * 100 / baseMana;
    var time = monster.getTimeToNextMove();
    var speed = monster.getSpeed();
    var speedPercentage = time * 100 / speed;

    return `<div class="monster stat-block">
        <h2>${name}</h2>
        <div class="bar hp" title="Hitpoints">
            <span class="text">${hp} / ${baseHP}</span>
            <div class="inner" style="width: ${hpPercentage}%"></div>
        </div>
        <div class="bar mana" title="Mana" data-has-mana="${baseMana > 0}">
            <div class="inner" style="width: ${manaPercentage}%"></div>
            <span class="text">${mana} / ${baseMana}</span>
        </div>
        <div class="bar action" title="Ticks to Next Move">
            <div class="inner" style="width: ${speedPercentage}%"></div>
            <span class="text">${time} / ${speed}</span>
        </div>
        <div class="equipment">
        </div>
    </div>`;
}

export default {
    bindTooltips: function(dungeon, grid) {
        var $grid = $(grid);
        if(!$grid.tooltip) {
            return; // TODO: Give unit tests access to jQuery UI
        }
        $grid.attr('title', 'Hi').tooltip({
            content: function() {
                var $cell = $(this);
                var x = +$cell.attr('data-x');
                var y = +$cell.attr('data-y');
                var tile = dungeon.getTile(x, y);
                var creature = tile.getCreature();
                var items = tile.getItems();

                var pc = dungeon.getPlayableCharacter();
                var pcHasSeenTile = pc.hasSeen(tile);
                var pcCanSeeTile = pc.canSee(dungeon, tile);

                if(!pcHasSeenTile) {
                    return null;
                } else {
                    return $(`
                        <div class="tooltip-wrap">
                            <div class="tile">${tile.getName()}</div>
                            ${
                                (creature && pcCanSeeTile) ? (
                                    (creature === pc) ? 'You are here' : getMonsterDom(creature)
                                ) : ''
                            }
                            ${
                                (items.length > 0) ? `
                                    <ul class="items">
                                        ${items.map((item)=>`<ul>${item.getName()}</ul>`)}
                                    </ul>` : ''
                            }
                        </div>
                    `);
                }
            },

            items: '.cell',

            tooltipClass: 'grid-tooltip',

            position: {
                my: 'left+15 top+5',
                at: 'right top'
            },

            show: {
                delay: 400
            }/*,

            close: function( event, ui ) {
                ui.tooltip.hover(function () {
                    $(this).stop(true).fadeTo(400, 1);
                    //.fadeIn("slow"); // doesn't work because of stop()
                }, function () {
                    $(this).fadeOut(400, function(){ $(this).remove(); });
                });
            }*/
        });
    }
};<commit_msg>Improved tooltip, again<commit_after>function getMonsterDom(monster) {
    var name = monster.getName();
    var hp = monster.getCurrentHP();
    var hpPercentage = hp * 100 / hp;
    var baseHP = monster.getBaseHP();
    var mana = monster.getCurrentMana();
    var baseMana = monster.getBaseMana();
    var manaPercentage = mana * 100 / baseMana;
    var time = monster.getTimeToNextMove();
    var speed = monster.getSpeed();
    var speedPercentage = time * 100 / speed;

    return `<div class="monster stat-block">
        <h2>${name}</h2>
        <div class="bar hp" title="Hitpoints">
            <span class="text">${hp} / ${baseHP}</span>
            <div class="inner" style="width: ${hpPercentage}%"></div>
        </div>
        <div class="bar mana" title="Mana" data-has-mana="${baseMana > 0}">
            <div class="inner" style="width: ${manaPercentage}%"></div>
            <span class="text">${mana} / ${baseMana}</span>
        </div>
        <div class="bar action" title="Ticks to Next Move">
            <div class="inner" style="width: ${speedPercentage}%"></div>
            <span class="text">${time} / ${speed}</span>
        </div>
        <div class="equipment">
        </div>
    </div>`;
}

export default {
    bindTooltips: function(dungeon, grid) {
        var $grid = $(grid);
        if(!$grid.tooltip) {
            return; // TODO: Give unit tests access to jQuery UI
        }
        $grid.attr('title', 'Hi').tooltip({
            content: function() {
                var $cell = $(this);
                var x = +$cell.attr('data-x');
                var y = +$cell.attr('data-y');
                var tile = dungeon.getTile(x, y);
                var creature = tile.getCreature();
                var items = tile.getItems();

                var pc = dungeon.getPlayableCharacter();
                var pcHasSeenTile = pc.hasSeen(tile);
                var pcCanSeeTile = pc.canSee(dungeon, tile);

                if(!pcHasSeenTile) {
                    return null;
                } else {
                    return $(`
                        <div class="tooltip-wrap">
                            <div class="tile">${tile.getName()}</div>
                            ${
                                (creature && pcCanSeeTile) ? (
                                    (creature === pc) ? 'You are here' : getMonsterDom(creature)
                                ) : ''
                            }
                            ${
                                (items.length > 0) ? `
                                    <ul class="items">
                                        ${items.map((item)=>`<ul>${item.getName()}</ul>`)}
                                    </ul>` : ''
                            }
                        </div>
                    `);
                }
            },

            items: '.cell',

            tooltipClass: 'grid-tooltip',

            position: {
                my: 'left+15 top+5',
                at: 'right top'
            },

            show: {
                delay: 400
            }/*,

            close: function( event, ui ) {
                ui.tooltip.hover(function () {
                    $(this).stop(true).fadeTo(400, 1);
                    //.fadeIn("slow"); // doesn't work because of stop()
                }, function () {
                    $(this).fadeOut(400, function(){ $(this).remove(); });
                });
            }*/
        }).on('click', function() {
            $grid.tooltip('disable');
        }).on('mousemove focus', function() {
            $grid.tooltip('enable');
        });
    }
};
{'fraction_non_alphanumeric': 0.15173674588665448, 'fraction_numerical': 0.007312614259597806, 'mean_word_length': 1.2364779874213836, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5552425', 'n_tokens_mistral': 2033, 'n_tokens_neox': 1885, 'n_words': 397}