SayHimHerIt.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. class SayHimHerIt extends Say {
  2. private node = document.createTextNode("a ");
  3. private target : Thing;
  4. private uppercase = true;
  5. public constructor (target : Thing, autoUppercase? : boolean) {
  6. super();
  7. this.target = target;
  8. if (autoUppercase != undefined) {
  9. this.uppercase = autoUppercase;
  10. }
  11. }
  12. public async getPureElements (say : Say) : Promise<Array<Element | Text>> {
  13. let next = this.target;
  14. if (next == undefined) {
  15. this.node.nodeValue = "";
  16. } else {
  17. if (next instanceof Humanoid) {
  18. let gender = next.getGenderValue();
  19. if (gender.genderValueCorrected > 65) {
  20. this.node.nodeValue = "her ";
  21. } else if (gender.genderValueCorrected < 35) {
  22. this.node.nodeValue = "him ";
  23. } else {
  24. // This person is androgynous...
  25. if (gender.hasPenisBulge || gender.hasPenis) {
  26. this.node.nodeValue = "him ";
  27. } else if (gender.hasVagina || gender.hasTits) {
  28. this.node.nodeValue = "her ";
  29. } else {
  30. this.node.nodeValue = "them ";
  31. }
  32. }
  33. } else {
  34. // TODO: If we ever have gendered non-humanoids, they must be added here.
  35. this.node.nodeValue = "it ";
  36. }
  37. if (this.uppercase && say.currentParagraph.length == 0) {
  38. this.node.nodeValue = this.node.nodeValue.charAt(0).toUpperCase()
  39. + this.node.nodeValue.substr(1, this.node.nodeValue.length - 1);
  40. }
  41. }
  42. return [this.node];
  43. }
  44. }