<commit_before>
module GameData.Data where
#include "Gamgine/Utils.cpp"
import qualified Data.List as L
import qualified Data.List.Zipper as LZ
import Gamgine.Utils (mapz, applyIf)
import qualified GameData.Level as LV
IMPORT_LENS


data Data = Data {
   levels :: LZ.Zipper LV.Level
   } deriving Show

LENS(levels)

currentLevelL    = currentLevelLens
currentLevelLens = LE.lens getCurrentLevel setCurrentLevel
   where
      getCurrentLevel dat       = LZ.cursor . levels $ dat
      setCurrentLevel level dat = LE.modL levelsL (LZ.replace level) dat


newData :: [LV.Level] -> Data
newData levels = Data $ LZ.fromList levels


allLevels :: Data -> [LV.Level]
allLevels dat = LZ.toList . levels $ dat


toNextLevel :: Data -> Data
toNextLevel d@Data {levels = lvs}
   | not . atLastLevel $ d = d {levels = LZ.right lvs}
   | otherwise             = d


toPreviousLevel :: Data -> Data
toPreviousLevel d@Data {levels = lvs}
   | not . atFirstLevel $ d = d {levels = LZ.left lvs}
   | otherwise              = d


addEmptyLevel :: Data -> Data
addEmptyLevel = LE.modL levelsL $ (LZ.insert LV.newEmptyLevel) . LZ.end


atFirstLevel :: Data -> Bool
atFirstLevel Data {levels = levels} = (not . LZ.emptyp $ levels) && LZ.beginp levels


atLastLevel :: Data -> Bool
atLastLevel Data {levels = levels} = (not . LZ.emptyp $ levels) && (LZ.endp $ LZ.right levels)<commit_msg>Some code simplyfication<commit_after>
module GameData.Data where
#include "Gamgine/Utils.cpp"
import qualified Data.List as L
import qualified Data.List.Zipper as LZ
import Gamgine.Utils (mapz, applyIf)
import qualified GameData.Level as LV
IMPORT_LENS


data Data = Data {
   levels :: LZ.Zipper LV.Level
   } deriving Show

LENS(levels)

currentLevelL    = currentLevelLens
currentLevelLens = LE.lens getCurrentLevel setCurrentLevel
   where
      getCurrentLevel       = LZ.cursor . levels
      setCurrentLevel level = LE.modL levelsL $ LZ.replace level


newData :: [LV.Level] -> Data
newData = Data . LZ.fromList


allLevels :: Data -> [LV.Level]
allLevels = LZ.toList . levels


toNextLevel :: Data -> Data
toNextLevel = LE.modL levelsL $ \lvs -> applyIf LZ.endp LZ.left $ LZ.right lvs


toPreviousLevel :: Data -> Data
toPreviousLevel = LE.modL levelsL $ applyIf (not . LZ.beginp) LZ.left


addEmptyLevel :: Data -> Data
addEmptyLevel = LE.modL levelsL $ (LZ.insert LV.newEmptyLevel) . LZ.end
{'fraction_non_alphanumeric': 0.10084388185654009, 'fraction_numerical': 0.0, 'mean_word_length': 3.407063197026022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4070199', 'n_tokens_mistral': 828, 'n_tokens_neox': 786, 'n_words': 232}