Discord

Preparing your files

Please wait until the download is ready.

Luka's Scripting Utilities

Luka's Scripting Utilities

by Luka S.J.

A pack full of various scripting utilities to ease your development!

v4.1.135,194
Download144 KB

Graphics Object Extensions

LUTS reopens the core graphics classes — Color, Tone, Rect, Sprite,
Viewport and Graphics — to add helpers and to mix in the animation, float
and shader concerns. Because the concerns are already included, every object of
these types can be animated, given a shader, or queried for its on-screen
position without any extra setup.

Color

Includes LUTS::Concerns::Animatable, so colours can be tweened.

  • Color.blank a fully transparent black (all components zero)
  • Color.dark_gray a dark gray preset (64, 64, 64)
  • color.darken(amt = 0.2) returns a darkened copy of the colour
  • color.blank? true when every component (R, G, B, A) is zero
  • color.present? true when any component is non-zero
  • color.to_vec3 normalised [r, g, b] floats (0.0–1.0), e.g. for shader uniforms
  • color.to_vec4 normalised [r, g, b, a] floats (0.0–1.0)

Tone

Includes LUTS::Concerns::Animatable.

  • tone.lookup_table a memoised Tone::LookupTable for fast per-channel pixel transforms
  • tone.all the average of the red, green and blue channels
  • tone.all = val sets all three colour channels at once

The nested Tone::LookupTable precomputes the channel mapping and
grayscale mix for a tone (using the standard YUV luma weights) so it can
transform(r, g, b) pixels efficiently — this is what Bitmap#apply_tone
uses.

Rect

Includes LUTS::Concerns::Animatable and
LUTS::Concerns::Floatable, so a rect's components can be animated
and tracked as floats.

Sprite

Includes Animatable, Floatable and
Shaderable. Adds viewport-aware geometry helpers:

  • sprite.in_viewport? true when the sprite is visible within its viewport (64-pixel margin)
  • sprite.apparent_x / sprite.apparent_y on-screen position accounting for origin and zoom
  • sprite.apparent_width / sprite.apparent_height on-screen size accounting for zoom

(See the Sprites section for the much larger Sprites::Base subclass.)

Viewport

Includes Animatable, Floatable, Shaderable
and BlockConstructor. Adds tagging, sprite enumeration and direct
geometry accessors.

Tagging

  • Viewport.get_by_tag(tag) all viewports carrying the given tag
  • viewport.tag = value adds a tag to the viewport
  • viewport.tags the list of assigned tags
  • viewport.tag?(tag) whether the viewport carries a tag

Sprites & compositing

  • viewport.sprites all non-disposed sprites in the viewport, sorted by z
  • viewport.flatten renders all visible sprites into a single Bitmap
  • viewport.reset_color clears any applied colour (sets it to blank)

Geometry & colour

Direct passthroughs to the underlying rect / colour so you don't have to reach
through .rect: viewport.x, viewport.y,
viewport.width, viewport.height and
viewport.alpha — each with a matching = writer.

Graphics

Adds a global animation driver used by the Animatable concern:

  • Graphics.animate(duration, &block) runs the block, then plays the registered animations of every cached object across duration frames, cleaning the cache up afterwards
  • Graphics.target_object_cache the list of objects queued for animation
Graphics.animate(20) do
  @sprite.animate(x: 320, opacity: 255)
  @other.animate(zoom_x: 2.0)
end