funtions.php: rework dice markup generation

This commit is contained in:
Zankaria 2024-10-14 10:52:00 +02:00
parent 22d76ad9f6
commit e6b345f8cc

View file

@ -2813,23 +2813,29 @@ function handle_dice_roll_markup(array $matches, ?string $img_path): string {
$dice_faces = 6;
}
$acc = '';
$text = "$dice_count d $dice_faces + $dice_offset";
for ($i = 0; $i < $dice_count; $i++) {
$res = $dice_offset + mt_rand(1, $dice_faces);
if ($img_path === null) {
$fmt = "<span>$text </span> <b>$res</b>";
} else {
$fmt = "<img src='{$config['root']}{$img_path}' alt='$text' title='$text' class=\"inline-dice\"/> <b>$res</b>";
}
if (empty($acc)) {
$acc = $fmt;
} else {
$acc .= " $fmt";
}
if ($dice_offset === 0) {
$dice_offset_text = '';
} elseif ($dice_offset > 0) {
$dice_offset_text = "+{$dice_offset}";
} else {
$dice_offset_text = (string)$dice_offset;
}
return $acc;
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;
}
function slugify($post) {