From 520f74cc66d9b5ebd8f1c95a06abdd7a42ea91f0 Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Tue, 23 Mar 2021 13:56:03 -0700 Subject: [PATCH] Re-roll the same dice expression. Yes, I got that idea from d20, and at some point, we need to figure out how to play better together. --- rpgdm-dice.el | 13 +++++++++++++ rpgdm.el | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/rpgdm-dice.el b/rpgdm-dice.el index a1c9a56..02e7859 100644 --- a/rpgdm-dice.el +++ b/rpgdm-dice.el @@ -32,6 +32,10 @@ ;; ;;; Code: +(defvar rpgdm-previous-roll-expression nil + "Whenever we roll a dice from an expression, we remember it + here, so that we can re-roll it again.") + ;; The basics of a dice roll is a random number from a given range. Note that if ;; we give a 6-sided die to the random number, we will end up with a range of 0 ;; to 5, so we need to increase this value by 1. @@ -282,9 +286,18 @@ Unless the point is on a dice roll description, e.g 2d12+3." (interactive (list (if (looking-at rpgdm-roll-regexp) (match-string-no-properties 0) (read-string "Dice Expression: ")))) + (setq rpgdm-previous-roll-expression expression) (let ((roll-results (rpgdm--roll-expression expression))) (rpgdm-message "Rolled: %s" (rpgdm--display-roll roll-results expression)))) +(defun rpgdm-roll-again () + "Roll the previous expression ... again. +Never rolled before? No problem, we'll query for the expression +if we need too." + (interactive) + (if rpgdm-previous-roll-expression + (rpgdm-roll rpgdm-previous-roll-expression) + (call-interactively 'rpgdm-roll))) ;; ---------------------------------------------------------------------- ;; ADVANTAGE and DISADVANTAGE ROLLS diff --git a/rpgdm.el b/rpgdm.el index 753bbf2..d21ad0a 100644 --- a/rpgdm.el +++ b/rpgdm.el @@ -43,7 +43,7 @@ _d_: Roll Dice _z_: Flip a coin _r_: Dashboard _s_: d20 Skill _m_: Moderate _o_: Links ⌘-l: Last Results _b_: Previous _f_: Next Dice Expr _t_: Load Tables _e_: Easy check _h_: Hard check _J_/_K_: Page up/dn ⌘-k: ↑ Previous _a_/_A_: Advantage/Disadvantage _c_: Choose Item _v_: Difficult _i_: Impossible _N_/_W_: Narrow/Widen ⌘-j: ↓ Next " - ("d" rpgdm-roll) + ("d" rpgdm-roll) ("D" rpgdm-roll-again) ("f" rpgdm-forward-roll) ("b" rpgdm-forward-roll) ("a" rpgdm-roll-advantage) ("A" rpgdm-roll-disadvantage) ("z" rpgdm-yes-and-50/50)