Open happy-cujo opened 3 years ago
Wow. Thank you. I'll definitely look into it. Honestly, the /timer function was a last minute addition I made for a game. With no plans for it to go anywhere. ...but people seem to like it! These improvements are amazing.
I'm wondering about changing it to /timer 5 message="Flavor Text" after="Message that appears afterwards and can also contain the id of a macro". That makes it more versatile than just parsing strings as you can add more arguments later.
I like the /countdown command, like you say, it makes it a lot less cryptic. And should probably think about adding /pause and /restart commands.
And... the more this expands, the more I'm thinking it should go into it's own module at some point.
When I get a chance I'll add these.
I've also though about separate module, because as simple as it gets there is a lot of potential in timers. And they can be not only based on real-time, but also on world-time. The biggest challenge would be controlling those timers and syncing their state across every user. That require a little bit of planning.
About the usage. The commands' arguments should be fairly simple. The ones that we have now - time, flavor and followup is reasonably easy to remember and quite easy to understand. Followup could be like you said either simple message or macro id/name (probably prefixed with something). And I think sticking to only 3 parameters with predefined order would be easier to grasp for others.
But that doesn't mean there should be no more options. Those can be created (and probably managed) via dedicated form. That would mean you can pre create timers and reuse them without need of diving into macros/code. Also there could be an option to rerun last one and so on.
The form could contain:
Aside from that, a list with
Also timers could be generic ones or scene specific. And there could be option to not only determine timer completion based on passed time, but also on number of performed ticks, example: execute this macro every second up to 5 times.
Probably people could think of more stuff to put into such module (style/look customization would be also nice).
With proper API for this there could be an option to integrate this with your Active Tile Triggers module or hooking into combat encounters, so players have visual reminder that they should/declare their actions faster (some GM are using such timers, especially within bigger groups).
If you extract this command to separate module/repo with it's current state, so we don't loose what we have right now I may be able to help you with work on this (in proper way and not by posting gists) after talking it through and creating some kind of roadmap.
Just wanted to drop a message that I havn't forgotten about this. I'm still planning to get this going at some point.
No problem. After I've created this issue I've found this module: https://foundryvtt.com/packages/timer. Maybe you'll find it useful. It uses interesting approach to time updates - sockets instead of direct db updates. That allows to get rid of unnecessary db calls on every tick. The chat message itself is saved only when the timer expires.
Moving to Chat Timer
I've played around with timer command and I saw that it can be improved a little and also expanded to create some API for developers. Also I've found that argument parsing and "followup" functionality doesn't look like it's fully complete.
What would be nice:
Obviously not everything is covered here, but those are my bits (I didn't create PR because I'm not sure where you want to go with it):
https://gist.github.com/happy-cujo/dec929e5be9e8da4a1e0bbfc8ea448e7#file-argsparser-js This allows parsing command arguments to array while respecting string surrounded by double quotes. Example:
ArgsParse.parse('01:00 "This is flavor text" "And this is follow up"')
will result in["01:00", "This is flavor text", "And this is follow up"]
. Regexp taken from https://stackoverflow.com/a/43766456.https://gist.github.com/happy-cujo/dec929e5be9e8da4a1e0bbfc8ea448e7#file-timer-js This could be potential "API" (nice API, one method, lol) for creating timers from the code level. There is a room for expansion, like callback functionality or macro execution after timer ends. I've split the command into two modes,
/timer
and/countdown
so misleading minus sign isn't involved.STATUS_
is a ground base for controlling a timer (stopping, resuming) but that probably will require additional adjustments how timer (interval) validates message status. Or it will be thrown away. Anyway it did a good job making the code more readable.Now the Hooks. chatCommandsReady and the renderChatMessage would look like this: https://gist.github.com/happy-cujo/dec929e5be9e8da4a1e0bbfc8ea448e7#file-chatcommandhooks-js https://gist.github.com/happy-cujo/dec929e5be9e8da4a1e0bbfc8ea448e7#file-renderchatmessagehook-js
Also this version supports Dice Roll Mode. So you can use the standard select to hide the timer from players. I've replaced the follow up message behavior and in my version I've put it in "Complete" string place, but probably updating the timer message and posting new message would be the best approach.
Maybe you'll find this useful. Also I can try to think about more proper API for chat timer and try to create PR with it.