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文字以内のものにしてください。

main.js 3.1KB

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