#34 tribes; elements

This commit is contained in:
Daniel 2018-03-20 18:18:34 -04:00
parent 6c3ccbdc32
commit c5ff4e64f7

View File

@ -32,8 +32,8 @@ export default class SearchCollection extends React.Component {
sets: {},
types: {attack: false, battlegear: false, creature: false, location: false, mugic: false},
rarity: {common: false, uncommon: false, rare: false, 'super rare': false, 'ultra rare': false, promo: false},
tribes: {danian: false, generic: false, 'm\'arrillian': false, 'mipedian': false, overworld: false, underworld: false, frozen: false},
elements: {fire: false, air: false, earth: false, water: false},
tribes: {danian: false, 'm\'arrillian': false, 'mipedian': false, overworld: false, underworld: false, generic: false},
elements: {fire: false, air: false, earth: false, water: false, none: false, and: false},
disciplines: {courage: false, power: false, wisdom: false, speed: false},
energy: {min: 0, max: 0},
mcbp: {min: 0, max: 0},
@ -63,11 +63,8 @@ export default class SearchCollection extends React.Component {
}
}
update("sets");
update("types");
update("rarity");
update("gender");
update("mull");
["sets", "types", "rarity", "gender", "mull", "elements"
].forEach(item => update(item));
}
async updateQuery() {
@ -85,11 +82,8 @@ export default class SearchCollection extends React.Component {
else return "";
}
queryString += update("sets");
queryString += update("types");
queryString += update("rarity");
queryString += update("gender");
queryString += update("mull");
["sets", "types", "rarity", "gender", "mull", "elements"
].forEach(item => queryString += update(item));
// Strip trailing &
queryString = queryString.replace(/\&$/, '');
@ -112,34 +106,38 @@ export default class SearchCollection extends React.Component {
return (<span>Loading...</span>);
}
let gen = (d, display) => {
let gen = (d, display, text) => {
let tmp = [];
Object.keys(this.input[d]).forEach((item, i) => {
tmp.push(<label style={{display: 'block'}} key={i}><input type="checkbox" name={item} checked={this.input[d][item]} onChange={e => this.handleChange(e, d)} />{display(item)}</label>
tmp.push(<label style={{display: display}} key={i}><input type="checkbox" name={item} checked={this.input[d][item]} onChange={e => this.handleChange(e, d)} />{text(item)}</label>
);
});
return tmp;
}
let sets = gen("sets", (item) => {
let sets = gen("sets", "block", (item) => {
return API.sets[item.toUpperCase()];
});
let types = gen("types", (item) => {
let types = gen("types", "block", (item) => {
return item.charAt(0).toUpperCase()+item.slice(1);
});
let rarity = gen("rarity", (item) => {
let rarity = gen("rarity", "block", (item) => {
return item.split(" ").map(st => {return st.charAt(0).toUpperCase()+st.slice(1)}).join(" ");
});
let gender = gen("gender", (item) => {
let gender = gen("gender", "block", (item) => {
return item.charAt(0).toUpperCase()+item.slice(1);
});
let tribes = [];
let tribes = gen("tribes", "inline", (item) => {
return (<span><img className="icon16" src={"/src/img/icons/tribes/"+item+".png"} />&nbsp;</span>);
});
let elements = [];
let elements = gen("elements", "inline", (item) => {
return (<span><img className="icon16" src={"/src/img/icons/elements/"+item+".png"} />&nbsp;</span>);
}).slice(0, -2);
let disciplines = [];
@ -168,12 +166,22 @@ export default class SearchCollection extends React.Component {
<label><input type="checkbox" ref={(input) => this.stones.mirage = input}/>Mirage</label>
</div>*/}
<br />
{tribes}
<span>Tribes</span>
<br />
{elements}
{tribes}
<br /> <br />
<span>Elements</span>
<br />
{elements}&nbsp;
<input type="button" value="or" style={{verticalAlign: "text-bottom"}} disabled={!this.input.elements.and} onClick={(e)=>{this.input.elements.and=false;}} />
<input type="button" value="and" style={{verticalAlign: "text-bottom"}} disabled={this.input.elements.and} onClick={(e)=>{this.input.elements.and=true;}} />
<br />
<label><input type="checkbox" name="none" checked={this.input.elements.none} onChange={e => this.handleChange(e, "elements")} />No Elements</label>
<br /> <br />
<span>Disciplines</span>
<br />
{disciplines}
<br />
<br /> <br />
{/*<div>
<span>Energy</span><br />
<label>Min: <input type="text" style={{width: '30px'}} ref={(input) => this.energy.min = input} /></label>&nbsp;
@ -192,7 +200,7 @@ export default class SearchCollection extends React.Component {
<Collapsible trigger="Sets">{sets}</Collapsible>
<Collapsible trigger="Gender (fan content)">{gender}</Collapsible>
<br />
<input type="submit" value="Search" />&nbsp;&nbsp;
<input type="submit" value="Search" />&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" value="Reset" onClick={this.reset} />
</form>
</div>
@ -232,6 +240,63 @@ export default class SearchCollection extends React.Component {
let locationResults = API.cards.locations.chain();
let mugicResults = API.cards.mugic.chain();
// Search by tribe
let tribesList = [];
for (const tribe in this.input.tribes) {
if (this.input.tribes[tribe])
tribesList.push({'$regex': new RegExp(tribe, 'i')});
}
if (tribesList.length > 0) {
creatureResults = creatureResults.find({'gsx$tribe': {'$or': tribesList} });
mugicResults = mugicResults.find({'gsx$tribe': {'$or': tribesList} });
attackResults = attackResults.limit(0);
battlegearResults = battlegearResults.limit(0);
locationResults = locationResults.limit(0);
}
// Search by elements
if (this.input.elements.none) {
attackResults = attackResults.where(
(obj) => {return (obj.gsx$fire == ('') );}
).where(
(obj) => {return (obj.gsx$air == ('') );}
).where(
(obj) => {return (obj.gsx$earth == ('') );}
).where(
(obj) => {return (obj.gsx$water == ('') );}
);
battlegearResults = battlegearResults.limit(0);
creatureResults = creatureResults.where(obj => (obj.gsx$elements == ''));
locationResults = locationResults.limit(0);
mugicResults = mugicResults.limit(0);
}
else {
let elementsList = [];
let elementsList2 = [];
for (const element in this.input.elements) {
if (element === "none" || element === "and") continue;
if (this.input.elements[element]) {
elementsList.push({'$regex': new RegExp(element, 'i')});
elementsList2.push({['gsx$'+element]: {'$gte': 0}})
}
}
if (elementsList.length > 0) {
console.log(elementsList, elementsList2);
if (this.input.elements.and) {
creatureResults = creatureResults.find({'gsx$elements': {'$and': elementsList} });
attackResults = attackResults.find({'$and': elementsList2});
}
else {
creatureResults = creatureResults.find({'gsx$elements': {'$or': elementsList} });
attackResults = attackResults.find({'$or': elementsList2});
}
battlegearResults = battlegearResults.limit(0);
locationResults = locationResults.limit(0);
mugicResults = mugicResults.limit(0);
}
}
// Unique
if (this.input.mull.unique) {
attackResults = attackResults.find({'gsx$unique': {'$gt': 0}});
battlegearResults = battlegearResults.find({'gsx$unique': {'$gt': 0}});
@ -240,6 +305,7 @@ export default class SearchCollection extends React.Component {
mugicResults = mugicResults.find({'gsx$unique': {'$gt': 0}});
}
// Loyal
if (this.input.mull.loyal) {
attackResults = attackResults.limit(0);
battlegearResults = battlegearResults.find({'gsx$loyal': {'$gt': 0}});
@ -248,14 +314,7 @@ export default class SearchCollection extends React.Component {
locationResults = locationResults.limit(0);
}
if (this.input.mull.mixed) {
attackResults = attackResults.limit(0);
creatureResults = creatureResults.find({'gsx$loyal': {'$lte': 0}});
battlegearResults = battlegearResults.find({'gsx$loyal': {'$lte': 0}});
mugicResults = mugicResults.limit(0);
locationResults = locationResults.limit(0);
}
// Legendary
if (this.input.mull.legendary) {
attackResults = attackResults.find({'gsx$legendary': {'$gt': 0}});
battlegearResults = battlegearResults.find({'gsx$legendary': {'$gt': 0}});
@ -264,6 +323,16 @@ export default class SearchCollection extends React.Component {
mugicResults = mugicResults.find({'gsx$legendary': {'$gt': 0}});
}
// Non Loyal
if (this.input.mull.mixed) {
attackResults = attackResults.limit(0);
creatureResults = creatureResults.find({'gsx$loyal': {'$lte': 0}});
battlegearResults = battlegearResults.find({'gsx$loyal': {'$lte': 0}});
mugicResults = mugicResults.limit(0);
locationResults = locationResults.limit(0);
}
// Sets
let setsList = [];
for (const key in this.input.sets) {
if (this.input.sets[key])
@ -277,6 +346,7 @@ export default class SearchCollection extends React.Component {
mugicResults = mugicResults.find({'gsx$set': {'$or': setsList} });
}
// Rarity
let rarityList = [];
for (const key in this.input.rarity) {
if (this.input.rarity[key])
@ -290,11 +360,11 @@ export default class SearchCollection extends React.Component {
mugicResults = mugicResults.find({'gsx$rarity': {'$or': rarityList} });
}
// Gender
let genderList = [];
for (const key in this.input.gender) {
if (this.input.gender[key]) {
if (this.input.gender[key])
genderList.push({'$regex': new RegExp(key, 'i')})
}
}
if (genderList.length > 0) {
attackResults = attackResults.limit(0);