SayThe.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. class SayThe extends Say {
  2. private node = document.createTextNode("");
  3. private uppercase = true;
  4. private alwaysPrint = false;
  5. public constructor (autoUppercase? : boolean, alwaysPrint? : boolean) {
  6. super();
  7. if (autoUppercase != undefined) {
  8. this.uppercase = autoUppercase;
  9. }
  10. if (alwaysPrint) {
  11. this.alwaysPrint = alwaysPrint;
  12. }
  13. }
  14. public async getPureElements (say : Say) : Promise<Array<Element | Text>> {
  15. let next = say.sequence[say.sequenceRunner + 1];
  16. if (this.alwaysPrint) {
  17. this.node.nodeValue = "the ";
  18. } else if (next == undefined) {
  19. this.node.nodeValue = "";
  20. } else {
  21. if (next instanceof Thing) {
  22. if (!(<Thing> next).properlyNamed) {
  23. this.node.nodeValue = "the ";
  24. } else {
  25. this.node.nodeValue = "";
  26. }
  27. } else {
  28. this.node.nodeValue = "";
  29. }
  30. }
  31. if (this.node.nodeValue != "") {
  32. if (this.uppercase && say.currentParagraph.length == 0) {
  33. this.node.nodeValue = this.node.nodeValue.charAt(0).toUpperCase()
  34. + this.node.nodeValue.substr(1, this.node.nodeValue.length - 1);
  35. }
  36. }
  37. return [this.node];
  38. }
  39. }