From 7ecbf4f5c7bd0c3c2f92559a2313274b6d075e6c Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 2 Dec 2016 12:29:17 +0100 Subject: Entity replacement --- src/Main.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Main.hs b/src/Main.hs index db49e14..9a51332 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -95,6 +95,7 @@ main = do , cmd "align" alignEntity "Align the focused entity to a faction – creating it, if necessary" , cmd "name" nameEntity "Name the current entity overriding previous name assignments" , cmd "spawn" spawnEntity "Create a new entity from an archetype focusing on it" + , cmd "replace" replaceEntity "Replace the focused entity with a different one carrying over some values" , cmd "spawn'" spawnFaction "Create a new faction and spawn multiple copies of an archetype in it" , cmd "test" rollTest "Roll a test using the stats of the currently focused entity" , cmd "combat" entitySeqVal "Roll sequence value for the current focus and enter combat" @@ -326,11 +327,25 @@ remove = withFocus $ \ident -> do blur -- Manage Entity -spawnEntity :: Completable Entity -> Sh GameState () +spawnEntity, replaceEntity :: Completable Entity -> Sh GameState () spawnEntity = withArg $ \entity -> do identifier <- use gNextId' modify $ insertEntity entity gFocus ?= identifier +replaceEntity = withArg $ \entity -> void . withFocus' $ \old -> do + let oldStats = old ^. eStats + modifying (gFocus' . eStats) . execState $ do + put $ entity ^. eStats + let + copy :: st -> Traversal' st a -> State st () + copy from lens = do + case preview lens from of + Just a -> lens .= a + Nothing -> return () + copy oldStats sSeqVal + copy oldStats sTimer + copy oldStats sModifiers + copy oldStats sEquipment nameEntity :: String -> Sh GameState () nameEntity ('#':_) = shellPutErrLn "We do not allow names that might shadow explicit access to entities via their number (‘#’)" -- cgit v1.2.3