diff --git a/README.md b/README.md index e6fa947..9311687 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ - + # fvtt-l5r4ed-dice-roller @@ -38,11 +38,12 @@ It can be used with roll, GM roll, self roll, blind roll and deferred inline rol Example: -- /r or /roll 6k5; +- /r or /roll 6k5[describing dice]#describing roll; - /gmr or /gmroll 6k5; - /sr or /selfroll 6k5; - /br or /broll or /blindroll 6k5; - Message [[/r 6k5]] works well; +- Message [[6k5]] works well; @@ -68,3 +69,10 @@ Example: - [Issue #7](https://github.com/eupolemo/fvtt-l5r4ed-dice-roller/issues/7) Discard excess dices from keep when have less than 10 dices on roll - [Issue #16](https://github.com/eupolemo/fvtt-l5r4ed-dice-roller/issues/17) Added untrained and emphasis roll + +### 1.4.0 + +- [Issue #11](https://github.com/eupolemo/fvtt-l5r4ed-dice-roller/issues/11) Immediate Inline Rolls added +- [Issue #12](https://github.com/eupolemo/fvtt-l5r4ed-dice-roller/issues/12) Describing roll added +- [Issue #13](https://github.com/eupolemo/fvtt-l5r4ed-dice-roller/issues/13) Describing dice added +- [Issue #24](https://github.com/eupolemo/fvtt-l5r4ed-dice-roller/issues/24) Now bonuses are shown correctly diff --git a/dice-roller.js b/dice-roller.js index aadf1e7..86a5fe0 100644 --- a/dice-roller.js +++ b/dice-roller.js @@ -1,33 +1,69 @@ Hooks.on("chatMessage", function (chatlog, message, chatdata) { // const pattern = /^\d+k\d+x\d+([+]\d+)?$/; - const pattern = /^(u|e)?\d+k\d+(x\d+)?([+]\d+)?$/; + const pattern = /^(u|e)?\d+k\d+(x\d+)?([+]\d+)?(\[.+\])?(\#(.*))?$/; const roll_pattern = /^(\/r(?:oll)? |\/gmr(?:oll)? |\/b(?:lind)?r(?:oll)? |\/s(?:elf)?r(?:oll)? ){1}/; - const inside_message_roll = /\[\[(\/r(?:oll)? |\/gmr(?:oll)? |\/b(?:lind)?r(?:oll)? |\/s(?:elf)?r(?:oll)? ){1}(u|e)?\d+k\d+(x\d+)?([+]\d+)?\]\]/; - + const deferred_inline_roll_pattern = /\[\[(\/r(?:oll)? |\/gmr(?:oll)? |\/b(?:lind)?r(?:oll)? |\/s(?:elf)?r(?:oll)? ){1}(u|e)?\d+k\d+(x\d+)?([+]\d+)?(\[.+\])?\]\]/; + const immediate_message_roll_pattern = new RegExp(/\[\[(u|e)?\d+k\d+(x\d+)?([+]\d+)?(\[.+\])?(\#(.*))?\]\]/) + const inside_message_roll_pattern = new RegExp("(" + immediate_message_roll_pattern.source + ")|(" + deferred_inline_roll_pattern.source + ")") if (roll_pattern.test(message)) { let parts = message.split(" "); // console.log(parts) + if (pattern.test(parts[1])) { - let roll_parsed = roll_parser(parts[1]); - chatlog.processMessage(`${parts[0]} ${roll_parsed}`); + const describing_dice_pattern = /\[.*\]*$/; + const describing_dice = parts[1].match(describing_dice_pattern); + let message_without_describing = parts[1].replace(describing_dice_pattern, ""); + + const describing_roll_pattern = /(\#(.*))*$/; + let describing_roll; + if(describing_roll_pattern.test(message_without_describing)) { + describing_roll = message_without_describing.match(describing_roll_pattern); + message_without_describing = message_without_describing.replace(describing_roll_pattern, ""); + } + + let roll_parsed = roll_parser(message_without_describing); + chatlog.processMessage(`${parts[0]} ${roll_parsed}${describing_dice ? describing_dice : ""}${describing_roll ? describing_roll[0] : ""}`); return false; } } else if (pattern.test(message)) { - message = roll_parser(message); + const describing_dice_pattern = /\[.*\]*$/; + const describing_dice = message.match(describing_dice_pattern); + let message_without_describing = message.replace(describing_dice_pattern, ""); + + const describing_roll_pattern = /(\#(.*))*$/; + let describing_roll; + if(describing_roll_pattern.test(message_without_describing)) { + describing_roll = message_without_describing.match(describing_roll_pattern); + message_without_describing = message_without_describing.replace(describing_roll_pattern, ""); + } - chatlog.processMessage(`/r ${message}`); + message = roll_parser(message_without_describing); + chatlog.processMessage(`/r ${message}${describing_dice && describing_dice.length > 0 ? describing_dice[0] : ""}${describing_roll ? describing_roll[0] : ""}`); return false; - } else if (inside_message_roll.test(message)) { + } else if (inside_message_roll_pattern.test(message)) { const deferred_roll_pattern = /\[\[(?:\/r(?:oll)? |\/gmr(?:oll)? |\/b(?:lind)?r(?:oll)? |\/s(?:elf)?r(?:oll)? ){1}(.*?)\]\]/g; const kxy_pattern = /(u|e)?\d+k\d+(x\d+)?([+]\d+)?/; - let result = message.replace( - deferred_roll_pattern, - function (match, token) { - if (!inside_message_roll.test(match)) return match; - return match.replace(kxy_pattern, roll_parser(token)); - } - ); + let result = message; + + const inline_message_pattern = /\[\[((u|e)?\d+k\d+(x\d+)?([+]\d+)?(\[.+\])?(\#(.*))?){1}\]\]/g + + if( deferred_roll_pattern.test(message)) + result = message.replace( + deferred_roll_pattern, + function (match, token) { + if (!deferred_roll_pattern.test(match)) return match; + return match.replace(kxy_pattern, roll_parser(token)); + } + ); + else if ( inline_message_pattern.test(message)) + result = message.replace( + inline_message_pattern, + function (match, token) { + if (!inline_message_pattern.test(match)) return match; + return match.replace(kxy_pattern, roll_parser(token)); + } + ); chatlog.processMessage(result); return false; } @@ -35,7 +71,7 @@ Hooks.on("chatMessage", function (chatlog, message, chatdata) { Hooks.on("renderChatMessage", async (app, html, msg) => { if (app.isRoll) { - const pattern = /^\d+d\d+(r1)?k\d+(x(>=)?\d+)?( \+\ \d+)?$/; + const pattern = /^\d+d\d+(r1)?k\d+(x(>=)?\d+)?( \+\ \d+)?(\[.+\])?$/; const roll = app.roll; const formula = roll.formula; @@ -51,9 +87,11 @@ Hooks.on("renderChatMessage", async (app, html, msg) => { const e_div_tag = ""; const b_span_tag = ''; const e_span_tag = ""; + const b_flavor_tag = '