-
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 #21 from thepeanutgalleryandco/v1-5-0
V1 5 0
- Loading branch information
Showing
10 changed files
with
191 additions
and
23 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.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Load modules and constants | ||
const { combinationOfTraitsAlreadyExists } = require('./exclusions/combination_traits'); | ||
const { incompatibleTraitsUsed } = require('./exclusions/incompatible_traits'); | ||
|
||
// Checks the different exclusions and return true if any of them are true | ||
const needsExclusion = (selectedTraitsList, newTraits, maxRepeatedTraits, incompatibleTraits) => { | ||
|
||
return combinationOfTraitsAlreadyExists(selectedTraitsList, newTraits, maxRepeatedTraits) || incompatibleTraitsUsed(newTraits, incompatibleTraits); | ||
}; | ||
|
||
module.exports = { | ||
needsExclusion, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// 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; | ||
} | ||
|
||
// 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; | ||
|
||
// 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++) { | ||
|
||
// Checks if the new trait is already in the selected traits list | ||
if (newTraits[i].id === existingTraits[i].id) { | ||
|
||
// Increment the selected traits value as it has been found before | ||
commonTraits++; | ||
} | ||
} | ||
|
||
// 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; | ||
} | ||
|
||
} | ||
|
||
// Return false if the traits have been looped through and the maximum repeatability have not been breached | ||
return false; | ||
}; | ||
|
||
module.exports = { | ||
combinationOfTraitsAlreadyExists, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Take in a list of layers and then build a simple json object that contains the layer name with the layer item next to it. | ||
const simplifyTraits = (traits) => { | ||
const simpleTraits = {}; | ||
traits.forEach((trait) => { | ||
simpleTraits[trait.layer] = trait.name; | ||
}); | ||
return simpleTraits; | ||
}; | ||
|
||
// Set true / false if the layer has defined incompatibilities | ||
const traitHasDefinedIncompatibilities = (newTrait, incompatibleTraits) => { | ||
const traitKey = `${newTrait.layer}/${newTrait.name}`; | ||
return incompatibleTraits[traitKey]; | ||
}; | ||
|
||
// Set true / false if incompatabale layers are used and return true if it is the case | ||
const incompatibleTraitsUsed = (newTraits, incompatibleTraits) => { | ||
|
||
// Check if incompatible traits check needs to be done and if not, return false and exit this check | ||
if (!incompatibleTraits) { | ||
return false; | ||
} | ||
|
||
// Generate a layer_name: layer_item json object from the traits list | ||
const simpleNewTraits = simplifyTraits(newTraits); | ||
|
||
// Loop through each layer in the list | ||
for (let i = 0; (i < newTraits.length); i++) { | ||
|
||
// Set true / false if the layer has a defined incompatibility | ||
const definedIncompatibilities = traitHasDefinedIncompatibilities(newTraits[i], incompatibleTraits); | ||
|
||
// Check if incompatibilities were found for the layer | ||
if (definedIncompatibilities !== undefined) { | ||
|
||
// Loop through each of the incompatibility layer items | ||
for (let n = 0; (n < definedIncompatibilities.length); n++) { | ||
|
||
// Split each of the incompatibility layers into a layer name and a layer item | ||
const [layer, trait] = definedIncompatibilities[n].split('/'); | ||
|
||
// Check if the layer name and layer item combination can be found in the layer_name and layer_item json object and if it can be found, return true and stop processing further | ||
if (simpleNewTraits[layer] === trait) { | ||
console.log("Combination of traits excluded because of incompatible layers exclusion rule!"); | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// If all layers and layer items were checked and no incompatibilities found, then return false | ||
return false; | ||
}; | ||
|
||
module.exports = { | ||
incompatibleTraitsUsed, | ||
}; |
Oops, something went wrong.