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.

88 lines
2.6KB

  1. import GlobalEvents from "/app/js/common/EventCaller.js";
  2. import EmitterElements from "/app/js/ui/Emitters.js";
  3. import Input from "/app/js/ui/Input.js";
  4. import Modal from "/app/js/ui/Modal.js";
  5. import CTRLPalettes from "/app/js/ctrls/CTRLPalettes.js";
  6. import CTRLPainter from "/app/js/ctrls/CTRLPainter.js";
  7. import NESPalette from "/app/js/models/NESPalette.js";
  8. import NESTile from "/app/js/models/NESTile.js";
  9. import NESBank from "/app/js/models/NESBank.js";
  10. function TitlePainter(pal){
  11. var elist = document.querySelectorAll(".color-NES-random");
  12. if (elist){
  13. elist.forEach(function(el){
  14. var ca = Math.floor(Math.random() * 11) + 1;
  15. var cb = Math.floor(Math.random() * 3);
  16. var index = (cb*16)+ca;
  17. el.style.color = pal[index];
  18. el.style["background-color"] = "#000";
  19. });
  20. }
  21. }
  22. function initialize(DOC){
  23. TitlePainter(NESPalette.SystemColor);
  24. EmitterElements.initialize();
  25. //GlobalEvents.listen("emitted-event", handle_emitted);
  26. //var nespainter = new NESPainter(DOC.getElementById("painter"));
  27. CTRLPainter.initialize();
  28. var palette = new NESPalette();
  29. // TODO: At least define a more useful set of palettes. As it is, these are just random.
  30. palette.set_palette([
  31. 44,
  32. 11,12,13,
  33. 54,23,43,
  34. 23,18,11,
  35. 4,8,60,
  36. 63,0,11,
  37. 0,15,14,
  38. 9,0,32,
  39. 5,10,20
  40. ]);
  41. console.log(palette.to_asm());
  42. GlobalEvents.emit("set_app_palette", palette);
  43. // TODO: Drop all of this below test code... or put it in a dedicated test app.
  44. var TileA = new NESTile();
  45. var TileB = new NESTile();
  46. TileB.setPixelIndex(0,0,2);
  47. var TileC = TileB.clone().flip(1);
  48. var TileD = TileB.clone().flip(3);
  49. //var TileC = TileB.clone();
  50. //TileC.flip(1);
  51. for (var i=0; i < 64; i++){
  52. console.log(TileC.pixels[i]);
  53. }
  54. console.log("TileA does NOT match TileB: ", TileA.isEq(TileB) == -1);
  55. console.log("TileA does NOT match TileC: ", TileA.isEq(TileC) == -1);
  56. console.log("TileB DOES match TileC with Flag 1: ", TileB.isEq(TileC) == 1);
  57. console.log("TileB DOES match TileD with Flag 3: ", TileB.isEq(TileD) == 3);
  58. console.log(TileC);
  59. console.log(TileC.dataArray);
  60. console.log(TileC.pixels[7]);
  61. var bnk = new NESBank();
  62. bnk.lp[1] = TileB;
  63. bnk.lp[0] = TileC;
  64. bnk.rp[16] = TileD;
  65. console.log(bnk.chr);
  66. console.log("Bank color at coordinates (8,0): ", bnk.getColor(8,0));
  67. console.log("Bank color at coordinates (7,0): ", bnk.getColor(7,0));
  68. console.log("Bank color at coordinates (135, 15): ", bnk.getColor(135,15));
  69. bnk.access_mode = 0;
  70. GlobalEvents.emit("change_surface", bnk);
  71. }
  72. //console.log(document.getElementByID("painter"));
  73. initialize(document);