diff options
author | Aki <please@ignore.pl> | 2024-11-07 18:28:16 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2024-11-07 18:28:16 +0100 |
commit | 2eee005702d1be7e0391399f203cdbd9d7d5a42a (patch) | |
tree | b4f8068a06ce198b70764e94169d1bd420e1d94f /automaton/init.lua | |
parent | 7a57438f8f6d30a8fe490e87f6f24c70847d2530 (diff) | |
download | noita-eyes-2eee005702d1be7e0391399f203cdbd9d7d5a42a.zip noita-eyes-2eee005702d1be7e0391399f203cdbd9d7d5a42a.tar.gz noita-eyes-2eee005702d1be7e0391399f203cdbd9d7d5a42a.tar.bz2 |
Sketch of Patrick's simplified automaton/cipher mechanism
Document: https://docs.google.com/document/d/1EwnCgP4eq1g_M2iZObSDZdhV3fFoZ0RXRBXWrUm-hw0
Discord: https://discord.com/channels/453998283174576133/1063583558154854521/1303784643342106645
Diffstat (limited to 'automaton/init.lua')
-rw-r--r-- | automaton/init.lua | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/automaton/init.lua b/automaton/init.lua new file mode 100644 index 0000000..8c4bc40 --- /dev/null +++ b/automaton/init.lua @@ -0,0 +1,129 @@ +local actions = {} + + +function actions:clone () + local new = {} + for i, v in ipairs(self) do + new[i] = v + end + return setmetatable(new, getmetatable(self)) +end + + +function actions:tostring () + return + table.concat(self, nil, 1, 9) .."\n ".. + table.concat(self, nil, 10, 16) .."\n".. + table.concat(self, nil, 17, 25) +end + + +function actions:pivot () + local new = self:clone() + new[10] = self[3] + new[3] = self[12] + new[12] = self[19] + new[19] = self[10] + return new +end + + +function actions:up () + local new = self:clone() + for i=1, 9 do + new[16 + i] = self[i] + end + for i=2, 8 do + new[i] = self[8 + i] + new[8 + i] = self[16 + i] + end + new[1] = self[17] + new[9] = self[25] + return new +end + + +function actions:right () + local new = self:clone() + new[1] = self[9] + for i=2, 9 do + new[i] = self[i - 1] + end + new[10] = self[16] + for i=11, 16 do + new[i] = self[i - 1] + end + new[17] = self[25] + for i=18, 25 do + new[i] = self[i - 1] + end + return new +end + + +function actions:down () + local new = self:clone() + for i=1, 9 do + new[i] = self[26 - i] + new[26 - i] = self[i] + end + for i=1, 3 do + new[9 + i] = self[17 - i] + new[17 - i] = self[9 + i] + end + new[13] = self[13] + return new +end + + +function actions:left () + local new = self:clone() + for i=1, 8 do + new[i] = self[i + 1] + end + new[9] = self[1] + for i=10, 15 do + new[i] = self[i + 1] + end + new[16] = self[10] + for i=17, 24 do + new[i] = self[i + 1] + end + new[25] = self[17] + return new +end + + +local map = { + [0] = actions.pivot, + [1] = actions.up, + [2] = actions.right, + [3] = actions.down, + [4] = actions.left, +} + + +function actions:apply (eye) + return map[eye](self) +end + + +local mt = { + __index = actions, + __tostring = actions.tostring, +} + + +local function new (data) + if type(data) == "string" then + local obj = {} + for i=1, 25 do + obj[i] = data:sub(i, i) + end + data = obj + end + return setmetatable(data, mt) +end + + +return new |