Source File
resource.go
Belonging Package
github.com/mlange-42/ark/ecs
package ecs// Resource provides access to a world resource.//// Create one with [NewResource].type Resource[ any] struct {world *Worldid ResID}// New creates a new [Resource]. It is safe to call on an uninitialized instance.// It is a helper method, intended to avoid repeated specification of the type parameter.func (Resource[]) ( *World) Resource[] {return NewResource[]()}// NewResource creates a new [Resource] mapper for a resource type.// This does not add a resource to the world, but only creates a mapper for resource access!//// See also [World.Resources].func [ any]( *World) Resource[] {return Resource[]{id: ResourceID[](),world: ,}}// Add adds a resource to the world.//// Panics if there is already a resource of the given type.func ( *Resource[]) ( *) {.world.Resources().Add(.id, )}// Remove removes a resource from the world.//// Panics if there is no resource of the given type.//// See also [ecs.Resources.Remove].func ( *Resource[]) () {.world.Resources().Remove(.id)}// Get gets the resource of the given type.//// Returns nil if there is no such resource.func ( *Resource[]) () * {:= .world.Resources().Get(.id)if == nil {return nil}return .(*)}// Has returns whether the world has the resource type.func ( *Resource[]) () bool {return .world.Resources().Has(.id)}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |