/* * Copyright (C) 2016-2020 phantombot.github.io/PhantomBot * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ // Function that querys all of the data we need. $(run = function() { // Check if the module is enabled. socket.getDBValue('death_counter_module', 'modules', './commands/deathctrCommand.js', function(e) { // If the module is off, don't load any data. if (!helpers.handleModuleLoadUp('deathCounterModule', e.modules)) { return; } // Get current game. socket.getDBValue('get_current_stream_info', 'panelData', 'stream', function(e) { socket.getDBValue('get_death_count', 'deaths', JSON.parse(e.panelData).game, function(e) { $('#death-number').html(helpers.parseNumber(helpers.getDefaultIfNullOrUndefined(e.deaths, '0'))); }); }); }); }); // Function that handlers the loading of events. $(function() { var canUpdate = true; // Toggle for the module. $('#deathCounterModuleToggle').on('change', function() { let toggle = $(this).is(':checked'); canUpdate = toggle; // Enable the module then query the data. socket.sendCommandSync('death_counter_module_toggle_cmd', 'module ' + (toggle ? 'enablesilent' : 'disablesilent') + ' ./commands/deathctrCommand.js', run); }); // Increase death button. $('#incr-deaths-button').on('click', function() { // Don't update deaths until new value is set. canUpdate = false; // Get current game. socket.getDBValue('get_current_stream_info', 'panelData', 'stream', function(e) { // Increase the deaths. socket.incrDBValue('incr_deaths_1', 'deaths', JSON.parse(e.panelData).game, '1', function() { // Set the new number. $('#death-number').html(helpers.parseNumber(parseInt($('#death-number').html().replace(/,/g, '')) + 1)); // New value is set so we can let the updates work. canUpdate = true; }); }); }); // Increase death button. $('#decr-deaths-button').on('click', function() { // Don't update deaths until new value is set. canUpdate = false; let deaths = parseInt($('#death-number').html().replace(/,/g, '')); // Make sure we don't go into the negatives. if (deaths < 1) { return; } // Get current game. socket.getDBValue('get_current_stream_info', 'panelData', 'stream', function(e) { // Decrease the deaths. socket.decrDBValue('decr_deaths_1', 'deaths', JSON.parse(e.panelData).game, '1', function() { // Set the new number $('#death-number').html(helpers.parseNumber(deaths - 1)); // New value is set so we can let the updates work. canUpdate = true; }); }); }); // Reset button. $('#reset-deaths-button').on('click', function() { // Don't update deaths until new value is set. canUpdate = false; // Get current game. socket.getDBValue('get_current_stream_info', 'panelData', 'stream', function(e) { // Delete deaths. socket.removeDBValue('rm_deaths_game', 'deaths', JSON.parse(e.panelData).game, function() { // Set the new number. $('#death-number').html('0'); // New value is set so we can let the updates work. canUpdate = true; }); }); }); // Settings button. $('#settings-deaths-button').on('click', function() { // Create custom modal for this module. helpers.getModal('death-settings', 'Death Counter Settings', 'Save', $('
', { 'role': 'form' }) // Main div for the browser source link. .append($('
', { 'class': 'form-group', }) // Append the lable. .append($('