4.3.0 • Published 6 years ago

ebabel v4.3.0

Weekly downloads
2
License
GPL-3.0
Repository
github
Last release
6 years ago

ebabel

Build Status

Library of re-useable game modules to build web browser HTML5 games.

Install

npm install --save ebabel

Generate this README.md document

npm run readme

Contribute to ebabel game modules

First of all, thank you! Please see the contributing guidelines so we can start working together effectively.

audio(input) ⇒ Object

ebabelAudio Play music or positional sound.

Kind: global function
Returns: Object - Multiple objects and properties: camera, url, listener, sound, and audioLoader.

ParamTypeDescription
inputObjectObject with properties to specify theme music parameters.
input.THREEObjectLibrary THREE.js
input.cameraObjectTHREE.js camera instance.
input.volumenumberLoudness of the music, ranges from 0 to 1.
input.urlstringPath to the theme music file.
input.distancenumberIf this is set we are using positional audio. Distance at which the sound is audible.
input.namestringUnique name to identify the theme music and listener in THREE.js camera children.
input.loopbooleanPlay theme music in a loop. False by default.
input.autostartbooleanStars playing the music as soon as it loads. False by default.

Constants

Functions

mockEG

EG Mock EG (eBabel Games) for unit testing purposes.

Kind: global constant

mockTHREE

mockTHREE Mock THREE.js for unit testing purposes.

Kind: global constant

mockTHREEx

mockTHREEx Mock THREEx.js for unit testing purposes.

Kind: global constant

hexStringToInt(input) ⇒ number

hexStringToInt Convert string hex to integer.

Kind: global function
Returns: number - Integer conversion.

ParamTypeDescription
inputstringInput hexadecimal color in string format, i.e. #ff0099

light(input) ⇒ Object

light Setup a THREE.js PointLight and add it to the scene.

Kind: global function
Returns: Object - THREE.PointLight instance.

ParamTypeDescription
inputObjectParameters and dependencies.
input.THREEObjectCore library of THREE.js
input.sceneObjectScene object where the light will be added.
input.colorhexDominant color of the light in hexadecima format. Defaults to pure white 0xffffff.
input.positionArray3D coordinates of where the light should be placed. Defaults to 1, 250, 1.
input.nameStringName of the light. Defaults to 'main-light'.

textSprite(input) ⇒ Object

ebabelTextSprite Create a 2D text sprite that can be added to any THREE.js mesh.

Kind: global function
Returns: Object - THREE.js sprite that can be added to a mesh.

ParamTypeDescription
inputObjectCollection of input properties.
input.THREEObjectLibrary THREE.js object.
input.canvasObjectDOM canvas, i.e. document.createElement('canvas')
input.textstringString of text to display above a sprite.

Functions

updatePlayerPositionRotation(camera, dataStore)

updatePlayerPositionRotation Update the position and rotation of the current player camera.

Kind: global function

ParamTypeDescription
cameraObjectTHREE.js camera.
dataStoreObjectCentral store of state data.

keyboardControls(dataStore)

keyboardControls Update the position and rotation of the current player camera based on keyboard keys pressed up or down.

Kind: global function

ParamTypeDescription
dataStoreObjectCentral store of state data.

Functions

skybox(input) ⇒ Object

Skybox Setup a skybox mesh and add it to the scene.

Kind: global function
Returns: Object - Skybox mesh.

ParamTypeDescription
inputObjectParameters and dependencies.
input.THREEObjectCore library of THREE.js
input.sceneObjectScene object where the skybox will be added.
input.directionsArrayArray of image paths for all skybox sides, by directions.
input.sizeNumberSize of the skybox. Defaults to 10000.
input.positionArrayPosition of the skybox as 3D coordinates. Defaults to 0, 0, 0.

userData(size, position)

userData Setup skybox default userData.

Kind: global function

ParamTypeDescription
sizeNumberLength of each side of the skybox cube.
positionArrayCoordinates where the skybox is to be positioned: Array of 3 numbers.

Functions

countArrayElements(input)

countArrayElements Returns an object that counts how many times each element is present in a given array.

Kind: global function

ParamTypeDescription
inputarrayArray where element occurences need to be counted.

deepCopy(input) ⇒ Object

deepCopy Make a deep copy of an object, i.e. breaks the pointers, so that updating the copy will not change the original.

Kind: global function
Returns: Object - Copy of the input onject.

ParamTypeDescription
inputObjectOriginal object that needs to be copied.

dice() ⇒ number

dice Throw 1 die.

Kind: global function
Returns: number - Return a random integer from 1 to 6.

distance(i, j) ⇒ number

distance Calculate the distance in 3D space from point "i" x, y, and z coordinates to point "j" x, y, and z coordinates.

Kind: global function
Returns: number - Distance between i and j.

ParamTypeDescription
iarrayArray start position in 3D space e.g. -10, 5.1, 3
jarrayArray end position in 3D space e.g. 0, 15.1, -7

guid() ⇒ string

guid Returns a globally unique id string following the standard guid format.

Kind: global function
Returns: string - Guid of 36 characters, including hyphens.

Ido()

Ido Returns a a string that commemorates how many days since Ido died.

Kind: global function

positive(input) ⇒ number

positive Computes the positive rounded up value of the input.

Kind: global function
Returns: number - Positive value of the input number.

ParamTypeDescription
inputnumberNumber to be converted into positive.

preventXss(input) ⇒ string

preventXss Processes an input string to prevent Cross Site Scripting injection attacks (XSS). Returns a safe version of that input.

Kind: global function
Returns: string - Cleaned string that shouldn't run any javascript code if displayed on a webpage.

ParamTypeDescription
inputstringThe user input string that needs to be sanitized, to remove the possibility of injecting script of other html tags.

randomList(input) ⇒ object

randomList Returns the subset of a list of x elements from a larger source list.

Kind: global function
Returns: object - 2 arrays in an object: list and rest.

ParamTypeDescription
inputobjectInput properties: source and max.
input.sourcearrayThe source property is the array from which a max number of elements will be randomly selected.
input.maxnumberNumber of elements that will be randomly selected from input.source

randomPosOrNeg(max) ⇒ number

randomPosOrNeg Calculates a positive or negative random number.

Kind: global function
Returns: number - Positive or negative number randomly generated.

ParamTypeDescription
maxnumberMaximum value that can be generated.

randomPosition(size) ⇒ array

randomPosition Calculate new coordinates in a 3D space randomly to generate a new position.

Kind: global function
Returns: array - Array of generated position coordinates.

ParamTypeDescription
sizearrayArray of 3 numbers for the width, height and depth, respectively.

random(max, min) ⇒ number

random Returns a random integer number from 1 to 100 or from min to max (min is non-inclusive).

Kind: global function
Returns: number - Integer between min and max (inclusively)

ParamTypeDescription
maxnumberthe maximum to be returned, should be an integer
minnumberthe minimum to be returned, should be an integer

reducedDistance(i, j, r) ⇒ array

reducedDistance Calculate new coordinates in a 3D space for point "i" in order to get closer to point "j" reducing the distance between the two points by "r" amount.

Kind: global function
Returns: array - Array of coordinates the i position should get to in order to get closer to j.

ParamTypeDescription
iarrayArray of 3 numbers for the coordinates x, y, z of the source point.
jarrayArray of 3 numbers for the coordicates x, y, z of the target point.
rnumberNumber by which the distance between i and j needs to be reduced.

trait() ⇒ number

trait Throw 3 dices.

Kind: global function
Returns: number - Return a random integer from 3 to 18.

boundingBox(THREE, mesh)

boundingBox Calculate a 3D bounding box for a THREE.js mesh.

Kind: global function

ParamTypeDescription
THREEobjectCore library of THREE.js
meshstring3D THREE.js object for a mesh that needs a bounding box calculated.
4.3.0

6 years ago

4.2.0

6 years ago

4.1.1

6 years ago

4.1.0

6 years ago

4.0.0

6 years ago

3.0.0

6 years ago

2.4.2

6 years ago

2.4.1

6 years ago

2.4.0

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.16

6 years ago

2.0.15

6 years ago

2.0.14

6 years ago

2.0.13

6 years ago

2.0.12

6 years ago

2.0.11

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago