forked from leftypol/leftypol
funtions.php: unify inline dice roll result
This commit is contained in:
parent
f35f9d5d67
commit
37d275468e
1 changed files with 12 additions and 15 deletions
|
@ -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 = "<img src='{$config['root']}{$img_path}' alt='dice' title='dice' class=\"inline-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 = "<span><img src='{$config['root']}{$img_path}' alt='dice' title='dice' class=\"inline-dice\"/>";
|
||||
} else {
|
||||
$text = '<span>';
|
||||
}
|
||||
|
||||
$text .= " {$dice_count}d{$dice_faces}{$dice_offset_text} =<b>";
|
||||
for ($i = 0; $i < $dice_count; $i++) {
|
||||
$res = $dice_offset + mt_rand(1, $dice_faces);
|
||||
$text .= " $res";
|
||||
}
|
||||
|
||||
$text .= '</b></span>';
|
||||
|
||||
return $text;
|
||||
return "<span>$img_text {$dice_count}d{$dice_faces}{$dice_offset_text} = <b>$tot</b></span>";
|
||||
}
|
||||
|
||||
function slugify($post) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue