feat(xanthous) Generate random volume+density for items
Generate random volumes and densities for items based on the ranges for those two quantities in the raw when building instances of items. Since this is the first time creating an item is impure, this also lifts entity generation into a (random) monadic context Change-Id: I2de4880e8144f7ff9e1304eb32806ed1d7affa18 Reviewed-on: https://cl.tvl.fyi/c/depot/+/3226 Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
This commit is contained in:
parent
8b97683f6e
commit
d8bd8e7eea
9 changed files with 108 additions and 25 deletions
|
|
@ -5,6 +5,8 @@ import Test.Prelude
|
|||
--------------------------------------------------------------------------------
|
||||
import Xanthous.Game.State
|
||||
import Xanthous.Entities.Raws (raws, entityFromRaw)
|
||||
import Control.Monad.Random (evalRandT)
|
||||
import System.Random (getStdGen)
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
main :: IO ()
|
||||
|
|
@ -13,13 +15,15 @@ main = defaultMain test
|
|||
test :: TestTree
|
||||
test = testGroup "Xanthous.Game.StateSpec"
|
||||
[ testGroup "entityTypeName"
|
||||
[ testCase "for a creature" $
|
||||
[ testCase "for a creature" $ do
|
||||
let gormlakRaw = raws ^?! ix "gormlak"
|
||||
creature = entityFromRaw gormlakRaw
|
||||
in entityTypeName creature @?= "Creature"
|
||||
, testCase "for an item" $
|
||||
creature <- runRand $ entityFromRaw gormlakRaw
|
||||
entityTypeName creature @?= "Creature"
|
||||
, testCase "for an item" $ do
|
||||
let stickRaw = raws ^?! ix "stick"
|
||||
item = entityFromRaw stickRaw
|
||||
in entityTypeName item @?= "Item"
|
||||
item <- runRand $ entityFromRaw stickRaw
|
||||
entityTypeName item @?= "Item"
|
||||
]
|
||||
]
|
||||
where
|
||||
runRand x = evalRandT x =<< getStdGen
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue