<commit_before>module Drawing where

import Data.Tuple
import Data.Char
import Data.Maybe
import Data.Foldable
import Data.String hiding (length, drop)
import Data.Array ((!!), (..), map, range, length, head, filter)
import Graphics.CanvasConsole
import qualified Data.Map as M
import Debug.Trace
import Math

import GameState
import GameData
import Level
import Utils
import Line


-- Draws the message buffer.
drawMessages :: Console -> Point -> Number -> [String] -> ConsoleEff Unit
drawMessages console p col (x:xs) = drawString console x (rgb col col col) p.x p.y
                                 >> drawMessages console {x: p.x, y: p.y - 1} (col - 50) xs
drawMessages _       _ _   []     = return unit

-- Draws an array of strings.
drawStrings :: Console -> Point -> String -> [String] -> ConsoleEff Unit
drawStrings console p col (x:xs) = drawString console x col p.x p.y
                                >> drawStrings console {x: p.x, y: p.y + 1} col xs
drawStrings _ _  _  []           = return unit

-- Draws the game when state.blink changes to true or false.
blinkDraw :: Console -> GameState -> ConsoleEff GameState
blinkDraw console g@(Game state) | state.blinkTimer == 0 = drawGame console g
blinkDraw console g@(Game state) | otherwise             = return g

fromCode :: Number -> String
fromCode = singleton <<< fromCharCode

drawFrame :: Console -> ConsoleEff Unit
drawFrame console = do
    drawString console leftSideFrame  "990000" 0 0
    drawString console rightSideFrame "990000" 79 0
    drawString console bar "990000" 1 0
    drawString console bar "990000" 1 19
    where
        rightSideFrame :: String
        rightSideFrame = fromCode 187 ++ "\n" ++ joinWith "\n" (replicate 18 $ fromCode 186) ++ "\n" ++ fromCode 188

        leftSideFrame :: String
        leftSideFrame = fromCode 201 ++ "\n" ++ joinWith "\n" (replicate 18 $ fromCode 186) ++ "\n" ++ fromCode 200

        bar :: String
        bar = foldl (++) "" (replicate 78 $ fromCode 205)


-- Draws the game state.
drawGame :: Console -> GameState -> ConsoleEff GameState
drawGame console g@(Game state@{ window = SkillW }) = do
    clear console
    drawString console ("Name: " ++ state.playerName ++ "   " ++ "Total score: " ++ show state.pointsTotal) "AAAAAA" 2 2
    drawFrame console
    drawString console (skillsInfo state.skills) "AAAAAA" 2 6
    drawString console (statsToString state.player.stats) "AAAAAA" 3 4
    drawString console "Press ESC or A to close skill window." "AAAAAA" 1 18
    return g
drawGame console g@(Game state@{ window = EquipW }) = do
    clear console
    drawFrame console
    drawString console "Press e to continue and i to open your inventory." "AAAAAA" 1 1
    drawString console "Items equipped: " "AAAAAA" 2 4
    drawString console (equipmentsToString state.equipments) "AAAAAA" 3 6
    drawString console "Press ESC or E to close equipment window." "AAAAAA" 1 18
    drawMessages console {x: 1, y: 23} 255 state.messageBuf
    return g
drawGame console g@(Game state@{ window = InventoryW { index = page , command = com, equip = equ }, inventory = inv, equipments = eq, player = pl }) = do
    clear console
    drawFrame console
    drawString console "Press i to continue and e to open your equipments. Change page with + and -." "AAAAAA" 1 1
    drawString console ("Inventory (page " ++ show (page + 1) ++ "/" ++ show (floor ((length inv) / 10) + 1) ++ "): (Carrying: " ++ (show ( carryingWeight (M.values eq) + carryingWeight inv )) ++ "/" ++ maxCarryingCapacity pl) "AAAAAA" 2 4
    drawInventoryPage inv 0 (page * 10) 4 5
    drawString console "Press ESC or I to close inventory window, D to drop item." "AAAAAA" 1 18
    drawCommandLine com
    drawChoseEquipment equ
    drawMessages console {x: 1, y: 23} 255 state.messageBuf
    return g
        where
            drawItemInfo :: Maybe Item -> Number -> Number -> ConsoleEff Unit
            drawItemInfo (Just i) x y = drawString console (showItem i) "AAAAAA" x y
            drawItemInfo _ x y        = drawString console "empty"      "AAAAAA" x y

            drawInventoryPage :: [Item] -> Number -> Number -> Number -> Number -> ConsoleEff Unit
            drawInventoryPage [] num i x y = drawString console "--- Empty ---" "AAAAAA" x y --End recursion when list is empty.
            drawInventoryPage _ 10 _ x y        = return unit
            drawInventoryPage items num i x y  = do
                drawItemInfo ((!!) items i) (x + 5) y
                drawString console ("(" ++ show num ++ "): ") "AAAAAA" x y
                drawInventoryPage items (num + 1) (i + 1) x (y + 1)

            drawCommandLine :: InventoryCommand -> ConsoleEff Unit
            drawCommandLine Drop = drawString console "Which item do you want to drop?" "AAAAAA" 1 19
            drawCommandLine Use  = drawString console "Which item do you want to drop?" "AAAAAA" 1 19
            drawCommandLine _    = return unit<commit_msg>Fixed max carrying weight display<commit_after>module Drawing where

import Data.Tuple
import Data.Char
import Data.Maybe
import Data.Foldable
import Data.String hiding (length, drop)
import Data.Array ((!!), (..), map, range, length, head, filter)
import Graphics.CanvasConsole
import qualified Data.Map as M
import Debug.Trace
import Math

import GameState
import GameData
import Level
import Utils
import Line


-- Draws the message buffer.
drawMessages :: Console -> Point -> Number -> [String] -> ConsoleEff Unit
drawMessages console p col (x:xs) = drawString console x (rgb col col col) p.x p.y
                                 >> drawMessages console {x: p.x, y: p.y - 1} (col - 50) xs
drawMessages _       _ _   []     = return unit

-- Draws an array of strings.
drawStrings :: Console -> Point -> String -> [String] -> ConsoleEff Unit
drawStrings console p col (x:xs) = drawString console x col p.x p.y
                                >> drawStrings console {x: p.x, y: p.y + 1} col xs
drawStrings _ _  _  []           = return unit

-- Draws the game when state.blink changes to true or false.
blinkDraw :: Console -> GameState -> ConsoleEff GameState
blinkDraw console g@(Game state) | state.blinkTimer == 0 = drawGame console g
blinkDraw console g@(Game state) | otherwise             = return g

fromCode :: Number -> String
fromCode = singleton <<< fromCharCode

drawFrame :: Console -> ConsoleEff Unit
drawFrame console = do
    drawString console leftSideFrame  "990000" 0 0
    drawString console rightSideFrame "990000" 79 0
    drawString console bar "990000" 1 0
    drawString console bar "990000" 1 19
    where
        rightSideFrame :: String
        rightSideFrame = fromCode 187 ++ "\n" ++ joinWith "\n" (replicate 18 $ fromCode 186) ++ "\n" ++ fromCode 188

        leftSideFrame :: String
        leftSideFrame = fromCode 201 ++ "\n" ++ joinWith "\n" (replicate 18 $ fromCode 186) ++ "\n" ++ fromCode 200

        bar :: String
        bar = foldl (++) "" (replicate 78 $ fromCode 205)


-- Draws the game state.
drawGame :: Console -> GameState -> ConsoleEff GameState
drawGame console g@(Game state@{ window = SkillW }) = do
    clear console
    drawString console ("Name: " ++ state.playerName ++ "   " ++ "Total score: " ++ show state.pointsTotal) "AAAAAA" 2 2
    drawFrame console
    drawString console (skillsInfo state.skills) "AAAAAA" 2 6
    drawString console (statsToString state.player.stats) "AAAAAA" 3 4
    drawString console "Press ESC or A to close skill window." "AAAAAA" 1 18
    return g
drawGame console g@(Game state@{ window = EquipW }) = do
    clear console
    drawFrame console
    drawString console "Press e to continue and i to open your inventory." "AAAAAA" 1 1
    drawString console "Items equipped: " "AAAAAA" 2 4
    drawString console (equipmentsToString state.equipments) "AAAAAA" 3 6
    drawString console "Press ESC or E to close equipment window." "AAAAAA" 1 18
    drawMessages console {x: 1, y: 23} 255 state.messageBuf
    return g
drawGame console g@(Game state@{ window = InventoryW { index = page , command = com, equip = equ }, inventory = inv, equipments = eq, player = pl }) = do
    clear console
    drawFrame console
    drawString console "Press i to continue and e to open your equipments. Change page with + and -." "AAAAAA" 1 1
    drawString console ("Inventory (page " ++ show (page + 1) ++ "/" ++ show (floor ((length inv) / 10) + 1) ++ "): (Carrying: " ++ (show ( carryingWeight (M.values eq) + carryingWeight inv )) ++ "/" ++ show (maxCarryingCapacity pl) ++ ")") "AAAAAA" 2 4
    drawInventoryPage inv 0 (page * 10) 4 5
    drawString console "Press ESC or I to close inventory window, D to drop item." "AAAAAA" 1 18
    drawCommandLine com
    drawChoseEquipment equ
    drawMessages console {x: 1, y: 23} 255 state.messageBuf
    return g
        where
            drawItemInfo :: Maybe Item -> Number -> Number -> ConsoleEff Unit
            drawItemInfo (Just i) x y = drawString console (showItem i) "AAAAAA" x y
            drawItemInfo _ x y        = drawString console "empty"      "AAAAAA" x y

            drawInventoryPage :: [Item] -> Number -> Number -> Number -> Number -> ConsoleEff Unit
            drawInventoryPage [] num i x y = drawString console "--- Empty ---" "AAAAAA" x y --End recursion when list is empty.
            drawInventoryPage _ 10 _ x y        = return unit
            drawInventoryPage items num i x y  = do
                drawItemInfo ((!!) items i) (x + 5) y
                drawString console ("(" ++ show num ++ "): ") "AAAAAA" x y
                drawInventoryPage items (num + 1) (i + 1) x (y + 1)

            drawCommandLine :: InventoryCommand -> ConsoleEff Unit
            drawCommandLine Drop = drawString console "Which item do you want to drop?" "AAAAAA" 1 19
            drawCommandLine Use  = drawString console "Which item do you want to drop?" "AAAAAA" 1 19
            drawCommandLine _    = return unit
{'fraction_non_alphanumeric': 0.10052642235270298, 'fraction_numerical': 0.02510629682121887, 'mean_word_length': 2.730740181268882, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6671185', 'n_tokens_mistral': 3034, 'n_tokens_neox': 2759, 'n_words': 1156}