1
1

Origin.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. printOrigin();
  13. while (leftSide.firstChild) leftSide.removeChild(leftSide.firstChild);
  14. await (new Say(new SayBold("Character Origin:")).getHTMLContent().then(eles => {
  15. eles.forEach(ele => {
  16. leftSide.appendChild(ele);
  17. })
  18. }));
  19. let origins = CharacterOrigin.getOrigins();
  20. for (let i = 0; i < origins.length; i++) {
  21. let origin = origins[i];
  22. let say = new Say(origin.name);
  23. if (origin.id == CharacterCreation.PlayerOrigin.value) {
  24. say.add(" - SELECTED");
  25. }
  26. await (say).getHTML("p", ["choice"]).then(elementArray => {
  27. Controls.Links.makeCustomLink(elementArray[0], {
  28. mouseover: () => {
  29. printOrigin(origin);
  30. },
  31. mouseout: () => {
  32. printOrigin();
  33. },
  34. click: () => {
  35. CharacterCreation.PlayerOrigin.value = origin.id;
  36. reset();
  37. }
  38. });
  39. Controls.KeyHandler.applyCode(elementArray[0], Controls.KeyHandler.getSecondKeyCode());
  40. leftSide.appendChild(elementArray[0]);
  41. });
  42. }
  43. }
  44. function printConfirm () {
  45. (new Say("Confirm")).getHTML("p", ["choice"]).then(elementArray => {
  46. elementArray[0].addEventListener("click", () => {
  47. resolver();
  48. });
  49. Controls.KeyHandler.applyCode(elementArray[0], Controls.KeyHandler.getSecondKeyCode());
  50. Elements.CurrentTurnHandler.print(elementArray[0]);
  51. });
  52. }
  53. function printOrigin (origin? : CharacterOrigin) {
  54. if (origin == undefined) {
  55. origin = CharacterOrigin.getOrigin(CharacterCreation.PlayerOrigin.value);
  56. }
  57. let say = new Say(origin.description);
  58. if (origin.bonusStats != undefined) {
  59. say.add(Say.PARAGRAPH_BREAK, origin.bonusStats);
  60. }
  61. say.getHTMLContent().then((eles => {
  62. while (rightSide.firstChild) rightSide.removeChild(rightSide.firstChild);
  63. for (let i = 0; i < eles.length; i++) {
  64. rightSide.appendChild(eles[i]);
  65. }
  66. }));
  67. }
  68. function reset () {
  69. Elements.CurrentTurnHandler.clear();
  70. Elements.CurrentTurnHandler.print(ccDiv);
  71. printTable();
  72. Elements.CurrentTurnHandler.print(document.createElement("br"));
  73. Elements.CurrentTurnHandler.print(document.createElement("br"));
  74. printConfirm();
  75. }
  76. export let CCOrigin = CharacterCreation.rulebook.createAndAddRule({
  77. name: "Character Creation - Origin",
  78. firstPriority: Rule.PRIORITY_MEDIUM,
  79. priority: Rule.PRIORITY_HIGH,
  80. code: async () => {
  81. Elements.startMenu();
  82. let promise = new Promise(resolve => {
  83. resolver = resolve;
  84. });
  85. reset();
  86. await promise;
  87. CharacterCreation.getOrigin().confirmPicked();
  88. Elements.endMenu();
  89. }
  90. });
  91. }