module Nomyx.Library.Examples where
import Prelude
import Control.Monad as X
import Nomyx.Language
import qualified Data.Time as DT
import Control.Applicative
nothing :: Rule
nothing = return ()
helloWorld :: Rule
helloWorld = outputAll_ "hello, world!"
delRule :: RuleNumber -> Rule
delRule rn = suppressRule_ rn >> autoDelete
displayCurrentTime :: Rule
displayCurrentTime = void $ outputAll $ do
t <- getCurrentTime
return $ "The current time is: " ++ (show t)
displayActivateTime :: Nomex ()
displayActivateTime = do
t <- getCurrentTime
outputAll_ $ "This rule was activated at: " ++ (show t)
bravoButton :: Rule
bravoButton = void $ onInputButton_ "Click here:" (const $ outputAll_ "Bravo!") 1
helloButton :: Rule
helloButton = do
me <- getProposerNumber_
let displayMsg a = void $ newOutput_ Nothing ("Msg: " ++ a)
let button = do
all <- liftEvent getPlayers
guard (length all >= 2) >> inputText me "send a message"
void $ onEvent_ button displayMsg
enterHaiku :: Rule
enterHaiku = void $ onInputTextarea_ "Enter a haiku:" outputAll_ 1
testTime :: Rule
testTime = do
t <- getCurrentTime
void $ onEvent_ (True <$ inputButton 1 "click here before 5 seconds:" <|> False <$ (timeEvent $ DT.addUTCTime 5 t)) f where
f a = outputAll_ $ show a