@@ -44,7 +44,7 @@ import Data.Yaml.Aeson (prettyPrintParseException)
44
44
import Swarm.Game.Display (displayChar )
45
45
import Swarm.Game.Entity (Entity , EntityMap (entitiesByName ), entityDisplay , entityName , loadEntities )
46
46
import Swarm.Game.Entity qualified as E
47
- import Swarm.Game.Recipe (Recipe , loadRecipes , recipeInputs , recipeOutputs , recipeRequirements )
47
+ import Swarm.Game.Recipe (Recipe , loadRecipes , recipeInputs , recipeOutputs , recipeRequirements , recipeTime , recipeWeight )
48
48
import Swarm.Game.Robot (installedDevices , instantiateRobot , robotInventory )
49
49
import Swarm.Game.Scenario (Scenario , loadScenario , scenarioRobots )
50
50
import Swarm.Game.WorldGen (testWorld2Entites )
@@ -113,13 +113,16 @@ generateDocs = \case
113
113
Capabilities -> simpleErrorHandle $ do
114
114
entities <- loadEntities >>= guardRight " load entities"
115
115
liftIO $ T. putStrLn $ capabilityPage address entities
116
- Recipes -> error " Recipes are not implemented"
117
116
Entities -> simpleErrorHandle $ do
118
117
let loadEntityList fp = left (from . prettyPrintParseException) <$> decodeFileEither fp
119
118
let f = " entities.yaml"
120
119
Just fileName <- liftIO $ getDataFileNameSafe f
121
120
entities <- liftIO (loadEntityList fileName) >>= guardRight " load entities"
122
121
liftIO $ T. putStrLn $ entitiesPage address entities
122
+ Recipes -> simpleErrorHandle $ do
123
+ entities <- loadEntities >>= guardRight " load entities"
124
+ recipes <- loadRecipes entities >>= guardRight " load recipes"
125
+ liftIO $ T. putStrLn $ recipePage address recipes
123
126
124
127
-- ----------------------------------------------------------------------------
125
128
-- GENERATE KEYWORDS: LIST OF WORDS TO BE HIGHLIGHTED
@@ -360,6 +363,40 @@ entitiesPage _a es =
360
363
]
361
364
<> map entityToSection es
362
365
366
+ -- -------------
367
+ -- RECIPES
368
+ -- -------------
369
+
370
+ recipeHeader :: [Text ]
371
+ recipeHeader = [" In" , " Out" , " Required" , " Time" , " Weight" ]
372
+
373
+ recipeRow :: PageAddress -> Recipe Entity -> [Text ]
374
+ recipeRow PageAddress {.. } r =
375
+ map
376
+ escapeTable
377
+ [ T. intercalate " , " (map formatCE $ view recipeInputs r)
378
+ , T. intercalate " , " (map formatCE $ view recipeOutputs r)
379
+ , T. intercalate " , " (map formatCE $ view recipeRequirements r)
380
+ , tshow $ view recipeTime r
381
+ , tshow $ view recipeWeight r
382
+ ]
383
+ where
384
+ formatCE (c, e) = T. unwords [tshow c, linkEntity $ view entityName e]
385
+ linkEntity t =
386
+ if T. null entityAddress
387
+ then t
388
+ else addLink (entityAddress <> " #" <> T. replace " " " -" t) t
389
+
390
+ recipeTable :: PageAddress -> [Recipe Entity ] -> Text
391
+ recipeTable a rs = T. unlines $ header <> map (listToRow mw) recipeRows
392
+ where
393
+ mw = maxWidths (recipeHeader : recipeRows)
394
+ recipeRows = map (recipeRow a) rs
395
+ header = [listToRow mw recipeHeader, separatingLine mw]
396
+
397
+ recipePage :: PageAddress -> [Recipe Entity ] -> Text
398
+ recipePage = recipeTable
399
+
363
400
-- ----------------------------------------------------------------------------
364
401
-- GENERATE GRAPHVIZ: ENTITY DEPENDENCIES BY RECIPES
365
402
-- ----------------------------------------------------------------------------
0 commit comments