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

Floatable & Shaderable

Floatable

LUTS::Concerns::Floatable adds sub-pixel float tracking to an object. RGSS
properties like x, y and opacity are integers, which makes slow or
fractional movement stutter. Floatable keeps a parallel set of float values
and writes the rounded result back to the object.

It is already included in Sprite, Viewport and Rect. To add it yourself,
include LUTS::Concerns::Floatable.

  • object.float returns the object's FloatValues wrapper (created on first use)

FloatValues

FloatValues tracks these properties as floats and pushes each change back to
the wrapped object when it responds to the matching setter:

x · y · ox · oy ·
width · height · opacity ·
angle

Each has a getter and a setter (e.g. float.x / float.x = 1.5).

@sprite.float.x += 0.4   # accumulates; the sprite's integer x updates when it crosses a pixel

Shaderable

LUTS::Concerns::Shaderable manages a stack of GLSL shaders on an object. It is
already included in Sprite and Viewport (both of which expose a writable
shaders array).

  • object.add_shader(key, properties = {}) adds a shader — pass a Symbol key to load a new Shader (with optional uniform properties), or pass an existing Shader instance
  • object.get_shader(key) fetches an applied shader by its key symbol or by array index
  • object.remove_shader(key) removes a shader by key symbol, index, or instance
  • object.dispose_shaders disposes every applied shader and clears the stack
@sprite.add_shader(:wave, intensity: 0.5)
@sprite.get_shader(:wave)
@sprite.remove_shader(:wave)

The Shader class

Shader.new(key, properties = {}) loads the GLSL file at
Data/Shaders/{key}.glsl and applies the given uniform properties. Uniform
values may be bitmaps, strings, or numeric vectors of 1–4 components (so a
Color#to_vec4 works directly). It raises Shader::ShaderError if the shader
file does not exist.

  • shader.key the shader's identifier symbol
  • shader.dispose / shader.disposed? standard disposal lifecycle

BlockConstructor

LUTS::Concerns::BlockConstructor lets a class accept a configuration block in
its constructor — a built-in alternative to .tap. After the normal
initialisation runs, the new instance is yielded to the block.

Viewport.new(0, 0, 640, 480) do |vp|
  vp.z = 9999
  vp.tag = :overlay
end

Viewport already includes this concern; include
LUTS::Concerns::BlockConstructor in your own class to gain the behaviour.