AdaptiveDifferential.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. class AdaptiveDifferential {
  2. public compareFunction : (noun : any) => boolean = () => false;
  3. public countsAs = 0;
  4. constructor (replacer : (noun : any) => boolean) {
  5. this.compareFunction = replacer;
  6. }
  7. public isMatch (noun : any) {
  8. return this.compareFunction(noun);
  9. }
  10. public static ANYOF (...acceptableValues) {
  11. return new AdaptiveDifferential((noun : any) => {
  12. //console.log(acceptableValues, noun);
  13. for (let i = 0; i < acceptableValues.length; i++) {
  14. if (ContentDifferential.compareNouns(acceptableValues[i], noun)) {
  15. return true;
  16. }
  17. }
  18. return false;
  19. });
  20. }
  21. public static FULLYADAPTIVE (...acceptableValues) {
  22. let ad = AdaptiveDifferential.ANYOF(...acceptableValues);
  23. ad.countsAs = -1;
  24. return ad;
  25. }
  26. public static MALE = new AdaptiveDifferential((noun : any) => {
  27. if (noun instanceof Humanoid) {
  28. return noun.isMale();
  29. }
  30. return false;
  31. });
  32. public static FEMALE = new AdaptiveDifferential((noun : any) => {
  33. if (noun instanceof Humanoid) {
  34. return noun.isMale();
  35. }
  36. return false;
  37. });
  38. public static MASCULINE = new AdaptiveDifferential((noun : any) => {
  39. if (noun instanceof Humanoid) {
  40. return noun.getGenderValue().genderValueCorrected <= 50;
  41. }
  42. return false;
  43. });
  44. public static FEMININE = new AdaptiveDifferential((noun : any) => {
  45. if (noun instanceof Humanoid) {
  46. return noun.getGenderValue().genderValueCorrected >= 50;
  47. }
  48. return false;
  49. });
  50. }