-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
92 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
-- | ||
-- Utility for determining the center of | ||
-- the map, outside the context of a | ||
-- running game | ||
module Swarm.Game.Scenario.Topography.Center where | ||
|
||
import Control.Lens (view) | ||
import Data.List.NonEmpty (NonEmpty) | ||
import Data.Maybe (fromMaybe, listToMaybe) | ||
import Swarm.Game.Location (Location, origin) | ||
import Swarm.Game.Robot (trobotLocation) | ||
import Swarm.Game.Scenario (Scenario) | ||
import Swarm.Game.State (SubworldDescription, genRobotTemplates) | ||
import Swarm.Game.Universe (Cosmic (..), SubworldName (DefaultRootSubworld)) | ||
|
||
determineViewCenter :: | ||
Scenario -> | ||
NonEmpty SubworldDescription -> | ||
Cosmic Location | ||
determineViewCenter s worldTuples = | ||
fromMaybe defaultVC baseRobotLoc | ||
where | ||
theRobots = genRobotTemplates s worldTuples | ||
defaultVC = Cosmic DefaultRootSubworld origin | ||
|
||
-- The first robot is guaranteed to be the base. | ||
baseRobotLoc :: Maybe (Cosmic Location) | ||
baseRobotLoc = do | ||
theBaseRobot <- listToMaybe theRobots | ||
view trobotLocation theBaseRobot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
-- | ||
-- Code for drawing the Swarm logo. | ||
module Swarm.TUI.View.Logo where | ||
|
||
import Brick | ||
import Brick.Widgets.Center (centerLayer) | ||
import Data.Text (Text) | ||
import Data.Text qualified as T | ||
import Swarm.Game.Entity.Cosmetic.Specimen | ||
import Swarm.TUI.Model.Name | ||
import Swarm.TUI.View.Attribute.Attr | ||
|
||
drawLogo :: Text -> Widget Name | ||
drawLogo = centerLayer . vBox . map (hBox . T.foldr (\c ws -> drawThing c : ws) []) . T.lines | ||
where | ||
drawThing :: Char -> Widget Name | ||
drawThing c = withAttr (attrFor c) $ str [c] | ||
|
||
attrFor :: Char -> AttrName | ||
attrFor c | ||
| c `elem` ("<>v^" :: String) = robotAttr | ||
attrFor 'T' = plantAttr | ||
attrFor '@' = rockAttr | ||
attrFor '~' = waterAttr | ||
attrFor '▒' = dirtAttr | ||
attrFor _ = defAttr | ||
|
||
waterAttr :: AttrName | ||
waterAttr = getWorldAttrName $ fst water | ||
|
||
rockAttr :: AttrName | ||
rockAttr = getWorldAttrName $ fst rock | ||
|
||
plantAttr :: AttrName | ||
plantAttr = getWorldAttrName $ fst rock | ||
|
||
dirtAttr :: AttrName | ||
dirtAttr = getTerrainAttrName $ fst dirt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters