From d8bd8e7eea5dcef4901bee14b8fe3027fd8605ac Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 19 Jun 2021 11:49:20 -0400 Subject: 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 Tested-by: BuildkiteCI --- users/grfn/xanthous/src/Xanthous/Entities/Raws.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'users/grfn/xanthous/src/Xanthous/Entities/Raws.hs') diff --git a/users/grfn/xanthous/src/Xanthous/Entities/Raws.hs b/users/grfn/xanthous/src/Xanthous/Entities/Raws.hs index d4cae7ccc299..441e870160a5 100644 --- a/users/grfn/xanthous/src/Xanthous/Entities/Raws.hs +++ b/users/grfn/xanthous/src/Xanthous/Entities/Raws.hs @@ -12,6 +12,7 @@ import Data.FileEmbed import qualified Data.Yaml as Yaml import Xanthous.Prelude import System.FilePath.Posix +import Control.Monad.Random (MonadRandom) -------------------------------------------------------------------------------- import Xanthous.Entities.RawTypes import Xanthous.Game.State @@ -52,8 +53,8 @@ rawsWithType = mapFromList . itoListOf (ifolded . _RawType) $ raws -------------------------------------------------------------------------------- -entityFromRaw :: EntityRaw -> SomeEntity +entityFromRaw :: MonadRandom m => EntityRaw -> m SomeEntity entityFromRaw (Creature creatureType) - = SomeEntity $ Creature.newWithType creatureType + = SomeEntity <$> Creature.newWithType creatureType entityFromRaw (Item itemType) - = SomeEntity $ Item.newWithType itemType + = SomeEntity <$> Item.newWithType itemType -- cgit 1.4.1