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个字符

157 行
3.7KB

  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_ModeChange(){
  50. if (ELCtrl !== null && SURF !== null){
  51. var val = this.options[this.selectedIndex].value;
  52. switch(val){
  53. case "8K":
  54. SURF.access_mode = NESBank.ACCESSMODE_8K;
  55. ELLab.classList.add("hidden");
  56. break;
  57. case "4K":
  58. SURF.access_mode = NESBank.ACCESSMODE_4K; break;
  59. case "2K":
  60. SURF.access_mode = NESBank.ACCESSMODE_2K; break;
  61. case "1K":
  62. SURF.access_mode = NESBank.ACCESSMODE_1K; break;
  63. case "1T":
  64. SURF.access_mode = NESBank.ACCESSMODE_1T; break;
  65. case "2T":
  66. SURF.access_mode = NESBank.ACCESSMODE_2T; break;
  67. }
  68. if (SURF.access_mode !== NESBank.ACCESSMODE_8K){
  69. ELLab.classList.remove("hidden");
  70. //ELOff.setAttribute("value", SURF.access_offset);
  71. ELOff.setAttribute("max", SURF.access_offset_length - 1);
  72. ELOff.value = SURF.access_offset;
  73. }
  74. }
  75. }
  76. function HANDLE_OffsetChange(){
  77. if (ELCtrl !== null && SURF !== null){
  78. var val = parseInt(this.value);
  79. SURF.access_offset = val;
  80. }
  81. }
  82. class CTRLBankTools{
  83. constructor(){
  84. GlobalEvents.listen("change_surface", HANDLE_SurfChange);
  85. }
  86. close(){
  87. if (ELSel)
  88. ELSel.removeEventListener("change", HANDLE_ModeChange);
  89. if (ELOff)
  90. ELOff.removeEventListener("change", HANDLE_OffsetChange);
  91. if (ELCtrl)
  92. ELCtrl.classList.add("hidden");
  93. ELCTRL = null;
  94. ELSel = null;
  95. ELLab = null;
  96. ELOff = null;
  97. }
  98. initialize(){
  99. if (ELCtrl === null){
  100. ELCtrl = document.querySelector(".painter-bank-controls");
  101. if (!ELCtrl){
  102. console.log("ERROR: Failed to find 'painter-bank-controls' element");
  103. return;
  104. }
  105. ELSel = ELCtrl.querySelector(".painter-bank-mode");
  106. if (!ELSel){
  107. this.close();
  108. console.log("ERROR: Failed to find 'painter-bank-mode' element.");
  109. return;
  110. }
  111. ELLab = ELCtrl.querySelector(".painter-bank-offset");
  112. if (!ELLab){
  113. this.close();
  114. console.log("ERROR: Failed to find 'painter-bank-offset' element.");
  115. return;
  116. }
  117. ELOff = ELLab.querySelector("#offset-select");
  118. if (!ELOff){
  119. this.close();
  120. console.log("ERROR: Failed to find 'offset-select' element.");
  121. return;
  122. }
  123. ELSel.addEventListener("change", HANDLE_ModeChange);
  124. ELOff.addEventListener("change", HANDLE_OffsetChange);
  125. OpenControls();
  126. }
  127. }
  128. }
  129. const instance = new CTRLBankTools();
  130. export default instance;