-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from thepeanutgalleryandco/v1-6-0
V1 6 0
- Loading branch information
Showing
15 changed files
with
578 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,55 @@ | ||
// Check if the maximum repeatability have been reached | ||
const combinationOfTraitsAlreadyExists = (selectedTraitsList, newTraits, maxRepeatedTraits) => { | ||
//console.log(newTraits); | ||
// Check if maximum repeatability check needs to be done and if not, return false and exit this check | ||
if (!maxRepeatedTraits) { | ||
return false; | ||
const combinationOfTraitsAlreadyExists = (selectedTraitsList, newTraits, maxRepeatedTraits, layerItemsMaxRepeatedTraits) => { | ||
|
||
let traitLayerCounts = {}; | ||
let traitLayerItemCounts = {}; | ||
|
||
// Loops through each trait list of previous selected traits list | ||
for (let existingTraits of selectedTraitsList) { | ||
|
||
// Loops through each trait and add to count | ||
for (let i = 0; i < existingTraits.length; i++) { | ||
|
||
// Check if trait exists in traitLayerCounts and traitLayerItemCounts objects and if it does, then add to the count, otherwise initialize with a count of 1. | ||
traitLayerCounts[`${existingTraits[i].layer}`] = traitLayerCounts[`${existingTraits[i].layer}`] ? traitLayerCounts[`${existingTraits[i].layer}`] + 1 : 1 ; | ||
traitLayerItemCounts[`${existingTraits[i].layer}/${existingTraits[i].name}`] = traitLayerItemCounts[`${existingTraits[i].layer}/${existingTraits[i].name}`] ? traitLayerItemCounts[`${existingTraits[i].layer}/${existingTraits[i].name}`] + 1 : 1 ; | ||
} | ||
} | ||
|
||
// Loops through each new trait and add to count | ||
for (let i = 0; i < newTraits.length; i++) { | ||
|
||
// Loops through each trait within the selected traits list | ||
for (let existingTraits of selectedTraitsList) { | ||
|
||
// Set a starting value of 0 for the selected traits | ||
let commonTraits = 0; | ||
// Check if trait exists in traitLayerCounts and traitLayerItemCounts objects and if it does, then add to the count, otherwise initialize with a count of 1. | ||
traitLayerCounts[`${newTraits[i].layer}`] = traitLayerCounts[`${newTraits[i].layer}`] ? traitLayerCounts[`${newTraits[i].layer}`] + 1 : 1 ; | ||
traitLayerItemCounts[`${newTraits[i].layer}/${newTraits[i].name}`] = traitLayerItemCounts[`${newTraits[i].layer}/${newTraits[i].name}`] ? traitLayerItemCounts[`${newTraits[i].layer}/${newTraits[i].name}`] + 1 : 1 ; | ||
|
||
// Loops through each new trait and only keep on looping if maximum repeatability have not been reached | ||
for (let i = 0; (i < newTraits.length) && (commonTraits <= maxRepeatedTraits); i++) { | ||
// Check if the selected trait has breached the layer maximum repeatability limit and return true if that is the case | ||
if (traitLayerCounts[`${newTraits[i].layer}`] > newTraits[i].maxRepeatedTrait) { | ||
console.log(`Combination of traits excluded because of layer (${newTraits[i].layer}) maximum repeatability exclusion rule!`); | ||
return true; | ||
} | ||
|
||
// Checks if the new trait is already in the selected traits list | ||
if (newTraits[i].id === existingTraits[i].id) { | ||
// Check if the selected trait has breached the global maximum repeatability limit and return true if that is the case | ||
if (traitLayerItemCounts[`${newTraits[i].layer}/${newTraits[i].name}`] > maxRepeatedTraits) { | ||
console.log(`Combination of traits excluded because of global (${maxRepeatedTraits}) maximum repeatability exclusion rule!`); | ||
return true; | ||
} | ||
} | ||
|
||
// Increment the selected traits value as it has been found before | ||
commonTraits++; | ||
} | ||
} | ||
// Loops through layerItemsMaxRepeatedTraits list | ||
for (layerItem in layerItemsMaxRepeatedTraits) { | ||
|
||
// Check if the selected trait has breached the maximum repeatability limit and return true if that is the case | ||
if (commonTraits > maxRepeatedTraits) { | ||
console.log("Combination of traits excluded because of maximum repeatability exclusion rule!"); | ||
return true; | ||
} | ||
|
||
// Check if the selected trait has breached the layer item maximum repeatability limit and return true if that is the case | ||
if (traitLayerItemCounts[`${layerItemsMaxRepeatedTraits[layerItem].name}`] > layerItemsMaxRepeatedTraits[layerItem].layerItemMaxRepeatedTrait) { | ||
console.log(`Combination of traits excluded because of layer item (${layerItemsMaxRepeatedTraits[layerItem].name}) maximum repeatability exclusion rule!`); | ||
return true; | ||
} | ||
} | ||
|
||
// Return false if the traits have been looped through and the maximum repeatability have not been breached | ||
return false; | ||
}; | ||
module.exports = { | ||
combinationOfTraitsAlreadyExists, | ||
}; | ||
// Return false if the traits have been looped through and the maximum repeatability have not been breached | ||
return false; | ||
}; | ||
|
||
module.exports = { | ||
combinationOfTraitsAlreadyExists, | ||
}; |
Oops, something went wrong.