Player

The files that describe a Pointing player: the fixed data they supply when they join, the per-instance state the engine keeps for them while they are connected, and the two scripts the server runs: one the moment they join, one when they leave.

gamehoster-player-join-schema.json

The shape of the data a client must send to join. Pointing provides nothing in this schema, an empty list, so players can drop straight in without providing any information.

[]
pointing/gamehoster-player/gamehoster-player-join-schema.json

gamehoster-player-schema.json

The per-instance state carried for each player: a smoothed x/y cursor that is shared back to everyone, and a sent color.

[
  {
    "gamehoster-player-schema-name": "x",
    "gamehoster-player-schema-type": "number",
    "gamehoster-player-schema-sync": "shared",
    "gamehoster-player-schema-audience": "all",
    "gamehoster-player-schema-smooth": true
  },
  {
    "gamehoster-player-schema-name": "y",
    "gamehoster-player-schema-type": "number",
    "gamehoster-player-schema-sync": "shared",
    "gamehoster-player-schema-audience": "all",
    "gamehoster-player-schema-smooth": true
  },
  {
    "gamehoster-player-schema-name": "color",
    "gamehoster-player-schema-type": "string",
    "gamehoster-player-schema-sync": "sent",
    "gamehoster-player-schema-audience": "all"
  }
]
pointing/gamehoster-player/gamehoster-player-schema.json

gamehoster-player-join.js

Runs on the server as a player connects: it routes them into an instance that still has room (or a fresh one), then seeds their state with a random palette colour and a centred cursor.

// Runs on the server the moment a player connects. It first routes them into an
// instance (a canvas that still has room, or a fresh one), then sets up their
// per-instance state: a random colour from the palette and a centred cursor.

// route: join an instance that has room, else start a new one
const open = Gamehoster.Instance.List().find(id =>
  Gamehoster.Instance.Info(id).players < Gamehoster.Instance.Info(id).capacity)

Gamehoster.Instance.Join(open !== undefined ? open : Gamehoster.Instance.Create())

// set up: a random colour from a fixed palette, cursor in the centre. Now that we
// have joined, Gamehoster.Context.playerId names us and Context.instanceId our canvas.
const palette = ["#e6194b", "#3cb44b", "#4363d8", "#f58231", "#911eb4", "#42d4f4", "#f032e6", "#ffe119"]
const me = Gamehoster.Context.playerId
const here = Gamehoster.Context.instanceId

Gamehoster.Player.State.Set(me, "color", palette[Math.floor(Gamehoster.Entropy() * palette.length)])
Gamehoster.Player.State.Set(me, "x", Gamehoster.Instance.State.Get(here, "width") / 2)
Gamehoster.Player.State.Set(me, "y", Gamehoster.Instance.State.Get(here, "height") / 2)
pointing/gamehoster-player/gamehoster-player-join.js

gamehoster-player-leave.js

Runs when a player disconnects. In Pointing there is nothing to undo: the engine reclaims the cursor and the dots already dropped stay on the shared canvas.

// A player has left. The engine reclaims their cursor; the dots they dropped
// stay on the shared canvas, so there is nothing to clean up here.
pointing/gamehoster-player/gamehoster-player-leave.js