A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

NESNameTable.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import Utils from "/app/js/common/Utils.js";
  2. import ISurface from "/app/js/ifaces/ISurface.js";
  3. import NESBank from "/app/js/models/NESBank.js";
  4. import NESPalette from "/app/js/models/NESPalette.js";
  5. export default class NESNameTable extends ISurface{
  6. constructor(){
  7. super();
  8. this.__bank = null;
  9. this.__palette = null;
  10. this.__tiles = [];
  11. this.__attribs = [];
  12. for (let i=0; i < 960; i++)
  13. this.__tiles[i] = 0;
  14. for (let i=0; i < 64; i++)
  15. this.__attribs[i] = [0,0,0,0];
  16. }
  17. get bank(){return this.__bank;}
  18. set bank(b){
  19. if (b !== null and !(b instanceof NESBank))
  20. throw new TypeError("Expected a NESBank object.");
  21. this.__bank = b;
  22. }
  23. get palette(){return this.__palette;}
  24. set palette(p){
  25. if (p !== null && !(p instanceof NESPalette))
  26. throw new TypeError("Expected a NESPalette object.");
  27. this.__palette = p;
  28. }
  29. get width(){return 256;}
  30. get height(){return 240;}
  31. get length(){return 0;}
  32. get undos(){return 0;}
  33. get redos(){return 0;}
  34. copy(b){
  35. this.bank = b.bank;
  36. this.palette = b.palette;
  37. for (let i=0; i < 960; i++)
  38. this.__tiles[i] = b.__tiles[i];
  39. for (let i=0; i < 64; i++){
  40. this.__attribs[i] = [
  41. b.__attribs[i][0],
  42. b.__attribs[i][1],
  43. b.__attribs[i][2],
  44. b.__attribs[i][3]
  45. ];
  46. }
  47. return this;
  48. }
  49. clone(){
  50. return (new NESNameTable()).clone(this);
  51. }
  52. snapshot(){return this;}
  53. undo(){return this;}
  54. redo(){return this;}
  55. clearUndos(){return this;}
  56. clearRedos(){return this;}
  57. clearHistory(){
  58. return this.clearUndos().clearRedos();
  59. }
  60. getColor(x, y){
  61. var pal = {pi:-1, ci:-1};
  62. try {
  63. pal = this.getColorIndex(x, y);
  64. } catch (e) {throw e;}
  65. if (this.__palette !== null && pal.pi >= 0 && pal.ci >= 0) {
  66. return this.__palette.get_palette_color(pal.pi, pal.ci);
  67. } else if (pal.ci >= 0){
  68. return NESPalette.Default(pal.ci);
  69. }
  70. return NESPalette.Default(4);
  71. }
  72. getColorIndex(x, y){
  73. if (x < 0 || x >= this.width || y < 0 || y >= this.height)
  74. throw new RangeError("Coordinates are out of bounds.");
  75. var pi = -1;
  76. var ci = -1;
  77. if (this.__bank !== null){
  78. var _x = Math.floor(x % 8);
  79. var _y = Math.floor(y % 8);
  80. var tileX = Math.floor(x / 32);
  81. var tileY = Math.floor(y / 32);
  82. var tileIndex = 256 + this.__tiles[(tileY * 32) + tileX];
  83. ci = this.__bank.rp[tileIndex].getPixelIndex(_x, _y);
  84. pi = this._PaletteFromCoords(x, y);
  85. }
  86. return {pi:pi, ci:ci};
  87. }
  88. setColorIndex(x, y, ci, pi){
  89. return this;
  90. }
  91. _PaletteFromCoords(x,y){
  92. var blockX = Math.floor(x / 32);
  93. var blockY = Math.floor(y / 32);
  94. var bIndex = (blockY * 8) + blockX;
  95. var palX = Math.floor(x % 16);
  96. var palY = Math.floor(y % 16);
  97. var pIndex = ((palX < 8) ? 0 : 1) + ((palY >= 8) ? 2 : 0);
  98. return this.__attribs[bIndex][pIndex];
  99. }
  100. }