Open main menu

Changes

MediaWiki:Gadget-artTab.js

1,606 bytes removed, 15:07, 14 October 2019
Added document-ready wait functionality as the MediaWiki does not wait for DOM
function switchVariant(eventartTabDivElement, variant) { var currentElement artTabDiv = $(eventartTabDivElement); artTabDiv.targetfind('.artTabLinks').removeClass('active'); switchVariantForElementartTabDiv.attr(currentElement'data-tdoll-variant', variant);  refreshView(artTabDiv); // Set "active" at the end artTabDiv.find(".artTabLinks[data-tdoll-variant='" + variant + "']").addClass('active');
}
function switchVariantForElementrefreshView(currentElement, variantartTabDiv) { var artTabDiv tdoll = currentElement.closest$('.artTab'); artTabDiv.find('.artTabLinks').removeClassdata('activetdollId'); var costume = $(artTabDiv).findattr('.artTabContent .fullartdata-tdoll-costume').hide(); var variant = $(artTabDiv).dataattr('tdollVariantdata-tdoll-variant', variant);// why not data though?
var tdoll = $(artTabDiv).datafind('tdollId'); var costume = artTabDiv.data('tdollCostumeartTabContent .fullart'); var variant = artTabDiv.data('tdollVariant'); var modelId = tdoll; if (costume != "") modelId += "_" + costume; if hide(variant != "") modelId += "_" + variant;
var live2dActive = $(artTabDiv).find('.live2dstage').is(':visible');
$(artTabDiv).addClass("loading");
if (live2dActive) {
createLive2dView(artTabDiv, function(view) {
view.show();
var stage = view.data('live2dStage');
stage.removeChildren(); var live2dData anythingFailedHandler = loadLive2dDatafunction(x,y,z) { view.closest(".artTab").removeClass(modelId"loading"); console.log("Failed loading Live2D", x, y, z); }; var loadLive2DgirlSuccessHandler = function(live2dData) { view.closest(".artTab").removeClass("loading"); stage.addChild(live2dData); };  var loadLive2DsuccessHandler = function() { gfUtils.live2dUtils.loadLive2dGirl($(artTabDiv), tdoll, costume, variant, loadLive2DgirlSuccessHandler, anythingFailedHandler); }; mw.loader.using('ext.gadget.live2dAnimation').then(loadLive2DsuccessHandler, anythingFailedHandler);
});
} else {
$(artTabDiv).find(".fullart[data-variant='" + currentElement.data('variant') +"']").show(); $(artTabDiv).removeClass("loading");
}
 
// Set "active" at the end
currentElement.addClass('active');
}
}
function getLive2dModelcreateLive2dSprite(modelId) { var model = {}; model.type = "Live2D Model Setting"; model.name = modelId; model.model = curl(modelId + "_live2d_model.moc.skel"); model.textures = []; model.textures.push(curl(modelId + "_live2d_texture_00.png")); model.physics = curl(modelId + "_live2d_physics.txt"); model.pose = curl(modelId + "_live2d_pose.txt"); model.expressions = []; model.layout = {}; model.hit_areas = []; model.hit_areas.push({"name":"bodybroken", "id":"D_REF.BODYBROKEN"}); model.hit_areas.push({"name":"head", "id":"D_REF.HEAD"}); model.hit_areas.push({"name":"leg", "id":"D_REF.LEG"}); model.hit_areas.push({"name":"body", "id":"D_REF.BODY"}); model.motions = {}; model.motions.idle = []; model.motions.idle.push({"file": curl(modelId + "_live2d_idle.mtn.txt")}); model.motions.idle.push({"file": curl(modelId + "_live2d_idle_01.mtn.txt")}); model.motions.idle.push({"file": curl(modelId + "_live2d_idle_02.mtn.txt")}); model.motions.idle.push({"file": curl(modelId + "_live2d_wait_1.mtn.txt")}); model.motions.idle.push({"file": curl(modelId + "_live2d_wait_2.mtn.txt")}); model.motions.tap_figure = []; model.motions.tap_figure.push({"file": curl(modelId + "_live2d_broken_1.mtn.txt")}); model.motions.tap_figure.push({"file": curl(modelId + "_live2d_broken_2.mtn.txt")}); model.motions.tap_figure.push({"file": curl(modelId + "_live2d_broken_3.mtn.txt")}); model.motions.tap_figure.push({"file": curl(modelId + "_live2d_broken_4.mtn.txt")}); model.motions.tap_figure.push({"file": curl(modelId + "_live2d_touch_1.mtn.txt")}); model.motions.tap_figure.push({"file": curl(modelId + "_live2d_touch_2.mtn.txt")}); model.motions.tap_figure.push({"file": curl(modelId + "_live2d_touch_3.mtn.txt")}); model.motions.tap_figure.push({"file": curl(modelId + "_live2d_touch_4.mtn.txt")}); model.motions.tap_figure.push({"file": curl(modelId + "_live2d_touch_5.mtn.txt")}); model.motions.tap_figure.push({"file": curl(modelId + "_live2d_shake.mtn.txt")}); model.motions.tap_figure.push({"file": curl(modelId + "_live2d_login.mtn.txt")}); model.motions.tap_figure.push({"file": curl(modelId + "_live2d_wedding.mtn.txt")}); model.motions.tap_figure.push({"file": curl(modelId + "_live2d_wedding_touch.mtn.txt")}); return model;} function loadLive2dGirl(tdoll, costume, variant) { var modelId = tdoll; if (costume.length > 0) { modelId = modelId + "_" + costume; } if (variant && variant.length > 0) { modelId = modelId + "_" + variant; } var model = getLive2dModel(modelId);
// Live 2D Sprite
var l2d_tdoll_sprite = new PIXI.Live2DSprite(model, {
debugLog: false,
randomMotion: false,
defaultMotionGroup: "idle",
eyeBlink: true
});
}
});
return l2d_tdoll_sprite;
}
stage.removeChildren();
}
 
refreshView(artTabDiv);
}
mw.loader.using('ext.gadget.live2d').then( function () {
// Init renderer
const l2d_tdoll_renderer = PIXI.autoDetectRenderer(500550, 500550,{transparent: true});
const l2d_tdoll_stage = new PIXI.Container();
costumeId = costumeId.substr(1);
}
artTabDiv.dataattr('tdollCostumedata-tdoll-costume', costumeId);
hideLive2dView(artTabDiv);
variantswitcherartTabDiv.find('.rightartTabLive2dSwitch').remove();
var basePath = mw.config.get("wgServer") + "/images/";
var cpp = window.gfUtils.createWikiPathPart;
var fullartPath = basePath + "thumb/" + cpp(artModelId +".png") + artModelId +".png/420px600px-" + artModelId +".png"; var fullartDamagedPath = basePath + "thumb/" + cpp(artModelId +"_D.png") + artModelId +"_D.png/420px600px-" + artModelId +"_D.png";
var normArt = artTabDiv.find(".fullart:not(.damaged) a");
normArt.attr("href", fullartPath "/wiki/File:" + artModelId + ".png");
normArt.find('img').attr("src", fullartPath );
normArt.find('img').attr("srcset", fullartPath );
var damagedArt = artTabDiv.find(".fullart.damaged a");
damagedArt.attr("href", fullartDamagedPath "/wiki/File:" + artModelId + "_D.png");
damagedArt.find('img').attr("src", fullartDamagedPath );
damagedArt.find('img').attr("srcset", fullartDamagedPath );
var isLive2dPossible = doesLive2dAnimationExist(artTabDiv, costumeSuffix);
if (isLive2dPossible) {
var live2dButton live2dButtonHandler = $('<button></button>'); live2dButton.addClass('artTabLinks'); live2dButton.addClass('right'); live2dButton.click(function() {
if (live2dButton.is('.enabled')) {
hideLive2dView($(artTabDiv));
live2dButton.removeClass('enabled');
} else {
$(artTabDiv).addClass("loading");
createLive2dView(artTabDiv, function(view) {
view.show();
$(artTabDiv).find('.artTabContent').first().append(view);
switchVariantForElementrefreshView(view, view.closest('.artTab').data('tdollVariant')artTabDiv);
});
live2dButton.addClass('enabled');
}
}); var live2dButton= gfUtils.textcreateSliderButton("Live2Dhttp://en.gfwiki.com/images/a/a3/live2d-logo.png", live2dButtonHandler); variantswitcherlive2dButton.addClass('artTabLive2dSwitch'); artTabDiv.append(live2dButton); } refreshView(artTabDiv);};
RLQ.push(['jquery', function () { $(document).ready(function() {
var artTabDiv = $('.artTab');
artTabDiv.on('costume_changed', modelChanged);
 
var buttonEventHandler = function(event) {
var currentElement = $(event.target);
var currentArtTab = currentElement.closest('.artTab');
var variant = currentElement.data('tdollVariant');
switchVariant(currentArtTab, variant);
};
var normalButton = $('<button></button>');
normalButton.addClass('artTabLinks');
normalButton.click(switchVariantbuttonEventHandler); normalButton.dataattr('data-tdoll-variant', "");
normalButton.text("Normal");
var damagedButton = $('<button></button>');
damagedButton.addClass('artTabLinks');
damagedButton.click(switchVariantbuttonEventHandler); damagedButton.dataattr('data-tdoll-variant', "D");
damagedButton.text("Damaged");
normalButton.click();
});
}]);