BROKEN partial redo of room tree composition
This commit is contained in:
@@ -53,7 +53,7 @@ roomThenCorridor theRoom = fmap
|
|||||||
(shuffleLinks corridor)
|
(shuffleLinks corridor)
|
||||||
|
|
||||||
{- | Create a random room tree structure from a list of annotations. -}
|
{- | Create a random room tree structure from a list of annotations. -}
|
||||||
anoToRoomTree :: [Annotation] -> State StdGen (LabSubCompTree Room)
|
anoToRoomTree :: [Annotation] -> State StdGen (Room -> Maybe ([String],Room), Tree Room)
|
||||||
anoToRoomTree anos = case anos of
|
anoToRoomTree anos = case anos of
|
||||||
[AnoApplyInt i f] -> f i
|
[AnoApplyInt i f] -> f i
|
||||||
-- [AnoApplyInt' i f str] -> f i <&> (,TreeSubLabelling str Nothing)
|
-- [AnoApplyInt' i f str] -> f i <&> (,TreeSubLabelling str Nothing)
|
||||||
|
|||||||
+1
-1
@@ -100,5 +100,5 @@ initialAnoTree = padSucWithDoors $ treeFromPost
|
|||||||
<&> (,TreeSubLabelling "telRoomLev" Nothing)]
|
<&> (,TreeSubLabelling "telRoomLev" Nothing)]
|
||||||
|
|
||||||
{- | A test level tree. -}
|
{- | A test level tree. -}
|
||||||
initialRoomTree :: State StdGen (Tree (LabSubCompTree Room))
|
initialRoomTree :: State StdGen (Tree (Room -> Maybe (String,Room), Tree Room))
|
||||||
initialRoomTree = mapM anoToRoomTree initialAnoTree
|
initialRoomTree = mapM anoToRoomTree initialAnoTree
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import Dodge.Room.Procedural
|
|||||||
import Dodge.Room.Tanks
|
import Dodge.Room.Tanks
|
||||||
import Dodge.Room.Link
|
import Dodge.Room.Link
|
||||||
import Dodge.Room.Ngon
|
import Dodge.Room.Ngon
|
||||||
|
import Dodge.UseAll
|
||||||
import LensHelp
|
import LensHelp
|
||||||
import Geometry
|
import Geometry
|
||||||
--import Dodge.Item.Equipment
|
--import Dodge.Item.Equipment
|
||||||
@@ -20,9 +21,10 @@ roomsContaining crs its = do
|
|||||||
[ randomFourCornerRoomCrsIts crs its
|
[ randomFourCornerRoomCrsIts crs its
|
||||||
, tanksRoom crs its
|
, tanksRoom crs its
|
||||||
]
|
]
|
||||||
return (treeFromPost [] $ UseAll endroom
|
return (toOnward ("roomsContaining-creatures:" ++ intercalate "," (map _crName crs)
|
||||||
,TreeSubLabelling ("roomsContaining-creatures:" ++ intercalate "," (map _crName crs)
|
++ "-items:" ++ intercalate "," (map (show . _iyBase . _itType) its))
|
||||||
++ "-items:" ++ intercalate "," (map (show . _iyBase . _itType) its)) Nothing)
|
, pure $ useAll endroom
|
||||||
|
)
|
||||||
|
|
||||||
pedestalRoom :: RandomGen g => Item -> State g Room
|
pedestalRoom :: RandomGen g => Item -> State g Room
|
||||||
pedestalRoom it = do
|
pedestalRoom it = do
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
{-# LANGUAGE TupleSections #-}
|
{-# LANGUAGE TupleSections #-}
|
||||||
module Dodge.Room.GlassLesson where
|
module Dodge.Room.GlassLesson where
|
||||||
|
import Dodge.UseAll
|
||||||
import Dodge.RoomLink
|
import Dodge.RoomLink
|
||||||
import Dodge.Creature
|
import Dodge.Creature
|
||||||
import Dodge.LevelGen.Data
|
import Dodge.LevelGen.Data
|
||||||
@@ -18,19 +19,18 @@ import LensHelp
|
|||||||
|
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
--import Control.Monad.Loops
|
--import Control.Monad.Loops
|
||||||
glassLesson :: RandomGen g => State g (SubCompTree Room)
|
glassLesson :: RandomGen g => State g (Tree Room)
|
||||||
glassLesson = do
|
glassLesson = do
|
||||||
i <- takeOne [1,2,3]
|
i <- takeOne [1,2,3]
|
||||||
corridors <- replicateM i $ PassDown <$> shuffleLinks corridor
|
corridors <- replicateM i $ shuffleLinks corridor
|
||||||
return $ Node (PassDown botRoom)
|
return $ Node botRoom
|
||||||
[ singleUseNone $ door & rmConnectsTo .~ fromWest North 1
|
[ pure $ door & rmConnectsTo .~ fromWest North 1
|
||||||
, uppers
|
, uppers
|
||||||
, treeFromPost (PassDown (door & rmConnectsTo .~ S.member (OnEdge East))
|
, treeFromPost ( (door & rmConnectsTo .~ S.member (OnEdge East))
|
||||||
: corridors) $ UseAll door]
|
: corridors) $ useAll door]
|
||||||
where
|
where
|
||||||
fromWest edge i s = S.member (OnEdge edge) s && S.member (FromWest i) s
|
fromWest edge i s = S.member (OnEdge edge) s && S.member (FromWest i) s
|
||||||
uppers = Node (PassDown $ door & rmConnectsTo .~ fromWest North 0)
|
uppers = Node (door & rmConnectsTo .~ fromWest North 0) [pure topRoom]
|
||||||
[singleUseNone topRoom]
|
|
||||||
botRoom = roomRect 200 200 1 1
|
botRoom = roomRect 200 200 1 1
|
||||||
& rmPmnts .~ botplmnts
|
& rmPmnts .~ botplmnts
|
||||||
& rmLinks %~ setInLinksByType (OnEdge West)
|
& rmLinks %~ setInLinksByType (OnEdge West)
|
||||||
@@ -54,6 +54,6 @@ glassLesson = do
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
glassLessonRunPast :: RandomGen g => State g (LabSubCompTree Room)
|
glassLessonRunPast :: RandomGen g => State g (LabSubCompTree Room)
|
||||||
glassLessonRunPast = (f <$> glassLesson) <&> (,TreeSubLabelling "glassLessonRunPast" Nothing)
|
glassLessonRunPast = (f <$> glassLesson) <&> (toOnward "glassLessonRunPast",)
|
||||||
where
|
where
|
||||||
f (Node r rs) = Node r $ return (UseLabel 0 $ door & rmConnectsTo .~ S.member (OnEdge West)) : rs
|
f (Node r rs) = Node r $ return (useLabel 0 $ door & rmConnectsTo .~ S.member (OnEdge West)) : rs
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ data ClusterStatus = ClusterStatus
|
|||||||
, _csLinks :: S.Set ClusterLink
|
, _csLinks :: S.Set ClusterLink
|
||||||
}
|
}
|
||||||
|
|
||||||
data ClusterLink = OnwardCluster | SideCluster
|
data ClusterLink = OnwardCluster | SideCluster | LabelCluster Int
|
||||||
deriving (Ord,Eq,Enum,Show)
|
deriving (Ord,Eq,Show)
|
||||||
|
|
||||||
makeLenses ''ClusterStatus
|
makeLenses ''ClusterStatus
|
||||||
|
|||||||
+45
-45
@@ -1,16 +1,16 @@
|
|||||||
{-# LANGUAGE TupleSections #-}
|
{-# LANGUAGE TupleSections #-}
|
||||||
{-| Combining and composing trees of trees. -}
|
{-| Combining and composing trees of trees. -}
|
||||||
module Dodge.Tree.Compose
|
module Dodge.Tree.Compose
|
||||||
( expandTree
|
( --expandTree
|
||||||
, singleUseAll
|
--, singleUseAll
|
||||||
, singleUseNone
|
--, singleUseNone
|
||||||
, passUntilUseAll
|
--, passUntilUseAll
|
||||||
, chainUses
|
--, chainUses
|
||||||
, useAllAtEnd
|
--, useAllAtEnd
|
||||||
, changeToPassDown
|
--, changeToPassDown
|
||||||
, overwriteLabel
|
--, overwriteLabel
|
||||||
, applyToCompRoot
|
--, applyToCompRoot
|
||||||
, composeTree
|
composeTree
|
||||||
, composeTree'
|
, composeTree'
|
||||||
, composeTreeRand
|
, composeTreeRand
|
||||||
-- , compTree
|
-- , compTree
|
||||||
@@ -26,49 +26,49 @@ import Data.Foldable
|
|||||||
import System.Random
|
import System.Random
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
|
||||||
expandTree :: CompTree a -> Tree a
|
--expandTree :: CompTree a -> Tree a
|
||||||
expandTree (Node rt extChildren) = case rt of
|
--expandTree (Node rt extChildren) = case rt of
|
||||||
Node (UseAll x) _ -> Node x (map expandTree extChildren)
|
-- Node (UseAll x) _ -> Node x (map expandTree extChildren)
|
||||||
Node (UseSome is x) _ -> Node x (map (expandTree . \i -> extChildren !! i) is)
|
-- Node (UseSome is x) _ -> Node x (map (expandTree . \i -> extChildren !! i) is)
|
||||||
Node (UseNone _) _ -> fmap _unCompose rt
|
-- Node (UseNone _) _ -> fmap _unCompose rt
|
||||||
Node (UseLabel _ _) _ -> fmap _unCompose rt
|
-- Node (UseLabel _ _) _ -> fmap _unCompose rt
|
||||||
Node (PassDown x) xs -> Node x $ map (expandTree . (`Node` extChildren)) xs
|
-- Node (PassDown x) xs -> Node x $ map (expandTree . (`Node` extChildren)) xs
|
||||||
Node (SplitDown x) xs -> Node x $ map expandTree $ zipWith Node xs
|
-- Node (SplitDown x) xs -> Node x $ map expandTree $ zipWith Node xs
|
||||||
$ map (:[]) extChildren ++ repeat []
|
-- $ map (:[]) extChildren ++ repeat []
|
||||||
|
|
||||||
applyToCompRoot :: (a -> a) -> SubCompTree a -> SubCompTree a
|
--applyToCompRoot :: (a -> a) -> SubCompTree a -> SubCompTree a
|
||||||
applyToCompRoot f = over root (unCompose %~ f)
|
--applyToCompRoot f = over root (unCompose %~ f)
|
||||||
|
|
||||||
overwriteLabel :: Int -> (a -> ComposingNode a) -> SubCompTree a -> [SubCompTree a] -> SubCompTree a
|
--overwriteLabel :: Int -> (a -> ComposingNode a) -> SubCompTree a -> [SubCompTree a] -> SubCompTree a
|
||||||
overwriteLabel i f t ts = errorHead ("tried to overwriteLabel " ++ show i)
|
--overwriteLabel i f t ts = errorHead ("tried to overwriteLabel " ++ show i)
|
||||||
$ updateSingleNodes islabel update t
|
-- $ updateSingleNodes islabel update t
|
||||||
where
|
-- where
|
||||||
islabel (UseLabel j _) | i == j = True
|
-- islabel (UseLabel j _) | i == j = True
|
||||||
islabel _ = False
|
-- islabel _ = False
|
||||||
update (Node x _) = Node (f $ _unCompose x) ts
|
-- update (Node x _) = Node (f $ _unCompose x) ts
|
||||||
|
|
||||||
passUntilUseAll :: SubCompTree a -> [SubCompTree a] -> SubCompTree a
|
--passUntilUseAll :: SubCompTree a -> [SubCompTree a] -> SubCompTree a
|
||||||
passUntilUseAll (Node (UseAll x) _) ts' = Node (PassDown x) ts'
|
--passUntilUseAll (Node (UseAll x) _) ts' = Node (PassDown x) ts'
|
||||||
passUntilUseAll (Node cn ts) ts' = Node (PassDown (_unCompose cn)) $ map (`passUntilUseAll` ts') ts
|
--passUntilUseAll (Node cn ts) ts' = Node (PassDown (_unCompose cn)) $ map (`passUntilUseAll` ts') ts
|
||||||
|
|
||||||
chainUses :: [SubCompTree a] -> SubCompTree a
|
--chainUses :: [SubCompTree a] -> SubCompTree a
|
||||||
chainUses (t:s:ts) = chainUses (passUntilUseAll t [s]:ts)
|
--chainUses (t:s:ts) = chainUses (passUntilUseAll t [s]:ts)
|
||||||
chainUses [t] = t
|
--chainUses [t] = t
|
||||||
chainUses [] = error "tried to concatenate an empty list of SubCompTrees"
|
--chainUses [] = error "tried to concatenate an empty list of SubCompTrees"
|
||||||
|
|
||||||
singleUseAll :: a -> Tree (ComposingNode a)
|
--singleUseAll :: a -> Tree (ComposingNode a)
|
||||||
singleUseAll x = Node (UseAll x) []
|
--singleUseAll x = Node (UseAll x) []
|
||||||
|
|
||||||
useAllAtEnd :: Tree a -> SubCompTree a
|
--useAllAtEnd :: Tree a -> SubCompTree a
|
||||||
useAllAtEnd tree = case tree of
|
--useAllAtEnd tree = case tree of
|
||||||
Node x (t:ts) -> Node (PassDown x) (useAllAtEnd t : map (fmap UseNone) ts)
|
-- Node x (t:ts) -> Node (PassDown x) (useAllAtEnd t : map (fmap UseNone) ts)
|
||||||
Node x [] -> Node (UseAll x) []
|
-- Node x [] -> Node (UseAll x) []
|
||||||
|
|
||||||
singleUseNone :: a -> SubCompTree a
|
--singleUseNone :: a -> SubCompTree a
|
||||||
singleUseNone x = Node (UseNone x) []
|
--singleUseNone x = Node (UseNone x) []
|
||||||
|
|
||||||
changeToPassDown :: ComposingNode a -> ComposingNode a
|
--changeToPassDown :: ComposingNode a -> ComposingNode a
|
||||||
changeToPassDown x = PassDown (_unCompose x)
|
--changeToPassDown x = PassDown (_unCompose x)
|
||||||
|
|
||||||
composeTreeRand :: RandomGen g => Tree (a -> Maybe a, Tree a) -> State g (Tree a)
|
composeTreeRand :: RandomGen g => Tree (a -> Maybe a, Tree a) -> State g (Tree a)
|
||||||
composeTreeRand (Node (_,t) ts) = attachListR t ts
|
composeTreeRand (Node (_,t) ts) = attachListR t ts
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ data ComposingNode a
|
|||||||
| UseSome {_composeIndices :: [Int], _unCompose :: a}
|
| UseSome {_composeIndices :: [Int], _unCompose :: a}
|
||||||
| UseNone {_unCompose :: a}
|
| UseNone {_unCompose :: a}
|
||||||
| UseLabel {_composeIndex :: Int, _unCompose :: a} -- defaults to using no children
|
| UseLabel {_composeIndex :: Int, _unCompose :: a} -- defaults to using no children
|
||||||
type SubCompTree a = Tree (ComposingNode a)
|
type SubCompTree a = Tree a
|
||||||
type CompTree a = Tree (SubCompTree a)
|
type CompTree a = Tree (Tree a)
|
||||||
type LabSubCompTree a = (Tree (ComposingNode a),TreeSubLabelling)
|
type LabSubCompTree a = (a -> Maybe ([String],a),Tree a)
|
||||||
type LabCompTree a = Tree (LabSubCompTree a)
|
type LabCompTree a = Tree (LabSubCompTree a)
|
||||||
data TreeSubLabelling = TreeSubLabelling
|
data TreeSubLabelling = TreeSubLabelling
|
||||||
{ _topLabel :: String
|
{ _topLabel :: String
|
||||||
@@ -20,3 +20,4 @@ data TreeSubLabelling = TreeSubLabelling
|
|||||||
}
|
}
|
||||||
makeLenses ''ComposingNode
|
makeLenses ''ComposingNode
|
||||||
makeLenses ''TreeSubLabelling
|
makeLenses ''TreeSubLabelling
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user