Widget:chibiCommander: Difference between revisions
Jump to navigation
Jump to search
Updated loading to new syntax |
Using colorkey for naming |
||
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<includeonly><script> | <includeonly><script> | ||
function initSelects(resourcesUl) { | |||
var resources = {}; | |||
var parts = resourcesUl; | |||
parts.children('li').each(function() { | |||
var part = $(this); | |||
part.typ = part.contents().get(0).nodeValue.trim(); | |||
part.costumes = {}; | |||
part.children('ul').children('li').each(function() { | |||
var costumeLi = $(this); | |||
var costume = {}; | |||
costumeLi.children('ul').children('li').each(function() { | |||
var dataLi = $(this); | |||
var paramFull = dataLi.contents().get(0).nodeValue.trim(); | |||
if (paramFull === "colors") { | |||
dataLi.children('ul').children('li').each(function() { | |||
var colorLi = $(this); | |||
costume.colors = costume.colors || []; | |||
var colorLink = colorLi.children('a').first().attr('href'); | |||
var colorLinkParts = colorLink.split('/'); | |||
costume.colors.push(colorLinkParts[colorLinkParts.length-1]); | |||
}); | |||
} else { | |||
var paramName = paramFull.split(":")[0]; | |||
var paramLink = dataLi.children('a').first().attr('href'); | |||
var paramLinkParts = paramLink.split('/'); | |||
costume[paramName] = paramLinkParts[paramLinkParts.length-1]; | |||
} | |||
}); | |||
costume.costumeId = costumeLi.contents().get(0).nodeValue.trim(); | |||
part.costumes[costume.costumeId] = costume; | |||
}); | |||
resources[part.typ] = part; | |||
}); | |||
for (var partKey in resources) { | |||
var part = resources[partKey]; | |||
for (var costumeKey in part.costumes) { | |||
var costume = part.costumes[costumeKey]; | |||
for (var colorKey in costume.colors) { | |||
var color = costume.colors[colorKey]; | |||
var colName = "(" + colorKey + ")"; | |||
$('.commander-sim-option.' + part.typ).append($('<option>', { | |||
value: costume.skel + ";" + costume.atlas + ";" + color, | |||
text: costume.costumeId + " " + colName | |||
})); | |||
} | |||
} | |||
} | |||
} | |||
RLQ.push(['jquery', function () { | |||
$(document).ready(function() { | $(document).ready(function() { | ||
$('select.commander-sim-option').on('change', function() { | var rendererDiv = $('#cancan'); | ||
mw.loader.using(['ext.gadget.md5hasher', 'ext.gadget.pixiLoader', 'ext.gadget.chibiAnimation']).then(function() { | |||
window.animations.PIXILoader.init().then(function() { | |||
// Let's make sure the correct values are shown | |||
initSelects($('.commander-chibi-controls-panel-resources>ul')); | |||
$('.commander-sim-option').first().change(); | |||
}, function(x,y,z) { | |||
console.error("Loading Spine failed"); | |||
rendererDiv.removeClass("loading"); | |||
} | |||
); | |||
$('select.commander-sim-option').on('change', function() { | |||
var selectedHead = $('.commander-sim-option.head option:selected').val(); | |||
var selectedBody = $('.commander-sim-option.body option:selected').val(); | |||
var selectedFeet = $('.commander-sim-option.feet option:selected').val(); | |||
var baseview = rendererDiv.data('baseview'); | |||
window.loadCommander(rendererDiv, baseview, selectedHead, selectedBody, selectedFeet); | |||
}); | |||
}, function(x,y,z) { | |||
console.error("Loading needed libraries failed"); | |||
rendererDiv.removeClass("loading"); | |||
}); | }); | ||
}); | }); | ||
}]); | }]); | ||
Line 20: | Line 93: | ||
<div class="commander-chibi-controls-panel"> | <div class="commander-chibi-controls-panel"> | ||
<label class="commander-sim-option-label head">Head: | <label class="commander-sim-option-label head">Head: | ||
<select class="gf-droplist commander-sim-option head" autocomplete="off"> | <select class="gf-droplist commander-sim-option head" autocomplete="off"></select> | ||
</label> | </label> | ||
<label class="commander-sim-option-label body">Body: | <label class="commander-sim-option-label body">Body: | ||
<select class="gf-droplist commander-sim-option body" autocomplete="off"> | <select class="gf-droplist commander-sim-option body" autocomplete="off"></select> | ||
</label> | </label> | ||
<label class="commander-sim-option-label feet">Feet: | <label class="commander-sim-option-label feet">Feet: | ||
<select class="gf-droplist commander-sim-option feet" autocomplete="off"> | <select class="gf-droplist commander-sim-option feet" autocomplete="off"></select> | ||
</label> | |||
</div></includeonly><noinclude>{{#widget:chibiCommander}}</noinclude> | </div></includeonly><noinclude>{{#widget:chibiCommander}}</noinclude> |
Latest revision as of 14:40, 28 November 2019