MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
mNo edit summary
No edit summary
Line 61:
 
 
/* Character stat calc */
mw.loader.load( '/w/index.php?title=MediaWiki:StatCalc.js&action=raw&ctype=text/javascript' );
/* Character affection table - end */
mw.loader.load( '/w/index.php?title=MediaWiki:Affection.js&action=raw&ctype=text/javascript' );
 
 
Line 110 ⟶ 112:
}
/* Character birthdays - end */
 
 
/* Character affection table - start */
const affection_start = 50;
const affection_cap = 50;
var affection_data = {};
var affectionTableCounter = 0;
 
$( document ).ready(function() {
initAffectionTable();
$(".affection-level input").on("change mouseup keyup click", function(){affectionChange($(this).closest("table"), $(this).val());});
$(".affection-data").children("div").on("click", function(){affectionChange($(this).closest("table"),$(this).attr('data-level'));});
});
 
function initAffectionTable(){
$(".character-affectiontable").each(function(){
var id = 'affectionTable-'+(++affectionTableCounter);
$(this).attr('id',id);
var data = {};
 
$(this).find(".affection-data > div").each(function(){
var level = $(this).attr('data-level');
data[level] = {};
var bonus = $(this).attr('data-stats').split(' ');
 
$.each( bonus, function( index ) {
bonus[index] = bonus[index].split('+');
data[level][bonus[index][0]] = parseInt(bonus[index][1]);
});
});
affection_data[id] = data;
 
$(this).find(".affection-level").html('<input type="number" value="'+affection_start+'" step="1" min="1" max="'+affection_cap+'" />');
affectionChange($(this), affection_start);
if (typeof statCalc !== 'undefined') {
affectionGet($(".character-stattable"));
statTableRecalc($(".character-stattable"));
}
});
}
 
function affectionChange (affectionTable, level){
var effective_bonus = {};
var html_out = '';
 
level = (typeof level !== 'undefined' && !isNaN(level)) ? level : 1 ;
if (level < 1) { affectionTable.find(".affection-level input").val(1); level = 1; }
if (level > affection_cap) { affectionTable.find(".affection-level input").val(affection_cap); level = affection_cap; }
 
for (var index = 2; index <= level; index++) {
$.each( affection_data[affectionTable.attr('id')][index], function(stat_name, stat_value){
if (typeof effective_bonus[stat_name] == 'undefined') effective_bonus[stat_name] = 0;
effective_bonus[stat_name] += stat_value;
});
}
$.each( effective_bonus, function(stat_name, stat_value){
html_out += '<b>' + stat_name + '</b>' + ' +' + stat_value + ', ';
});
 
affection_data[affectionTable.attr('id')].current = effective_bonus;
 
if (affectionTable.find(".affection-level input").val() !== level) affectionTable.find(".affection-level input").val(level);
affectionTable.find(".affection-total").html(html_out.substring(0,html_out.length-2));
 
//update StatCalc if present
if (typeof statCalc !== 'undefined') {
affectionGet($(".character-stattable"));
statTableRecalc($(".character-stattable"));
}
}
/* Character affection table - end */
 
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu