Kekilla0 / Item-Macro

Store macros in your items, execute them from your character sheet or from your favorite automation module!
MIT License
18 stars 21 forks source link

v10 migration #41

Closed tposney closed 2 years ago

tposney commented 2 years ago

Not sure where you are on this, but had a play with the v10 branch. There seems to be a problem with editing item macros and the call to item.getMacro

 Item.prototype.getMacro = function(){
      let hasMacro = this.hasMacro();
      let flag = this.getFlag(settings.data.name, `macro`);

      logger.debug("Item | getMacro | ", { hasMacro, flag });

      if(hasMacro)
        return new Macro(flag.data ?? flag);
      return new Macro({ img : this.img, name : this.name, scope : "global", type : "script", });
    }

The line

          return new Macro(flag.data ?? flag);

will always return the old macro if there is one, not the new one (this only affects pre v10 items in a v10 world). I think it should be (or can be)

     Item.prototype.getMacro = function(){
      let hasMacro = this.hasMacro();
      let flag = this.getFlag(settings.data.name, `macro`);

      logger.debug("Item | getMacro | ", { hasMacro, flag });

      if(hasMacro)
        return new Macro(flag.command ? flag : flag?.data);
      return new Macro({ img : this.img, name : this.name, scope : "global", type : "script", });
    }
trioderegion commented 2 years ago

Huge thanks for the report. There has been some development, but nothing ready quite yet. This is very helpful!

tposney commented 2 years ago

As far as I can tell with this change everything I use from itemacros is working, but I only use it to fetch the macro command and run it myself, and edit the macro. So I've not checked anything else.

The use of macro.command ?? macro.data.command to fetch the macro command seems very useful.