Skip to content

Commit

Permalink
finish the other half of the inventory details bit
Browse files Browse the repository at this point in the history
  • Loading branch information
PPKFS committed Sep 21, 2024
1 parent aa682b0 commit 3d1c845
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 24 deletions.
18 changes: 18 additions & 0 deletions yaifl/src/Yaifl/Model/Kinds/Container.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module Yaifl.Model.Kinds.Container
, isOpenContainer
, isEmptyContainer
, isClosedContainer
, isLockedContainer
, isEmptyTransparentContainer
, isTransparentContainer
) where

import Yaifl.Prelude
Expand Down Expand Up @@ -84,11 +87,26 @@ isClosedContainer ::
-> Bool
isClosedContainer = (== Closed) . view (#openable % #opened)

isLockedContainer ::
Container
-> Bool
isLockedContainer = (== Closed) . view (#openable % #opened)

isEmptyContainer ::
Container
-> Bool
isEmptyContainer = ES.null . view (#enclosing % #contents)

isEmptyTransparentContainer ::
Container
-> Bool
isEmptyTransparentContainer c = isEmptyContainer c && isTransparentContainer c

isTransparentContainer ::
Container
-> Bool
isTransparentContainer = (== Transparent) . view #opacity

makeContainer ::
Maybe Int
-> Maybe Opacity
Expand Down
63 changes: 39 additions & 24 deletions yaifl/src/Yaifl/Text/ListWriter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Yaifl.Text.ListWriter
, ListWriterResponses(..)
) where

import Yaifl.Prelude hiding (Reader, runReader)
import Yaifl.Prelude hiding (asks, Reader, runReader)
import Yaifl.Model.Rules.RuleEffects
--import Effectful.Writer.Static.Local ( tell )
import Yaifl.Text.Say
Expand Down Expand Up @@ -310,6 +310,7 @@ writeAfterEntry numberOfItem itemMember = do
-- TODO: should we just cut out non-things here
whenJust asThing $ \thingWrittenAbout -> do
let lit = thingIsLit thingWrittenAbout
asCont = getContainerMaybe thingWrittenAbout
if
| givingBriefInventoryInformation s -> do
-- start the room description details activity
Expand All @@ -321,7 +322,6 @@ writeAfterEntry numberOfItem itemMember = do
beginActivity #printingRoomDescriptionDetails thingWrittenAbout
void $ whenHandling' #printingRoomDescriptionDetails $ do
let locationLit = roomIsLighted locP
asCont = getContainerMaybe thingWrittenAbout
isCC = thingIsClosedContainer thingWrittenAbout
opClosed = isOpaqueClosedContainer <$> asCont
visiblyEmpty = isEmptyContainer <$?> asCont
Expand All @@ -348,31 +348,46 @@ writeAfterEntry numberOfItem itemMember = do
let isWorn = thingIsWorn thingWrittenAbout
combo = lit || isWorn
when combo $ sayTellResponse A ()
case (lit, isWorn) of
(True, True) ->
pass
alreadyPrinted <- case (lit, isWorn) of
(True, True) -> sayTellResponse K () >> pure True
(True, False) -> sayTellResponse D () >> pure True
(False, True) -> sayTellResponse L () >> pure True
_ -> pure False
printedContainerPart <- case asCont of
Just container -> do
if isOpenableContainer container
then do
-- either close off the clause or
-- open a parenthesis
if alreadyPrinted
then do
serialComma <- asks oxfordCommaEnabled
when serialComma $ tell ","
sayTellResponse C ()
else
sayTellResponse A ()
-- open check
if isOpenContainer container
then
if isEmptyContainer container
then sayTellResponse N ()
else sayTellResponse M ()
else
if isLockedContainer container
then sayTellResponse P ()
else sayTellResponse O ()
pure True
else do
when (isEmptyTransparentContainer container) $
if alreadyPrinted
then sayTellResponse C () >> sayTellResponse F ()
else sayTellResponse A () >> sayTellResponse F () >> sayTellResponse B ()
pure alreadyPrinted
Nothing -> pure alreadyPrinted
when printedContainerPart $ sayTellResponse B ()
| otherwise -> pass
-- combos are as follows
{-
then for full inventory
light and worn: A then K (providing light and being worn))
light: D
worn: A, being worn L
container:
if openable: (I guess to aovid supporters)
potential and (C) or open the bracket (A)
if open and has stuff:
open (M)
open but empty (N)
if locked:
closed and locked (P)
else:
closed (O)
otherwise it's a supporter:
transparent and without children,
"and" if needbe (C) and empty (F)
( (A), empty (F), ) (B)
if (parenth_flag) LW_Response('B');
loop over all children of o
Expand Down

0 comments on commit 3d1c845

Please sign in to comment.