A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.4KB

  1. import GlobalEvents from "/app/js/common/EventCaller.js";
  2. import Utils from "/app/js/common/Utils.js";
  3. import NESBank from "/app/js/models/NESBank.js";
  4. import NESPalette from "/app/js/models/NESPalette.js";
  5. var SURF = null;
  6. function LoadFile(file){
  7. if (SURF !== null){
  8. if (SURF instanceof NESBank){
  9. var reader = new FileReader();
  10. reader.onload = function(e){
  11. try {
  12. SURF.chr = new Uint8Array(e.target.result);
  13. } catch (e) {
  14. console.log(e.toString());
  15. }
  16. }
  17. reader.readAsArrayBuffer(file);
  18. }
  19. }
  20. }
  21. function HANDLE_DragOver(e){
  22. e.stopPropagation();
  23. e.preventDefault();
  24. e.dataTransfer.dropEffect = 'copy';
  25. };
  26. function HANDLE_FileDrop(e){
  27. e.stopPropagation();
  28. e.preventDefault();
  29. var files = e.dataTransfer.files;
  30. for (let i=0; i < files.length; i++){
  31. LoadFile(files[i]);
  32. }
  33. }
  34. function HANDLE_SurfChange(surf){
  35. if (surf instanceof NESBank){
  36. SURF = surf;
  37. } else {
  38. SURF = null;
  39. }
  40. }
  41. class CTRLIO{
  42. constructor(){
  43. GlobalEvents.listen("change_surface", HANDLE_SurfChange);
  44. }
  45. initialize(){
  46. var e = document.querySelectorAll(".drop-zone");
  47. for (let i=0; i < e.length; e++){
  48. e[i].addEventListener("dragover", HANDLE_DragOver);
  49. e[i].addEventListener("drop", HANDLE_FileDrop);
  50. }
  51. }
  52. }
  53. const instance = new CTRLIO();
  54. export default instance;