Welcome to IOPWiki, Commander.
We are searching for editors to complete gameplay topics in all games. You can contribute without an account. Learn how to contribute and join our Discord server.

Widget:costumeSwitcher: Difference between revisions

Welcome to IOP Wiki. This website is maintained by the Girls' Frontline community and is free to edit by anyone.
Jump to navigation Jump to search
First try finding out the right path
Added document-ready wait functionality as the MediaWiki does not wait for DOM
 
(26 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<includeonly><script>
<includeonly><script>
/* This part is a md5 hash generator */
RLQ.push(['jquery', function () {
function md5cycle(f,h){var i=f[0],n=f[1],r=f[2],g=f[3];i=ff(i,n,r,g,h[0],7,-680876936),g=ff(g,i,n,r,h[1],12,-389564586),r=ff(r,g,i,n,h[2],17,606105819),n=ff(n,r,g,i,h[3],22,-1044525330),i=ff(i,n,r,g,h[4],7,-176418897),g=ff(g,i,n,r,h[5],12,1200080426),r=ff(r,g,i,n,h[6],17,-1473231341),n=ff(n,r,g,i,h[7],22,-45705983),i=ff(i,n,r,g,h[8],7,1770035416),g=ff(g,i,n,r,h[9],12,-1958414417),r=ff(r,g,i,n,h[10],17,-42063),n=ff(n,r,g,i,h[11],22,-1990404162),i=ff(i,n,r,g,h[12],7,1804603682),g=ff(g,i,n,r,h[13],12,-40341101),r=ff(r,g,i,n,h[14],17,-1502002290),n=ff(n,r,g,i,h[15],22,1236535329),i=gg(i,n,r,g,h[1],5,-165796510),g=gg(g,i,n,r,h[6],9,-1069501632),r=gg(r,g,i,n,h[11],14,643717713),n=gg(n,r,g,i,h[0],20,-373897302),i=gg(i,n,r,g,h[5],5,-701558691),g=gg(g,i,n,r,h[10],9,38016083),r=gg(r,g,i,n,h[15],14,-660478335),n=gg(n,r,g,i,h[4],20,-405537848),i=gg(i,n,r,g,h[9],5,568446438),g=gg(g,i,n,r,h[14],9,-1019803690),r=gg(r,g,i,n,h[3],14,-187363961),n=gg(n,r,g,i,h[8],20,1163531501),i=gg(i,n,r,g,h[13],5,-1444681467),g=gg(g,i,n,r,h[2],9,-51403784),r=gg(r,g,i,n,h[7],14,1735328473),n=gg(n,r,g,i,h[12],20,-1926607734),i=hh(i,n,r,g,h[5],4,-378558),g=hh(g,i,n,r,h[8],11,-2022574463),r=hh(r,g,i,n,h[11],16,1839030562),n=hh(n,r,g,i,h[14],23,-35309556),i=hh(i,n,r,g,h[1],4,-1530992060),g=hh(g,i,n,r,h[4],11,1272893353),r=hh(r,g,i,n,h[7],16,-155497632),n=hh(n,r,g,i,h[10],23,-1094730640),i=hh(i,n,r,g,h[13],4,681279174),g=hh(g,i,n,r,h[0],11,-358537222),r=hh(r,g,i,n,h[3],16,-722521979),n=hh(n,r,g,i,h[6],23,76029189),i=hh(i,n,r,g,h[9],4,-640364487),g=hh(g,i,n,r,h[12],11,-421815835),r=hh(r,g,i,n,h[15],16,530742520),n=hh(n,r,g,i,h[2],23,-995338651),i=ii(i,n,r,g,h[0],6,-198630844),g=ii(g,i,n,r,h[7],10,1126891415),r=ii(r,g,i,n,h[14],15,-1416354905),n=ii(n,r,g,i,h[5],21,-57434055),i=ii(i,n,r,g,h[12],6,1700485571),g=ii(g,i,n,r,h[3],10,-1894986606),r=ii(r,g,i,n,h[10],15,-1051523),n=ii(n,r,g,i,h[1],21,-2054922799),i=ii(i,n,r,g,h[8],6,1873313359),g=ii(g,i,n,r,h[15],10,-30611744),r=ii(r,g,i,n,h[6],15,-1560198380),n=ii(n,r,g,i,h[13],21,1309151649),i=ii(i,n,r,g,h[4],6,-145523070),g=ii(g,i,n,r,h[11],10,-1120210379),r=ii(r,g,i,n,h[2],15,718787259),n=ii(n,r,g,i,h[9],21,-343485551),f[0]=add32(i,f[0]),f[1]=add32(n,f[1]),f[2]=add32(r,f[2]),f[3]=add32(g,f[3])}function cmn(f,h,i,n,r,g){return h=add32(add32(h,f),add32(n,g)),add32(h<<r|h>>>32-r,i)}function ff(f,h,i,n,r,g,t){return cmn(h&i|~h&n,f,h,r,g,t)}function gg(f,h,i,n,r,g,t){return cmn(h&n|i&~n,f,h,r,g,t)}function hh(f,h,i,n,r,g,t){return cmn(h^i^n,f,h,r,g,t)}function ii(f,h,i,n,r,g,t){return cmn(i^(h|~n),f,h,r,g,t)}function md51(f){txt="";var h,i=f.length,n=[1732584193,-271733879,-1732584194,271733878];for(h=64;h<=f.length;h+=64)md5cycle(n,md5blk(f.substring(h-64,h)));f=f.substring(h-64);var r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(h=0;h<f.length;h++)r[h>>2]|=f.charCodeAt(h)<<(h%4<<3);if(r[h>>2]|=128<<(h%4<<3),h>55)for(md5cycle(n,r),h=0;16>h;h++)r[h]=0;return r[14]=8*i,md5cycle(n,r),n}function md5blk(f){var h,i=[];for(h=0;64>h;h+=4)i[h>>2]=f.charCodeAt(h)+(f.charCodeAt(h+1)<<8)+(f.charCodeAt(h+2)<<16)+(f.charCodeAt(h+3)<<24);return i}function rhex(f){for(var h="",i=0;4>i;i++)h+=hex_chr[f>>8*i+4&15]+hex_chr[f>>8*i&15];return h}function hex(f){for(var h=0;h<f.length;h++)f[h]=rhex(f[h]);return f.join("")}function md5(f){return hex(md51(f))}function add32(f,h){return f+h&4294967295}function add32(f,h){var i=(65535&f)+(65535&h),n=(f>>16)+(h>>16)+(i>>16);return n<<16|65535&i}var hex_chr="0123456789abcdef".split("");"5d41402abc4b2a76b9719d911017c592"!=md5("hello");
  $(document).ready(function() {
    // Let's make sure the correct values are shown
    $('.modswitcher').change();
  });
}]);


function createPathPart(filename) {
function swap_mod(element) {
   var hash = md5(filename);
   var selectBox = $(element);
   return hash[0] + "/" + hash[0] + hash[1] + "/";
   var selectedValue = selectBox.find(':selected').val();
  var tmp = new DOMParser().parseFromString(selectedValue, "text/html");
  var tdollData = jQuery.parseJSON(tmp.documentElement.textContent);
 
  var statContainer = selectBox.closest('.stattable');
 
  tdollData = updateCalculatedValues(tdollData);
 
  for (var key in tdollData) {
    if (tdollData.hasOwnProperty(key)) {
      var valField = statContainer.find('*[data-tdoll-stat-id="' + key + '"]');
      var newValue = tdollData[key];
      valField.text(newValue);
    }
  }
 
  // ToDo: find a better way of finding out if it's a mod
  // ToDo: find a better way of telling which skills are available with which mod
  var isMod = selectBox.find(':selected').text().indexOf('MOD') >= 0;
  statContainer.find('.skillform .tabButtonLane button').last().toggle(isMod);
 
  // With mod-change the visible skillbuttons might change, too, so trigger the last visible one
  // For now it only has to be set if we change to Base, as it has only one skill
  if (!isMod) {
    statContainer.find('.skillform .tabButtonLane button:visible').last().click();
  }
}
 
function updateCalculatedValues(data) {
  var ret = data;
 
  // Calculating Max HP for full dummied T-Doll
  if (ret.hasOwnProperty("max_hp_t")) {
    ret.hpmaxwd = ret.max_hp_t * 5;
  }
 
  return ret;
}
}


function swap_costume(element) {
function swap_costume(element) {
    var neededGadgets = [ 'ext.gadget.md5hasher' ];
    if (mw.user.options.get("gadget-chibiAnimation") == 1) {
      neededGadgets.push("ext.gadget.chibiAnimation");
    }
    if (mw.user.options.get("gadget-live2dAnimation") == 1) {
      neededGadgets.push("ext.gadget.live2dAnimation");
    }
   
    // Switch costume when everything is ready
    mw.loader.using(neededGadgets).then(function () {
      swap_costume_intern(element);
    });
}
function swap_costume_intern(element) {
         var selectBox = $(element);
         var selectBox = $(element);
          
          
Line 18: Line 73:
         }
         }


         selectBox.closest('.costumeContainer').find('.chibiAnimation,.live2dAnimation').trigger("costume_changed", chibiCostumeName);
         selectBox.closest('.costumeContainer').find('.chibiAnimation,.live2dAnimation,.artTab').trigger("costume_changed", chibiCostumeName);
          
          
         var basePath = "http://en.gfwiki.com/images/"; // ToDo: find a better way to find out the base path
         var basePath = "https://en.gfwiki.com/images/"; // ToDo: find a better way to find out the base path
         var tdollId = selectBox.closest('.costumeContainer').find('.tdoll_chibi').data('tdollId');
         var tdollId = selectBox.closest('.costumeContainer').find('.tdoll_chibi').data('tdollId');
         var costumeId = tdollId + chibiCostumeName;
         var costumeId = tdollId + chibiCostumeName;
 
       
         var fullartPath = basePath + "thumb/" + createPathPart(costumeId +".png") + costumeId +".png/420px-" + costumeId +".png";
         var cpp = window.gfUtils.createWikiPathPart;
         var fullartDamagedPath = basePath + "thumb/" + createPathPart(costumeId +"_D.png") + costumeId +"_D.png/420px-" + costumeId +"_D.png";
          
         var fullartSPath = basePath + createPathPart(costumeId +"_S.png") + costumeId +"_S.png";
         var fullartSPath = basePath + cpp (costumeId +"_S.png") + costumeId +"_S.png";
         var chibiPath = basePath + createPathPart(costumeId +"_chibi.png") + costumeId +"_chibi.png";
         var chibiPath = basePath + cpp(costumeId +"_chibi.png") + costumeId +"_chibi.png";
 
       
        console.log(fullartPath);
        console.log(fullartDamagedPath);
        console.log(fullartSPath);
        console.log(chibiPath);
 
        $("#fullart a").attr("href", fullartPath );
        $("#fullart a img").attr("src", fullartPath );
        $("#fullart a img").attr("srcset", fullartPath );
        $("#fullart a img").attr("alt", fullartPath );
 
        $("#fullart_D a").attr("href", fullartDamagedPath );
        $("#fullart_D a img").attr("src", fullartDamagedPath );
        $("#fullart_D a img").attr("srcset", fullartDamagedPath );
        $("#fullart_D a img").attr("alt", fullartDamagedPath );
         $("#fullart_S").attr("src", fullartSPath);
         $("#fullart_S").attr("src", fullartSPath);
         $("#fullart_S").attr("srcset", fullartSPath);
         $("#fullart_S").attr("srcset", fullartSPath);


         $(".tdoll_chibi img").attr("src", chibiPath);
         $(".tdoll_chibi>img").attr("src", chibiPath);
 
          
          
         // As we change the link, we have to update the Thumb-Cache of the Media Viewer
         // As we change the link, we have to update the Thumb-Cache of the Media Viewer
Line 63: Line 102:
}
}


</script><select class="skill" style="background-color:rgba(250,250,250,0.9);width:100%" autocomplete="off" onchange="swap_costume(this)" >
</script>
<div style="display:flex">
<!--{if $moddable neq ''}--><select class="gf-droplist modswitcher" style="padding-left: 2px;padding-right: 8px;margin-right: 2px;" autocomplete="off" onchange="swap_mod(this)">
<option value='<!--{$defaultstats|escape:'html'}-->'>BASE</option>
<option value='<!--{$mod1stats|escape:'html'}-->'>MOD1</option>
<option value='<!--{$mod2stats|escape:'html'}-->'>MOD2</option>
<option value='<!--{$mod3stats|escape:'html'}-->' selected="selected">MOD3</option>
</select><!--{/if}-->
<select class="gf-droplist" style="flex-grow: 1;" autocomplete="off" onchange="swap_costume(this)" >
<option value="<!--{$defaultpaths|escape:'html'}-->" selected="selected">Default</option>
<option value="<!--{$defaultpaths|escape:'html'}-->" selected="selected">Default</option>
<!--{if $costume1name neq ''}--><option value="<!--{$costume1paths|escape:'html'}-->"><!--{$costume1name|escape:'html'}--></option><!--{/if}-->
<!--{if $costume1name neq ''}--><option value="<!--{$costume1paths|escape:'html'}-->"><!--{$costume1name|escape:'html'}--></option><!--{/if}-->
Line 70: Line 117:
<!--{if $costume4name neq ''}--><option value="<!--{$costume4paths|escape:'html'}-->"><!--{$costume4name|escape:'html'}--></option><!--{/if}-->
<!--{if $costume4name neq ''}--><option value="<!--{$costume4paths|escape:'html'}-->"><!--{$costume4name|escape:'html'}--></option><!--{/if}-->
<!--{if $costume5name neq ''}--><option value="<!--{$costume5paths|escape:'html'}-->"><!--{$costume5name|escape:'html'}--></option><!--{/if}-->
<!--{if $costume5name neq ''}--><option value="<!--{$costume5paths|escape:'html'}-->"><!--{$costume5name|escape:'html'}--></option><!--{/if}-->
</select></includeonly>
</select></div></includeonly>


<noinclude>
<noinclude>
Line 78: Line 125:
|defaultpaths={{filepath:Springfield.png|420}},,{{filepath:Springfield_D.png|420}},,{{filepath:Springfield_S.png|420}},,{{filepath:Springfield_chibi.png|420}}
|defaultpaths={{filepath:Springfield.png|420}},,{{filepath:Springfield_D.png|420}},,{{filepath:Springfield_S.png|420}},,{{filepath:Springfield_chibi.png|420}}
|costume1name=test1
|costume1name=test1
|moddable=1
|costume1paths={{filepath:Springfield_costume1.png|420}},,{{filepath:Springfield_costume1_D.png|420}},,{{filepath:Springfield_costume1_S.png|420}},,{{filepath:Springfield_costume1_chibi.png|420}}
|costume1paths={{filepath:Springfield_costume1.png|420}},,{{filepath:Springfield_costume1_D.png|420}},,{{filepath:Springfield_costume1_S.png|420}},,{{filepath:Springfield_costume1_chibi.png|420}}
|costume2name=test2
|costume2name=test2

Latest revision as of 15:07, 14 October 2019


test