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

167 行
3.7KB

  1. export class NESPalette {
  2. constructor(){
  3. this.__BGColor = 63; // Index to the background color ALL palettes MUST share.
  4. this.__palette = [
  5. // Tile/Background Palettes
  6. 0,0,0,
  7. 0,0,0,
  8. 0,0,0,
  9. 0,0,0,
  10. // Sprite Palettes
  11. 0,0,0,
  12. 0,0,0,
  13. 0,0,0,
  14. 0,0,0
  15. ];
  16. }
  17. set_palette(idx, p=8){
  18. if (typeof(p) != 'number')
  19. throw new TypeError("First argument expected to be a number.");
  20. if (!(idx instanceof Array))
  21. throw new TypeError("Expected an array of color index values.");
  22. if (p < 0 || p >= 8){ // Setting ALL palettes!
  23. if (idx.length != 25)
  24. throw new RangeError("Color array must contain 25 color values to fill all palettes.");
  25. this.__BGColor = idx[0];
  26. for (var i=0; i < 24; i++){
  27. this.__palette[i] = idx[i+1]
  28. }
  29. } else { // Setting a specific palette.
  30. if (idx.length != 3)
  31. throw new RangeError("Color array must contain three color values.");
  32. p *= 3;
  33. for (var i=0; i < 4; i++){
  34. if (typeof(idx[i]) === 'number'){
  35. this.__palette[p+i] = idx[i];
  36. }
  37. }
  38. }
  39. }
  40. get_palette_syscolor_index(p, idx){
  41. if (typeof(p) != 'number' || typeof(idx) != 'number')
  42. throw new TypeError("Palette and color index expected to be numbers.");
  43. if (p < 0 || p >= 8){
  44. throw new RangeError("Palette index is out of bounds.");
  45. }
  46. if (idx < 0 || idx >= 4){
  47. throw new RangeError("Palette color index is out of bounds.");
  48. }
  49. return (idx === 0) ? this.__BGColor : this.__palette[(p*3)+(idx-1)];
  50. }
  51. get_palette_color(p, idx){
  52. if (typeof(p) != 'number' || typeof(idx) != 'number')
  53. throw new TypeError("Palette and color index expected to be numbers.");
  54. if (p < 0 || p >= 8){
  55. throw new RangeError("Palette index is out of bounds.");
  56. }
  57. if (idx < 0 || idx >= 4){
  58. throw new RangeError("Palette color index is out of bounds.");
  59. }
  60. return NESPalette.SystemColor(this.get_palette_syscolor_index(p, idx));
  61. }
  62. to_asm(memname="PaletteData"){
  63. var NumToHex=function(n){
  64. var h = n.toString(16);
  65. if (h.length %2)
  66. h = '0' + h;
  67. return '$' + h;
  68. };
  69. var BGHex = NumToHex(this.__BGColor);
  70. var s = memname + ":\n\t.db ";
  71. // Storing background palette data.
  72. for (var i=0; i < 12; i++){
  73. if (i % 3 == 0)
  74. s += ((i == 0) ? "" : " ") + BGHex;
  75. s += " " + NumToHex(this.__palette[i]);
  76. }
  77. s += "\t; Background palette data.\n\t.db ";
  78. // Storing foreground palette data.
  79. for (var i=12; i < 24; i++){
  80. if (i % 3 == 0)
  81. s += ((i == 12) ? "" : " ") + BGHex;
  82. s += " " + NumToHex(this.__palette[i]);
  83. }
  84. s += "\t; Foreground palette data.";
  85. return s;
  86. }
  87. }
  88. // NES Palette color information comes from the following site...
  89. // http://www.thealmightyguru.com/Games/Hacking/Wiki/index.php/NES_Palette
  90. NESPalette.SystemColor = [
  91. "#7C7C7C",
  92. "#0000FC",
  93. "#0000BC",
  94. "#4428BC",
  95. "#940084",
  96. "#A80020",
  97. "#A81000",
  98. "#881400",
  99. "#503000",
  100. "#007800",
  101. "#006800",
  102. "#005800",
  103. "#004058",
  104. "#000000",
  105. "#000000",
  106. "#000000",
  107. "#BCBCBC",
  108. "#0078F8",
  109. "#0058F8",
  110. "#6844FC",
  111. "#D800CC",
  112. "#E40058",
  113. "#F83800",
  114. "#E45C10",
  115. "#AC7C00",
  116. "#00B800",
  117. "#00A800",
  118. "#00A844",
  119. "#008888",
  120. "#000000",
  121. "#000000",
  122. "#000000",
  123. "#F8F8F8",
  124. "#3CBCFC",
  125. "#6888FC",
  126. "#9878F8",
  127. "#F878F8",
  128. "#F85898",
  129. "#F87858",
  130. "#FCA044",
  131. "#F8B800",
  132. "#B8F818",
  133. "#58D854",
  134. "#58F898",
  135. "#00E8D8",
  136. "#787878",
  137. "#000000",
  138. "#000000",
  139. "#FCFCFC",
  140. "#A4E4FC",
  141. "#B8B8F8",
  142. "#D8B8F8",
  143. "#F8B8F8",
  144. "#F8A4C0",
  145. "#F0D0B0",
  146. "#FCE0A8",
  147. "#F8D878",
  148. "#D8F878",
  149. "#B8F8B8",
  150. "#B8F8D8",
  151. "#00FCFC",
  152. "#F8D8F8",
  153. "#000000",
  154. "#000000"
  155. ];