Permalink
Browse files

Update to be compatible with newer libraries.

  • Loading branch information...
1 parent d4fc466 commit a9bfd4bae6d9fb9445b8092df6196836f01f71a5 @clanehin committed May 14, 2014
Showing with 37 additions and 51 deletions.
  1. +13 −25 Makefile
  2. +1 −2 Roguestar/Lib/Data/MonsterData.hs
  3. +3 −8 Roguestar/Lib/HTML/Mustache.hs
  4. +20 −16 Roguestar/Server/Main.hs
View
38 Makefile
@@ -1,28 +1,16 @@
dontuse:
- echo "This makefile is for the convenience of the developer(s)."
- echo "Use:"
- echo "cabal configure"
- echo "cabal build"
- echo "cabal install"
+ @echo "This makefile is for the convenience of the developer(s)."
+ @echo "Use:"
+ @echo "cabal configure"
+ @echo "cabal build"
+ @echo "cabal install"
-configure:
- cabal-dev configure --ghc-options="-Werror"
+setup:
+ cabal sandbox init
+ cabal install --only-dependencies -j
+ cabal configure --ghc-options="-Werror"
+ cabal build
-configure-profiling:
- --enable-library-profiling --enable-executable-profiling
-
-build:
- cabal-dev build
-
-clean:
- cabal-dev clean
-
-run:
- ./dist/build/roguestar-server/roguestar-server +RTS -xc -p -s 2> ./log/stdout.log
-
-check: clean
- cabal-dev configure --ghc-options="-O0" --disable-library-profiling --disable-executable-profiling
- cabal-dev build
-
-depends:
- cabal-dev install-deps -j
+takedown:
+ cabal clean
+ cabal sandbox delete
View
3 Roguestar/Lib/Data/MonsterData.hs
@@ -15,7 +15,6 @@ module Roguestar.Lib.Data.MonsterData
import Roguestar.Lib.Data.PersistantData
import Data.Ratio
-import qualified Data.Text as Text
import Data.Maybe
import Data.Aeson
import Roguestar.Lib.Data.FactionData
@@ -166,4 +165,4 @@ creatureHealth c = case () of
creature_max_health = creatureAbilityScore ToughnessTrait c }
instance GetFaction MonsterData where
- getFaction = creature_faction
+ getFaction = creature_faction
View
11 Roguestar/Lib/HTML/Mustache.hs
@@ -4,12 +4,8 @@ module Roguestar.Lib.HTML.Mustache (renderPage, roguestar_muconfig) where
import Text.Hastache
import Data.Text.Lazy as T
import Data.Aeson as Aeson
-import Data.Attoparsec.Number as AesonNumber
import Data.HashMap.Strict as Map
import Data.Vector as V
-import Data.Text.Encoding as Encoding
-import Data.Text.Lazy.Encoding as LazyEncoding
-import Control.Monad
import Control.Monad.IO.Class
roguestar_muconfig :: (MonadIO m) => MuConfig m
@@ -19,17 +15,16 @@ roguestar_muconfig = defaultConfig {
muTemplateFileExt = Just ".mustache" }
mkAesonContext :: (Monad m) => Aeson.Value -> MuContext m
-mkAesonContext (Object obj) key = return $ maybe MuNothing aesonToMu $ Map.lookup (Encoding.decodeUtf8 key) obj
+mkAesonContext (Object obj) key = return $ maybe MuNothing aesonToMu $ Map.lookup key obj
mkAesonContext x _ = return $ aesonToMu x
aesonToMu :: (Monad m) => Aeson.Value -> MuType m
aesonToMu obj@(Object {}) = MuList [mkAesonContext obj]
aesonToMu (Array arr) = MuList $ Prelude.map mkAesonContext $ V.toList arr
aesonToMu (String txt) = MuVariable txt
-aesonToMu (Number (I num)) = MuVariable num
-aesonToMu (Number (D num)) = MuVariable num
+aesonToMu (Number n) = MuVariable $ show n
aesonToMu (Bool bool) = MuBool bool
aesonToMu Null = MuNothing
renderPage :: FilePath -> Aeson.Value -> IO T.Text
-renderPage filepath value = liftM LazyEncoding.decodeUtf8 $ hastacheFile roguestar_muconfig filepath (mkAesonContext value)
+renderPage filepath value = hastacheFile roguestar_muconfig filepath (mkAesonContext value)
View
36 Roguestar/Server/Main.hs
@@ -2,8 +2,8 @@
import Prelude
import qualified Data.ByteString as BS
-import qualified Data.ByteString.Lazy.Char8 as LBS8
import qualified Data.Text as T
+import qualified Data.Text.Lazy as LT
import Data.Text.Encoding
import Control.Exception (SomeException)
import qualified Control.Monad.CatchIO as CatchIO
@@ -25,7 +25,6 @@ import Roguestar.Lib.Perception
import Roguestar.Lib.Data.SpeciesData
import Roguestar.Lib.Data.ToolData
import Roguestar.Lib.Data.TerrainData as TerrainData
-import Roguestar.Lib.Data.MonsterData
import Roguestar.Lib.Data.FacingData
import Roguestar.Lib.Logging
import Roguestar.Lib.UnitTests
@@ -68,14 +67,15 @@ makeGlobals =
handle500 :: MonadSnap m => m a -> m ()
handle500 m = (m >> return ()) `CatchIO.catch` \(e::SomeException) -> do
- let t = LBS8.pack $ show e
+ let t = LT.pack $ show e
putResponse r
- writeBS "<html><head><title>Internal Server Error</title></head>"
- writeBS "<body><h1>Internal Server Error</h1>"
- writeBS "<p>A web handler threw an exception. Details:</p>"
- writeBS "<pre>\n"
- writeLBS $ htmlEscape t
- writeBS "\n</pre></body></html>"
+ writeText "<html><head><title>oh noes</title></head>"
+ writeText "<body style=\"background:black; color:white;\"><h1>theirs a porblem</h1>"
+ writeText "<p>i'm so sorry the website broke a little</p>"
+ writeText "<img src=\"static/art/TabularMonstrosity.svg\"/>"
+ writeText "<pre>\n"
+ writeLazyText $ htmlEscape t
+ writeText "\n</pre></body></html>"
where
r = setContentType "text/html" $
setResponseStatus 500 "Internal Server Error" emptyResponse
@@ -121,7 +121,10 @@ postFeedback = method POST $ ifTop $
getMemoryStatistics :: IO String
getMemoryStatistics =
- do ok <- getGCStatsEnabled
+ do -- this requires ghc 7.6 but I'm still living in 7.4 world
+ -- just disable for now
+ -- ok <- getGCStatsEnabled
+ let ok = False
if ok then liftM show $ getGCStats
else return "(Memory statistics disabled. Use +RTS -T -RTS to collect memory statistics.)"
@@ -344,12 +347,13 @@ oops action =
return $ error "oops: Unreachable code."
Left (DBError bad) ->
do putResponse r
- writeBS "<html><head><title>Gameplay Error</title></head>"
- writeBS "<body><h1>Gameplay Error</h1>"
- writeBS "<p>Roguestar returned an error condition. Details:</p>"
- writeBS "<pre>\n"
- writeLBS $ htmlEscape $ LBS8.pack bad
- writeBS "\n</pre></body></html>"
+ writeText "<html><head><title>gameplay error</title></head>"
+ writeText "<body style=\"background:black; color:white;\"><h1>oh oh the game is confused</h1>"
+ writeText "<p>some things happened and i didn't know what do</p>"
+ writeText "<img src=\"static/art/TabularMonstrosity.svg\"/>"
+ writeText "<pre>\n"
+ writeLazyText $ htmlEscape $ LT.pack bad
+ writeText "\n</pre></body></html>"
finishWith =<< getResponse
where
r = setContentType "text/html" $

0 comments on commit a9bfd4b

Please sign in to comment.