Class ScriptContext<T>
- Type Parameters:
T- The type of object hosting the script.
- All Implemented Interfaces:
AutoCloseable
Runtime services and binding values supplied to a script instance.
A context owns the input listeners, scheduled actions, UI elements, and other subscriptions
registered through it. close() releases those resources when the script detaches or reloads.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionScriptContext(ScriptDefinition definition, ScriptBinding binding, T host) Creates a context for one attached script instance. -
Method Summary
Modifier and TypeMethodDescriptionbinding()Returns the binding applied to this instance.camera()Returns the active camera from the game world.booleanChecks if an ability on a specific executor creature can currently be cast.booleanChecks if an ability on the current host creature can currently be cast.Casts an ability on a specific executor creature by name.Casts an ability on the current host creature by name.voidclose()createAbility(Creature executor, String name) Begins building a scripted ability for a specific executor creature.createAbility(String name) Begins building a scripted ability executed by the current host creature.Returns the definition used to create the script.<E> EntityQuery<E> Starts a fluent query against the current environment.Returns the environment associated with this host.globals()Returns the game-wide script globals.host()Returns the object hosting this script.input()Returns the managed input helper owned by this context.booleanisOnCooldown(Creature executor, String name) Checks if an ability on a specific executor creature is currently on cooldown.booleanisOnCooldown(String name) Checks if an ability on the current host creature is currently on cooldown.<L> LRegisters a listener and automatically removes it when the script detaches or reloads.logger()Returns a logger named for the script definition.<R> ROwns an arbitrary resource and invokes its release action when the script detaches or reloads.<S extends Subscription>
Smanage(S subscription) Adds a registration that will be released when the script is detached or reloaded.Looks up a binding parameter.Looks up a binding parameter with a fallback.Returns the parameters configured by the binding.Schedules a cancellable action on the game loop.sequence()Creates an ordered, cancellable sequence of actions and delays owned by this context.<E extends IEntity>
Espawn(E entity, double x, double y) Spawns the given entity at the specified coordinates.<E extends IEntity>
ESpawns the given entity at the specified location.<E extends IEntity>
ESpawns an entity of the given type at the specified coordinates.<E extends IEntity>
ESpawns an entity of the given type at the specified location.spawnCreature(String spritePrefix, double x, double y) Spawns a creature with the given sprite prefix at the specified coordinates.spawnCreature(String spritePrefix, Point2D location) Spawns a creature with the given sprite prefix at the specified location.spawner()Returns a fluent spawner for creating entities in the current environment.Begins building and spawning a scripted projectile in the current environment.Spawns a prop with the given spritesheet at the specified coordinates.Spawns a prop with the given spritesheet at the specified location.ui()Returns the scripted UI overlay service owned by this context.
-
Constructor Details
-
ScriptContext
Creates a context for one attached script instance.- Parameters:
definition- The registered script definition.binding- The binding that created the instance.host- The object hosting the script.
-
-
Method Details
-
definition
Returns the definition used to create the script.- Returns:
- The script definition.
-
binding
Returns the binding applied to this instance.- Returns:
- The script binding.
-
host
-
logger
Returns a logger named for the script definition.- Returns:
- The script logger.
-
globals
Returns the game-wide script globals.- Returns:
- The shared global registry.
-
parameters
-
parameter
-
parameter
-
environment
Returns the environment associated with this host.
Entity hosts use their current environment; environment hosts return themselves.
- Returns:
- The associated environment, or
nullif neither the host nor the game world has one.
-
entities
Starts a fluent query against the current environment.- Type Parameters:
E- The entity type.- Parameters:
type- The entity type to query.- Returns:
- A query over matching entities in the current environment.
-
createAbility
Begins building a scripted ability executed by the current host creature.- Parameters:
name- The ability name.- Returns:
- A builder for the new ability.
- Throws:
IllegalStateException- if the host is not a creature.
-
createAbility
Begins building a scripted ability for a specific executor creature.- Parameters:
executor- The creature that will execute the ability.name- The ability name.- Returns:
- A builder for the new ability.
-
cast
Casts an ability on the current host creature by name.- Parameters:
name- The registered ability name.- Returns:
- The ability execution, or
nullwhen the ability cannot be cast. - Throws:
IllegalStateException- if the host is not a creature.
-
cast
Casts an ability on a specific executor creature by name.- Parameters:
executor- The creature that will execute the ability.name- The registered ability name.- Returns:
- The ability execution, or
nullwhen the executor is absent or cannot cast it.
-
canCast
Checks if an ability on the current host creature can currently be cast.- Parameters:
name- The registered ability name.- Returns:
trueif the host is a creature and can cast the ability.
-
canCast
-
isOnCooldown
Checks if an ability on the current host creature is currently on cooldown.- Parameters:
name- The registered ability name.- Returns:
trueif the host is a creature and the ability is cooling down.
-
isOnCooldown
-
spawnProjectile
Begins building and spawning a scripted projectile in the current environment.- Returns:
- A projectile builder bound to the current environment.
-
ui
Returns the scripted UI overlay service owned by this context.- Returns:
- The lazily created overlay service.
-
camera
Returns the active camera from the game world.- Returns:
- The active camera, or
nullif none is configured.
-
input
Returns the managed input helper owned by this context.- Returns:
- The lazily created input helper.
-
spawner
Returns a fluent spawner for creating entities in the current environment.- Returns:
- A spawner bound to the current environment.
- Throws:
IllegalStateException- if no environment is active.
-
spawnCreature
-
spawnCreature
-
spawnProp
-
spawnProp
-
spawn
Spawns an entity of the given type at the specified coordinates.- Type Parameters:
E- The entity type.- Parameters:
entityType- The concrete type, which must have a no-argument constructor.x- The map x-coordinate.y- The map y-coordinate.- Returns:
- The spawned entity.
-
spawn
Spawns an entity of the given type at the specified location.- Type Parameters:
E- The entity type.- Parameters:
entityType- The concrete type, which must have a no-argument constructor.location- The location in map coordinates.- Returns:
- The spawned entity.
-
spawn
Spawns the given entity at the specified coordinates.- Type Parameters:
E- The entity type.- Parameters:
entity- The entity to add to the environment.x- The map x-coordinate.y- The map y-coordinate.- Returns:
- The supplied entity.
-
spawn
-
manage
Adds a registration that will be released when the script is detached or reloaded.- Type Parameters:
S- The subscription type.- Parameters:
subscription- The subscription to own.- Returns:
- The supplied subscription.
-
manage
Owns an arbitrary resource and invokes its release action when the script detaches or reloads.- Type Parameters:
R- The resource type.- Parameters:
resource- The resource to own.release- The action that releases it.- Returns:
- The supplied resource.
-
listen
Registers a listener and automatically removes it when the script detaches or reloads.- Type Parameters:
L- The listener type.- Parameters:
add- The operation that registers the listener.remove- The operation that unregisters it.listener- The listener instance.- Returns:
- The supplied listener.
-
schedule
Schedules a cancellable action on the game loop.- Parameters:
delay- The delay in milliseconds.action- The action to invoke.- Returns:
- A subscription that cancels the scheduled action.
-
sequence
Creates an ordered, cancellable sequence of actions and delays owned by this context.- Returns:
- A new sequence owned by this context.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-