1
1

Perks.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. module CharacterCreation {
  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("Perks (Choose any):")).getHTMLContent().then(eles => {
  14. eles.forEach(ele => {
  15. leftSide.appendChild(ele);
  16. })
  17. }));
  18. let perks = Perk.getPerks();
  19. for (let i = 0; i < perks.length; i++) {
  20. let perk = perks[i];
  21. let say = new Say(perk.name);
  22. if (perk.isEnabled()) {
  23. if (perk.isForced()) {
  24. say.add (" (Mandatory)");
  25. } else {
  26. say.add(" - Selected");
  27. }
  28. } else if (perk.isForced()) {
  29. say.add(" (Forbidden)");
  30. }
  31. await (say).getHTML("p", ["choice"]).then(elementArray => {
  32. Controls.Links.makeCustomLink(elementArray[0], {
  33. mouseover: () => {
  34. printPerk(perk);
  35. },
  36. mouseout: () => {
  37. emptyPerk();
  38. },
  39. click: () => {
  40. if (!perk.isForced()) {
  41. perk.value = !perk.value;
  42. }
  43. reset();
  44. }
  45. });
  46. Controls.KeyHandler.applyCode(elementArray[0], Controls.KeyHandler.getSecondKeyCode());
  47. leftSide.appendChild(elementArray[0]);
  48. });
  49. }
  50. }
  51. function printConfirm () {
  52. (new Say("Confirm")).getHTML("p", ["choice"]).then(elementArray => {
  53. elementArray[0].addEventListener("click", () => {
  54. resolver();
  55. });
  56. Controls.KeyHandler.applyCode(elementArray[0], Controls.KeyHandler.getSecondKeyCode());
  57. Elements.CurrentTurnHandler.print(elementArray[0]);
  58. });
  59. }
  60. function emptyPerk () {
  61. while (rightSide.firstChild) rightSide.removeChild(rightSide.firstChild);
  62. }
  63. function printPerk (perk : Perk) {
  64. let say = new Say(perk.description);
  65. say.getHTMLContent().then((eles => {
  66. emptyPerk();
  67. for (let i = 0; i < eles.length; i++) {
  68. rightSide.appendChild(eles[i]);
  69. }
  70. }));
  71. }
  72. function reset () {
  73. Perk.updatePerks();
  74. Elements.CurrentTurnHandler.clear();
  75. Elements.CurrentTurnHandler.print(ccDiv);
  76. printTable();
  77. Elements.CurrentTurnHandler.print(document.createElement("br"));
  78. Elements.CurrentTurnHandler.print(document.createElement("br"));
  79. printConfirm();
  80. }
  81. export let CCPerk = CharacterCreation.rulebook.createAndAddRule({
  82. name: "Character Creation - Origin",
  83. firstPriority: Rule.PRIORITY_LOW,
  84. priority: Rule.PRIORITY_HIGH,
  85. code: async () => {
  86. Elements.startMenu();
  87. let promise = new Promise(resolve => {
  88. resolver = resolve;
  89. });
  90. reset();
  91. await promise;
  92. let perks = Perk.getPerks();
  93. perks.forEach(perk => {
  94. if (perk.isEnabled()) {
  95. perk.confirmPicked();
  96. }
  97. });
  98. Elements.endMenu();
  99. }
  100. });
  101. }