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

CTRLPalettes.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import GlobalEvents from "/app/js/EventCaller.js";
  2. import {NESPalette} from "/app/js/NESPalette.js";
  3. const ATTRIB_NESIDX = "nesidx";
  4. // The two attributes below MUST BOTH be in the element.
  5. const ATTRIB_PALIDX = "palidx"; // This is the palette index (0 - 3 (Tiles) 4 - 7 (Sprites))
  6. const ATTRIB_COLIDX = "palcolidx"; // This is the color index in the selected palette (0 - 3)
  7. var Active_Palette_Index = 0;
  8. var Active_Color_Index = 0;
  9. class CTRLPalettes{
  10. constructor(){
  11. this.__NESPalette = null;
  12. this.__pi = 0; // Palette index.
  13. this.__ci = 0; // Palette color index.
  14. var self = this;
  15. var handle_syspalette_clicked = function(event){
  16. if (this.hasAttribute(ATTRIB_NESIDX)){
  17. var idx = parseInt(this.getAttribute(ATTRIB_NESIDX), 16);
  18. if (idx >= 0 && idx < NESPalette.SystemColors.length){
  19. console.log(idx);
  20. // TODO: Set a selected Tile/Sprite palette index to the color index clicked.
  21. }
  22. }
  23. };
  24. var elist = document.querySelectorAll("[" + ATTRIB_NESIDX + "]");
  25. elist.forEach(function(el){
  26. var idx = parseInt(el.getAttribute(ATTRIB_NESIDX), 16);
  27. if (idx >= 0 && idx < NESPalette.SystemColor.length){
  28. el.style["background-color"] = NESPalette.SystemColor[idx];
  29. el.addEventListener("click", handle_syspalette_clicked);
  30. }
  31. });
  32. var handle_palcolor_clicked = function(event){
  33. if (this.hasAttribute(ATTRIB_PALIDX) && this.hasAttribute(ATTRIB_COLIDX)){
  34. self.__pi = this.getAttribute(ATTRIB_PALIDX);
  35. self.__ci = this.getAttribute(ATTRIB_COLIDX);
  36. console.log("Requesting Palette: " + self.__pi + " | Color: " + self.__ci);
  37. }
  38. };
  39. var elist = document.querySelectorAll("[" + ATTRIB_PALIDX + "]");
  40. elist.forEach(function(el){
  41. if (el.hasAttribute(ATTRIB_PALIDX) && el.hasAttribute(ATTRIB_COLIDX)){
  42. el.addEventListener("click", handle_palcolor_clicked);
  43. }
  44. });
  45. }
  46. get palette(){
  47. return this.__NESPalette;
  48. }
  49. set palette(p){
  50. if (!(p instanceof NESPalette)){
  51. throw new TypeError("Expected NESPalette object instance.");
  52. }
  53. this.__NESPalette = p;
  54. }
  55. }
  56. const instance = new CTRLPalettes();
  57. export default instance;