A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

90 lines
2.5KB

  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. function on_palette_changed(e){
  9. if (e.type == "ALL"){
  10. console.log("ALL");
  11. } else if (e.type == "TILE"){
  12. console.log("TILE Palette:", e.pindex, " | Color:", e.cindex);
  13. } else if (e.type == "SPRITE"){
  14. console.log("SPRITE Palette:", e.pindex, " | Color:", e.cindex);
  15. }
  16. }
  17. function handle_emitted(){
  18. console.log("EMITTED EVENT!");
  19. }
  20. function handle_keyevent(e){
  21. console.log(e);
  22. }
  23. function handle_mouseevent(e){
  24. console.log(e);
  25. }
  26. function handle_mouseclickevent(e){
  27. console.log("MOUSE CLICK ON BUTTON: ", e.button);
  28. }
  29. function TitlePainter(pal){
  30. var elist = document.querySelectorAll(".color-NES-random");
  31. if (elist){
  32. elist.forEach(function(el){
  33. var ca = Math.floor(Math.random() * 11) + 1;
  34. var cb = Math.floor(Math.random() * 3);
  35. var index = (cb*16)+ca;
  36. el.style.color = pal[index];
  37. el.style["background-color"] = "#000";
  38. });
  39. }
  40. }
  41. function initialize(DOC){
  42. TitlePainter(NESPalette.SystemColor);
  43. EmitterElements.initialize();
  44. //EventWindow.enable_emitter_attributes();
  45. GlobalEvents.listen("emitted-event", handle_emitted);
  46. //var nespainter = new NESPainter(DOC.getElementById("painter"));
  47. var palette = new NESPalette();
  48. // TODO: This is just test code. I should remove this.
  49. palette.listen("palettes_changed", on_palette_changed);
  50. // TODO: At least define a more useful set of palettes. As it is, these are just random.
  51. palette.set_palette([
  52. 44,
  53. 11,12,13,
  54. 54,23,43,
  55. 23,18,11,
  56. 4,8,60,
  57. 63,0,11,
  58. 0,15,14,
  59. 9,0,32,
  60. 5,10,20
  61. ]);
  62. console.log(palette.to_asm());
  63. GlobalEvents.emit("set_app_palette", palette);
  64. var input = new Input();
  65. input.preventDefaults = true;
  66. input.mouseTargetElement = document.getElementById("painter");
  67. input.listen("keydown", handle_keyevent);
  68. input.listen("keyup", handle_keyevent);
  69. input.listen("keypress", handle_keyevent);
  70. input.listen("mousemove", handle_mouseevent);
  71. input.listen("mousedown", handle_mouseevent);
  72. input.listen("mouseup", handle_mouseevent);
  73. input.listen("mouseclick", handle_mouseclickevent);
  74. }
  75. //console.log(document.getElementByID("painter"));
  76. initialize(document);