A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

165 lines
3.9KB

  1. import GlobalEvents from "/app/js/common/EventCaller.js";
  2. import NESBank from "/app/js/models/NESBank.js";
  3. var ELCtrl = null;
  4. var ELSel = null;
  5. var ELLab = null;
  6. var ELOff = null;
  7. var SURF = null;
  8. function OpenControls(){
  9. if (ELCtrl !== null && SURF !== null){
  10. switch(SURF.access_mode){
  11. case NESBank.ACCESSMODE_8K:
  12. ELSel.value = "8K";
  13. ELLab.classList.add("hidden");
  14. break;
  15. case NESBank.ACCESSMODE_4K:
  16. ELSel.value = "4K"; break;
  17. case NESBank.ACCESSMODE_2K:
  18. ELSel.value = "2K"; break;
  19. case NESBank.ACCESSMODE_1K:
  20. ELSel.value = "1K"; break;
  21. case NESBank.ACCESSMODE_1T:
  22. ElSel.value = "1T"; break;
  23. case NESBank.ACCESSMODE_2T:
  24. ElSel.value = "2T"; break;
  25. }
  26. if (ELSel.value !== "8K"){
  27. ELLab.classList.remove("hidden");
  28. ELOff.setAttribute("max", SURF.access_offset_length - 1);
  29. ELOff.value = SURF.access_offset;
  30. //ELOff.setAttribute("value", SURF.access_offset);
  31. }
  32. ELCtrl.classList.remove("hidden");
  33. }
  34. }
  35. function CloseControls(){
  36. if (ELCtrl !== null){
  37. ELCtrl.classList.add("hidden");
  38. }
  39. }
  40. function HANDLE_SurfChange(surf){
  41. if (surf instanceof NESBank){
  42. SURF = surf;
  43. OpenControls();
  44. } else {
  45. SURF = null;
  46. CloseControls();
  47. }
  48. }
  49. function HANDLE_RemoveDuplicates(){
  50. if (SURF !== null){
  51. SURF.removeDuplicates().compact();
  52. }
  53. }
  54. function HANDLE_ModeChange(){
  55. if (ELCtrl !== null && SURF !== null){
  56. var val = this.options[this.selectedIndex].value;
  57. switch(val){
  58. case "8K":
  59. SURF.access_mode = NESBank.ACCESSMODE_8K;
  60. ELLab.classList.add("hidden");
  61. break;
  62. case "4K":
  63. SURF.access_mode = NESBank.ACCESSMODE_4K; break;
  64. case "2K":
  65. SURF.access_mode = NESBank.ACCESSMODE_2K; break;
  66. case "1K":
  67. SURF.access_mode = NESBank.ACCESSMODE_1K; break;
  68. case "1T":
  69. SURF.access_mode = NESBank.ACCESSMODE_1T; break;
  70. case "2T":
  71. SURF.access_mode = NESBank.ACCESSMODE_2T; break;
  72. }
  73. if (SURF.access_mode !== NESBank.ACCESSMODE_8K){
  74. ELLab.classList.remove("hidden");
  75. //ELOff.setAttribute("value", SURF.access_offset);
  76. ELOff.setAttribute("max", SURF.access_offset_length - 1);
  77. ELOff.value = SURF.access_offset;
  78. }
  79. }
  80. }
  81. function HANDLE_OffsetChange(){
  82. if (ELCtrl !== null && SURF !== null){
  83. var val = parseInt(this.value);
  84. SURF.access_offset = val;
  85. }
  86. }
  87. class CTRLBankTools{
  88. constructor(){
  89. GlobalEvents.listen("change_surface", HANDLE_SurfChange);
  90. GlobalEvents.listen("bank_remove_duplicates", HANDLE_RemoveDuplicates);
  91. }
  92. close(){
  93. if (ELSel)
  94. ELSel.removeEventListener("change", HANDLE_ModeChange);
  95. if (ELOff)
  96. ELOff.removeEventListener("change", HANDLE_OffsetChange);
  97. if (ELCtrl)
  98. ELCtrl.classList.add("hidden");
  99. ELCTRL = null;
  100. ELSel = null;
  101. ELLab = null;
  102. ELOff = null;
  103. }
  104. initialize(){
  105. if (ELCtrl === null){
  106. ELCtrl = document.querySelector(".painter-bank-controls");
  107. if (!ELCtrl){
  108. console.log("ERROR: Failed to find 'painter-bank-controls' element");
  109. return;
  110. }
  111. ELSel = ELCtrl.querySelector(".painter-bank-mode");
  112. if (!ELSel){
  113. this.close();
  114. console.log("ERROR: Failed to find 'painter-bank-mode' element.");
  115. return;
  116. }
  117. ELLab = ELCtrl.querySelector(".painter-bank-offset");
  118. if (!ELLab){
  119. this.close();
  120. console.log("ERROR: Failed to find 'painter-bank-offset' element.");
  121. return;
  122. }
  123. ELOff = ELLab.querySelector("#offset-select");
  124. if (!ELOff){
  125. this.close();
  126. console.log("ERROR: Failed to find 'offset-select' element.");
  127. return;
  128. }
  129. ELSel.addEventListener("change", HANDLE_ModeChange);
  130. ELOff.addEventListener("change", HANDLE_OffsetChange);
  131. OpenControls();
  132. }
  133. }
  134. }
  135. const instance = new CTRLBankTools();
  136. export default instance;