summaryrefslogtreecommitdiff
path: root/reading.lua
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2024-11-02 03:27:03 +0100
committerAki <please@ignore.pl>2024-11-02 03:27:03 +0100
commit1a2c8b663ed89b4d4a75463e28260a7c4955ecb1 (patch)
tree1197fd5279771e8aa8fa3f7b20f8d96be59fb8a8 /reading.lua
parentf87fb2cb7b044a73284c75dfcd06f25e068df8e1 (diff)
downloadnoita-eyes-1a2c8b663ed89b4d4a75463e28260a7c4955ecb1.zip
noita-eyes-1a2c8b663ed89b4d4a75463e28260a7c4955ecb1.tar.gz
noita-eyes-1a2c8b663ed89b4d4a75463e28260a7c4955ecb1.tar.bz2
Cleaned up and added common reading scripts
Diffstat (limited to 'reading.lua')
-rw-r--r--reading.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/reading.lua b/reading.lua
new file mode 100644
index 0000000..2b74446
--- /dev/null
+++ b/reading.lua
@@ -0,0 +1,38 @@
+local function next_trigram (message, index)
+ index = (index or 0) + 1
+ local offset = (index - 1) * 3
+ local a = message[offset + 1]
+ if not a then
+ return nil
+ end
+ return index, a, message[offset + 2], message[offset + 3]
+end
+
+
+local function next_value (message, index)
+ local a, b, c
+ index, a, b, c = next_trigram(message, index)
+ if not index then
+ return nil
+ end
+ return index, a * 25 + b * 5 + c
+end
+
+
+local reading = {
+ next_trigram = next_trigram,
+ next_value = next_value,
+}
+
+
+function reading.trigrams (message, start)
+ return next_trigram, message, start
+end
+
+
+function reading.values (message, start)
+ return next_value, message, start
+end
+
+
+return reading