Class AbstractScript<T>
- Type Parameters:
T- The required host type.
- All Implemented Interfaces:
ScriptInstance
- Direct Known Subclasses:
EntityScript, EnvironmentScript, GameScript
Base implementation that provides typed access to a script host, context, and global state.
Override the protected lifecycle and input callbacks needed by the script. Resources registered
through context() are automatically released after detached() completes.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ScriptGlobalsGame-wide values shared between scripts. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidattach(ScriptContext<?> context) Attaches this instance to a host context.protected voidattached()Called after the context is installed and the script becomes active.protected final ICameracamera()Returns the active camera from the game world.protected final ScriptContext<T> context()Returns the current attachment context.final voiddetach()Releases resources acquired by this attachment.protected voiddetached()Called before context-owned resources are released.protected final EnvironmentReturns the host's current environment, ornullfor game scripts without one.protected final ScriptGlobalsglobals()Returns game-wide values shared between scripts.protected final Thost()Returns the current script host.protected final ScriptInputinput()Returns the managed input helper for key/mouse bindings and state queries.protected voidonKeyPressed(KeyEvent event) Called when a key is pressed.protected voidonKeyReleased(KeyEvent event) Called when a key is released.protected voidonKeyTyped(KeyEvent event) Called when a key is typed.protected voidonMouseClicked(MouseEvent event) Called when a mouse button is clicked (pressed and released).protected voidonMouseMoved(MouseEvent event) Called when the mouse is moved.protected voidonMousePressed(MouseEvent event) Called when a mouse button is pressed.protected voidonMouseReleased(MouseEvent event) Called when a mouse button is released.protected voidonMouseWheel(MouseWheelEvent event) Called when the mouse wheel is rotated.protected voidCalled during the render pass for custom graphics rendering.voidrender(Graphics2D g) Renders script-owned content.protected final <E extends IEntity>
Espawn(E entity, double x, double y) Spawns the given entity at the specified coordinates.protected final <E extends IEntity>
ESpawns the given entity at the specified location.protected final <E extends IEntity>
ESpawns an entity of the given type at the specified coordinates.protected final <E extends IEntity>
ESpawns an entity of the given type at the specified location.protected final CreaturespawnCreature(String spritePrefix, double x, double y) Spawns a creature with the given sprite prefix at the specified coordinates.protected final CreaturespawnCreature(String spritePrefix, Point2D location) Spawns a creature with the given sprite prefix at the specified location.protected final ScriptedSpawnerspawner()Returns a fluent spawner for creating entities in the current environment.protected final PropSpawns a prop with the given spritesheet at the specified coordinates.protected final PropSpawns a prop with the given spritesheet at the specified location.protected final ScriptUiOverlayui()Returns the scripted UI overlay service owned by this context.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ScriptInstance
update
-
Field Details
-
globals
Game-wide values shared between scripts.
-
-
Constructor Details
-
AbstractScript
public AbstractScript()
-
-
Method Details
-
attach
Description copied from interface:ScriptInstanceAttaches this instance to a host context.- Specified by:
attachin interfaceScriptInstance- Parameters:
context- The context for this attachment.- Throws:
Exception- if initialization fails.
-
detach
Description copied from interface:ScriptInstanceReleases resources acquired by this attachment.- Specified by:
detachin interfaceScriptInstance- Throws:
Exception- if cleanup fails.
-
render
Description copied from interface:ScriptInstanceRenders script-owned content.- Specified by:
renderin interfaceScriptInstance- Parameters:
g- The current graphics context.- Throws:
Exception- if script rendering fails.
-
onRender
Called during the render pass for custom graphics rendering.- Parameters:
g- The current graphics context.- Throws:
Exception- if rendering fails.
-
onKeyPressed
-
onKeyReleased
-
onKeyTyped
-
onMouseClicked
Called when a mouse button is clicked (pressed and released).- Parameters:
event- The mouse event.- Throws:
Exception- if handling fails.
-
onMousePressed
Called when a mouse button is pressed.- Parameters:
event- The mouse event.- Throws:
Exception- if handling fails.
-
onMouseReleased
Called when a mouse button is released.- Parameters:
event- The mouse event.- Throws:
Exception- if handling fails.
-
onMouseMoved
Called when the mouse is moved.- Parameters:
event- The mouse event.- Throws:
Exception- if handling fails.
-
onMouseWheel
Called when the mouse wheel is rotated.- Parameters:
event- The wheel event.- Throws:
Exception- if handling fails.
-
context
Returns the current attachment context.- Returns:
- The current context.
- Throws:
IllegalStateException- if the script is not attached.
-
host
-
environment
Returns the host's current environment, ornullfor game scripts without one.- Returns:
- The current environment, or
nullwhen unavailable.
-
globals
Returns game-wide values shared between scripts.- Returns:
- The shared global registry.
-
input
Returns the managed input helper for key/mouse bindings and state queries.- Returns:
- The input helper owned by this attachment.
-
ui
Returns the scripted UI overlay service owned by this context.- Returns:
- The overlay owned by this attachment.
-
camera
Returns the active camera from the game world.- Returns:
- The active camera, or
nullwhen unavailable.
-
spawner
Returns a fluent spawner for creating entities in the current environment.- Returns:
- A spawner bound to the current environment.
-
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 entity type.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 entity type.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.x- The map x-coordinate.y- The map y-coordinate.- Returns:
- The supplied entity.
-
spawn
-
attached
-
detached
-