Skip to content

Commit

Permalink
Let scripts define the delegate themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Feb 3, 2024
1 parent 96be22f commit 56524f5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@
package nz.net.ultraq.redhorizon.cli.mediaplayer

import nz.net.ultraq.redhorizon.engine.scenegraph.Scene
import nz.net.ultraq.redhorizon.engine.scenegraph.nodes.SpriteScript
import nz.net.ultraq.redhorizon.engine.scenegraph.nodes.Sprite
import nz.net.ultraq.redhorizon.engine.scripting.Script

/**
* A script to make a sprite node behave as a full-screen image.
*
* @author Emanuel Rabina
*/
class ImageScript extends SpriteScript {
class ImageScript extends Script<Sprite> {

@Delegate
private final Sprite sprite = scriptable

@Override
void onSceneAdded(Scene scene) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ package nz.net.ultraq.redhorizon.cli.mediaplayer

import nz.net.ultraq.redhorizon.engine.input.KeyControl
import nz.net.ultraq.redhorizon.engine.scenegraph.Scene
import nz.net.ultraq.redhorizon.engine.scenegraph.nodes.SoundEffectScript
import nz.net.ultraq.redhorizon.engine.scenegraph.nodes.SoundEffect
import nz.net.ultraq.redhorizon.engine.scripting.Script

import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE

Expand All @@ -27,7 +28,10 @@ import static org.lwjgl.glfw.GLFW.GLFW_KEY_SPACE
*
* @author Emanuel Rabina
*/
class SoundPlaybackScript extends SoundEffectScript {
class SoundPlaybackScript extends Script<SoundEffect> {

@Delegate
private final SoundEffect soundEffect = scriptable

@Override
void onSceneAdded(Scene scene) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package nz.net.ultraq.redhorizon.engine.scripting

import nz.net.ultraq.redhorizon.engine.scenegraph.SceneEvents

import groovy.transform.PackageScope

/**
* A script is a piece of code attached to an entity to customize its behaviour.
*
Expand All @@ -31,6 +33,7 @@ abstract class Script<T extends Scriptable> implements SceneEvents {
* Attach the script target to this script, allowing it to act as a delegate
* within other script methods.
*/
@PackageScope
Script<T> attachScriptable(T scriptable) {

this.scriptable = scriptable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package nz.net.ultraq.redhorizon.engine.scripting

/**
* Any class that can have a script attached to customize its behaviour.
* A class that can have a script attached to customize its behaviour.
*
* @author Emanuel Rabina
*/
Expand Down

0 comments on commit 56524f5

Please sign in to comment.