forked from leftypol/leftypol
funtions.php: rework dice markup generation
This commit is contained in:
parent
22d76ad9f6
commit
e6b345f8cc
1 changed files with 21 additions and 15 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue