Class: Pod

PodJS. Pod

Abstract Base class for a convenience library containing a set of blocks and resources, providing new capabilities to an application.

Makes it convenient to import a set of blocks together and associate them with resources, and provides useful utility methods.

To create a new Pod, create a new JavaScript file that contains a concrete class that extends this class and registers the class via PodJS.REGISTER_POD_CLASS. Applications will need to include your JavaScript file.

new Pod(initParams)

Constructs a new Pod with the given initialization parameters.
Parameters:
Name Type Description
initParams PodJS.PodInitParams Initialization parameters provided by the environment.
Author:
  • markroth8
Source:

Classes

Block
BlockContext
Resource
ResourceContext

Methods

deleteResourceByName(resourceName)

Deletes the resource with the given name and deregisters it from the pod.
Parameters:
Name Type Description
resourceName string The name of the resource to delete
Source:
Throws:
If a resource with the given name could not be found
Type
Error

getAllResources() → {object}

Returns an object containing a list of all registered resources, keyed by type.

This method is the most efficient way to enumerate all resources.

Source:
Returns:
Map of resource type to all resources registered to this pod of that type.
Type
object

<abstract> getBlockTypes() → {PodJS.BlockInfo[]}

Returns a list of block types that this Pod provides.

Note that block type names must be globally unique across all pods. Pod authors should use the website http://podjs.com/ to register block type names so there are no conflicts.

Source:
Returns:
An array of supported block types.
Type
PodJS.BlockInfo[]

getResourceByName(resourceName) → {PodJS.Pod#Resource}

Returns the resource with the given name or null if no such resource was found.
Parameters:
Name Type Description
resourceName string The name of the resource being queried.
Source:
Returns:
The resource with the given name or null if no such resource was found.
Type
PodJS.Pod#Resource

getResourcesByType(resourceType) → {object}

Returns a list of resources of the given type that have been created.
Parameters:
Name Type Description
resourceType string The type of resource being queried.
Source:
Returns:
An object mapping resource name to resource instance.
Type
object

<abstract> getResourceTypeNames() → {string[]}

Returns a list of names of resource types supported by this pod.

This is a convenience method that effectively calls PodJS.Pod#getResourceTypes and then returns an array of all resourceType property values of each info object.

Source:
Returns:
An array of supported resource type names
Type
string[]

<abstract> getResourceTypes() → {PodJS.ResourceInfo[]}

Returns a list of information about resource types that this Pod provides.

Note that resource type names must be globally unique across all pods. Pod authors should use the website http://podjs.com/ to register resource type names so there are no conflicts.

Source:
Returns:
An array of supported resource types.
Type
PodJS.ResourceInfo[]

<abstract> newBlock(blockType, resource, script) → {PodJS.Pod#Block}

Called when a PodJS.ScriptBuilder wishes to create a new instance of a block.

Subclasses should call PodJS.Pod#newBlockClass to return the constructor for the super-object of the block. The super-object will be bound to the Pod base class. This pattern is mostly done to enforce the contract that no blocks can be created other than for the types specified in getBlockTypes(), and for any future bookkeeping needs.

Parameters:
Name Type Description
blockType string The type of block to be created (e.g. "gotoXY"). Must be one of the block types returned by PodJS.Pod#getBlockTypes.
resource PodJS.Block#Resource The resource this block is to be bound to.
script PodJS.Script The script this block is to be bound to.
Source:
Throws:
  • If the block type provided was not one of the valid block types returned by PodJS.Pod#getBlockTypes. This check is performed by PodJS.Pod#newBlockClass.
    Type
    Error
  • If the block to be returned would not be compatible with the resource provided. This check must be performed by the subclass.
    Type
    Error
Returns:
The instance of the block.
Type
PodJS.Pod#Block

newBlockClass(blockType, resource, blockScript) → {function}

Called by the concrete Pod class when it wishes to create a new Block, in order to provide the constructor of the super-class of the block object.

The constructor will be bound to the Pod base class so that it can update the resource registry during the lifecycle of the block.

Parameters:
Name Type Description
blockType string The type of block to be created (e.g. "gotoXY"). Must be one of the block types returned by PodJS.Pod#getBlockTypes.
resource PodJS.Block#Resource The resource this block is to be bound to.
blockScript PodJS.Script The script this block is to be bound to.
Source:
Throws:
If the block type provided was not one of the valid block types returned by PodJS.Pod#getBlockTypes.
Type
Error
Returns:
The constructor of the Block class that the subclass should create a new instance of.
Type
function

<abstract> newResource(resourceType, resourceName, options) → {PodJS.Pod#Resource}

Called when the environment or an application wishes to create a new resource of the given type.

Most Pods also provide convenience methods (e.g. newSprite(...) instead of newResource("sprite", ...) but this method is necessary for reflection-style access.

Subclasses should call PodJS.Pod#newResourceClass to return the constructor for the super-class of the resource. The constructor will be bound to the Pod base class so that it can update the resource registry during the lifecycle of the resource.

Parameters:
Name Type Argument Description
resourceType string The type of resource to be created (e.g. "sprite"). Must be one of the resource types returned by getResourceTypes.
resourceName string The name of the resource to create. This name must be unique for the type of resource so that the resource can be later retrieved and, if necessary, deleted.
options object <optional>
Set of parameters to be used when creating the resource.
Source:
Throws:
Returns:
Returns the instance of the resource.
Type
PodJS.Pod#Resource

newResourceClass(resourceType, resourceName, options) → {function}

Called by the concrete Pod class when it wishes to create a new Resource, in order to provide the constructor of the super-class of the object.

The constructor will be bound to the Pod base class so that it can update the resource registry during the lifecycle of the resource.

Parameters:
Name Type Argument Description
resourceType string The type of resource to be created (e.g. "sprite"). Must be one of the resource types returned by getResourceTypes.
resourceName string The name of the resource to create. This name must be unique for the type of resource so that the resource can be later retrieved and, if necessary, deleted.
options object <optional>
Set of parameters to be used when creating the resource.
Source:
Throws:
  • If the resource type provided was not valid.
    Type
    Error
  • If a resource of this type already exists with the given name.
    Type
    Error
Returns:
the constructor of the Resource class that the subclass should create a new instance of.
Type
function

newScriptBuilder(blockScript) → {PodJS.ScriptBuilder}

Create a new ScriptBuilder which will build a script attached to the provided resource.

The ScriptBuilder will be bound to this environment and so the available blocks will come from all pods registered in this environment.

Parameters:
Name Type Description
blockScript PodJS.Script The script to add blocks to (should already be created and bound to its environment and resource).
Source:
Returns:
The ScriptBuilder that will build the script.
Type
PodJS.ScriptBuilder

tick()

Gets called periodically by the environment when the next action is to take place.

Pods are not responsible for calling tick() on their own resources or blocks. That is taken care of by the environment.

The super-class version of tick() does nothing. Subclasses can optionally override to perform additional actions on each environment tick.

Source:

tick()

Gets called periodically by the environment when the next action is to take place. This is part of the standard PodJS interface.
Source: