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

104 行
3.1KB

  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. function InvertRGB(hex){
  10. var h = (255 - parseInt(hex, 16)).toString(16);
  11. return (h.length < 2) ? "0" + h : h;
  12. }
  13. function InvertColor(chex, bw){
  14. bw = (bw === true);
  15. if (chex.indexOf("#") === 0){
  16. chex = chex.slice(1);
  17. }
  18. if (chex.length === 3){
  19. chex = chex[0] + chex[0] + chex[1] + chex[1] + chex[2] + chex[2];
  20. }
  21. if (chex.length !== 6){
  22. throw new ValueError("Hex color expected to be 3 or 6 characters long.");
  23. }
  24. if (bw) {
  25. var r = parseInt(chex.slice(0, 2), 16);
  26. var g = parseInt(chex.slice(2, 4), 16);
  27. var b = parseInt(chex.slice(4, 6), 16);
  28. // http://stackoverflow.com/a/3943023/112731
  29. return (r * 0.299 + g * 0.587 + b * 0.114) > 186
  30. ? '#000000' : '#FFFFFF';
  31. }
  32. return "#" + InvertRGB(chex.slice(0, 2)) + InvertRGB(chex.slice(2, 4)) + InvertRGB(chex.slice(4, 6));
  33. }
  34. class CTRLPalettes{
  35. constructor(){
  36. this.__NESPalette = null;
  37. this.__pi = 0; // Palette index.
  38. this.__ci = 0; // Palette color index.
  39. var self = this;
  40. var handle_syspalette_clicked = function(event){
  41. if (this.hasAttribute(ATTRIB_NESIDX)){
  42. var idx = parseInt(this.getAttribute(ATTRIB_NESIDX), 16);
  43. if (idx >= 0 && idx < NESPalette.SystemColor.length){
  44. console.log(idx);
  45. // TODO: Set a selected Tile/Sprite palette index to the color index clicked.
  46. }
  47. }
  48. };
  49. var elist = document.querySelectorAll("[" + ATTRIB_NESIDX + "]");
  50. elist.forEach(function(el){
  51. var idx = parseInt(el.getAttribute(ATTRIB_NESIDX), 16);
  52. if (idx >= 0 && idx < NESPalette.SystemColor.length){
  53. el.style["background-color"] = NESPalette.SystemColor[idx];
  54. el.style.color = InvertColor(NESPalette.SystemColor[idx], true);
  55. el.addEventListener("click", handle_syspalette_clicked);
  56. }
  57. });
  58. var handle_palcolor_clicked = function(event){
  59. if (this.hasAttribute(ATTRIB_PALIDX) && this.hasAttribute(ATTRIB_COLIDX)){
  60. self.__pi = this.getAttribute(ATTRIB_PALIDX);
  61. self.__ci = this.getAttribute(ATTRIB_COLIDX);
  62. console.log("Requesting Palette: " + self.__pi + " | Color: " + self.__ci);
  63. }
  64. };
  65. var elist = document.querySelectorAll("[" + ATTRIB_PALIDX + "]");
  66. elist.forEach(function(el){
  67. if (el.hasAttribute(ATTRIB_PALIDX) && el.hasAttribute(ATTRIB_COLIDX)){
  68. el.addEventListener("click", handle_palcolor_clicked);
  69. }
  70. });
  71. }
  72. get palette(){
  73. return this.__NESPalette;
  74. }
  75. set palette(p){
  76. if (!(p instanceof NESPalette)){
  77. throw new TypeError("Expected NESPalette object instance.");
  78. }
  79. this.__NESPalette = p;
  80. }
  81. }
  82. const instance = new CTRLPalettes();
  83. export default instance;