mirror of
https://github.com/webxoss/webxoss-client.git
synced 2024-11-20 05:49:55 +01:00
1 line
No EOL
14 KiB
JavaScript
1 line
No EOL
14 KiB
JavaScript
"use strict";function callConstructor(e){var r=e.bind.apply(e,arguments);return new r}function applyToConstructor(e,r){var t=concat(null,toArr(r)),n=e.bind.apply(e,t);return new n}function nextTick(e){setTimeout(e,0)}function DeckManager(){this.getDeckNames()}function TextualRule(e,r,t){this.prop=e,this.map=r,this.exact=t}function NumericRule(e,r){this.prop=e,this.keywords=r}function Searcher(){this.infos=[];for(var e in CardInfo)this.infos.push(CardInfo[e]);this.rules=[ColorRule,CrossRule,TypeRule,RarityRule,SkillRule,NoBurstRule,TimmingRule,LimitingRule,ClassRule,PowerRule,LevelRule,LimitRule,NumberRule,IllustRule,WxidRule,NameRule]}var concat=Array.prototype.concat.bind([]),toArr=function(e){return e?"string"==typeof e?[]:Array.prototype.slice.call(e,0):[]},isArr=Array.isArray,inArr=function(e,r){return toArr(r).indexOf(e)!=-1},removeFromArr=function(e,r){var t=r.indexOf(e);return!(t<0)&&(r.splice(t,1),!0)},isStr=function(e){return"string"==typeof e},isObj=function(e){return e&&"object"==typeof e&&!isArr(e)},isNum=function(e){return"number"==typeof e},isFunc=function(e){return"function"==typeof e},pEach=function(e,r,t){return e.reduce(function(e,t){return e.then(function(){return r(t)})},Promise.resolve())};DeckManager.prototype.getDeckNames=function(){var e=localStorage.getItem("deck_filenames");return this._deckNames=e?JSON.parse(e):[],this._deckNames},DeckManager.prototype._updateDeckNames=function(){this._deckNames.sort(),localStorage.setItem("deck_filenames",JSON.stringify(this._deckNames))},DeckManager.prototype.createDeck=function(e,r){return!inArr(e,this._deckNames)&&(this._deckNames.push(e),this._updateDeckNames(),this.saveDeck(e,r),!0)},DeckManager.prototype.renameDeck=function(e,r){if(!inArr(e,this._deckNames))return!1;if(inArr(r,this._deckNames))return!1;var t=this.loadDeck(e);return this.deleteDeck(e),this.createDeck(r,t),!0},DeckManager.prototype.deleteDeck=function(e){return!!removeFromArr(e,this._deckNames)&&(this._updateDeckNames(),localStorage.removeItem("deck_file_"+e),!0)},DeckManager.prototype.loadDeck=function(e){var r=localStorage.getItem("deck_file_"+e);return r?JSON.parse(r):null},DeckManager.prototype.saveDeck=function(e,r){return!!inArr(e,this._deckNames)&&(localStorage.setItem("deck_file_"+e,JSON.stringify(r)),!0)},DeckManager.prototype.checkMainDeck=function(e){if(!isArr(e))return!1;if(40!==e.length)return!1;for(var r=[],t=0;t<e.length;t++){var n=CardInfo[e[t]];if(!n)return!1;if(n=CardInfo[n.cid],!n)return!1;r.push(n)}return!r.some(function(e){return"LRIG"===e.cardType||("ARTS"===e.cardType||("RESONA"===e.cardType||void 0))})&&(20===this.burstCount(e)&&(!!this.checkDuplicate(e)&&r))},DeckManager.prototype.checkLrigDeck=function(e){if(!isArr(e))return!1;if(e.length>10)return!1;for(var r=[],t=0;t<e.length;t++){var n=CardInfo[e[t]];if(!n)return!1;if(n=CardInfo[n.cid],!n)return!1;r.push(n)}return!r.some(function(e){return"SIGNI"===e.cardType||("SPELL"===e.cardType||void 0)})&&(!!r.some(function(e){return"LRIG"===e.cardType&&0===e.level})&&(!!this.checkDuplicate(e)&&r))},DeckManager.prototype.checkMayusRoom=function(e){for(var r=[],t=0;t<e.length;t++){var n=CardInfo[e[t]];if(!n)return!1;if(n=CardInfo[n.cid],!n)return!1;r.push(n)}if(r.some(function(e){return 33===e.cid})&&r.some(function(e){return 34===e.cid||84===e.cid}))return!1;if(r.some(function(e){return 1202===e.cid})&&r.some(function(e){return 884===e.cid||1369===e.cid}))return!1;if(r.some(function(e){return 534===e.cid})&&r.some(function(e){return 408===e.cid||570===e.cid}))return!1;if(r.some(function(e){return 814===e.cid})&&r.some(function(e){return 1090===e.cid}))return!1;if(r.some(function(e){return 649===e.cid})&&r.some(function(e){return 1562===e.cid}))return!1;if(r.some(function(e){return 957===e.cid})&&r.some(function(e){return 1652===e.cid}))return!1;for(var i={37:2,34:2,178:2,534:1,474:0,23:0,689:0,1030:0,1457:0},t=0;t<r.length;t++){var n=r[t],u=n.cid;if(u in i&&(i[u]--,i[u]<0))return!1}return!0},DeckManager.prototype.checkDeck=function(e,r){var t=this.checkMainDeck(e.mainDeck)&&this.checkLrigDeck(e.lrigDeck);return!!t&&(r===!1||this.checkMayusRoom(e.mainDeck.concat(e.lrigDeck)))},DeckManager.prototype.burstCount=function(e){var r=0;return e.forEach(function(e){var t=CardInfo[e];t=CardInfo[t.cid],t.burstEffectTexts&&t.burstEffectTexts.length&&r++}),r},DeckManager.prototype.checkDuplicate=function(e){var r={};e.forEach(function(e){var t=CardInfo[e];t.sideA&&(t=CardInfo[t.sideA]),t.cid in r?r[t.cid]++:r[t.cid]=1});for(var t in r)if(r[t]>4)return!1;return!0},TextualRule.prototype.parse=function(e){for(var r=[],t=0;t<e.length;t++){var n=e[t],i=this.parseWord(n);i&&(r.push(i),e.splice(t,1),t--)}var u=this.prop,o=this.exact;return function(e){return!r.length||r.some(function(r){var t=e[u].toLowerCase();return o?t===r:t.indexOf(r)!==-1})}},TextualRule.prototype.parseWord=function(e){for(var r in this.map){var t=this.map[r];if(t.some(function(r){return e===Localize.traditionalize(r)},this))return r}return null};var ColorRule=new TextualRule("color",{colorless:["colorless","无","无色","無","incolore","무","무색"],white:["white","白","白色","白","белая","bianco","백","백색"],black:["black","黑","黑色","黒","чёрная","nero","흑","흑색"],red:["red","红","红色","赤","красная","rosso","적","적색"],blue:["blue","蓝","蓝色","青","синяя","blu","청","청색"],green:["green","绿","绿色","緑","зелёная","verde","녹","녹색"]},!1),TypeRule=new TextualRule("cardType",{lrig:["l","lrig","分身","ルリグ","идел","루리그"],signi:["s","signi","精灵","シグニ","запись","시그니"],spell:["spell","魔法","スペル","магия","스펠"],arts:["arts","必杀","技艺","アーツ","умение","아츠"],resona:["resona","共鸣","レゾナ","отголосок","레조나"]},!0),RarityRule=new TextualRule("rarity",{c:["c"],r:["r"],lc:["lc"],sr:["sr"],lr:["lr"],st:["st"],pr:["pr"],sp:["sp"]},!0),SkillRule={};SkillRule.parse=function(e){for(var r=[],t=0;t<e.length;t++){var n=e[t],i=this.parseWord(n);i&&(r.push(i),e.splice(t,1),t--)}return function(e){return!r.length||(e=CardInfo[e.cid],r.some(function(r){var t=e[r];return t&&t.length}))}},SkillRule.parseWord=TextualRule.prototype.parseWord,SkillRule.map={constEffectTexts:["【常】","常","常时","常时效果","常時能力","【常】","常","常時","常時效果","常時能力","[constant]","const","constant","[постоянно]","постоянно","상시","[상시]"],startUpEffectTexts:["【出】","出","出场","出场效果","出场能力","【出】","出","出現","出現效果","出現能力","[on-play]","[onplay]","on-play","onplay","[при вводе]","при вводе","출현","[출현]"],actionEffectTexts:["【起】","起","起动","起动效果","起动能力","【起】","起","起動","起動效果","起動能力","[action]","action","[действие]","действие","기동","[기동]"],burstEffectTexts:["【※】","※","爆发","迸发","爆发效果","迸发效果","生命爆发","生命迸发","生命爆发效果","生命迸发效果","ライフバースト","バースト","burst","lifeburst","lb","вспышка","жизненная вспышка","라이프 버스트","라이프버스트","버스트"]};var NoBurstRule={};NoBurstRule.parse=function(e){for(var r=!1,t=0;t<e.length;t++){var n=e[t];this.parseWord(n)&&(r=!0,e.splice(t,1),t--)}return function(e){return!r||(e=CardInfo[e.cid],!("SIGNI"!==e.cardType&&"SPELL"!==e.cardType||e.burstEffectTexts&&e.burstEffectTexts.length))}},NoBurstRule.parseWord=TextualRule.prototype.parseWord,NoBurstRule.map={burstEffectTexts:["无爆发","无迸发","无爆发效果","无迸发效果","无生命爆发","无生命迸发","无生命爆发效果","无生命迸发效果","noburst","ライフバースト-","バースト-","迸发-","爆发-","burst-","lifeburst-","lb-","вспышка-","жизненная вспышка-","버스트-","라이프버스트-"]};var CrossRule={};CrossRule.parse=function(e){for(var r=!1,t=0;t<e.length;t++){var n=e[t];this.parseWord(n)&&(r=!0,e.splice(t,1),t--)}return function(e){return!r||(e=CardInfo[e.cid],"SIGNI"===e.cardType&&(e.crossLeft||e.crossRight))}},CrossRule.parseWord=TextualRule.prototype.parseWord,CrossRule.map={cross:["cross","交错","クロス","связь","크로스","[cross]",">cross<","【cross】","【交错】","【クロス】","[связь]",">크로스<"]};var TimmingRule={};TimmingRule.parse=function(e){for(var r=[],t=0;t<e.length;t++){var n=e[t],i=this.parseWord(n);i&&(r.push(i),e.splice(t,1),t--)}return function(e){return!r.length||r.some(function(r){return!!e.timmings&&inArr(r,e.timmings)})}},TimmingRule.parseWord=TextualRule.prototype.parseWord,TimmingRule.map={mainPhase:["主要阶段","【主要阶段】","主要","メインフェイズ","【メインフェイズ】","[mainphase]","mainphase","main","[основнаяфаза]","основнаяфаза","основная","메인","메인페이즈","[메인페이즈]"],attackPhase:["攻击阶段","【攻击阶段】","攻击","アタックフェイズ","【アタックフェイズ】","[attackphase]","attackphase","attack","[фазаатаки]","фазаатаки","атака","어택","어택페이즈","[어택페이즈]"],spellCutIn:["魔法切入","【魔法切入】","切入","スペルカットイン","【スペルカットイン】","[spellcut-in]","[cut-in]","[spellcutin]","[cutin]","spellcutin","cutin","cut","[ответнамагию]","[ответ]","ответнамагию","ответ","컷인","컷인","[스펠컷인]","스펠컷인"]};var LimitingRule={};LimitingRule.parse=function(e){for(var r=[],t=!1,n=0;n<e.length;n++)for(var i=e[n],u=["タマ","花代","ユヅキ","ピルルク","エルドラ","ミルルン","緑子","アン","ウリス","イオナ","ウムル","リメンバ","タウィル","サシェ","ミュウ","アイヤイ","アルフォウ","ハナレ","リル","メル"],o=0;o<u.length;o++){var a=u[o],s=!1,c=Localize("class",a).toLowerCase();if(i===c?s=!0:i===c+"+"&&(s=!0,t=!0),s){r.push(a),e.splice(n,1),n--;break}}return function(e){return!r.length||("LRIG"===e.cardType?r.some(function(r){return!!e.classes&&inArr(r,e.classes)},this):e.limiting?inArr(e.limiting,r):t)}};var ClassRule={};ClassRule.parse=function(e){for(var r=[],t=0;t<e.length;t++)for(var n=e[t],i=["精像","天使","悪魔","美巧","精武","アーム","ウェポン","遊具","毒牙","精羅","鉱石","宝石","植物","原子","宇宙","精械","電機","古代兵器","迷宮","精生","水獣","空獣","地獣","龍獣","凶蟲","精元"],u=0;u<i.length;u++){var o=i[u];if(n===Localize("class",o).toLowerCase().replace(" ","")){r.push(o),e.splice(t,1),t--;break}}return function(e){return!r.length||r.some(function(r){return!!e.classes&&inArr(r,e.classes)},this)}},NumericRule.prototype.parseExpression=function(e){var r;if(r=e.match(/^=*(\d+)$/)){var t=parseInt(r[1]);return[t,t]}if(r=e.match(/^>=*(\d+)\+?$/),r||(r=e.match(/^(\d+)\+$/)),r){var t=parseInt(r[1]);return[t,1/0]}if(r=e.match(/^<=*(\d+)\-?$/),r||(r=e.match(/^(\d+)\-$/)),r){var t=parseInt(r[1]);return[-(1/0),t]}if(r=e.match(/^(\d+)[\-\~](\d+)$/)){var n=parseInt(r[1]),i=parseInt(r[2]);return[n,i]}return null},NumericRule.prototype.parseWord=function(e){for(var r=0;r<this.keywords.length;r++){var t=Localize.traditionalize(this.keywords[r]);if(0===e.indexOf(t))return e=e.slice(t.length).replace(/^:/,""),this.parseExpression(e)}return null},NumericRule.prototype.parse=function(e){for(var r=[],t=0;t<e.length;t++){var n=e[t],i=this.parseWord(n);i&&(r.push(i),e.splice(t,1),t--)}var u=this.prop;return function(e){return!r.length||"SPELL"!==e.cardType&&"ARTS"!==e.cardType&&r.every(function(r){var t=e[u],n=r[0],i=r[1];return t>=n&&t<=i})}};var PowerRule=new NumericRule("power",["力量","パワー","power","сила","파워"]),LevelRule=new NumericRule("level",["等级","レベル","level","lv.","lv","уровень","livello","레벨"]),LimitRule=new NumericRule("limit",["界限","リミット","limite","limit","ограничение","리미트"]),NumberRule=new NumericRule("",[""]);NumberRule.parse=function(e){for(var r=[],t=0;t<e.length;t++){var n=e[t],i=this.parseWord(n);i&&(r.push(i),e.splice(t,1),t--)}return function(e){return r.every(function(r){function t(e){return!isFinite(e)||e<10}if("SPELL"===e.cardType||"ARTS"===e.cardType)return!1;var n=r.every(t)?e.level:e.power,i=r[0],u=r[1];return n>=i&&n<=u})}};var IllustRule={};IllustRule.parseWord=function(e){var r=e.match(/illust:?(.+)/);return r||(r=e.match(/画师:?(.+)/)),r||(r=e.match(/畫師:?(.+)/)),r?r[1]:null},IllustRule.parse=function(e){for(var r=[],t=0;t<e.length;t++){var n=e[t],i=this.parseWord(n);i&&(r.push(i),e.splice(t,1),t--)}return function(e){return!r.length||r.some(function(r){var t=e.illust.toLowerCase();return t.indexOf(r)!==-1})}};var WxidRule={};WxidRule.parseWord=function(e){var r=e.match(/^(wx\d{2}|wd\d{2}|pr|sp\d{2})-?(re\d{0,2}|cb\d{0,2}|\d{0,3}[a|b]?)$/);return r?r[1]+"-"+r[2]:null},WxidRule.parse=function(e){for(var r=[],t=0;t<e.length;t++){var n=e[t],i=this.parseWord(n);i&&(r.push(i),e.splice(t,1),t--)}return function(e){return!r.length||r.some(function(r){return 0===e.wxid.toLowerCase().indexOf(r)})}};var NameRule={};NameRule.dotRegex=/[\u00B7\u0387\u05BC\u2022\u2027\u2219\u22C5\u30FB\uFF0E\uFF65⁑:*†]/g,NameRule.fullWidth="0123456789=@#ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",NameRule.halfWidth="0123456789=@#ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",NameRule.normalizeString=function(e){var r=e.replace(this.dotRegex,"").split("");return r.forEach(function(e,t){var n=this.fullWidth.indexOf(e);r[t]=this.halfWidth[n]||e},this),r.join("").toLowerCase()},NameRule.parse=function(e){var r=[];e.forEach(function(e){r.push(e.split(/\|+/))},this),e.length=0;var t=this;return function(e){return r.every(function(r){return!r.length||r.some(function(r){var n=t.normalizeString(Localize.cardName(e)),i=t.normalizeString(r);return n.indexOf(i)!==-1},this)},this)}},Searcher.prototype.search=function(e){var r=e.toLowerCase().split(/\s+/),t=this.rules.map(function(e){return e.parse(r)},this);return t.reduce(function(e,r){return e.filter(r)},this.infos)}; |