ContentTypes.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. module CharacterCreation.ContentTypes {
  2. let ccDiv = document.createElement("div");
  3. ccDiv.id = "characterCreation";
  4. let rightSide = document.createElement("div");
  5. rightSide.id = "ccRight";
  6. let leftSide = document.createElement("div");
  7. leftSide.id = "ccLeft";
  8. ccDiv.appendChild(leftSide);
  9. ccDiv.appendChild(rightSide);
  10. let resolver;
  11. async function printTable () {
  12. while (leftSide.firstChild) leftSide.removeChild(leftSide.firstChild);
  13. await (new Say(new SayBold("Fetishes:")).getHTMLContent().then(eles => {
  14. eles.forEach(ele => {
  15. leftSide.appendChild(ele);
  16. })
  17. }));
  18. let perks = ContentHandler.getContentTypes().sort((a : ContentType, b : ContentType) => {
  19. let na = a.getName().toUpperCase();
  20. let nb = b.getName().toUpperCase();
  21. if (na < nb) return -1;
  22. if (na > nb) return 1;
  23. return 0;
  24. });
  25. for (let i = 0; i < perks.length; i++) {
  26. let perk = perks[i];
  27. let say = new Say(perk.getName());
  28. if (perk.isAllowed()) {
  29. if (!perk.isChangeable()) {
  30. say.add (" (Mandatory)");
  31. } else {
  32. say.add(" - Into it");
  33. }
  34. } else if (!perk.isChangeable()) {
  35. say.add(" (Forbidden)");
  36. }
  37. await (say).getHTML("p", ["choice"]).then(elementArray => {
  38. Controls.Links.makeCustomLink(elementArray[0], {
  39. mouseover: () => {
  40. printPerk(perk);
  41. },
  42. mouseout: () => {
  43. emptyPerk();
  44. },
  45. click: () => {
  46. perk.toggle();
  47. reset();
  48. }
  49. });
  50. Controls.KeyHandler.applyCode(elementArray[0], Controls.KeyHandler.getSecondKeyCode());
  51. leftSide.appendChild(elementArray[0]);
  52. });
  53. }
  54. }
  55. function printConfirm () {
  56. (new Say("Confirm")).getHTML("p", ["choice"]).then(elementArray => {
  57. elementArray[0].addEventListener("click", () => {
  58. resolver();
  59. });
  60. Controls.KeyHandler.applyCode(elementArray[0], Controls.KeyHandler.getSecondKeyCode());
  61. Elements.CurrentTurnHandler.print(elementArray[0]);
  62. });
  63. }
  64. function emptyPerk () {
  65. while (rightSide.firstChild) rightSide.removeChild(rightSide.firstChild);
  66. printRightSideInfo();
  67. }
  68. function printRightSideInfo() {
  69. let p = document.createElement("p");
  70. p.classList.add("content");
  71. p.appendChild(document.createTextNode("The fetishes the player character has will tailor the world the Obelisk will create for them."));
  72. rightSide.appendChild(p);
  73. }
  74. function printPerk (perk : ContentType) {
  75. let say = new Say(perk.getDescription());
  76. say.getHTMLContent().then((eles => {
  77. emptyPerk();
  78. for (let i = 0; i < eles.length; i++) {
  79. rightSide.appendChild(eles[i]);
  80. }
  81. }));
  82. }
  83. function reset () {
  84. Elements.CurrentTurnHandler.clear();
  85. Elements.CurrentTurnHandler.print(ccDiv);
  86. printTable();
  87. Elements.CurrentTurnHandler.print(document.createElement("br"));
  88. Elements.CurrentTurnHandler.print(document.createElement("br"));
  89. printConfirm();
  90. }
  91. export async function selectContentTypes () {
  92. Elements.startMenu();
  93. let promise = new Promise(resolve => {
  94. resolver = resolve;
  95. });
  96. reset();
  97. await promise;
  98. Elements.endMenu();
  99. }
  100. }