aboutsummaryrefslogtreecommitdiff
path: root/src/Chelleport/KeySequence.hs
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2024-12-26 21:48:01 +0530
committerAkshay Nair <phenax5@gmail.com>2024-12-26 21:48:01 +0530
commit2819868eb398ebe7da0e59391367e5825f8fe2c5 (patch)
tree7c684f23487cc39132b8099205791ef3f9a1bad1 /src/Chelleport/KeySequence.hs
parent7dfa0f2866ea6d3441c6c343d841e969aa2ea77d (diff)
downloadchelleport-2819868eb398ebe7da0e59391367e5825f8fe2c5.tar.gz
chelleport-2819868eb398ebe7da0e59391367e5825f8fe2c5.zip
Minor refactoring
Diffstat (limited to 'src/Chelleport/KeySequence.hs')
-rw-r--r--src/Chelleport/KeySequence.hs26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/Chelleport/KeySequence.hs b/src/Chelleport/KeySequence.hs
index fd8eaa7..70d56e2 100644
--- a/src/Chelleport/KeySequence.hs
+++ b/src/Chelleport/KeySequence.hs
@@ -14,8 +14,8 @@ nextChars keySequence cells =
[] -> Nothing
_ -> Just nextCharactersInSequence
where
- matches = concatMap (filter $ isPrefixOf keySequence) cells
nextCharactersInSequence = uniq $ concatMap (take 1 . drop (length keySequence)) matches
+ matches = concatMap (filter $ isPrefixOf keySequence) cells
findMatchPosition :: KeySequence -> KeyGrid -> Maybe (Int, Int)
findMatchPosition keySequence = findWithIndex searchRows 0
@@ -23,16 +23,16 @@ findMatchPosition keySequence = findWithIndex searchRows 0
searchRows = fmap fst . findWithIndex searchInRow 0
searchInRow = guard . (== keySequence)
-isValidKey :: SDL.Keycode -> Bool
-isValidKey = (`Map.member` keycodeCharMapping)
+isAlphabetic :: SDL.Keycode -> Bool
+isAlphabetic = (`Map.member` keycodeCharMapping)
-- Linear Congruential Generator
lcg :: Int -> Int
-lcg seed = (a * seed + c) `mod` fromIntegral m
+lcg seed = (multiplier * seed + increment) `mod` modulus
where
- a = 1664525
- c = 1013904223
- m = (2 :: Integer) ^ (32 :: Integer)
+ multiplier = 1664525
+ increment = 1013904223
+ modulus = fromIntegral $ (2 :: Integer) ^ (32 :: Integer)
getIndexRounded :: Int -> [a] -> a
getIndexRounded i ls = ls !! (i `mod` length ls)
@@ -54,6 +54,12 @@ generateGrid seed (rows, columns) hintKeys
toKeyChar :: SDL.Keycode -> Maybe Char
toKeyChar = (`Map.lookup` keycodeCharMapping)
+keycodeToInt :: SDL.Keycode -> Maybe Int
+keycodeToInt = (`elemIndex` digitKeycodes)
+
+isKeycodeDigit :: SDL.Keycode -> Bool
+isKeycodeDigit = isJust . keycodeToInt
+
keycodeCharMapping :: Map.Map SDL.Keycode Char
keycodeCharMapping =
Map.fromList
@@ -85,12 +91,6 @@ keycodeCharMapping =
(SDL.KeycodeZ, 'Z')
]
-keycodeToInt :: SDL.Keycode -> Maybe Int
-keycodeToInt = (`elemIndex` digitKeycodes)
-
-isKeycodeDigit :: SDL.Keycode -> Bool
-isKeycodeDigit = isJust . keycodeToInt
-
digitKeycodes :: [SDL.Keycode]
digitKeycodes =
[ SDL.Keycode0,