Skip to content

Commit

Permalink
Start on doorlike
Browse files Browse the repository at this point in the history
  • Loading branch information
PPKFS committed Nov 9, 2023
1 parent 47e4f17 commit f6e856f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/Yaifl/Activities/PrintingTheLocaleDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ alsoSee = Rule "You can also see" [] (\v ->
isASupporter <- dom `isType` "supporter"
isAnAnimal <- dom `isType` "animal"

let isInLoc = True -- TODO TODOmaybe False (dom `objectEquals`) plRoom
let isInLoc = maybe False (dom `objectEquals`) plRoom
if
--if the domain is the location: say "[We] " (A);
| isRoom dom && isInLoc ->
| isInLoc ->
sayYCASResponse #youCanAlsoSeeA ()
-- otherwise if the domain is a supporter or the domain is an animal:
-- say "On [the domain] [we] " (B);
Expand Down
4 changes: 2 additions & 2 deletions src/Yaifl/Model/Objects/RoomConnections.hs
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ isBelow = isDownOf
addDoorToConnection ::
NoMissingObjects wm es
=> WMHasProperty wm DoorSpecifics
=> Thing wm
=> DoorLike wm d
=> d
-> (Room wm, WMDirection wm)
-> (Room wm, WMDirection wm)
-> Eff es ()
addDoorToConnection d (front, frontDir) (back, backDir) = do
-- this is probably best done as an asDoor thing TODO
mbDs <- getDoorSpecificsMaybe d
case mbDs of
Nothing -> error $ "Tried to add a door, except it wasn't a door " <> show (getID d)
Expand Down
24 changes: 23 additions & 1 deletion src/Yaifl/Model/Properties/Door.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

module Yaifl.Model.Properties.Door
( DoorSpecifics(..)
, DoorLike
, blankDoor
, getDoorSpecificsMaybe
, isOpen
, isClosed
) where


Expand All @@ -28,4 +31,23 @@ blankDoor :: Entity -> DoorSpecifics
blankDoor e = Door e False Closed

makeFieldLabelsNoPrefix ''DoorSpecifics
makeSpecificsWithout [] ''DoorSpecifics
makeSpecificsWithout [] ''DoorSpecifics

isClosed ::
NoMissingRead wm es
=> WMHasProperty wm Openable
=> ObjectLike wm o
=> o
-> Eff es Bool
isClosed o = (Just Closed ==) <$> getOpenableMaybe o

isOpen ::
NoMissingRead wm es
=> WMHasProperty wm Openable
=> ObjectLike wm o
=> o
-> Eff es Bool
isOpen o = (Just Open ==) <$> getOpenableMaybe o


type DoorLike wm o = PropertyLike wm DoorSpecifics o
20 changes: 1 addition & 19 deletions src/Yaifl/Model/Properties/Openable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module Yaifl.Model.Properties.Openable
( -- * Types
Openable(..)
, getOpenableMaybe
, isClosed
, isOpen
) where


Expand All @@ -21,20 +19,4 @@ import Yaifl.Model.Objects.Effects
data Openable = Open | Closed
deriving stock (Eq, Show, Read, Ord, Generic)

makeSpecificsWithout [] ''Openable

isClosed ::
NoMissingRead wm es
=> WMHasProperty wm Openable
=> ObjectLike wm o
=> o
-> Eff es Bool
isClosed o = (Just Closed ==) <$> getOpenableMaybe o

isOpen ::
NoMissingRead wm es
=> WMHasProperty wm Openable
=> ObjectLike wm o
=> o
-> Eff es Bool
isOpen o = (Just Open ==) <$> getOpenableMaybe o
makeSpecificsWithout [] ''Openable
4 changes: 4 additions & 0 deletions src/Yaifl/Model/Properties/PropertyLike.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Yaifl.Model.Properties.PropertyLike
(

) where
5 changes: 2 additions & 3 deletions src/Yaifl/Model/Properties/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ class PropertyLike wm prop o where
getAs :: (WMHasProperty wm prop, NoMissingObjects wm es) => o -> Eff es prop

type EnclosingLike wm o = PropertyLike wm Enclosing o

instance PropertyLike wm Enclosing Enclosing where
instance PropertyLike wm a a where
getAs = pure

instance PropertyLike wm Enclosing (TaggedEntity EnclosingTag) where
Expand All @@ -108,4 +107,4 @@ instance PropertyLike wm Enclosing (TaggedEntity RoomTag) where
getAs a

instance PropertyLike wm Enclosing (Room wm) where
getAs o = pure $ o ^. #objectData % #enclosing
getAs o = pure $ o ^. #objectData % #enclosing
3 changes: 2 additions & 1 deletion test/Yaifl/Test/Chapter3/StarryVoid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Yaifl.Rules.RuleEffects
import Yaifl.Text.AdaptiveNarrative
import Yaifl.Text.DynamicText
import Yaifl.Text.SayQQ
import Yaifl.Model.Direction

boothDesc :: WMHasProperty wm Openable => Room wm -> DynamicText wm
boothDesc tcr = DynamicText $ Right ("description of magician's booth door", RuleLimitedEffect $ withThing $ \t -> do
Expand All @@ -35,5 +36,5 @@ starryVoid = do
tsv <- addRoom "The Starry Void" ""
tmb <- addDoor "The magician's booth" (Just $ boothDesc tcr) tcr tsv Nothing
tcr `isInsideFrom` tsv
--addDoorToConnection tmb (Out, tcr) (In, tsv)
addDoorToConnection tmb (Out, tcr) (In, tsv)
pass

0 comments on commit f6e856f

Please sign in to comment.