Code Monkey home page Code Monkey logo

item-macro's Introduction

Item Macro

This is a FoundryVTT module for the **5e, SFRPG, SWADE, Old-School Essentials, Dungeon World, and Simple Worldbuilding (as of now) systems. It allow macros to be saved inside of an item and for various different ways to execute macros.
You can execute the macro from the "item" class using the executeMacro(...args) function, from the character sheet (if the settings are satisfied to do so), from the hotbar using the default rollItemMacro function for your system (if the settings are satisfied to do so), or from token-action-hud.

Installation

  1. Inside Foundry's Configuration and Setup screen, go to Add-on Modules
  2. Click "Install Module"
  3. Seach for the Module, install in the Module Manager.
  4. In the Manifest URL field paste: https://github.com/Kekilla0/Item-Macro/releases/download/v1.5.3/module.json

Usage

Once activated, open an Item Sheet, click on the Item Macro button to open the Macro window. In Action

Various different settings will change the way Item Macro interacts with the game server. In Action

With no settings enabled, you can still execute the macro that is saved in the item, perfect for macros! In Action

Added context menu support allowing GM users to mass update item-macros on like named items throughout the game! (the context menu is on items in the game directory, will update all item-macros in the item-directory, actor items, and token items)

Added Item Functionality

  1. Item.hasMacro() => returns boolean on if the item has a macro command
  2. Item.getMacro() => returns Macro instance, if the item has a macro command
  3. Item.setMacro(Macro) => overwrites and saves given Macro to the Item
  4. Item.executeMacro(...args) => executes Macro command, giving item, speaker, actor, token, character, and event constants. This is recognized as the macro itself. Pass an event as the first argument.

Added System Functionality

Simple Worldbuilding

  • Item names on actor sheets have been converted to rollable links that will execute the macro attached to the item when the "Enable Character Sheet Hook" is enabled.
  • Item names will now highlight on hover to indicate this added functionality.
  • Dragging an item to the hotbar will create a macro utilizing an added system helper game.worldbuilding.rollItemMacro(itemNameString).
  • Dropping formula-type item attributes will continue to create the default new Roll system macro.

Support

For questions, feature requests, or bug reports, feel free to contact me on the Foundry Discord (honeybadger#2614) or open an issue here directly.

License

This Foundry VTT module, writen by Kekilla, is licensed under a MIT License.

This work is licensed under Foundry Virtual Tabletop EULA - Limited License Agreement for module development.

item-macro's People

Contributors

espositos avatar injustfr avatar kekilla0 avatar krbz999 avatar operation404 avatar trioderegion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

item-macro's Issues

stack overflow when trying to update item macro

I'm currently using item-macro on my V10 server and I tried to update an older macro. When I hit Save Macro, I got a massive error stack "Maximum depth exceeded" with almost exclusively calls to Object.expandObject. The item macro is not saved and any already existing macro is deleted,

image
It's expandObject all the way down. :/

[Bug] v10 Update World Macros does not work

DnD5e 2.0.3, Foundry 10.288, Item Macro 1.8.0
Trying to right-click an item in the sidebar and using update world macros fails with the error Cannot read properties of undefined (reading 'name'). Looking at the console, it seems to be trying to fetch it by _id and it's coming back undefined.
image

Magic Item Spell throwing error when trying to roll.

When trying to use a spell from a magic item(using the "Magic Items" module), the following error gets thrown since dnd5e v 1.2.0 and in foundry v0.7.8.
item-macro-error

Edit 12/19/2020
It looks like this is only happening on 5e character sheets that are not the default sheet. I've replicated it on both tidysheet and sky's alternative sheet.

Add option to run the macro in addition to the base item roll, rather than replacing the base item roll

(dnd5e system for reference)

There may often be times that a user would like an item to perform the standard system item roll, but additionally perform some macro magic. It would be nice to have a checkbox in the item macro config that would cause the base item roll to be rolled prior to the item macro.

edit: Actually I just realized that you can call item.roll() in the item macro to do basically this.

Add support for V9 sheet registration

Foundry V9 adds the Macros.registerSheet method which allows modules to register custom sheets for the macro sheet. Though Item Macro doesn't take this method into account yet when rendering it's macro sheet.

Support for Simple Worldbuilding

Simple Worldbuilding is one of the core Foundry modules and, even though it is very limited, it is flexible.

Item creation on that module basically only allow short formulas to be associated with items. If the item entity could call for a macro, it would basically solve all problems for custom games.

I do not even know if that is possible, however, I hope this gets to be considered with care.

Foundry V11 Update?

While Item-Macro seems to run on V11 it causes a maximum call stack error.

RangeError: undefined. Maximum call stack size exceeded
[Detected 1 package: itemacro]
    at mergeObject (commons.js:2667:23)
    at _mergeUpdate (commons.js:2737:14)
    at mergeObject (commons.js:2694:41)
    at _mergeUpdate (commons.js:2737:14)
    at mergeObject (commons.js:2694:41)
    at _mergeUpdate (commons.js:2737:14)
    at mergeObject (commons.js:2694:41) (Repeats till it runs out of space)

I am pretty clueless when it comes to these things, but I figured I should report it.

error on actor hook setting

following error is thrown when setting the character sheet hook setting. I believe this is also causing that setting to not work. foundry 0.8.7

image

Items dragged onto the hotbar no longer execute item macros.

This seems to have broken in dnd5e 1.6.

When dragging an item from the sheet to the hotbar, it now produces the macro game.dnd5e.macros.rollItem("item name"), which Item Macro doesn't touch.

game.dnd5e.rollItemMacro("item name") still works.

Manifest URL Not Found

Works fine via Forge VTT on Foundry 10.291.
Manifest URL "Error: Unable to load valid module manifest data from... Module validation errors: packs: 0: type: may not be undefined via Home Server on V11.305. Also does not show on Install Module screen.

Running item effect and item macro at the same time.

I am using SWADE and I have a power (bolt) it has an electric graphic effect from token magic FX and JB2, in the macro. I am wanting to fire the macro and the power at the same time. All examples of this seem to need the DAE or Midi QOL to work, but I don't have access to either of these modules (As it isn't a D20 system) Is there a way to launch the macro when you use the normal effect of the spell (rolling dice, etc)?

Support For Generic RolePlaying Game Aid

Hello there,

I would love if you would consider having a look at GRPGA and to see if it is possible to add ItemMacro to it

As always thank you and have a nice day

Problem with Tidy5E-Sheet

When using Tidy5E-Sheet, Item Macro is triggering macros when using items from the Features tab. However when you add an item to favorites, Tidy5E shows them on the Attributes tab and Item Macro doesn't trigger when rolling the item from there.

Item Icon

Hi everyone,

I'm using simple worldbuilding, with the new update I'm now able to drag anything from the items list of an actor and drop it to roll a macro, but the icon of the item reset, like it wont stay, it's only the default dice icon.

Is there a way to keep the item icon that you drag in the macro bar? Thanks in advance.

Where is version 1.9.0?

I am using Midiqol and i am getting a warning saying i need 1.9.0. I don't see that version listed here.

Feature Suggestion: Icon on item image if a macro is being used

Can a small icon be added to the item's image in the character sheet to denote if an item macro is on the item?

This would help when using character sheet hooks and knowing which items do and do not have a macro assigned.

I am guessing this would need to be an option since not everyone would want it.

opening a new ItemMacro closes existing ItemMacro editing window with no option to save

originally submitted to Improved Macro Editor, but it persists even with the stock foundry editor:
teroparvinen/foundry-improved-macro-editor#5

I often want to reference multiple macros when developing and I forget that ItemMacro can only have one window open so I lose work because the window is replaced without a prompt to save.

Ideally support multiple windows, but at least don't close without prompting for a save

Item Macros don't accept arguments when called via macro

(Throwing an issue here, rather than talking on Discord about this)

I think this is possible with some small edits to "executeMacro()" and "runMacro()", but don't have the javascript knowledge to put this into practice. (any code in the following should be assumed to be wrong!)

In runMacro, (line 139 of itemMacro.js), change its arguments to runMacro(_actorID, _itemID, arguments[])

In executeMacro (line 81), change its arguments to executeMacro(_actorID, _itemID, arguments[])

And then change line 102 to }).execute(arguments)

It might need some extra stuff to unpack the arguments from the array before passing them to execute, but it should then allow any macro to call runMacro("Actor", "Item", ["arg0", "arg1", "arg2"]) and have those arguments passed on to the item macro.

Why is this useful? it means that for an item in a shared compendium, you can set up Dynamic Effects to call a macro with specific arguments, and then share this item between worlds without having to also share the macro. (or in my somewhat excessive case, all I would need to share are the non-item-specific helper macros, like the one that applies damage)

trying to update or re-install item macro - k is not defined

Getting "k is not defined" on update attempt. Tried instead to uninstall+install, but re-install gives same error. Re install console below. Foundry 0.8.6

setup.js:224 ReferenceError: k is not defined
at Function.getManifest (/home/pi/foundryvtt/resources/app/dist/packages/package.mjs:1)
at runMicrotasks ()
at processTicksAndRejections (internal/process/task_queues.js:93)
at async checkPackage (/home/pi/foundryvtt/resources/app/dist/packages/views.mjs:1)
at async Module.installPackage (/home/pi/foundryvtt/resources/app/dist/packages/views.mjs:1)
at async setupPost (/home/pi/foundryvtt/resources/app/dist/server/views.mjs:1)

SWADE support update

change the way to swade system , and provide args.

swade.js:

export function register_helper()
{
  logger.info(`Registering SWADE Helpers`);
  
  Hooks.on("swadeAction", async (SwadeTokenOrActor, SwadeItem, SwadeAction, SwadeRoll, SwadeUserId) => {
    //console.log([SwadeTokenOrActor, SwadeItem, SwadeAction, SwadeRoll, SwadeUserId]);  
    
    if( item.hasMacro() && settings.value("defaultmacro") ) {
        //console.log([SwadeTokenOrActor, SwadeItem, SwadeAction, SwadeRoll, SwadeUserId]);
        return SwadeItem.executeMacro(SwadeTokenOrActor, SwadeItem, SwadeAction, SwadeRoll, SwadeUserId);
      }
    });
}

"Save Macro" button causes the macro to be configured as "chat", which does not properly execute.

Reproduced on a fresh world with no modules ever installed.
Foundry v0.8.8
dnd 5e v1.3.6
item-macro v1.5.4

Steps to reproduce (may be a more minimal set):

  1. Create dnd5e world, create scene, create a test actor, drag actor to scene
  2. Give actor an item
  3. Enable item-macro with character sheet hook
  4. Add macro to item, something basic like log to console, save without executing. Try clicking the item, nothing happens.
  5. Reopen macro, click execute, close without saving
  6. Item now functions totally as expected

After step 4, I added a breakpoint here https://github.com/Kekilla0/Item-Macro/blob/master/scripts/helper.js#L31
And found the chat configuration.
image

An additional breakpoint here https://github.com/Kekilla0/Item-Macro/blob/master/scripts/ItemMacroConfig.js#L51
Revealed:
image

Option to only show symbol in the header bar

I wanted to ask if it would be possible to add an option to only show the symbol in the header bar and not also the text to preserve space? Since I'm running Foundry with a lot of modules that also use the header bar, it got kinda overcrowded now and doesn't show the close button anymore. Only when I resize each window manually every time I open a spell/journal entry etc. to accomodate all the symbols.

Before resizing:
image

After resizing:
image

Request: Let player edit item macros

It could be a toggleable box in the module settings. I think this would be useful for players with technical knowledge so they don't need to pester their GM every time they want to test an item macro.

Foundry 8.9 error

I know 8.9 isn't tested yet but getting an error when updating add-on modules from Foundry Configuration and Setup that says; k is not defined.

Preventing Magic Item mod firing

If I create a magic item and attach a spell to it. You go into the spellbook to fire the magic item.
This cannot happen when itemmacro module is enabled.

itemMacro.js:291 Uncaught (in promise) TypeError: Cannot read property 'data' of null at HTMLDivElement.<anonymous> (itemMacro.js:291) at HTMLDivElement.dispatch (jquery.min.js:2) at HTMLDivElement.v.handle (jquery.min.js:2)

Opening the macro editor mutates the item's flag data

This is pretty minor. Steps to reproduce:

  • Create item macro in an item. See in the console that it has all the data such as "author" and "_id".
  • Unset a value such as "author", "ownership", or "_id". See in the console that these values are now gone.
  • Open the item macro editor. Do not make any changes.
  • Close the editor (this performs no update on the item).
  • See in the console that the flag data for the item macro has all the values previously removed.

Execute as GM disabled

Can't seem to figure out how to execute a macro as GM rather than the player. Nothing I'm doing allows the checkbox to be selected.

v10 migration

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", });
    }

Right click override doesn't work

The macro override by using right click doesn't really work anymore for dnd5e (as of 2.1.x.) as the right click is used to open a little menu to edit, attune, equip etc an item or feature. Is it possible to have it instead be if you left click on the item while holding a configurable hotkey?

No more manifest for releases prior to 0.8

No more manifest URL are provided for people who are still using 0.7.X version of the foundry. All the provided URL manifests published are linked to the 1.5.2 version which needs a 0.8.X version of the foundry.

can't drag item to hotbar in Simple Worldbuilding

can't drag items from either the item directory or an actor sheet into the hotbar in the Simple Worldbuilding system. Unfortunately I don't currently have a way to easily set up a test environment with just the Item Macro module and no others enabled, so I can't confirm whether that's a problem with Item Macro or some other module.

Incompatible With Foundry V11

The module is judged incompatible with version 11 of foundry, since it is a necessary dependency in many automatisms to manage macros, could it be made compatible with 11?

Feature suggestion: Execute on Save Failed/Passed

Description: I would love the addition of a 'After Save Failed' and 'After Save Passed' option in the execute macro box as there doesn't seem to be a way to only execute a macro if the item succeeds.

Example usage:

  • I.E. create a macro to move a target 10m closer, and add it to the Gust spell with the execute option 'After Save Failed'. Now if the target fails their save, it activates the macro and moves the target 10m closer, but only if the target fails their save.

image
+ After Save Failed
+ After Save Passed

ItemMacro not getting arguments from parent

When executing an ItemMacro, it's not receiving any arguments from the parent item in v10. I have an onuse macro = "ItemMacro", but when I log out parameters (console.log(args)), the length is zero. This prevents any of the item macros from working correctly for me. Maybe it's a configuration issue? It seems to work fine in v9.

Below is one of the possible errors that can result, but this could cause any number of issues. If you try with the compendium version of Hunter's Mark SRD (Hunter's Mark - MQ0.8.20), you get a slightly different error against "hitTargets".

Uncaught (in promise) TypeError: undefined. Cannot read properties of undefined (reading 'tag')
[Detected 1 package: itemacro]
at eval (eval at Item._executeScript (helper.js:82:18), :8:12)
at Macro.eval (eval at Item._executeScript (helper.js:82:18), :11:9)
at Item._executeScript (helper.js:88:12)
at Item.executeMacro (helper.js:60:23)
at HTMLDivElement. (helper.js:170:20)
at HTMLDivElement.dispatch (jquery.min.js:2:43064)
at y.handle (jquery.min.js:2:41048)

warning about Macros.db does not exist

vtt logs are throwing this warning.

[warn] The itemacro Compendium path packs/Macros.db does not exist

I see that is mentioned in the modules.json file, but the file does not exist.

Support for SW5e

I've submitted the update to module.json (I think). This is essentially D&D5e, but for Star Wars.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.