A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
3.5KB

  1. import GlobalEvents from "/app/js/common/EventCaller.js";
  2. import NESBank from "/app/js/models/NESBank.js";
  3. var EL = null;
  4. var SURF = null;
  5. var LastVal = "all";
  6. function GetSubControls(){
  7. var els = [];
  8. if (EL !== null){
  9. var ellab = EL.querySelectorAll(".painter-bank-offset");
  10. var eloff = null;
  11. if (ellab.length === 1){
  12. els.push(ellab[0]);
  13. eloff = els[0].querySelectorAll("#offset-select");
  14. if (eloff.length === 1){
  15. els.push(eloff[0]);
  16. } else {
  17. console.log("Ambiguous number of 'offset-select' elements.");
  18. }
  19. } else {
  20. console.log("Ambiguous number of 'painter-bank-offset' elements.");
  21. }
  22. }
  23. return (els.length == 2) ? els : null;
  24. }
  25. function OpenControls(){
  26. if (EL !== null && SURF !== null){
  27. var subel = GetSubControls();
  28. switch(SURF.access_mode){
  29. case NESBank.ACCESSMODE_8K:
  30. subel[0].classList.add("hidden");
  31. break;
  32. case NESBank.ACCESSMODE_4K:
  33. case NESBank.ACCESSMODE_2K:
  34. case NESBank.ACCESSMODE_1K:
  35. subel[0].classList.remove("hidden");
  36. subel[1].setAttribute("max", SURF.access_offset_length - 1);
  37. subel[1].setAttribute("value", SURF.access_offset);
  38. break;
  39. }
  40. EL.classList.remove("hidden");
  41. }
  42. }
  43. function CloseControls(){
  44. if (EL !== null){
  45. EL.classList.add("hidden");
  46. }
  47. }
  48. function HANDLE_SurfChange(surf){
  49. if (surf instanceof NESBank){
  50. SURF = surf;
  51. OpenControls();
  52. } else {
  53. SURF = null;
  54. CloseControls();
  55. }
  56. }
  57. function HANDLE_ModeChange(){
  58. if (EL !== null && SURF !== null){
  59. var val = this.options[this.selectedIndex].value;
  60. var subel = GetSubControls();
  61. switch(val){
  62. case "8K":
  63. SURF.access_mode = NESBank.ACCESSMODE_8K;
  64. subel[0].classList.add("hidden");
  65. break;
  66. case "4K":
  67. SURF.access_mode = NESBank.ACCESSMODE_4K;
  68. subel[0].classList.remove("hidden");
  69. subel[1].setAttribute("value", SURF.access_offset);
  70. subel[1].setAttribute("max", SURF.access_offset_length - 1);
  71. break;
  72. case "2K":
  73. SURF.access_mode = NESBank.ACCESSMODE_2K;
  74. subel[0].classList.remove("hidden");
  75. subel[1].setAttribute("value", SURF.access_offset);
  76. subel[1].setAttribute("max", SURF.access_offset_length - 1);
  77. break;
  78. case "1K":
  79. SURF.access_mode = NESBank.ACCESSMODE_1K;
  80. subel[0].classList.remove("hidden");
  81. subel[1].setAttribute("value", SURF.access_offset);
  82. subel[1].setAttribute("max", SURF.access_offset_length - 1);
  83. break;
  84. }
  85. }
  86. }
  87. function HANDLE_OffsetChange(){
  88. if (EL !== null && SURF !== null){
  89. var val = parseInt(this.value);
  90. SURF.access_offset = val;
  91. }
  92. }
  93. class CTRLBankTools{
  94. constructor(){
  95. GlobalEvents.listen("change_surface", HANDLE_SurfChange);
  96. }
  97. initialize(){
  98. if (EL === null){
  99. EL = document.querySelectorAll(".painter-bank-controls");
  100. if (EL.length !== 1){
  101. console.log("ERROR: More than one painter-bank-controls element found. Ambiguous State.");
  102. return;
  103. }
  104. EL = EL[0];
  105. var elsel = EL.querySelectorAll(".painter-bank-mode");
  106. if (elsel.length !== 1){
  107. console.log("Ambiguous number of 'painter-bank-mode' elements.");
  108. EL = null;
  109. return;
  110. }
  111. elsel = elsel[0];
  112. elsel.addEventListener("change", HANDLE_ModeChange);
  113. var subel = GetSubControls();
  114. subel[1].addEventListener("change", HANDLE_OffsetChange);
  115. OpenControls();
  116. }
  117. }
  118. }
  119. const instance = new CTRLBankTools();
  120. export default instance;