From 9fd18e475f427dc20f58942325f97416e4426e27 Mon Sep 17 00:00:00 2001
From: Malin Freeborn <malinfreeborn@posteo.net>
Date: Tue, 5 Sep 2023 01:03:19 +0200
Subject: [PATCH] meta-spell-automation

(automation on the automation, rather than automation on metamagic)
---
 docs.tex                          | 47 +++++++++++++++++++++++++++----
 magic.sty                         | 38 +++++++++++++++++++------
 spells/{air1.tex => Air1.tex}     |  0
 spells/{air2.tex => Air2.tex}     |  0
 spells/{air3.tex => Air3.tex}     |  0
 spells/{death1.tex => Death1.tex} |  0
 spells/{death2.tex => Death2.tex} |  0
 spells/{death3.tex => Death3.tex} |  0
 spells/Earth1.tex                 | 11 ++++++++
 spells/{fate1.tex => Fate1.tex}   |  0
 spells/{fate2.tex => Fate2.tex}   |  0
 spells/{fire1.tex => Fire1.tex}   |  0
 spells/{fire2.tex => Fire2.tex}   |  0
 spells/{light1.tex => Light1.tex} |  0
 spells/{light2.tex => Light2.tex} |  0
 spells/{light3.tex => Light3.tex} |  0
 spells/{mind1.tex => Mind1.tex}   |  0
 spells/{mind2.tex => Mind2.tex}   |  0
 spells/{mind3.tex => Mind3.tex}   |  0
 spells/{water1.tex => Water1.tex} |  0
 spells/{water2.tex => Water2.tex} |  0
 test.tex                          |  6 ++--
 22 files changed, 85 insertions(+), 17 deletions(-)
 rename spells/{air1.tex => Air1.tex} (100%)
 rename spells/{air2.tex => Air2.tex} (100%)
 rename spells/{air3.tex => Air3.tex} (100%)
 rename spells/{death1.tex => Death1.tex} (100%)
 rename spells/{death2.tex => Death2.tex} (100%)
 rename spells/{death3.tex => Death3.tex} (100%)
 create mode 100644 spells/Earth1.tex
 rename spells/{fate1.tex => Fate1.tex} (100%)
 rename spells/{fate2.tex => Fate2.tex} (100%)
 rename spells/{fire1.tex => Fire1.tex} (100%)
 rename spells/{fire2.tex => Fire2.tex} (100%)
 rename spells/{light1.tex => Light1.tex} (100%)
 rename spells/{light2.tex => Light2.tex} (100%)
 rename spells/{light3.tex => Light3.tex} (100%)
 rename spells/{mind1.tex => Mind1.tex} (100%)
 rename spells/{mind2.tex => Mind2.tex} (100%)
 rename spells/{mind3.tex => Mind3.tex} (100%)
 rename spells/{water1.tex => Water1.tex} (100%)
 rename spells/{water2.tex => Water2.tex} (100%)

diff --git a/docs.tex b/docs.tex
index a3a51944..dbb2b847 100644
--- a/docs.tex
+++ b/docs.tex
@@ -173,19 +173,56 @@ After inputting that, you can get the spell, and the `printindex' command will c
 
 Alternatively, pull in a bunch of spells from a sphere at a particular level with:
 
-\verb"\showSpells{fate1,air2,mind2}"
+\verb"\showSpells{Fate1,Air2,Mind2}"
 
-\showSpells{fire1,fate1,air2,mind2}
+%\showSpells{Fire1,Fate1,Air2,Mind2}
 
 \ldots which shows Air spells of level 2, and Fate at level 1.
 
-Alternatively, input the spells after a creature, with:
+Alternatively, input the spells after a creature, with a `show standard spells' command:
 
-\verb"\creatureSpells{fate1,air2,mind2}"
+\begin{verbatim}
+
+  \demilich
+  \showStdSpells
+
+\end{verbatim}
+
+This will take an educated guestimate of a few spells you want to show.
 
 \demilich
 
-\creatureSpells{fate1,air2,mind2}
+\showStdSpells
+
+Or you can specify a list of spells, with an optional argument to take any spell you like.
+
+\begin{verbatim}
+
+  \elf
+
+  \creatureSpells[
+    \spell{Quake}% Name
+      {Earth}% Spheres
+      {Wane}% Action
+      {\distant, \duplicated}% Enhancements
+      {the rock's density}% Skill
+      {Ground shakes}% Short Description
+      {Brrrrrr}% Long Description
+  ]{Fate1,Air2}
+
+\end{verbatim}
+
+\elf
+
+\creatureSpells[
+  \spell{Quake}% Name
+    {Earth}% Spheres
+    {Wane}% Action
+    {\distant, \duplicated}% Enhancements
+    {the rock's density}% Skill
+    {Ground shakes}% Short Description
+    {Brrrrrr}% Long Description
+]{Fate1,Air2}
 
 \subsubsection{Magical Items}
 
diff --git a/magic.sty b/magic.sty
index 2f603a43..bb469a1b 100644
--- a/magic.sty
+++ b/magic.sty
@@ -203,21 +203,41 @@
   \vspace{.3em}
 }
 
-\newcommand\creatureSpells[1]{
+\newcommand\creatureSpells[2][]{
   \begin{description}
     \settoggle{genExamples}{false}
-    \foreach \s in {#1}{
-      \input{config/spells/\s.tex}
+    #1
+    \foreach \s in {#2}{
+      \IfFileExists{config/spells/\s.tex}{
+        \input{config/spells/\s.tex}
+      }{}
     }
   \end{description}
 }
 
-\newcommand\showSpells[1]{
-    \needspace{3em}\bigLine
-    \settoggle{genExamples}{true}
-    \foreach \s in {#1}{
-      \input{config/spells/\s.tex}
+\newcommand\showStdSpells{
+  \setcounter{enc}{0}
+  \begin{description}
+    \settoggle{genExamples}{false}
+    \foreach\n in {3,2,1}{
+      \ifnum\value{enc}<3
+        \foreach \s in {Earth,Air,Fire,Water,Fate}{
+          \ifnumcomp{\value{\s}}{=}{\n}{
+              \input{config/spells/\s\n.tex}
+              \stepcounter{enc}
+          }{}
+        }
+      \fi
     }
-    \bigLine
+  \end{description}
+}
+
+\newcommand\showSpells[1]{
+  \needspace{3em}\bigLine
+  \settoggle{genExamples}{true}
+  \foreach \s in {#1}{
+    \input{config/spells/\s.tex}
+  }
+  \bigLine
 }
 
diff --git a/spells/air1.tex b/spells/Air1.tex
similarity index 100%
rename from spells/air1.tex
rename to spells/Air1.tex
diff --git a/spells/air2.tex b/spells/Air2.tex
similarity index 100%
rename from spells/air2.tex
rename to spells/Air2.tex
diff --git a/spells/air3.tex b/spells/Air3.tex
similarity index 100%
rename from spells/air3.tex
rename to spells/Air3.tex
diff --git a/spells/death1.tex b/spells/Death1.tex
similarity index 100%
rename from spells/death1.tex
rename to spells/Death1.tex
diff --git a/spells/death2.tex b/spells/Death2.tex
similarity index 100%
rename from spells/death2.tex
rename to spells/Death2.tex
diff --git a/spells/death3.tex b/spells/Death3.tex
similarity index 100%
rename from spells/death3.tex
rename to spells/Death3.tex
diff --git a/spells/Earth1.tex b/spells/Earth1.tex
new file mode 100644
index 00000000..62590cac
--- /dev/null
+++ b/spells/Earth1.tex
@@ -0,0 +1,11 @@
+\spell{Slide}% Name
+  {\mAir}% Spheres
+  {Wax}% Action
+  {}% Enhancements
+  {\roll{Dexterity}{Athletics}}% Resist with
+  {targets standing on snow or mud fall prone}% Description
+  {
+    The mage creates subtle vibrations across the ground, forcing it to move.
+    This does nothing of any consequence on solid ground, but soft ground, such as any area covered in thick mud, or snow, can throw anyone standing on two legs.
+  }
+
diff --git a/spells/fate1.tex b/spells/Fate1.tex
similarity index 100%
rename from spells/fate1.tex
rename to spells/Fate1.tex
diff --git a/spells/fate2.tex b/spells/Fate2.tex
similarity index 100%
rename from spells/fate2.tex
rename to spells/Fate2.tex
diff --git a/spells/fire1.tex b/spells/Fire1.tex
similarity index 100%
rename from spells/fire1.tex
rename to spells/Fire1.tex
diff --git a/spells/fire2.tex b/spells/Fire2.tex
similarity index 100%
rename from spells/fire2.tex
rename to spells/Fire2.tex
diff --git a/spells/light1.tex b/spells/Light1.tex
similarity index 100%
rename from spells/light1.tex
rename to spells/Light1.tex
diff --git a/spells/light2.tex b/spells/Light2.tex
similarity index 100%
rename from spells/light2.tex
rename to spells/Light2.tex
diff --git a/spells/light3.tex b/spells/Light3.tex
similarity index 100%
rename from spells/light3.tex
rename to spells/Light3.tex
diff --git a/spells/mind1.tex b/spells/Mind1.tex
similarity index 100%
rename from spells/mind1.tex
rename to spells/Mind1.tex
diff --git a/spells/mind2.tex b/spells/Mind2.tex
similarity index 100%
rename from spells/mind2.tex
rename to spells/Mind2.tex
diff --git a/spells/mind3.tex b/spells/Mind3.tex
similarity index 100%
rename from spells/mind3.tex
rename to spells/Mind3.tex
diff --git a/spells/water1.tex b/spells/Water1.tex
similarity index 100%
rename from spells/water1.tex
rename to spells/Water1.tex
diff --git a/spells/water2.tex b/spells/Water2.tex
similarity index 100%
rename from spells/water2.tex
rename to spells/Water2.tex
diff --git a/test.tex b/test.tex
index 0760c854..50a6294a 100644
--- a/test.tex
+++ b/test.tex
@@ -169,13 +169,13 @@ This section is non-verbose, so only basic stats are shown.
 
 \gnollshaman
 
-\creatureSpells{fire1}
+\creatureSpells{Fire1}
 
 \gnollshaman
 
-\creatureSpells{fate1}
+\creatureSpells{Fate1}
 
-\creatureSpells{fate2}
+\creatureSpells{Fate2}
 
 \end{multicols}
 
-- 
GitLab