ohhecs-0.0.2: An Entity-Component-Systems engine core.
Copyright(C) 2020 Sophie Taylor
LicenseAGPL-3.0-or-later
MaintainerSophie Taylor <sophie@spacekitteh.moe>
Stabilityexperimental
PortabilityGHC
Safe HaskellTrustworthy
LanguageGHC2021

Games.ECS.World

Description

Infrastructure for defining ECS worlds.

Synopsis

Documentation

data Access Source #

HKD parameterisation for an ECS.

Constructors

Storing

We are dealing with the entire collection of entities in a world, represented structure-of-array style.

Individual

We are dealing with a specific individual with specific component values.

data Props Source #

Different arities.

Constructors

Normal

An individual may or may not have this component.

Required

Every individual must have this component.

Unique

Either a single individual, or none, may have this component.

class World (w :: Access -> Type) where Source #

An entity component system, parameterised by its access type.

Methods

newWorld :: w 'Storing Source #

Construct a new world.

createNewEntity :: MonadIO m => m (w 'Individual) Source #

Create a new entity

createNewEntityWithRef :: Entity -> w 'Individual Source #

Create a new entity with a given reference.

entities :: IndexedTraversal' Entity (w 'Storing) (w 'Individual) Source #

Traversal over all entities in the ECS.

entityReference :: IndexedGetter Entity (w 'Individual) Entity Source #

Get the entity reference of an individual

unsafeEntityReference :: Lens' (w 'Individual) Entity Source #

Get and set the entity reference of an individual

entityReferences :: IndexedFold Entity (w 'Storing) Entity Source #

Get all of the entity references stored in the world.

lookupEntity :: w 'Storing -> Entity -> Maybe (w 'Individual) Source #

Check if a given entity exists in the world, and if so, return the individual.

prototype :: HasPrototypeID p => p -> AffineTraversal' (w 'Storing) (w 'Individual) Source #

Get a prototype specification from its name.

lookupEntities :: forall f p fol. (Indexable Entity p, Applicative f, Foldable fol) => fol Entity -> p (w 'Individual) (f (w 'Individual)) -> w 'Storing -> f (w 'Storing) Source #

An IndexedTraversal' which returns the individuals associated to the entities given as input.

entitiesWith :: forall f p. (Indexable Entity p, Applicative f) => (forall r. Monoid r => Getting r (w 'Storing) IntersectionOfEntities) -> p (w 'Individual) (f (w 'Individual)) -> w 'Storing -> f (w 'Storing) Source #

An IndexedTraversal' of individuals matching some constraints. The constraints are included monoidally.

storeEntity :: w 'Individual -> w 'Storing -> w 'Storing Source #

Store an individual in a world, returning the new world.

entity :: Entity -> AffineTraversal' (w 'Storing) (w 'Individual) Source #

Affine traversal for a specified individual from the world.

type family OpticsFor (name :: Symbol) (hkd :: Access -> Type) (acc :: Access) (p :: Props) a where ... Source #

We want to make sure that the API is consistent based on the access type and availability property, so we have a type family to give us the correct optics.

type EntRefStoringType = IntSet Source #

A type which holds a collection of Entity.

type family EntRefField (acc :: Access) where ... Source #

A type function for simplifying the higher-kinded data implementation.

type AffineTraversal s t a b = Traversal s t a b Source #

An AffineTraversal is one which traverses either 0 or 1 elements.

affine :: (s -> Either t a) -> (s -> b -> t) -> Traversal s t a b Source #

Construct an AffineTraversal.

affine' :: (s -> Maybe a) -> (s -> a -> s) -> Traversal' s a Source #

Construct an AffineTraversal'.

newUniqueEntRef :: IO Entity Source #

Atomically construct a new entity reference.