<commit_before>{-# LANGUAGE OverloadedStrings #-}
{-
  Copyright 2016 The CodeWorld Authors. All Rights Reserved.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-}

module Blocks.Types(setBlockTypes, getTypeBlocks)
  where

import Blockly.DesignBlock 
import Blockly.General
import Blockly.Event
import Data.List(intersperse)
import qualified Data.Text as T

colorPicture = Color 160
colorNumber = Color 210
colorProgram = Color 0
colorColor = Color 290
colorPoly = Color 180
colorBool = Color 100
colorText = Color 45

typePicture = Picture
typeNumber = Number
typeProgram = Program
typeColor = Col
typeBool = Truth
typeText = Str
typeComment = Comment

inlineDef = Inline True

icon :: T.Text -> Field
icon name = FieldImage ("ims/" `T.append` name) 20 20


standardFunction cwName funcName ico types inputNames color tooltip = 
    DesignBlock cwName (Function funcName types)
      (header : (Dummy [Text "("])  : (argInputs ++ [ Dummy [Text ")"]] ) ) 
      inlineDef
      color
      (Tooltip tooltip)
  where
    header = case ico of
                Just i -> Dummy [TextE funcName, icon i] 
                Nothing -> Dummy [TextE funcName]
    argInputs = intersperse (Dummy [Text ","]) $ map (\name -> Value name []) inputNames

-- PICTURE ----------------------------------------------
cwBlank = DesignBlock "cwBlank" (Function "blank" [Picture])
          [Dummy 
            [TextE "blank"]
          ]
          inlineDef colorPicture 
          (Tooltip "Blank picture")

cwCoordinatePlane = DesignBlock "cwCoordinatePlane" (Function "coordinatePlane" [Picture] )
          [Dummy 
            [TextE "coordinatePlane"]
          ]
          inlineDef colorPicture 
          (Tooltip "Picture of coordinate plane")

cwCodeWorldLogo = DesignBlock "cwCodeWorldLogo" (Function "codeWorldLogo" [Picture])
          [Dummy 
            [TextE "codeWorldLogo"]
          ]
          inlineDef colorPicture 
          (Tooltip "Picture of CodeWorld logo")

cwText = standardFunction "cwText" "text" Nothing [typeText, Picture]
            ["TEXT"] colorPicture "Picture of text"

cwDrawingOf = DesignBlock "cwDrawingOf" (Top "drawingOf" [typePicture, typeProgram])
          [Dummy [Text "(", TextE "drawingOf", icon "shape-plus.svg"] 
            ,Value "VALUE" []
            ,Dummy [Text ")"]] 
          inlineDef colorProgram 
          (Tooltip "Displays a drawing of a picture")


cwCircle = standardFunction "cwCircle" "circle" Nothing [typeNumber, typePicture] ["RADIUS"] colorPicture "Picture of a circle"

cwThickCircle = standardFunction "cwThickCircle" "thickCircle" Nothing [typeNumber, typeNumber, typePicture] ["RADIUS", "LINEWIDTH"] 
                  colorPicture "Picture of a circle with a border"

cwSolidCircle = standardFunction "cwSolidCircle" "solidCircle" Nothing [typeNumber, typePicture] ["RADIUS"] 
                  colorPicture "Picture of a solid circle"

cwRectangle = standardFunction "cwRectangle" "rectangle" Nothing [typeNumber, typeNumber, typePicture] ["WIDTH", "HEIGHT"]
                colorPicture "Picture of a rectangle"

cwThickRectangle = standardFunction "cwThickRectangle" "thickRectangle" Nothing 
                    [typeNumber, typeNumber, typeNumber, typePicture] ["WIDTH", "HEIGHT", "LINEWIDTH"]
                    colorPicture "Picture of a rectangle with a border"

cwSolidRectangle = standardFunction "cwSolidRectangle" "solidRectangle" Nothing [typeNumber, typeNumber, typePicture] ["WIDTH", "HEIGHT"]
                      colorPicture "Picture of a solid rectangle"

cwArc = standardFunction "cwArc" "arc" Nothing [typeNumber, typeNumber, typeNumber, typePicture] ["STARTANGLE", "ENDANGLE", "RADIUS"]
          colorPicture "A thin arc"

cwSector = standardFunction "cwSector" "sector" Nothing [typeNumber, typeNumber, typeNumber, typePicture] ["STARTANGLE", "ENDANGLE", "RADIUS"]
              colorPicture "A solid sector of a circle"

cwThickArc = standardFunction "cwThickArc" "thickArc" Nothing [typeNumber, typeNumber, typeNumber, typeNumber, typePicture]
                ["STARTANGLE", "ENDANGLE", "RADIUS", "LINEWIDTH"]
                colorPicture "An arc with variable line width"

-- Transformations -----------------------------------------------
cwColored = standardFunction "cwColored" "colored" (Just "format-color-fill.svg") [typePicture, typeColor, typePicture]
              ["PICTURE", "COLOR"] colorPicture "A colored picture"

cwTranslate = standardFunction "cwTranslate" "translated" (Just "cursor-move.svg") [typePicture, typeNumber, typeNumber, typePicture]
                ["PICTURE", "X", "Y"] colorPicture "A translated picture"

cwScale = standardFunction "cwScale" "scaled" (Just "move-resize-variant.svg") [typePicture, typeNumber, typeNumber, typePicture]
            ["PICTURE", "HORZ", "VERTZ"] colorPicture "A scaled picture"

cwRotate = standardFunction "cwRotate" "rotated" (Just "rotate-3d.svg") [typePicture, typeNumber, typePicture ]
              ["PICTURE", "ANGLE"] colorPicture "A rotated picture"

-- NUMBERS ---------------------------------------------

numAdd = DesignBlock "numAdd" (Function "+" [typeNumber, typeNumber, typeNumber])
        [ Value "LEFT"  [] 
         ,Value "RIGHT" [TextE "+"] 
         ]
         (Inline True) colorNumber 
         (Tooltip "Add two numbers")

numSub = DesignBlock "numSub" (Function "-" [typeNumber, typeNumber, typeNumber])
        [ Value "LEFT"  [] 
         ,Value "RIGHT" [TextE "-"] 
         ]
         (Inline True) colorNumber 
         (Tooltip "Subtract two numbers")

numMult = DesignBlock "numMult" (Function "*" [typeNumber, typeNumber, typeNumber])
        [ Value "LEFT"  [] 
         ,Value "RIGHT" [TextE "\xD7"] 
         ]
         (Inline True) colorNumber 
         (Tooltip "Multiply two numbers")

numDiv = DesignBlock "numDiv" (Function "/" [typeNumber, typeNumber, typeNumber])
        [ Value "LEFT"  [] 
         ,Value "RIGHT" [TextE "\xF7"] 
         ]
         (Inline True) colorNumber 
         (Tooltip "Divide two numbers")

numExp = DesignBlock "numExp" (Function "^" [typeNumber, typeNumber, typeNumber])
        [ Value "LEFT"  [] 
         ,Value "RIGHT" [TextE "^"] 
         ]
         (Inline True) colorNumber 
         (Tooltip "Raise a number to a power")

numMax = standardFunction "numMax" "max" (Just "arrow-up.svg") [typeNumber, typeNumber, typeNumber]
            ["LEFT", "RIGHT"] colorNumber "The maximum of two numbers"

numMin = standardFunction "numMin" "min" (Just "arrow-down.svg") [typeNumber, typeNumber, typeNumber]
            ["LEFT", "RIGHT"] colorNumber "Take the minimum of two numbers"

numOpposite = standardFunction "numOpposite" "opposite" (Just "minus-box.svg") [typeNumber, typeNumber]
                ["NUM"] colorNumber "The opposite of a number"

numAbs = standardFunction "numAbs" "abs" Nothing [typeNumber, typeNumber]
            ["NUM"] colorNumber "The absolute value of a number"

numRound = standardFunction "numRound" "round" Nothing [typeNumber, typeNumber]
            ["NUM"] colorNumber "The rounded value of a number"

numReciprocal = standardFunction "numReciprocal" "reciprocal" Nothing [typeNumber, typeNumber]
                  ["NUM"] colorNumber "The reciprocal of a number"

numQuot = standardFunction "numQuot" "quotient" Nothing [typeNumber, typeNumber, typeNumber]
              ["LEFT", "RIGHT"] colorNumber "The integer part when dividing two numbers"

numRem = standardFunction "numRem" "remainder" Nothing [typeNumber, typeNumber, typeNumber]
            ["LEFT", "RIGHT"] colorNumber "The remainder when dividing two numbers"

numPi = DesignBlock "numPi" (Function "pi" [typeNumber])
          [Dummy 
            [TextE "\x3C0"]
          ]
          inlineDef colorNumber 
          (Tooltip "The number pi, 3.1415..")

numSqrt = DesignBlock "numSqrt" (Function "sqrt" [typeNumber, typeNumber])
        [Value "NUM" [TextE "\x221A"] ]
         (Inline True) colorNumber 
         (Tooltip "Gives the square root of a number")

numGCD = standardFunction "numGCD" "gcd" Nothing [typeNumber, typeNumber, typeNumber]
            ["LEFT", "RIGHT"] colorNumber "The greatest common demonitator between two numbers"

numLCM = standardFunction "numLCM" "lcm" Nothing [typeNumber, typeNumber, typeNumber]<commit_msg>Fix the `rounded` function, which was typo'd as `round`.<commit_after>{-# LANGUAGE OverloadedStrings #-}
{-
  Copyright 2016 The CodeWorld Authors. All Rights Reserved.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-}

module Blocks.Types(setBlockTypes, getTypeBlocks)
  where

import Blockly.DesignBlock 
import Blockly.General
import Blockly.Event
import Data.List(intersperse)
import qualified Data.Text as T

colorPicture = Color 160
colorNumber = Color 210
colorProgram = Color 0
colorColor = Color 290
colorPoly = Color 180
colorBool = Color 100
colorText = Color 45

typePicture = Picture
typeNumber = Number
typeProgram = Program
typeColor = Col
typeBool = Truth
typeText = Str
typeComment = Comment

inlineDef = Inline True

icon :: T.Text -> Field
icon name = FieldImage ("ims/" `T.append` name) 20 20


standardFunction cwName funcName ico types inputNames color tooltip = 
    DesignBlock cwName (Function funcName types)
      (header : (Dummy [Text "("])  : (argInputs ++ [ Dummy [Text ")"]] ) ) 
      inlineDef
      color
      (Tooltip tooltip)
  where
    header = case ico of
                Just i -> Dummy [TextE funcName, icon i] 
                Nothing -> Dummy [TextE funcName]
    argInputs = intersperse (Dummy [Text ","]) $ map (\name -> Value name []) inputNames

-- PICTURE ----------------------------------------------
cwBlank = DesignBlock "cwBlank" (Function "blank" [Picture])
          [Dummy 
            [TextE "blank"]
          ]
          inlineDef colorPicture 
          (Tooltip "Blank picture")

cwCoordinatePlane = DesignBlock "cwCoordinatePlane" (Function "coordinatePlane" [Picture] )
          [Dummy 
            [TextE "coordinatePlane"]
          ]
          inlineDef colorPicture 
          (Tooltip "Picture of coordinate plane")

cwCodeWorldLogo = DesignBlock "cwCodeWorldLogo" (Function "codeWorldLogo" [Picture])
          [Dummy 
            [TextE "codeWorldLogo"]
          ]
          inlineDef colorPicture 
          (Tooltip "Picture of CodeWorld logo")

cwText = standardFunction "cwText" "text" Nothing [typeText, Picture]
            ["TEXT"] colorPicture "Picture of text"

cwDrawingOf = DesignBlock "cwDrawingOf" (Top "drawingOf" [typePicture, typeProgram])
          [Dummy [Text "(", TextE "drawingOf", icon "shape-plus.svg"] 
            ,Value "VALUE" []
            ,Dummy [Text ")"]] 
          inlineDef colorProgram 
          (Tooltip "Displays a drawing of a picture")


cwCircle = standardFunction "cwCircle" "circle" Nothing [typeNumber, typePicture] ["RADIUS"] colorPicture "Picture of a circle"

cwThickCircle = standardFunction "cwThickCircle" "thickCircle" Nothing [typeNumber, typeNumber, typePicture] ["RADIUS", "LINEWIDTH"] 
                  colorPicture "Picture of a circle with a border"

cwSolidCircle = standardFunction "cwSolidCircle" "solidCircle" Nothing [typeNumber, typePicture] ["RADIUS"] 
                  colorPicture "Picture of a solid circle"

cwRectangle = standardFunction "cwRectangle" "rectangle" Nothing [typeNumber, typeNumber, typePicture] ["WIDTH", "HEIGHT"]
                colorPicture "Picture of a rectangle"

cwThickRectangle = standardFunction "cwThickRectangle" "thickRectangle" Nothing 
                    [typeNumber, typeNumber, typeNumber, typePicture] ["WIDTH", "HEIGHT", "LINEWIDTH"]
                    colorPicture "Picture of a rectangle with a border"

cwSolidRectangle = standardFunction "cwSolidRectangle" "solidRectangle" Nothing [typeNumber, typeNumber, typePicture] ["WIDTH", "HEIGHT"]
                      colorPicture "Picture of a solid rectangle"

cwArc = standardFunction "cwArc" "arc" Nothing [typeNumber, typeNumber, typeNumber, typePicture] ["STARTANGLE", "ENDANGLE", "RADIUS"]
          colorPicture "A thin arc"

cwSector = standardFunction "cwSector" "sector" Nothing [typeNumber, typeNumber, typeNumber, typePicture] ["STARTANGLE", "ENDANGLE", "RADIUS"]
              colorPicture "A solid sector of a circle"

cwThickArc = standardFunction "cwThickArc" "thickArc" Nothing [typeNumber, typeNumber, typeNumber, typeNumber, typePicture]
                ["STARTANGLE", "ENDANGLE", "RADIUS", "LINEWIDTH"]
                colorPicture "An arc with variable line width"

-- Transformations -----------------------------------------------
cwColored = standardFunction "cwColored" "colored" (Just "format-color-fill.svg") [typePicture, typeColor, typePicture]
              ["PICTURE", "COLOR"] colorPicture "A colored picture"

cwTranslate = standardFunction "cwTranslate" "translated" (Just "cursor-move.svg") [typePicture, typeNumber, typeNumber, typePicture]
                ["PICTURE", "X", "Y"] colorPicture "A translated picture"

cwScale = standardFunction "cwScale" "scaled" (Just "move-resize-variant.svg") [typePicture, typeNumber, typeNumber, typePicture]
            ["PICTURE", "HORZ", "VERTZ"] colorPicture "A scaled picture"

cwRotate = standardFunction "cwRotate" "rotated" (Just "rotate-3d.svg") [typePicture, typeNumber, typePicture ]
              ["PICTURE", "ANGLE"] colorPicture "A rotated picture"

-- NUMBERS ---------------------------------------------

numAdd = DesignBlock "numAdd" (Function "+" [typeNumber, typeNumber, typeNumber])
        [ Value "LEFT"  [] 
         ,Value "RIGHT" [TextE "+"] 
         ]
         (Inline True) colorNumber 
         (Tooltip "Add two numbers")

numSub = DesignBlock "numSub" (Function "-" [typeNumber, typeNumber, typeNumber])
        [ Value "LEFT"  [] 
         ,Value "RIGHT" [TextE "-"] 
         ]
         (Inline True) colorNumber 
         (Tooltip "Subtract two numbers")

numMult = DesignBlock "numMult" (Function "*" [typeNumber, typeNumber, typeNumber])
        [ Value "LEFT"  [] 
         ,Value "RIGHT" [TextE "\xD7"] 
         ]
         (Inline True) colorNumber 
         (Tooltip "Multiply two numbers")

numDiv = DesignBlock "numDiv" (Function "/" [typeNumber, typeNumber, typeNumber])
        [ Value "LEFT"  [] 
         ,Value "RIGHT" [TextE "\xF7"] 
         ]
         (Inline True) colorNumber 
         (Tooltip "Divide two numbers")

numExp = DesignBlock "numExp" (Function "^" [typeNumber, typeNumber, typeNumber])
        [ Value "LEFT"  [] 
         ,Value "RIGHT" [TextE "^"] 
         ]
         (Inline True) colorNumber 
         (Tooltip "Raise a number to a power")

numMax = standardFunction "numMax" "max" (Just "arrow-up.svg") [typeNumber, typeNumber, typeNumber]
            ["LEFT", "RIGHT"] colorNumber "The maximum of two numbers"

numMin = standardFunction "numMin" "min" (Just "arrow-down.svg") [typeNumber, typeNumber, typeNumber]
            ["LEFT", "RIGHT"] colorNumber "Take the minimum of two numbers"

numOpposite = standardFunction "numOpposite" "opposite" (Just "minus-box.svg") [typeNumber, typeNumber]
                ["NUM"] colorNumber "The opposite of a number"

numAbs = standardFunction "numAbs" "abs" Nothing [typeNumber, typeNumber]
            ["NUM"] colorNumber "The absolute value of a number"

numRound = standardFunction "numRound" "rounded" Nothing [typeNumber, typeNumber]
            ["NUM"] colorNumber "The rounded value of a number"

numReciprocal = standardFunction "numReciprocal" "reciprocal" Nothing [typeNumber, typeNumber]
                  ["NUM"] colorNumber "The reciprocal of a number"

numQuot = standardFunction "numQuot" "quotient" Nothing [typeNumber, typeNumber, typeNumber]
              ["LEFT", "RIGHT"] colorNumber "The integer part when dividing two numbers"

numRem = standardFunction "numRem" "remainder" Nothing [typeNumber, typeNumber, typeNumber]
            ["LEFT", "RIGHT"] colorNumber "The remainder when dividing two numbers"

numPi = DesignBlock "numPi" (Function "pi" [typeNumber])
          [Dummy 
            [TextE "\x3C0"]
          ]
          inlineDef colorNumber 
          (Tooltip "The number pi, 3.1415..")

numSqrt = DesignBlock "numSqrt" (Function "sqrt" [typeNumber, typeNumber])
        [Value "NUM" [TextE "\x221A"] ]
         (Inline True) colorNumber 
         (Tooltip "Gives the square root of a number")

numGCD = standardFunction "numGCD" "gcd" Nothing [typeNumber, typeNumber, typeNumber]
            ["LEFT", "RIGHT"] colorNumber "The greatest common demonitator between two numbers"

numLCM = standardFunction "numLCM" "lcm" Nothing [typeNumber, typeNumber, typeNumber]
{'fraction_non_alphanumeric': 0.11974515046362137, 'fraction_numerical': 0.0048922009215541275, 'mean_word_length': 3.052558782849239, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7374067', 'n_tokens_mistral': 5198, 'n_tokens_neox': 4892, 'n_words': 1605}