Welcome to IOPWiki, Commander.
We are searching for new editors to keep track of Girls' Frontline 2 content, as well as veteran players to complete existing Girls' Frontline and Project Neural Cloud articles.
You can contribute without an account. Learn how to contribute and join our Discord server.

MediaWiki:Gadget-artTab.js: 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
Added live2d check
Prepared Live2D button
Line 33: Line 33:
   var tdollId = artTabDiv.data('tdollId');
   var tdollId = artTabDiv.data('tdollId');
   var artModelId = tdollId + costumeSuffix;
   var artModelId = tdollId + costumeSuffix;
  var variantswitcher = artTabDiv.find('.variantswitcher');
  // ToDo: Shut down Live2d view
  variantswitcher.find('.right').remove();
    
    
   var basePath = mw.config.get("wgServer") + "/images/";
   var basePath = mw.config.get("wgServer") + "/images/";
Line 52: Line 56:


   var isLive2dPossible = doesLive2dAnimationExist(artTabDiv, costumeSuffix);
   var isLive2dPossible = doesLive2dAnimationExist(artTabDiv, costumeSuffix);
   console.log("Live2D check", isLive2dPossible);
   if (isLive2dPossible) {
    var live2dButton = $('<button></button>');
    live2dButton.addClass('artTabLinks');
    live2dButton.addClass('right');
    live2dButton.click(function() { alert("Not yet implemented :("); });
    live2dButton.text("Live2D");
    variantswitcher.append(live2dButton);
  }
};
};



Revision as of 16:20, 13 January 2018

function switchVariant(event, variant) {
  var currentElement = $(event.target);
  var artTabDiv = currentElement.closest('.artTab');
  artTabDiv.find('.artTabLinks').removeClass('active');
  artTabDiv.find('.artTabContent .fullart').hide();
  
  var live2dActive = false; // ToDo
  if (live2dActive) {
    console.log("?");
  } else {
    artTabDiv.find("[data-variant='" + currentElement.data('variant') +"']").show();
  }

  // Set "active" at the end
  currentElement.addClass('active');
}

function doesLive2dAnimationExist(artTabDiv, costume) {
  var costumeId = costume;
  if (costumeId[0] === '_') {
    costumeId = costumeId.substr(1);
  }
  if (costume == "") {
    costumeId = "costume0";
  }
  
  return $(artTabDiv).attr("data-live2d-exist-" + costumeId) == "true";
}

function modelChanged(event, costumeSuffix) {
  console.log(event);
  var artTabDiv = $(event.target).closest('.artTab');
  var tdollId = artTabDiv.data('tdollId');
  var artModelId = tdollId + costumeSuffix;
  var variantswitcher = artTabDiv.find('.variantswitcher');

  // ToDo: Shut down Live2d view
  variantswitcher.find('.right').remove();
  
  var basePath = mw.config.get("wgServer") + "/images/";
  var cpp = window.gfUtils.createWikiPathPart;
  var fullartPath = basePath + "thumb/" + cpp(artModelId +".png") + artModelId +".png/420px-" + artModelId +".png";
  var fullartDamagedPath = basePath + "thumb/" + cpp(artModelId +"_D.png") + artModelId +"_D.png/420px-" + artModelId +"_D.png";
    
  var normArt = artTabDiv.find(".fullart:not(.damaged) a");
  normArt.attr("href", fullartPath );
  normArt.find('img').attr("src", fullartPath );
  normArt.find('img').attr("srcset", fullartPath );
  normArt.find('img').attr("alt", fullartPath );

  var damagedArt = artTabDiv.find(".fullart.damaged a");
  damagedArt.attr("href", fullartDamagedPath );
  damagedArt.find('img').attr("src", fullartDamagedPath );
  damagedArt.find('img').attr("srcset", fullartDamagedPath );
  damagedArt.find('img').attr("alt", fullartDamagedPath );

  var isLive2dPossible = doesLive2dAnimationExist(artTabDiv, costumeSuffix);
  if (isLive2dPossible) {
    var live2dButton = $('<button></button>');
    live2dButton.addClass('artTabLinks');
    live2dButton.addClass('right');
    live2dButton.click(function() { alert("Not yet implemented :("); });
    live2dButton.text("Live2D");
    variantswitcher.append(live2dButton);
  } 
};

RLQ.push(function () {
  $(document).ready(function() { 
    var artTabDiv = $('.artTab');
    artTabDiv.on('costume_changed', modelChanged);
  
    var normalButton = $('<button></button>');
    normalButton.addClass('artTabLinks');
    normalButton.click(switchVariant);
    normalButton.data('variant', "");
    normalButton.text("Normal");

    var damagedButton = $('<button></button>');
    damagedButton.addClass('artTabLinks');
    damagedButton.click(switchVariant);
    damagedButton.data('variant', "D");
    damagedButton.text("Damaged");
  
    var variantswitcher = $('<div></div>');
    variantswitcher.addClass('variantswitcher');
    variantswitcher.append(normalButton);
    variantswitcher.append(damagedButton);
    
    artTabDiv.prepend(variantswitcher);

    normalButton.click();
  });
});