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

CTRLBankTools.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. break;
  22. }
  23. if (ELSel.value !== "8K"){
  24. ELLab.classList.remove("hidden");
  25. ELOff.setAttribute("max", SURF.access_offset_length - 1);
  26. ELOff.value = SURF.access_offset;
  27. //ELOff.setAttribute("value", SURF.access_offset);
  28. }
  29. ELCtrl.classList.remove("hidden");
  30. }
  31. }
  32. function CloseControls(){
  33. if (ELCtrl !== null){
  34. ELCtrl.classList.add("hidden");
  35. }
  36. }
  37. function HANDLE_SurfChange(surf){
  38. if (surf instanceof NESBank){
  39. SURF = surf;
  40. OpenControls();
  41. } else {
  42. SURF = null;
  43. CloseControls();
  44. }
  45. }
  46. function HANDLE_ModeChange(){
  47. if (ELCtrl !== null && SURF !== null){
  48. var val = this.options[this.selectedIndex].value;
  49. switch(val){
  50. case "8K":
  51. SURF.access_mode = NESBank.ACCESSMODE_8K;
  52. ELLab.classList.add("hidden");
  53. break;
  54. case "4K":
  55. SURF.access_mode = NESBank.ACCESSMODE_4K; break;
  56. case "2K":
  57. SURF.access_mode = NESBank.ACCESSMODE_2K; break;
  58. case "1K":
  59. SURF.access_mode = NESBank.ACCESSMODE_1K; break;
  60. }
  61. if (SURF.access_mode !== NESBank.ACCESSMODE_8K){
  62. ELLab.classList.remove("hidden");
  63. //ELOff.setAttribute("value", SURF.access_offset);
  64. ELOff.setAttribute("max", SURF.access_offset_length - 1);
  65. ELOff.value = SURF.access_offset;
  66. }
  67. }
  68. }
  69. function HANDLE_OffsetChange(){
  70. if (ELCtrl !== null && SURF !== null){
  71. var val = parseInt(this.value);
  72. SURF.access_offset = val;
  73. }
  74. }
  75. class CTRLBankTools{
  76. constructor(){
  77. GlobalEvents.listen("change_surface", HANDLE_SurfChange);
  78. }
  79. close(){
  80. if (ELSel)
  81. ELSel.removeEventListener("change", HANDLE_ModeChange);
  82. if (ELOff)
  83. ELOff.removeEventListener("change", HANDLE_OffsetChange);
  84. if (ELCtrl)
  85. ELCtrl.classList.add("hidden");
  86. ELCTRL = null;
  87. ELSel = null;
  88. ELLab = null;
  89. ELOff = null;
  90. }
  91. initialize(){
  92. if (ELCtrl === null){
  93. ELCtrl = document.querySelector(".painter-bank-controls");
  94. if (!ELCtrl){
  95. console.log("ERROR: Failed to find 'painter-bank-controls' element");
  96. return;
  97. }
  98. ELSel = ELCtrl.querySelector(".painter-bank-mode");
  99. if (!ELSel){
  100. this.close();
  101. console.log("ERROR: Failed to find 'painter-bank-mode' element.");
  102. return;
  103. }
  104. ELLab = ELCtrl.querySelector(".painter-bank-offset");
  105. if (!ELLab){
  106. this.close();
  107. console.log("ERROR: Failed to find 'painter-bank-offset' element.");
  108. return;
  109. }
  110. ELOff = ELLab.querySelector("#offset-select");
  111. if (!ELOff){
  112. this.close();
  113. console.log("ERROR: Failed to find 'offset-select' element.");
  114. return;
  115. }
  116. ELSel.addEventListener("change", HANDLE_ModeChange);
  117. ELOff.addEventListener("change", HANDLE_OffsetChange);
  118. OpenControls();
  119. }
  120. }
  121. }
  122. const instance = new CTRLBankTools();
  123. export default instance;