Bluespess

Bluespess

new Bluespess()

Source:
Example
const Bluespess = require('bluespess');

let server = new Bluespess();

Classes

Atom
Component
Panel
Sound
VisibilityGroup

Members

(static, constant) EAST

Source:
Default Value:
  • 4

(static, constant) NORTH

Source:
Default Value:
  • 1

(static, constant) SOUTH

Source:
Default Value:
  • 2

(static, constant) WEST

Source:
Default Value:
  • 8

atoms_for_components :Object.<string, Set.<Bluespess.Atom>>

Source:
An object containing lists of atoms for each component type
Type:

clients :Object.<string, Client>

Source:
An object containing all the clients by their key
Type:

clients_by_name :Object.<string, Client>

Source:
An object containing all the clients by their display name
Type:

dc_mobs :Object.<string, Bluespess.Atom.<Mob>>

Source:
An object containing mobs with keys but no client
Type:

is_server_started :boolean

Source:
True if the server has been started.
Type:
  • boolean

Methods

(static) audible_message(message) → {Bluespess.ChatMessage}

Source:
Has template literal form, see Bluespess.format_html Builds an audible chat message object
Parameters:
Name Type Description
message string
Returns:
(this object)
Type
Bluespess.ChatMessage

(static) chain_func(func1, func2) → {function}

Source:
Used for overriding functions. Similar to underscore's wrap function.
Example
function foo(a) {
	return a;
}
console.log(foo("bar")); // logs "bar"
foo = chain_func(foo, function(prev) {
	return prev() + "baz";
});
let splice = foo.splice;
console.log(foo("bar")); // logs "barbaz"
splice();
console.log(foo("bar")); // logs "bar"
Parameters:
Name Type Description
func1 function The original Function
func2 function The function overriding this one. The first argument should be prev
Returns:
Type
function

(static) escape_html(str) → {string}

Source:
Escapes the characters &, <, >, ", and ' using their HTML encodings.
Parameters:
Name Type Description
str string
Returns:
Type
string

(static) format_html()

Source:
A tagged template literal function. Anything in the ${} is escaped.
Example
// obj gets html-escaped.
let obj = "<b>hah</b>";
let formatted = format_html`<span class='warning'>The ${str} explodes!</span>`;
console.log(formatted);
// <span class='warning'>The &lt;b&gt;hah&lt;/b&gt; explodes!</span>

(static) has_component(atom, name) → {boolean}

Source:
Checks if a given object is an atom and has the given component
Parameters:
Name Type Description
atom Bluespess.Atom The object to check
name string The name of the component
Returns:
Type
boolean

(static) is_atom(atom) → {boolean}

Source:
Checks if a given object is an atom
Parameters:
Name Type Description
atom Bluespess.Atom The object to check
Returns:
Type
boolean

(async, static) sleep(time)

Source:
Returns a promise that resolves in the given amount of time.
Parameters:
Name Type Description
time number The amount of time before resolving the promise, in milliseconds.

(async, static) stoplag()

Source:
Returns a promise that resolves on setImmediate(). Useful for doing expensive things without blocking the node.js event loop.

(static) to_chat(target, message)

Source:
See:
  • Bluespess#format_html
Sends the given chat message to the given clients. There's a tagged template literal form of this function that uses format_html that is demonstrated in the example
Example
to_chat(user, "<span class='warning'>The action failed</span>");

// If you use this in tagged template literal form:
to_chat`<span class='warning'>The ${this.a} explodes!</span>`(user);
// It's the equivalent to:
to_chat(user, format_html`<span class='warning'>The ${this.a} explodes!</span>`);

// Be careful, if you do this, the HTML will not be escaped! Use one of the above 2 formats to ensure that your HTML is escaped to prevent XSS exploits.
to_chat(user, `<span class='warning'>The ${this.a} explodes!</span>`);
Parameters:
Name Type Description
target Bluespess.Atom | Client | Array.<(Bluespess.Atom|Client)>
message string

(static) turn_dir(dir, angle) → {number}

Source:
Rotates the given direction by the given angle clockwise
Parameters:
Name Type Description
dir number The direction to turn
angle number The angle to turn it by
Returns:
The resulting direction
Type
number

(static) visible_message(message) → {Bluespess.ChatMessage}

Source:
Has template literal form, see Bluespess.format_html Builds a visible chat message object
Parameters:
Name Type Description
message string
Returns:
(this object)
Type
Bluespess.ChatMessage

(static) weak_deep_assign(a, b)

Source:
Sort of like Object.assign(), but it assigns *behind* the other object, and it's also recursive.
Parameters:
Name Type Description
a Object
b Object

compute_inrange_tiles(origin, dist) → {Set.<Location>}

Source:
Parameters:
Name Type Description
origin Bluespess.Atom | Location The origin
dist number The radius to go out
Returns:
A set of tiles a given distance away from the origin
Type
Set.<Location>

compute_visible_tiles(origin, dist) → {Set.<Location>}

Source:
Parameters:
Name Type Description
origin Bluespess.Atom | Location The origin
dist number The radius to go out
Returns:
A set of tiles a given distance away from the origin that are visible to the origin (not blocked by opaque atoms)
Type
Set.<Location>

get_template_variant(template, variant_leaf_path)

Source:
Extends the template with the given variant.
Parameters:
Name Type Description
template template
variant_leaf_path Array

(abstract) handle_login(ws)

Source:
Handles login.
Parameters:
Name Type Description
ws WebSocket The websocket

importModule(mod)

Source:
Imports a module into the server code.
Parameters:
Name Type Description
mod Object
Properties
Name Type Attributes Description
components Object <optional>
An object containing the component constructors you want to import
templates Object <optional>
An object containing the templates you want to import
now function <optional>
A callback which is called immediately with an instance of this server object
server_start function <optional>
A callback which is called when the server starts (or now if it already has) with an instance of this server object

(async) instance_map(obj, x, y, z, percentage_callbackopt)

Source:
Instances a map
Parameters:
Name Type Attributes Default Description
obj Object Parsed JSON object representing the map
x number 0
y number 0
z number 0
percentage_callback function <optional>
A callback that is called periodically with a number 0 to 1 denoting how far along the instancing process is done.

instance_map_sync(obj, x, y, z)

Source:
Instances a map, like instance_map, but synchronous, and no callback for percentage.
Parameters:
Name Type Default Description
obj Object Parsed JSON object representing the map
x number 0
y number 0
z number 0

location(x, y, z) → {Location}

Source:
Used for getting a specific location.
Parameters:
Name Type Description
x number
y number
z number
Returns:
The location object.
Type
Location

login(socket, key, name) → {Client}

Source:
Creates a client with the given parameters
Parameters:
Name Type Description
socket WebSocket The websocket
key String | number The unique key string identifying the client.
name String The name to display for the client
Returns:
Type
Client

now() → {number}

Source:
Returns a precise timestamp, in milliseconds, since the server was constructed. This timestamp is sent to clients periodically.
Returns:
The timestamp
Type
number

process_template(template)

Source:
Processes a template, sorting out all the dependencies and applying default values. Usually called internally.
Parameters:
Name Type Description
template template

startServer(opts)

Source:
Starts the server.
Parameters:
Name Type Description
opts Object
Properties
Name Type Description
websocket Object The parameters passed to the websocket server