webxoss-client/DeckEditor/Searcher.js

39 lines
705 B
JavaScript
Raw Normal View History

2016-10-23 07:28:51 +02:00
'use strict';
function Searcher () {
this.rules = [
ColorRule,
CrossRule,
TypeRule,
RarityRule,
2017-05-07 18:06:10 +02:00
RiseRule,
TrapRule,
AcceRule,
2016-10-23 07:28:51 +02:00
SkillRule,
NoBurstRule,
// LifeBurstRule,
TimmingRule,
LimitingRule,
ClassRule,
PowerRule,
LevelRule,
LimitRule,
NumberRule,
IllustRule,
WxidRule,
NameRule
];
}
Searcher.prototype.search = function (str) {
// if (!str) return [];
var words = str.toLowerCase().split(/\s+/);
var filters = this.rules.map(function (rule) {
return rule.parse(words);
},this);
2017-05-09 20:19:24 +02:00
var infos = [];
for (var pid in CardInfo) {
infos.push(CardInfo[pid]);
}
2016-10-23 07:28:51 +02:00
return filters.reduce(function (results,filter) {
return results.filter(filter);
2017-05-07 10:51:30 +02:00
},infos);
2016-10-23 07:28:51 +02:00
};