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 символів.

92 lines
2.1KB

  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 OpenControls(){
  7. if (EL !== null && SURF !== null){
  8. EL.classList.remove("hidden");
  9. var e = EL.querySelectorAll("input[type='radio']:checked");
  10. if (e.length > 0){
  11. var val = e[0].getAttribute("value");
  12. LastVal = val;
  13. if (val === "tiles"){
  14. SURF.access_mode = 0;
  15. GlobalEvents.emit("set_palette_mode", 0);
  16. } else if (val === "sprites"){
  17. SURF.access_mode = 1;
  18. GlobalEvents.emit("set_palette_mode", 1);
  19. } else {
  20. SURF.access_mode = 2;
  21. }
  22. }
  23. }
  24. }
  25. function CloseControls(){
  26. if (EL !== null){
  27. EL.classList.add("hidden");
  28. }
  29. }
  30. function HANDLE_ModeChanged(){
  31. var val = this.getAttribute("value");
  32. if (val !== LastVal){
  33. LastVal = val;
  34. if (val === "all"){
  35. SURF.access_mode = NESBank.ACCESSMODE_FULL;
  36. } else if (val === "sprites"){
  37. SURF.access_mode = NESBank.ACCESSMODE_SPRITE;
  38. GlobalEvents.emit("set_palette_mode", 1);
  39. } else if (val === "tiles"){
  40. SURF.access_mode = NESBank.ACCESSMODE_BACKGROUND;
  41. GlobalEvents.emit("set_palette_mode", 0);
  42. }
  43. }
  44. }
  45. class CTRLBankTools{
  46. constructor(){
  47. var handle_surfchange = function(surf){
  48. if (surf instanceof NESBank){
  49. SURF = surf;
  50. OpenControls();
  51. } else {
  52. SURF = null;
  53. CloseControls();
  54. }
  55. };
  56. GlobalEvents.listen("change_surface", handle_surfchange);
  57. }
  58. initialize(){
  59. if (EL === null){
  60. EL = document.querySelectorAll(".painter-bank-controls");
  61. if (EL.length !== 1){
  62. console.log("ERROR: More than one painter-bank-controls element found. Ambiguous State.");
  63. return;
  64. }
  65. EL = EL[0];
  66. var rel = EL.querySelectorAll("input[type='radio']");
  67. for (let i=0; i < rel.length; i++){
  68. rel[i].addEventListener("change", HANDLE_ModeChanged);
  69. }
  70. OpenControls();
  71. }
  72. }
  73. }
  74. const instance = new CTRLBankTools();
  75. export default instance;