Skip to content

Latest commit

 

History

History
69 lines (50 loc) · 2.5 KB

README.md

File metadata and controls

69 lines (50 loc) · 2.5 KB

📡 CodeCon-Gather API

An API that interacts with Gather.town API and customizes the user experience on the CodeCon Tech Event!

Test Map: https://app.gather.town/mapmaker/Ixw7EUhrLHlfQwqb/codecon-gather-api-test-1

How to Develop

# Copy .env.example to .env
cp .env.example .env

# Set the environment variables on .env
# Get GATHER_API_KEY from https://app.gather.town/apiKeys
# Get GATHER_SPACE_ID_1 from your space URL.
# Eg: 5jnhRfDYRIUyDmbF/my-space

# Install dependencies
npm install

# Run server
npm run dev

Tips

Finding the event name and payload you wish to use

Go to node_modules/@gathertown/gather-game-common/src/events.proto and check ServerClientEvent message.
You might want to add this extension for syntax highlight.
On VSCode, select the event name such as MapSetObjects, press Ctrl+D and find its payload.
You can also Ctrl+Click on the payload class names to check their content. In this case, WireObject.

Debugging user space stats

You can use the logSpaceStatsOnUserMovement function to log the space stats (steps, online time, etc) for a user on the current date and the current space they are located at.

Usage example:

import { logSpaceStatsOnUserMovement } from "../../utils/debug";
//...

export async function trackSteps(data: PlayerMovesEventData, context: ServerClientEventContext) {
  try {
    const playerId = context?.playerId!
    const friendlySpaceId = getFriendlySpaceId(context?.spaceId)

    const userManager = UserManager.getInstance()
    const user = userManager.getUserInMemory(playerId)
    if (!user) return

    logSpaceStatsOnUserMovement(user, friendlySpaceId)
    const playerNewPosition = getPosition(data)
    //...
  } catch (error) {
    console.log(error)
  }
}

References