Fixed two bugs when creating new characters

The bonds used to get inserted into the middle of a heading. Not good.
Also, we got an exception when going up a heading level when we were
already at the highest level. Easy enough to fix.
This commit is contained in:
Howard Abrams 2022-05-01 22:15:58 -07:00
parent 1cb1e45efa
commit 0ebc0edd74
2 changed files with 38 additions and 16 deletions

View file

@ -616,7 +616,9 @@ This function will query the user for all of the stats and other properties that
(rpgdm-ironsworn-progress-create (read-string "What title should we give this new character's Epic vow: ") 1) (rpgdm-ironsworn-progress-create (read-string "What title should we give this new character's Epic vow: ") 1)
(rpgdm-ironsworn-progress-create "Bonds" 1) (rpgdm-ironsworn-progress-create "Bonds" 1)
(rpgdm-ironsworn-progress-mark "Bonds") (rpgdm-ironsworn-progress-mark "Bonds")
(next-line)
(org-top-heading)
(re-search-forward (rx line-start (zero-or-more space) line-end))
(insert "\n** Bonds\n") (insert "\n** Bonds\n")
(insert (format " - My home settlement of %s\n" (rpgdm-tables-choose "settlement/name")))) (insert (format " - My home settlement of %s\n" (rpgdm-tables-choose "settlement/name"))))
#+END_SRC #+END_SRC
@ -1946,7 +1948,7 @@ But we roll some of these more than others, especially since "moves" does most o
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defhydra hydra-rpgdm (:color pink :hint nil) (defhydra hydra-rpgdm (:color pink :hint nil)
" "
^Dice^ 0=d100 1=d10 6=d6 ^Roll/Adjust^ ^Oracles/Tables^ ^Moving/Editing^ ^Messages^ ^Dice^ 0=d100 1=d10 6=d6 ^Roll/Adjust^ ^Oracles/Tables^ ^Moving/Editing^ ^Messages^
------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------
_D_: Roll Dice _h_: Roll Shadow _l_/_L_: Health _z_/_Z_: Yes/No Oracle _o_: Links ⌘-h: Show Stats _D_: Roll Dice _h_: Roll Shadow _l_/_L_: Health _z_/_Z_: Yes/No Oracle _o_: Links ⌘-h: Show Stats
_e_: Roll Edge _w_: Roll Wits _t_/_T_: Spirit _c_/_C_: Show Oracle _J_/_K_: Page up/dn ⌘-l: Last Results _e_: Roll Edge _w_: Roll Wits _t_/_T_: Spirit _c_/_C_: Show Oracle _J_/_K_: Page up/dn ⌘-l: Last Results
@ -2028,9 +2030,7 @@ But since most character stats do not simply /go away/ but are constantly in flu
Note that STAT should be a symbol, like `supply' and VALUE should be a Note that STAT should be a symbol, like `supply' and VALUE should be a
number, but doesn't have to be." number, but doesn't have to be."
(save-excursion (save-excursion
(org-up-heading) (org-top-heading)
(while (> (org-heading-level) 1)
(org-up-heading))
(rpgdm-ironsworn-store-character-temp-state stat value))) (rpgdm-ironsworn-store-character-temp-state stat value)))
#+END_SRC #+END_SRC
@ -2110,11 +2110,23 @@ Since [[help:org-up-element][org-up-element]]s behavior has changed, and [[he
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun org-up-heading () (defun org-up-heading ()
"Move the point to next parent heading, unless already at the top-level." "Move the point to next parent heading, unless already at the top-level."
(if (= 0 (org-heading-level)) (interactive)
(org-previous-visible-heading 1) (cl-case (org-heading-level)
(outline-up-heading 1))) (0 (org-previous-visible-heading 1))
(1 nil)
(t (outline-up-heading 1))))
#+END_SRC #+END_SRC
And a function to move the point to the top-most heading (where we store the characters details:
#+BEGIN_SRC emacs-lisp
(defun org-top-heading ()
"Move the point to the top-most heading in the org document.
Note that this is based on the current point position."
(interactive)
(org-up-heading)
(while (> (org-heading-level) 1)
(org-up-heading)))
#+END_SRC
Enough chit-chat, let's write this function. While we are at it, let's convert the property symbols into short symbols, e.g. =:IRONSWORN-SHADOW= should just be =shadow=, and number values should be numeric: Enough chit-chat, let's write this function. While we are at it, let's convert the property symbols into short symbols, e.g. =:IRONSWORN-SHADOW= should just be =shadow=, and number values should be numeric:
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp

View file

@ -248,7 +248,9 @@ Note: The stats are added as properties using the
(rpgdm-ironsworn-progress-create (read-string "What title should we give this new character's Epic vow: ") 1) (rpgdm-ironsworn-progress-create (read-string "What title should we give this new character's Epic vow: ") 1)
(rpgdm-ironsworn-progress-create "Bonds" 1) (rpgdm-ironsworn-progress-create "Bonds" 1)
(rpgdm-ironsworn-progress-mark "Bonds") (rpgdm-ironsworn-progress-mark "Bonds")
(next-line)
(org-top-heading)
(re-search-forward (rx line-start (zero-or-more space) line-end))
(insert "\n** Bonds\n") (insert "\n** Bonds\n")
(insert (format " - My home settlement of %s\n" (rpgdm-tables-choose "settlement/name")))) (insert (format " - My home settlement of %s\n" (rpgdm-tables-choose "settlement/name"))))
@ -1105,7 +1107,7 @@ You'll need to pick and choose what works and discard what doesn't."
(defhydra hydra-rpgdm (:color pink :hint nil) (defhydra hydra-rpgdm (:color pink :hint nil)
" "
^Dice^ 0=d100 1=d10 6=d6 ^Roll/Adjust^ ^Oracles/Tables^ ^Moving/Editing^ ^Messages^ ^Dice^ 0=d100 1=d10 6=d6 ^Roll/Adjust^ ^Oracles/Tables^ ^Moving/Editing^ ^Messages^
------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------
_D_: Roll Dice _h_: Roll Shadow _l_/_L_: Health _z_/_Z_: Yes/No Oracle _o_: Links -h: Show Stats _D_: Roll Dice _h_: Roll Shadow _l_/_L_: Health _z_/_Z_: Yes/No Oracle _o_: Links -h: Show Stats
_e_: Roll Edge _w_: Roll Wits _t_/_T_: Spirit _c_/_C_: Show Oracle _J_/_K_: Page up/dn -l: Last Results _e_: Roll Edge _w_: Roll Wits _t_/_T_: Spirit _c_/_C_: Show Oracle _J_/_K_: Page up/dn -l: Last Results
@ -1166,9 +1168,7 @@ number, but doesn't have to be."
Note that STAT should be a symbol, like `supply' and VALUE should be a Note that STAT should be a symbol, like `supply' and VALUE should be a
number, but doesn't have to be." number, but doesn't have to be."
(save-excursion (save-excursion
(org-up-heading) (org-top-heading)
(while (> (org-heading-level) 1)
(org-up-heading))
(rpgdm-ironsworn-store-character-temp-state stat value))) (rpgdm-ironsworn-store-character-temp-state stat value)))
(defalias 'rpgdm-ironsworn-store-default-character-state (defalias 'rpgdm-ironsworn-store-default-character-state
@ -1204,9 +1204,19 @@ Return 0 if not at a heading, or above first headline."
(defun org-up-heading () (defun org-up-heading ()
"Move the point to next parent heading, unless already at the top-level." "Move the point to next parent heading, unless already at the top-level."
(if (= 0 (org-heading-level)) (interactive)
(org-previous-visible-heading 1) (cl-case (org-heading-level)
(outline-up-heading 1))) (0 (org-previous-visible-heading 1))
(1 nil)
(t (outline-up-heading 1))))
(defun org-top-heading ()
"Move the point to the top-most heading in the org document.
Note that this is based on the current point position."
(interactive)
(org-up-heading)
(while (> (org-heading-level) 1)
(org-up-heading)))
(defun rpgdm-ironsworn--current-character-state (results) (defun rpgdm-ironsworn--current-character-state (results)
"Recursive helper to insert current header properties in RESULTS. "Recursive helper to insert current header properties in RESULTS.