A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

66 líneas
1.8KB

  1. import Utils from "/app/js/common/Utils.js";
  2. import {EventCaller} from "/app/js/common/EventCaller.js";
  3. export default class EditableText extends EventCaller{
  4. constructor(srcel, clsname){
  5. super();
  6. this.__spanEl = null;
  7. this.__inputEl = null;
  8. var els = srcel.querySelectorAll("." + clsname);
  9. for (let i=0; i < els.length; i++){
  10. if (els[i].nodeName === "SPAN")
  11. this.__spanEl = els[i];
  12. else if (els[i].nodeName === "INPUT")
  13. this.__inputEl = els[i];
  14. }
  15. if (this.__spanEl === null || this.__inputEl === null)
  16. throw new Error("Missing required SPAN and INPUT elements.");
  17. var self = this;
  18. this.__inputEl.addEventListener("blur", function(){
  19. if (!this.classList.contains("hidden")){
  20. self.__spanEl.innerHTML = this.value;
  21. this.classList.add("hidden");
  22. self.__spanEl.classList.remove("hidden");
  23. self.emit("value_change", this.value);
  24. }
  25. });
  26. this.__spanEl.addEventListener("click", function(){
  27. if (!this.classList.contains("hidden")){
  28. self.__inputEl.value = this.innerHTML;
  29. this.classList.add("hidden");
  30. self.__inputEl.classList.remove("hidden");
  31. }
  32. });
  33. if (this.__spanEl.classList.contains("hidden") && this.__inputEl.classList.contains("hidden")){
  34. this.__spanEl.classList.remove("hidden");
  35. } else if (!this.__spanEl.classList.contains("hidden") && !this.__inputEl.classList.contains("hidden")){
  36. this.__inputEl.classList.add("hidden");
  37. }
  38. }
  39. get value(){
  40. if (this.__spanEl.classList.contains("hidden")){
  41. return this.__inputEl.value;
  42. } else {
  43. return this.__spanEl.innerHTML;
  44. }
  45. }
  46. set value(v){
  47. this.__inputEl.value = v;
  48. this.__spanEl.innerHTML = v;
  49. this.emit("value_change", v);
  50. }
  51. }