webxoss-client/DeckEditor/DeckEditor.js

1 line
9.6 KiB
JavaScript
Raw Normal View History

2017-08-20 17:43:42 +02:00
"use strict";function callConstructor(e){var n=e.bind.apply(e,arguments);return new n}function applyToConstructor(e,n){var t=concat(null,toArr(n)),r=e.bind.apply(e,t);return new r}function nextTick(e){setTimeout(e,0)}function hide(e){e.style.display="none"}function show(e){e.style.display=""}function disable(e){e.disabled=!0}function enable(e){e.disabled=!1}function newElement(e){for(var n=document.createElement(e),t=1;t<arguments.length;t++)n.classList.add(arguments[t]);return n}function getImageUrlByPid(e){return imageManager.getUrlByPid(e)}function search(){var e=$("search-input").value;results=searcher.search(e),showResults()}function showResults(){_shown=0,$("search-list").innerHTML="",showMore()}function showMore(){for(var e=0;e<RESULTS_LENGTH;e++){var n=_shown;if(n>=results.length)break;var t=results[n],r=newElement("li"),c=new Image;c.src=getImageUrlByPid(t.pid),c.alt=Localize.cardName(t),c.title=Localize.cardName(t),c.onmousemove=showDetail.bind(null,t),c.onclick=addCardByInfo.bind(null,t,!1),r.appendChild(c),$("search-list").appendChild(r),_shown++}_shown<results.length?show($("search-show-more")):hide($("search-show-more"))}function showDetail(e){detail.show(e.pid)}function updateDeckList(){return $("select-decks").innerHTML="",deckNames=deckManager.getDeckNames(),deckNames.length?void deckNames.forEach(function(e){var n=newElement("option");n.textContent=e,$("select-decks").appendChild(n)},this):void createDeck("WHITE_HOPE",whiteHope)}function loadDeck(e){var n=deckManager.loadDeck(e);removeAllCards(mainData),n.mainDeck.forEach(function(e){var n=CardInfo[e];addCardByInfo(n,!0)}),removeAllCards(lrigData),n.lrigDeck.forEach(function(e){var n=CardInfo[e];addCardByInfo(n,!0)}),updateDeck(mainData),updateDeck(lrigData)}function saveDeck(e){deckManager.saveDeck(e,getCurrentDeck())}function createDeck(e,n){if(!e)return!1;var t=deckNames.indexOf(e);return t>=0?void selectDeck(t):(deckManager.createDeck(e,n||getCurrentDeck()),updateDeckList(),t=deckNames.indexOf(e),void selectDeck(t))}function deleteDeck(e){var n=deckIndex;deckManager.deleteDeck(e),updateDeckList(),n>=deckNames.length&&(n=deckNames.length-1),selectDeck(n)}function renameDeck(e){var n=deckName;createDeck(e),deleteDeck(n)}function selectDeck(e){deckIndex=e,deckName=deckNames[e],loadDeck(deckName),$("select-decks").selectedIndex=e}function getCurrentDeck(){var e={};return e.mainDeck=mainData.deckObjs.map(function(e){return e.info.pid}),e.lrigDeck=lrigData.deckObjs.map(function(e){return e.info.pid}),e}function dataToPids(e){return e.deckObjs.map(function(e){return e.info.pid})}function addCardByInfo(e,n){var t;t="LRIG"===e.cardType||"ARTS"===e.cardType||"RESONA"===e.cardType?lrigData:mainData,t.deckObjs.length>=t.limit||(t.deckObjs.push({idx:t.deckObjs.length,info:e,img:null}),n||(updateDeck(t),saveDeck(deckName)))}function removeCardByIndex(e,n,t){e.zone.removeChild(e.deckObjs[n].img),e.deckObjs.splice(n,1),updateDeck(e),t||saveDeck(deckName)}function removeAllCards(e){e.zone.innerHTML="",e.deckObjs.length=0}function updateDeck(e){defaultSort(e);var n,t,r=dataToPids(e);"main"===e.deck?(n=deckManager.checkMainDeck(r),t=$("main-deck-title"),$("main-deck-burst-count").textContent=deckManager.burstCount(r)):(n=deckManager.checkLrigDeck(r),t=$("lrig-deck-title")),n?t.classList.remove("invalid"):t.classList.add("invalid"),t=$("main-deck-mayus-room"),n=deckManager.checkMayusRoom(dataToPids(mainData).concat(dataToPids(lrigData))),n?t.classList.remove("invalid"):t.classList.add("invalid"),e.deckObjs.forEach(function(n,t){var r=n.info,c=n.img;c||(c=new Image,c.src=getImageUrlByPid(r.pid),c.alt=Localize.cardName(r),c.onmousemove=showDetail.bind(null,r),n.img=c,e.zone.appendChild(c)),c.onclick=removeCardByIndex.bind(null,e,t,!1),c.style.left=t%10*WIDTH+"px",c.style.top=Math.floor(t/10)*HEIGHT+"px"},this)}function defaultSort(e){e.deckObjs.sort(function(e,n){var t=e.info,r=n.info,c=e.idx,a=n.idx;if("LRIG"===t.cardType){if("LRIG"!==r.cardType)return-1;if(r.level!==t.level)return t.level-r.level}if("ARTS"===t.cardType&&"ARTS"!==r.cardType)return 1;if("RESONA"===t.car