Skip to content
RnbwNoise edited this page Dec 23, 2014 · 5 revisions

IsItChristmas JavaScript API

By @RnbwNoise.

Example

var x = 10;
setInterval(function() {
    var t = x / 80;
    IIC.setAngle(Math.cos(t) * (Math.PI / 4));
    IIC.makeGhost(x, 50 + 100 * (Math.sin(t) + 1));
    x += 30;
    if(x > 800)
        x = 10;
}, 300);

User-defined event listeners

[ string, int ] IIC.addEventListener(string event, function(object eventData) listener)

Adds an event handler and returns its identifier (an array).

  • string event -- event name.
  • function(...) listener -- the function to be called when the event occurs.
    • object eventData -- the data associated with the event.

boolean IIC.removeEventListener([ string, int ] listenerId)

Removes an event handler. Returns true if the listener was successfully removed.

  • [ string, int ] listenerId -- event handler identifier.

Connection

string IIC.getId()

Returns your id.

string[] IIC.getConnectedIds()

Returns the ids of all connected users.

boolean IIC.isConnected(string userId)

Returns true if a user is still connected.

  • string userId -- user's id.

[ string, int ] IIC.onConnection(function(string userId) listener)

Adds a new connection handler and returns its identifier.

  • function(...) listener -- the function to be called when a new user joins the room.
    • string userId -- new user's id.

Chat

[ string, int ] IIC.onChat(function(string userId, string name, string message) listener)

Adds a chat message handler and returns its identifier.

  • function(...) listener -- the function to be called when a new message (including your own) is posted in the chat.
    • string userId -- author's id.
    • string name -- author's name (set using rename()).
    • string message -- message text.

Countries

string | null IIC.getCountry(string | undefined userId)

Returns a user's country code (ISO 3166-1 Alpha-2) or null if that user is disconnected.

  • string | undefined userId -- user's id. If undefined, the function will return your current country code.

void IIC.setCountry(string countryCode)

Changes your country and flag.

  • string countryCode -- the code of the new country.

Flag Dimensions

int IIC.getFlagWidth(string countryCode)

Returns the width of a flag in pixels.

  • string countryCode -- the country code.

int IIC.getFlagHeight(string countryCode)

Returns the height of a flag in pixels.

  • string countryCode -- the country code.

Flag Position

{ int x, int y } | null IIC.getPosition(string | undefined userId)

Returns the position of a flag or null if it does not exist.

  • string | undefined userId -- user's id. If undefined, the function will return your current position.

void IIC.setPosition(int x, int y)

Moves your flag.

  • int x and int y -- the point where to move the flag to.

[ string, int ] IIC.onMovement(function(string userId, int newX, int newY) listener)

Sets a flag movement handler and returns its identifier.

  • function(...) listener -- a function to be called when a flag is moved.
    • string userId -- user's id.
    • int newX and int newY -- the new location of the flag.

Flag Rotation

float | null IIC.getAngle(string | undefined userId)

Returns a user's angle of flag rotation (in radians) or null if that user is disconnected.

  • string | undefined userId -- user's id. If undefined, the function will return your current angle of rotation.

void IIC.setAngle(float angle)

Sets your flag's angle of rotation.

  • float angle -- new angle of rotation in radians.

[ string, int ] IIC.onRotation(function(string userId, float newAngle) listener)

Sets a flag rotation handler and returns its identifier.

  • function(...) listener -- a function to be called when a flag is rotated.
    • string userId -- user's id.
    • int newAngle -- the new angle of flag rotation in radians.

Waves and Ghosts

void IIC.makeWave(int x, int y)

Creates a concentric "wave".

  • int x and int y -- the coordinates of a point where the wave will be created.

[ string, int ] IIC.onWave(function(string userId, int waveX, int waveY) listener)

Sets a wave handler and returns its identifier.

  • function(...) listener -- a function to be called when a wave is created.
    • string userId -- user's id.
    • int waveX and int waveY -- the location of the wave.

void IIC.makeGhost(int x, int y)

Sets a ghost handler and returns its identifier.

  • function(...) listener -- a function to be called when a ghost is created.
    • string userId -- user's id.
    • int ghostX and int ghostY -- the location of the ghost.

[ string, int ] IIC.onGhost(function(string userId, int ghostX, int ghostY) listener)

Sets a ghost handler and returns its identifier.

  • function(...) listener -- a function to be called when a ghost is created.
    • string userId -- user's id.
    • int ghostX and int ghostY -- the location of the ghost.

Debugging

The following functions draw shapes on the screen that will only be visible to you.

int IIC.debugPoint(int x, int y, string color)

Draws a point and returns its id.

  • int x and int y -- the location of the point.
  • string color -- the color of the point.

int IIC.debugLine(int x1, int y1, int x2, int y2, string color)

Draws a line and returns its id.

  • int x1 and int y1 -- the location of the first point.
  • int x2 and int y2 -- the location of the second point.
  • string color -- the color of the line.

int IIC.debugRay(int x, int y, float length, float angle, string color)

Draws a ray and returns its id.

  • int x and int y -- the position of the ray's initial point.
  • float length -- the length of the ray in pixels.
  • float angle -- the angle between the positive x-axis and the ray.
  • string color -- the color of the ray.

int IIC.debugText(int x, int y, string text, string color)

Draws a string and returns its id.

  • int x and int y -- the position of the top left corner of the textbox.
  • string text -- text to be written on the screen.
  • string color -- color of the string.

int IIC.debugFlag(int x, int y, float a, string countryCode)

Draws a ghost flag and returns its id.

  • int x and int y -- the position of the center point of the flag.
  • float a -- the angle of flag's rotation in radians.
  • string countryCode -- the flag's country code.

boolean IIC.debugErase(int elementId)

Erases a debugging mark. Returns true if the mark was successfully erased.

  • int elementId -- the mark's id.

void IIC.debugEraseAll()

Erases all debugging marks.

Clone this wiki locally