From 37d275468e08930db5090f363fa40431461c14aa Mon Sep 17 00:00:00 2001 From: Zankaria Date: Mon, 14 Oct 2024 14:02:27 +0200 Subject: [PATCH] funtions.php: unify inline dice roll result --- inc/functions.php | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/inc/functions.php b/inc/functions.php index 9c956cda..72e6afaa 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -2813,6 +2813,17 @@ function handle_dice_roll_markup(array $matches, ?string $img_path): string { $dice_faces = 6; } + $tot = $dice_offset; + for ($i = 0; $i < $dice_count; $i++) { + $tot += mt_rand(1, $dice_faces); + } + + if ($img_path !== null) { + $img_text = "dice"; + } else { + $img_text = ''; + } + if ($dice_offset === 0) { $dice_offset_text = ''; } elseif ($dice_offset > 0) { @@ -2821,21 +2832,7 @@ function handle_dice_roll_markup(array $matches, ?string $img_path): string { $dice_offset_text = (string)$dice_offset; } - if ($img_path !== null) { - $text = "dice"; - } else { - $text = ''; - } - - $text .= " {$dice_count}d{$dice_faces}{$dice_offset_text} ="; - for ($i = 0; $i < $dice_count; $i++) { - $res = $dice_offset + mt_rand(1, $dice_faces); - $text .= " $res"; - } - - $text .= ''; - - return $text; + return "$img_text {$dice_count}d{$dice_faces}{$dice_offset_text} = $tot"; } function slugify($post) {