-
class SpectrumAttachable :
Object
,IQueryable
¶ -
__new(self:
Object
, ...:any
)¶ The default constructor for the class. Subclasses should override this.
-
inBounds: fun(self:
any
, x:integer
, y:integer
)¶
-
debug:
boolean
¶
-
__new(self:
-
class Display :
Object
¶ -
width:
integer
¶ The width of the display in cells.
-
height:
integer
¶ The height of the display in cells.
-
cells:
table
<number
,table
<number
, {char: (string
|integer
)?, fg:Color4
, bg:Color4
, depth:number
}>>¶
-
pushed:
boolean
¶ Whether to draw with the camera offset applied or not.
-
__new(self:
Display
, width:integer
, height:integer
, spriteAtlas:SpriteAtlas
, cellSize:Vector2
)¶ Initializes the terminal display.
- Parameters:
width (
integer
) – The width of the display in cells.height (
integer
) – The height of the display in cells.spriteAtlas (
SpriteAtlas
) – The sprite atlas used for drawing characters.cellSize (
Vector2
) – The size of each cell in pixels.
-
spriteAtlas:
SpriteAtlas
¶ A simple sprite atlas. Used by spectrum.Display to render cells and actors.
-
draw(self:
Display
)¶ Draws the entire display to the screen. This function iterates through all cells and draws their background colors and then their characters.
-
putLevel(self:
Display
, attachable:SpectrumAttachable
)¶ Puts the drawable components of a level (cells and actors) onto the display. This function uses the current camera position to determine what part of the level to draw.
- Parameters:
attachable (
SpectrumAttachable
) – An object representing the level, capable of providing cell and actor information.
-
putSenses(self:
Display
, primary:Senses
[], secondary:Senses
[])¶ Puts vision and explored areas from primary and secondary senses onto the display. Cells and actors from primary senses are drawn fully opaque, while those from secondary senses are drawn with reduced opacity. Explored areas are drawn with even lower opacity.
-
putDrawable(self:
Display
, x:integer
, y:integer
, drawable:Drawable
, color?:Color4
, layer?:number
)¶ Puts a Drawable object onto the display grid at specified coordinates, considering its depth. If a color or layer is provided, they will override the drawable’s default values.
-
put(self:
Display
, x:integer
, y:integer
, char:string
|integer
, fg?:Color4
, bg?:Color4
, layer?:number
)¶ Puts a character, foreground color, and background color at a specific grid position. This function respects drawing layers, so higher layer values will overwrite lower ones.
- Parameters:
-
putBG(self:
Display
, x:integer
, y:integer
, bg:Color4
, layer?:number
)¶ Sets only the background color of a cell at a specific grid position, with depth checking.
- Parameters:
x (
integer
) – The X grid coordinate.y (
integer
) – The Y grid coordinate.bg (
Color4
) – The background color to set.layer? (
number
) – The draw layer (optional, higher numbers draw on top). Defaults to -math.huge.
-
putString(self:
Display
, x:integer
, y:integer
, str:string
, fg?:Color4
, bg?:Color4
, layer?:number
, align?: "center" | "left" | "right", width?:integer
)¶ Draws a string of characters at a grid position, with optional alignment.
- Parameters:
x (
integer
) – The starting X grid coordinate.y (
integer
) – The Y grid coordinate.str (
string
) – The string to draw.fg? (
Color4
) – The foreground color (defaults to white).bg? (
Color4
) – The background color (defaults to transparent).layer? (
number
) – The draw layer (optional).align? ("center" | "left" | "right") – The alignment of the string within the specified width.
width? (
integer
) – The width within which to align the string.
-
getQuad(self:
Display
, index:string
|integer
) optquad?:love.graphics.Quad
¶ Retrieves the appropriate sprite atlas quad based on an index (number) or name (string).
- Parameters:
index (
string
|integer
) – The index (number) or name (string) of the quad to retrieve.- Returns:
optquad? (
love.graphics.Quad
) – The quad object, or nil if not found.
-
clear(self:
Display
, bg?:Color4
)¶ Clears the entire display grid, resetting all cell characters to nil, setting backgrounds to a specified color (or transparent), and resetting depth.
- Parameters:
bg? (
Color4
) – Optional background color to clear to (defaults to transparent).
-
fitWindowToTerminal(self:
Display
)¶ Adjusts the Love2D window size to perfectly fit the terminal display’s dimensions, considering cell size.
-
getCenterOffset(self:
Display
, x:integer
, y:integer
) offsetx:integer
, offsety:integer
¶ Calculates the top-left offset needed to center a given position on the display.
- Parameters:
x (
integer
) – The X coordinate to center.y (
integer
) – The Y coordinate to center.
- Returns:
offsetx (
integer
) – The calculated X offset.offsety (
integer
) – The calculated Y offset.
-
drawDrawable(self:
Display
, x:number
, y:number
, drawable:Drawable
)¶ Draws a Drawable object directly at pixel coordinates on the screen, without considering the grid or camera, and handling multi-cell drawables.
- Parameters:
x (
number
) – The pixel X coordinate of the top-left corner.y (
number
) – The pixel Y coordinate of the top-left corner.drawable (
Drawable
) – The drawable object to render.
-
getCellUnderMouse(self:
Display
, mx?:number
, my?:number
) x?:integer
, y?:integer
¶ Returns the grid cell under the current mouse position, adjusted by optional grid offsets.
- Parameters:
mx? (
number
) – A custom X coordinate to use for the mouse position.my? (
number
) – A custom Y coordinate to use for the mouse position.
- Returns:
x? (
integer
) – The X grid coordinate, or nil if out of bounds.y? (
integer
) – The X grid coordinate, or nil if out of bounds.
-
setCamera(self:
Display
, x:integer
, y:integer
)¶ Sets the camera’s position. This position acts as an offset for drawing elements from the level or other world-space coordinates onto the display.
- Parameters:
x (
integer
) – The X coordinate for the camera.y (
integer
) – The Y coordinate for the camera.
-
moveCamera(self:
Display
, dx:integer
, dy:integer
)¶ Moves the camera by a specified delta.
- Parameters:
dx (
integer
) – The change in the camera’s X position.dy (
integer
) – The change in the camera’s Y position.
-
putRect(self:
Display
, x:integer
, y:integer
, w:integer
, h:integer
, char:string
|integer
, fg?:Color4
, bg?:Color4
, layer?:number
)¶ Draws a hollow rectangle on the display grid using specified characters and colors.
- Parameters:
x (
integer
) – The starting X grid coordinate of the rectangle.y (
integer
) – The starting Y grid coordinate of the rectangle.w (
integer
) – The width of the rectangle.h (
integer
) – The height of the rectangle.char (
string
|integer
) – The character or index to draw the rectangle with.fg? (
Color4
) – The foreground color.bg? (
Color4
) – The background color.layer? (
number
) – The draw layer.
-
putFilledRect(self:
Display
, x:integer
, y:integer
, w:integer
, h:integer
, char:string
|integer
, fg?:Color4
, bg?:Color4
, layer?:number
)¶ Draws a filled rectangle on the display grid using specified characters and colors.
- Parameters:
x (
integer
) – The starting X grid coordinate of the rectangle.y (
integer
) – The starting Y grid coordinate of the rectangle.w (
integer
) – The width of the rectangle.h (
integer
) – The height of the rectangle.char (
string
|integer
) – The character or index to fill the rectangle with.fg? (
Color4
) – The foreground color.bg? (
Color4
) – The background color.layer? (
number
) – The draw layer.
-
putLine(self:
Display
, x0:integer
, y0:integer
, x1:integer
, y1:integer
, char:string
|integer
, fg?:Color4
, bg?:Color4
, layer?:number
)¶ Draws a line between two grid points using Bresenham’s line algorithm.
- Parameters:
x0 (
integer
) – The starting X grid coordinate.y0 (
integer
) – The starting Y grid coordinate.x1 (
integer
) – The ending X grid coordinate.y1 (
integer
) – The ending Y grid coordinate.char (
string
|integer
) – The character or index to draw the line with.fg? (
Color4
) – The foreground color.bg? (
Color4
) – The background color.layer? (
number
) – The draw layer.
-
width: