<commit_before>﻿/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/// <reference path="../vendor/jquery.d.ts" />

module Character {

    cuAPI.OpenUI("addons.ui");

    var hpWidth: number = -1;
    var manaWidth: number = -1;
    var cachedEffects: string = "[]";
    var $healthBar: JQuery;
    var $manaBar: JQuery;
    var $healthText: JQuery;
    var $name: JQuery;
    var $effectsBox: JQuery;

    function Update() {
        if (hpWidth < 0) hpWidth = $healthBar.width();
        if (manaWidth < 0) manaWidth = $manaBar.width();

        var maxHP = 1000;
        var curHP = Math.round(Math.random() * maxHP);
        var name = "";
        var effects = "[]";
        if (cu.HasAPI()) {
            curHP = cuAPI.hp;
            maxHP = cuAPI.maxHP;
            name = cuAPI.characterName;
            effects = cuAPI.selfEffects;
        }
        var hpRatio = curHP / maxHP;
        $healthBar.width(hpRatio * hpWidth);
        $healthText.text(curHP + "/" + maxHP);
        $name.text(name);

        var maxMana = 500;
        var curMana = maxMana;
        var manaRatio = curMana / maxMana;
        $manaBar.width(manaRatio * manaWidth);

        if (cachedEffects != effects) {
            var fxList: any = [];

            if (_.isString(effects)) {
                fxList = $.parseJSON(effects);
            }

            $effectsBox.empty(); // TODO: Don't burn effects if they're still alive

            for (var i = 0; i < fxList.length; ++i) {
                var fx = fxList[i];
                var img = $('<img />').attr({ 'class': 'effectIcon', 'src': fx.icon });
                img.appendTo($effectsBox);
            }

            cachedEffects = effects;
        }
    }

    cu.OnInitialized(() => {
        $healthBar = cu.FindElement('#healthBar');

        $manaBar = cu.FindElement('#manaBar');

        $healthText = cu.FindElement('#healthText');

        $name = cu.FindElement('#name');

        $effectsBox = cu.FindElement('#effectsBox');

        // How often we call Update
        var updateFPS = 5;
        cu.RunAtInterval(Update, updateFPS);
    });
}<commit_msg>Move opening of addon UI until after cu has initialised<commit_after>﻿/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/// <reference path="../vendor/jquery.d.ts" />

module Character {

    var hpWidth: number = -1;
    var manaWidth: number = -1;
    var cachedEffects: string = "[]";
    var $healthBar: JQuery;
    var $manaBar: JQuery;
    var $healthText: JQuery;
    var $name: JQuery;
    var $effectsBox: JQuery;

    function Update() {
        if (hpWidth < 0) hpWidth = $healthBar.width();
        if (manaWidth < 0) manaWidth = $manaBar.width();

        var maxHP = 1000;
        var curHP = Math.round(Math.random() * maxHP);
        var name = "";
        var effects = "[]";
        if (cu.HasAPI()) {
            curHP = cuAPI.hp;
            maxHP = cuAPI.maxHP;
            name = cuAPI.characterName;
            effects = cuAPI.selfEffects;
        }
        var hpRatio = curHP / maxHP;
        $healthBar.width(hpRatio * hpWidth);
        $healthText.text(curHP + "/" + maxHP);
        $name.text(name);

        var maxMana = 500;
        var curMana = maxMana;
        var manaRatio = curMana / maxMana;
        $manaBar.width(manaRatio * manaWidth);

        if (cachedEffects != effects) {
            var fxList: any = [];

            if (_.isString(effects)) {
                fxList = $.parseJSON(effects);
            }

            $effectsBox.empty(); // TODO: Don't burn effects if they're still alive

            for (var i = 0; i < fxList.length; ++i) {
                var fx = fxList[i];
                var img = $('<img />').attr({ 'class': 'effectIcon', 'src': fx.icon });
                img.appendTo($effectsBox);
            }

            cachedEffects = effects;
        }
    }

    cu.OnInitialized(() => {
        $healthBar = cu.FindElement('#healthBar');

        $manaBar = cu.FindElement('#manaBar');

        $healthText = cu.FindElement('#healthText');

        $name = cu.FindElement('#name');

        $effectsBox = cu.FindElement('#effectsBox');

        cuAPI.OpenUI("addons.ui");

        // How often we call Update
        var updateFPS = 5;
        cu.RunAtInterval(Update, updateFPS);
    });
}
{'fraction_non_alphanumeric': 0.14030501089324618, 'fraction_numerical': 0.007407407407407408, 'mean_word_length': 1.894703656998739, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3269246', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1408, 'n_words': 371}