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.

88 Zeilen
2.4KB

  1. import GlobalEvents from "/app/js/common/EventCaller.js";
  2. import Input from "/app/js/ui/Input.js";
  3. class Modal{
  4. constructor(){
  5. this.__currentModalEl = null;
  6. window.addEventListener("click", (function(event){
  7. if (event.target === this.__currentModalEl){
  8. this.close_modal();
  9. }
  10. }).bind(this));
  11. GlobalEvents.listen("modal-open", (function(target, event){
  12. if (event.hasOwnProperty("id") && typeof(event.id) === 'string'){
  13. var force = (event.hasOwnProperty("force")) ? event.force === true : false;
  14. this.open_modal_id(event.id, force);
  15. }
  16. }).bind(this));
  17. GlobalEvents.listen("modal-close", (function(target, event){
  18. this.close_modal();
  19. }).bind(this));
  20. GlobalEvents.listen("modal-submit", (function(target, event){
  21. if (!event.hasOwnProperty("subevent"))
  22. return;
  23. var ename = event.subevent;
  24. var vals = {};
  25. if (event.hasOwnProperty("ids")){
  26. var ids = event.ids.split(",");
  27. var cel = this.__currentModalEl;
  28. ids.forEach((item) => {
  29. var id = item.trim();
  30. var el = cel.querySelector("[name='" + id + "']");
  31. if (el) // TODO: Check if el is an INPUT node and switch between the node types.
  32. vals[id] = el.value;
  33. });
  34. }
  35. GlobalEvents.emit(ename, vals);
  36. if (event.hasOwnProperty("closeoncomplete"))
  37. this.close_modal();
  38. }).bind(this));
  39. }
  40. get currentModalElement(){
  41. return this.__currentModalEl;
  42. }
  43. open_modal_id(idname, force=false){
  44. var el = document.getElementById(idname);
  45. if (el.classList.contains("modal") && this.__currentModalEl !== el){
  46. if (this.__currentModalEl !== null && force)
  47. this.close_modal();
  48. if (this.__currentModalEl === null){
  49. if (el){
  50. return this.open_modal_element(el);
  51. }
  52. }
  53. }
  54. return this;
  55. }
  56. open_modal_element(el, force=false){
  57. if (el.classList.contains("modal")){
  58. if (this.__currentModalEl !== null && force)
  59. this.close_modal();
  60. if (this.__currentModalEl === null){
  61. el.classList.add("modal-visible");
  62. this.__currentModalEl = el;
  63. }
  64. }
  65. return this;
  66. }
  67. close_modal(){
  68. if (this.__currentModalEl !== null){
  69. this.__currentModalEl.classList.remove("modal-visible");
  70. this.__currentModalEl = null;
  71. }
  72. return this;
  73. }
  74. }
  75. const instance = new Modal();
  76. export default instance;