-
Notifications
You must be signed in to change notification settings - Fork 52
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
11 changed files
with
540 additions
and
105 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,105 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "https://raw.githubusercontent.com/swarm-game/swarm/main/data/schema/entity.json", | ||
"title": "Entity", | ||
"description": "Description of an entity in the Swarm game", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"properties": { | ||
"name": { | ||
"type": "string", | ||
"description": "The name of the entity. This is what will show up in the inventory and how the entity can be referred to." | ||
}, | ||
"display": { | ||
"type": "object", | ||
"$ref": "./display.json", | ||
"description": "Display information for the entity." | ||
}, | ||
"plural": { | ||
"default": "null", | ||
"type": "string", | ||
"description": "An explicit plural form of the name of the entity. If omitted, standard heuristics will be used for forming the English plural of its name." | ||
}, | ||
"description": { | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"type": "string" | ||
} | ||
], | ||
"description": "A description of the entity, as a list of paragraphs." | ||
}, | ||
"orientation": { | ||
"default": "null", | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"name": "X coordinate", | ||
"type": "number" | ||
}, | ||
{ | ||
"name": "Y coordinate", | ||
"type": "number" | ||
} | ||
], | ||
"description": "A 2-tuple of integers specifying an orientation vector for the entity. Currently unused." | ||
}, | ||
"growth": { | ||
"default": "null", | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"name": "minimum", | ||
"type": "number" | ||
}, | ||
{ | ||
"name": "maximum", | ||
"type": "number" | ||
} | ||
], | ||
"description": "For growable entities, a 2-tuple of integers specifying the minimum and maximum amount of time taken for one growth stage. The actual time for one growth stage will be chosen uniformly at random from this range; it takes two growth stages for an entity to be fully grown." | ||
}, | ||
"combustion": { | ||
"type": "object", | ||
"$ref": "./combustion.json", | ||
"description": "Properties of combustion." | ||
}, | ||
"yields": { | ||
"default": "null", | ||
"type": "string", | ||
"description": "The name of the entity which will be added to a robot's inventory when it executes grab or harvest on this entity. If omitted, the entity will simply yield itself." | ||
}, | ||
"properties": { | ||
"default": "[]", | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"type": "string", | ||
"examples": [ | ||
"unwalkable", | ||
"portable", | ||
"infinite", | ||
"known", | ||
"growable" | ||
] | ||
} | ||
], | ||
"description": "A list of properties of this entity. See Entity properties." | ||
}, | ||
"capabilities": { | ||
"default": "[]", | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"type": "string" | ||
} | ||
], | ||
"description": "A list of capabilities provided by entity, when it is equipped as a device. See Capabilities." | ||
} | ||
}, | ||
"required": [ | ||
"name", | ||
"display", | ||
"description" | ||
] | ||
} |
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,39 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
-- | | ||
-- SPDX-License-Identifier: BSD-3-Clause | ||
-- | ||
-- Refined JSON schema after converting | ||
-- all JSON Value types to their specific sum types | ||
module Swarm.Doc.Schema.Refined where | ||
|
||
import Data.Aeson | ||
import Control.Applicative ((<|>)) | ||
import Data.Text (Text) | ||
import Text.Pandoc.Builder | ||
import Data.Text qualified as T | ||
|
||
newtype SingleOrList a = SingleOrList { | ||
getList :: [a] | ||
} deriving (Eq, Ord, Show) | ||
|
||
instance (FromJSON a) => FromJSON (SingleOrList a) where | ||
parseJSON x = SingleOrList <$> do | ||
(pure <$> parseJSON x) <|> parseJSON x | ||
|
||
type SchemaIdReference = Text | ||
|
||
data SchemaType = | ||
Simple (SingleOrList Text) | ||
| Reference SchemaIdReference | ||
| Alternates [Value] | ||
deriving (Eq, Ord, Show) | ||
|
||
fragmentHref :: SchemaIdReference -> Text | ||
fragmentHref = T.cons '#' . T.filter (/= '.'). T.toLower | ||
|
||
listToText :: SchemaType -> Inlines | ||
listToText = \case | ||
Simple xs -> code $ T.intercalate " | " $ getList xs | ||
Reference x -> link (fragmentHref x) "Link to object properties" $ text $ "Object schema" | ||
Alternates xs -> code $ T.intercalate " | " $ map (T.pack . show) xs |
Oops, something went wrong.