This file contains the main tile engine namespace. All coordinates are assumed to be integers - behaviour is undefined if you feed in floats (or anything other) as x and y (or similar) parameters.
unicodetiles.js | This file contains the main tile engine namespace. |
ut | Container namespace. |
Constants | |
Semi-internal constants for ut namespace | |
Tile | Represents a unicode character tile with various attributes. |
Functions | |
Tile | Constructs a new Tile object. |
getChar | Returns the character of this tile. |
setChar | Sets the character of this tile. |
setColor | Sets the foreground color of this tile. |
setGrey | Sets the foreground color to the given shade (0-255) of grey. |
setBackground | Sets the background color of this tile. |
resetColor | Clears the color of this tile / assigns default color. |
resetBackground | Clears the background color of this tile. |
getColorHex | Returns the hexadecimal representation of the color |
getBackgroundHex | Returns the hexadecimal representation of the background color |
getColorRGB | Returns the CSS rgb(r,g,b) representation of the color |
getBackgroundRGB | Returns the CSS rgb(r,g,b) representation of the background color |
getColorJSON | Returns the JSON representation of the color, i.e. |
getBackgroundJSON | Returns the JSON representation of the background color, i.e. |
copy | Makes this tile identical to the one supplied. |
clone | Returns a new copy of this tile. |
Viewport | The tile engine viewport / window. |
Functions | |
Viewport | Constructs a new Viewport object. |
updateStyle | If the style of the parent element is modified, this needs to be called. |
setRenderer | Switch renderer at runtime. |
getRendererString | Gets the currently used renderer. |
put | Puts a tile to the given coordinates. |
unsafePut | Puts a tile to the given coordinates. |
putString | Creates a row of tiles with the chars of the given string. |
get | Returns the tile in the given coordinates. |
clear | Clears the viewport buffer by assigning empty tiles. |
render | Renders the buffer as html to the element specified at construction. |
Engine | The tile engine itself. |
Functions | |
Engine | Constructs a new Engine object. |
setTileFunc | Sets the function to be called with coordinates to fetch each tile. |
setMaskFunc | Sets the function to be called to fetch mask information according to coordinates. |
setShaderFunc | Sets the function to be called to post-process / shade each visible tile. |
setWorldSize | Tiles outside of the range x = [0,width[; y = [0,height[ are not fetched. |
setCacheEnabled | Enables or disables the usage of tile cache. |
update | Updates the viewport according to the given player coordinates. |
Represents a unicode character tile with various attributes.
Functions | |
Tile | Constructs a new Tile object. |
getChar | Returns the character of this tile. |
setChar | Sets the character of this tile. |
setColor | Sets the foreground color of this tile. |
setGrey | Sets the foreground color to the given shade (0-255) of grey. |
setBackground | Sets the background color of this tile. |
resetColor | Clears the color of this tile / assigns default color. |
resetBackground | Clears the background color of this tile. |
getColorHex | Returns the hexadecimal representation of the color |
getBackgroundHex | Returns the hexadecimal representation of the background color |
getColorRGB | Returns the CSS rgb(r,g,b) representation of the color |
getBackgroundRGB | Returns the CSS rgb(r,g,b) representation of the background color |
getColorJSON | Returns the JSON representation of the color, i.e. |
getBackgroundJSON | Returns the JSON representation of the background color, i.e. |
copy | Makes this tile identical to the one supplied. |
clone | Returns a new copy of this tile. |
ut.Tile = function( ch, r, g, b, br, bg, bb )
Constructs a new Tile object.
ch | a character to display for this tile |
r | (optional) red foregorund color component 0-255 |
g | (optional) green foreground color component 0-255 |
b | (optional) blue foreground color component 0-255 |
br | (optional) red background color component 0-255 |
bg | (optional) green background color component 0-255 |
bb | (optional) blue background color component 0-255 |
The tile engine viewport / window. Takes care of initializing a proper renderer.
Functions | |
Viewport | Constructs a new Viewport object. |
updateStyle | If the style of the parent element is modified, this needs to be called. |
setRenderer | Switch renderer at runtime. |
getRendererString | Gets the currently used renderer. |
put | Puts a tile to the given coordinates. |
unsafePut | Puts a tile to the given coordinates. |
putString | Creates a row of tiles with the chars of the given string. |
get | Returns the tile in the given coordinates. |
clear | Clears the viewport buffer by assigning empty tiles. |
render | Renders the buffer as html to the element specified at construction. |
ut.Viewport = function( elem, w, h, renderer, squarify )
Constructs a new Viewport object. If you wish to display a player character at the center, you should use odd sizes.
elem | the DOM element which shall be transformed into the tile engine |
w | (integer) width in tiles |
h | (integer) height in tiles |
renderer | (optional) choose rendering engine, see Viewport.setRenderer, defaults to “auto”. |
squarify | (optional) set to true to force the tiles square; may break some box drawing |
this.setRenderer = function( newrenderer )
Switch renderer at runtime. All methods fallback to “dom” if unsuccesful. Possible values:
ut.Viewport.prototype.putString = function( str, x, y, r, g, b, br, bg, bb )
Creates a row of tiles with the chars of the given string. Wraps to next line if it can’t fit the chars on one line.
str | (string) the string to put |
x | (integer) x coordinate (column) |
y | (integer) y coordinate (row) |
r | (optional) red foregorund color component 0-255 |
g | (optional) green foreground color component 0-255 |
b | (optional) blue foreground color component 0-255 |
br | (optional) red background color component 0-255 |
bg | (optional) green background color component 0-255 |
bb | (optional) blue background color component 0-255 |
The tile engine itself.
Functions | |
Engine | Constructs a new Engine object. |
setTileFunc | Sets the function to be called with coordinates to fetch each tile. |
setMaskFunc | Sets the function to be called to fetch mask information according to coordinates. |
setShaderFunc | Sets the function to be called to post-process / shade each visible tile. |
setWorldSize | Tiles outside of the range x = [0,width[; y = [0,height[ are not fetched. |
setCacheEnabled | Enables or disables the usage of tile cache. |
update | Updates the viewport according to the given player coordinates. |
ut.Engine = function( vp, func, w, h )
Constructs a new Engine object. If width or height is given, it will not attempt to fetch tiles outside the boundaries. In that case 0,0 is assumed as the upper-left corner of the world, but if no width/height is given also negative coords are valid.
vp | the Viewport instance to use as the viewport |
func | the function used for fetching tiles |
w | (integer) (optional) world width in tiles |
h | (integer) (optional) world height in tiles |
ut.Engine.prototype.setTileFunc = function( func, effect, duration )
Sets the function to be called with coordinates to fetch each tile. Optionally can apply a transition effect. Effects are: “boxin”, “boxout”, “circlein”, “circleout”, “random”
func | function taking parameters (x, y) and returning an ut.Tile |
effect | (string) (optional) name of effect to use (see above for legal values) |
duration | (integer) (optional) how many milliseconds the transition effect should last |
ut.Engine.prototype.setMaskFunc = function( func )
Sets the function to be called to fetch mask information according to coordinates. If mask function returns false to some coordinates, then that tile is not rendered.
func | function taking parameters (x, y) and returning a true if the tile is visible |
ut.Engine.prototype.setShaderFunc = function( func )
Sets the function to be called to post-process / shade each visible tile. Shader function is called even if caching is enabled, see Engine.setCacheEnabled.
func | function taking parameters (tile, x, y) and returning an ut.Tile |
ut.Engine.prototype.setCacheEnabled = function( mode )
Enables or disables the usage of tile cache. This means that extra measures are taken to not call the tile function unnecessarily. This means that all animating must be done in a shader function, see Engine.setShaderFunc. Cache is off by default, but should be enabled if the tile function does more computation than a simple array look-up.
mode | true to enable, false to disable |
ut.Engine.prototype.update = function( x, y )
Updates the viewport according to the given player coordinates. The algorithm goes as follows:
x | (integer) viewport center x coordinate in the tile world |
y | (integer) viewport center y coordinate in the tile world |
Constructs a new Tile object.
ut.Tile = function( ch, r, g, b, br, bg, bb )
Returns the character of this tile.
ut.Tile.prototype.getChar = function()
Sets the character of this tile.
ut.Tile.prototype.setChar = function( ch )
Sets the foreground color of this tile.
ut.Tile.prototype.setColor = function( r, g, b )
Sets the foreground color to the given shade (0-255) of grey.
ut.Tile.prototype.setGrey = function( grey )
Sets the background color of this tile.
ut.Tile.prototype.setBackground = function( r, g, b )
Clears the color of this tile / assigns default color.
ut.Tile.prototype.resetColor = function()
Clears the background color of this tile.
ut.Tile.prototype.resetBackground = function()
Returns the hexadecimal representation of the color
ut.Tile.prototype.getColorHex = function()
Returns the hexadecimal representation of the background color
ut.Tile.prototype.getBackgroundHex = function()
Returns the CSS rgb(r,g,b) representation of the color
ut.Tile.prototype.getColorRGB = function()
Returns the CSS rgb(r,g,b) representation of the background color
ut.Tile.prototype.getBackgroundRGB = function()
Returns the JSON representation of the color, i.e.
ut.Tile.prototype.getColorJSON = function()
Returns the JSON representation of the background color, i.e.
ut.Tile.prototype.getBackgroundJSON = function()
Makes this tile identical to the one supplied.
ut.Tile.prototype.copy = function( other )
Returns a new copy of this tile.
ut.Tile.prototype.clone = function()
Constructs a new Viewport object.
ut.Viewport = function( elem, w, h, renderer, squarify )
If the style of the parent element is modified, this needs to be called.
this.updateStyle = function( updateRenderer )
Switch renderer at runtime.
this.setRenderer = function( newrenderer )
Gets the currently used renderer.
ut.Viewport.prototype.getRendererString = function()
Puts a tile to the given coordinates.
ut.Viewport.prototype.put = function( tile, x, y )
Puts a tile to the given coordinates.
ut.Viewport.prototype.unsafePut = function( tile, x, y )
Creates a row of tiles with the chars of the given string.
ut.Viewport.prototype.putString = function( str, x, y, r, g, b, br, bg, bb )
Returns the tile in the given coordinates.
ut.Viewport.prototype.get = function( x, y )
Clears the viewport buffer by assigning empty tiles.
ut.Viewport.prototype.clear = function()
Renders the buffer as html to the element specified at construction.
ut.Viewport.prototype.render = function()
Constructs a new Engine object.
ut.Engine = function( vp, func, w, h )
Sets the function to be called with coordinates to fetch each tile.
ut.Engine.prototype.setTileFunc = function( func, effect, duration )
Sets the function to be called to fetch mask information according to coordinates.
ut.Engine.prototype.setMaskFunc = function( func )
Sets the function to be called to post-process / shade each visible tile.
ut.Engine.prototype.setShaderFunc = function( func )
Tiles outside of the range x = [0,width[; y = [0,height[ are not fetched.
ut.Engine.prototype.setWorldSize = function( width, height )
Enables or disables the usage of tile cache.
ut.Engine.prototype.setCacheEnabled = function( mode )
Updates the viewport according to the given player coordinates.
ut.Engine.prototype.update = function( x, y )