A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

124 linhas
2.8KB

  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. var Banks = {};
  5. var CurrentBank = "";
  6. class CTRLBanksStore{
  7. constructor(){
  8. var HANDLE_ChangeSurface = function(surf){
  9. if (!(surf instanceof NESBank)){
  10. // TODO: Unselect any current bank element.
  11. CurrentBankIndex = "";
  12. } else {
  13. if (Banks.length <= 0 || (CurrentBank !== "" && Banks[CurrentBank].bank !== surf)){
  14. console.log("WARNING: Bank object being set outside of Bank Store.");
  15. }
  16. }
  17. }
  18. GlobalEvents.listen("change_surface", HANDLE_ChangeSurface);
  19. }
  20. get length(){
  21. return Object.keys(Banks).length;
  22. }
  23. get json(){
  24. var data = [];
  25. Object.keys(Banks).forEach((key) => {
  26. if (Banks.hasOwnProperty(key)){
  27. data.push({name:key, data:Banks[key].bank.base64});
  28. }
  29. });
  30. return JSON.stringify(data);
  31. }
  32. initialize(){
  33. if (this.length <= 0){
  34. this.createBank("Bank");
  35. }
  36. return this;
  37. }
  38. createBank(name, bbase64){
  39. if (!(name in Banks)){
  40. var bank = new NESBank();
  41. if (typeof(bbase64) === "string"){
  42. try {
  43. bank.base64 = bbase64;
  44. } catch (e) {
  45. console.log("Failed to create Bank. " + e.toString());
  46. bank = null;
  47. }
  48. }
  49. if (bank !== null){
  50. var el = null; // This will be the element associated with this Bank. For now, it's a place holder.
  51. Banks[name] = {bank:bank, el:el};
  52. //Banks.push([name, bank, el]);
  53. if (this.length <= 1){
  54. GlobalEvents.emit("change_surface", bank);
  55. }
  56. }
  57. }
  58. return this;
  59. }
  60. removeBank(name){
  61. if (name in Banks){
  62. if (name === CurrentBank){
  63. var keys = Object.keys(Banks);
  64. if (keys.length > 1){
  65. CurrentBank = (keys[0] !== name) ? keys[0] : keys[1];
  66. } else {
  67. CurrentBank = "";
  68. }
  69. }
  70. // TODO: Remove Banks[name].el from the DOM.
  71. delete Banks[name];
  72. if (CurrentBank !== ""){
  73. // TODO: Activate new Bank.
  74. }
  75. }
  76. return this;
  77. }
  78. renameBank(name, newname){
  79. if ((name in Banks) && !(newname in Banks)){
  80. Banks[newname] = Banks[name];
  81. delete Banks[name];
  82. // TODO: Change the name in Banks[newname].el
  83. }
  84. return this;
  85. }
  86. activateBank(name){
  87. if (CurrentBank !== name && (name in Banks)){
  88. // TODO: Switch the active element object.
  89. CurrentBank = name;
  90. GlobalEvents.emit("change_surface", Banks[CurrentBank].bank);
  91. }
  92. return this;
  93. }
  94. clear(){
  95. // TODO: Loop through all keys and remove the elements from the DOM.
  96. Banks = {};
  97. CurrentBank = "";
  98. }
  99. }
  100. const instance = new CTRLBanksStore();
  101. export default instance;