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 символов.

100 lines
2.4KB

  1. import {EventCaller} from '/app/js/EventCaller.js'
  2. function handle_emitter(event){
  3. var el = event.target;
  4. if (el.hasAttribute("emit")){
  5. var args = [el.getAttribute("emit")];
  6. if (el.hasAttribute("emit-args")){
  7. try {
  8. var j = JSON.parse(el.getAttribute("emit-args"));
  9. if (j instanceof Array){
  10. args.concat(j);
  11. } else {
  12. args.push(j);
  13. }
  14. } catch (e) {
  15. console.log("Failed to emit '" + args[0] + "'. Arguments not in valid JSON form.");
  16. return;
  17. }
  18. }
  19. EventWindow.instance.emit.apply(EventWindow.instance, args);
  20. }
  21. }
  22. /**
  23. * Wraps the browser's window object around the EventCaller allowing the user to connect to system events
  24. * by listening for those events (ex: "onclick", "onresize", etc).
  25. *
  26. * Users should not directly set the window event handler functions if using this class.
  27. */
  28. class EventWindow extends EventCaller{
  29. constructor(){
  30. super();
  31. if (!EventWindow.instance)
  32. EventWindow.instance = this;
  33. return EventWindow.instance;
  34. }
  35. get emitter_attributes_enabled(){
  36. return this.is_listening("onclick", handle_emitter);
  37. }
  38. enable_emitter_attributes(enable=true){
  39. if (enable === true){
  40. this.listen("onclick", handle_emitter);
  41. } else {
  42. this.unlisten("onclick", handle_emitter);
  43. }
  44. }
  45. listen(eventName, callback, owner=null, once=false){
  46. if (window.hasOwnProperty(eventName)){
  47. if (window[eventName] === null || typeof(window[eventName]) === 'undefined'){
  48. window[eventName] = (function(event){
  49. this.emit(eventName, event);
  50. }).bind(this);
  51. }
  52. }
  53. super.listen(eventName, callback, owner, once);
  54. return this;
  55. }
  56. unlisten(eventName, callback, owner=null){
  57. super.unlisten(eventName, callback, owner);
  58. if (window.hasOwnProperty(eventName)){
  59. if (super.event_listener_count(eventName) == 0){
  60. window[eventName] = undefined;
  61. }
  62. }
  63. return this;
  64. }
  65. unlisten_event(eventName){
  66. super.unlisten_event(eventName);
  67. if (window.hasOwnProperty(eventName)){
  68. window[eventName] = undefined;
  69. }
  70. return this;
  71. }
  72. unlisten_all(){
  73. var we = this.watchedEvents;
  74. super.unlisten_all();
  75. for (var i=0; i < we.length; i++){
  76. if (window.hasOwnProperty(we[i])){
  77. window[we[i]] = undefined;
  78. }
  79. }
  80. return this;
  81. }
  82. }
  83. const instance = new EventWindow();
  84. //Object.freeze(instance);
  85. export default instance;