Add "seq" card type
John Smith

John Smith commited on 2023-179 17:42:36
Showing 2 changed files, with 23 additions and 0 deletions.


The `CardType` field of a card can now have value "seq" (rather than
just "bmc" as in b39812d), indicating that each double-semicolon (`;;`)
in the `BaseNote` indicates a point at which to split the text, which
is to be memorised in sequential steps. The text before the first `;;`
is presented in any case as a prompt.

The "a" option (addcards.lua) still produces `bmc` cards. Making a `seq`
card requires a lot of manual effort for now.
... ...
@@ -50,6 +50,23 @@ function Card:fromrecs(recs, conf)
50 50
                     ctr = ctr + 1
51 51
                 end
52 52
                 table.insert(ret, cc)
53
+            elseif cc.ct == "seq" then
54
+                local m, n = cc.note:find(";;")
55
+                local ctr = 1
56
+                while m do
57
+                    table.insert(cc.pr, Prompt:new({
58
+                        card = cc,
59
+                        ind = n + 1,
60
+                        time = tonumber((rec.LastReview or {})[ctr]),
61
+                        delay = tonumber((rec.LastDelay or {})[ctr]),
62
+                        succ = tonumber((rec.Successes or {})[ctr]),
63
+                        fail = tonumber((rec.Failures or {})[ctr]),
64
+                        ease = tonumber((rec.Ease or {})[ctr]),
65
+                    }))
66
+                    m, n = cc.note:find(";;", n)
67
+                    ctr = ctr + 1
68
+                end
69
+                table.insert(ret, cc)
53 70
             else
54 71
                 print("error: unsupported card type " .. cc.ct)
55 72
             end
... ...
@@ -38,6 +38,8 @@ function Prompt:text()
38 38
     if self.card.ct == "bmc" then
39 39
         local _, eoa = self.card.note:find("{[^}]+}", self.ind)
40 40
         return (self.card.note:sub(1, self.ind - 1) .. "%A" .. self.card.note:sub(eoa + 1)):gsub("{([^}]+)}", "%1")
41
+    elseif self.card.ct == "seq" then
42
+        return (self.card.note:sub(1, self.ind - 1) .. "%A"):gsub(";;", "")
41 43
     else
42 44
         return "error: unrecognised card type " .. self.card.ct
43 45
     end
... ...
@@ -49,6 +51,10 @@ function Prompt:ans()
49 51
     end
50 52
     if self.card.ct == "bmc" then
51 53
         return self.card.note:match("{([^}]+)}", self.ind)
54
+    elseif self.card.ct == "seq" then
55
+        local m = self.card.note:match("[^;]+;;", self.ind)
56
+        if not m then m = self.card.note:sub(self.ind) end
57
+        return m:gsub(";;", "")
52 58
     else
53 59
         return "error: unrecognised card type " .. self.card.ct
54 60
     end
55 61