Skip to content

Commit

Permalink
bring back docusaurus (nextra is dogshit)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaxkr committed Oct 29, 2024
1 parent 45a575e commit d90da01
Show file tree
Hide file tree
Showing 57 changed files with 18,699 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Website

This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.

### Installation

```
$ yarn
```

### Local Development

```
$ yarn start
```

This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.

### Build

```
$ yarn build
```

This command generates static content into the `build` directory and can be served using any static contents hosting service.

### Deployment

Using SSH:

```
$ USE_SSH=true yarn deploy
```

Not using SSH:

```
$ GIT_USER=<Your GitHub username> yarn deploy
```

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
};
5 changes: 5 additions & 0 deletions docs/discord/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Discord Activities

Discord Activites are games that run inside Discord. You can read more about them [here](https://discord.com/developers/docs/activities/overview).

Dreamlab natively supports running your games inside Discord.
91 changes: 91 additions & 0 deletions docs/discord/publishing.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
description: Get your game running as a Discord Activity in five minutes!
---

import DetailsDiscord from '../../static/img/discordapp_details_discord.png'
import DetailsDreamlab from '../../static/img/discordapp_details_dreamlab.png'
import OAuth2 from '../../static/img/discordapp_oauth2.png'
import UrlMappings from '../../static/img/discordapp_url_mappings.png'

# Publishing Your Game as a Discord Activity

Publishing your Dreamlab game as an Application on Discord is a fairly straightforward process.

## Step 1: Create a Application on Discord Developers

To create an application, go to https://discord.com/developers/applications and click `New Application` in the top-right.
You will want to give it a cool name that matches the Dreamlab game you wish to publish.

Once created you can set an app icon, description, and tags to better identify your game and allow people to find it more easily.
Right now this is strictly optional, but once Discord rolls out the App Discovery page this will be important for discoverability.

## Step 2: Link your Discord Application to Dreamlab

To link your Discord application to Dreamlab you will need to add its OAuth2 details to your Dreamlab world.
These can be found in the **OAuth2** tab in the sidebar on the Discord Developers page for your application.

<img
src={OAuth2}
style={{ width: 'auto', maxHeight: '45rem' }}
alt="Sidebar of the Discord Developers page for an application named 'My Dreamlab Game', the OAuth2 section under the subheading 'Settings' is selected."
/>


You will need both the **Client ID** and **Client Secret**. In Dreamlab, go to your Library and find the world you want to link to your Discord app.
Click the Edit Details button and scroll to the Discord Activities Settings section and paste in the Client ID and Secret from Discord.
Make sure these match exactly and then click the save button at the top.

:::warning
**Keep these credentials safe and do not share them with anyone except Dreamlab.**.

Dreamlab will only use these credentials to authenticate the Discord SDK for your application.
:::



<img src={DetailsDiscord} alt="Top section of the OAuth2 page on Discord Developers showing the app's Client ID and Client Secret, copy buttons are visible under both." />

<img
src={DetailsDreamlab}
alt="Bottom section of the Edit World page on Dreamlab titled 'Discord Activities Settings', showing two input boxes labelled 'Discord Client ID' and 'Discord Client Secret'. These have been filled with the information from the above image."
/>

## Step 3: Setup OAuth2 Redirects

Discord requires your app to have at least one OAuth2 Redirect configured in order to enable authentication.
While the Activity SDK is still in preview these are not validated so you can enter any valid URL, such as `http://localhost:3000`.

![Screenshot of the URL Mappings table filled in with the above data.](../../static/img/discordapp_redirects.png)

## Step 4: Setup the Activity URL Mappings

Discord Activities run in a sandboxed environment and must specify all required external dependencies manually. Dreamlab will take care of

In the Discord Developers page sidebar, select the **URL Mappings** page. If you have not yet created an activity for your application go to the **Getting Started** page and click the **Enable** button.
Fill in the following URL mappings exactly.

| Prefix | Target |
| ------------- | -------------------------------- |
| `/` | `discord-activities.dreamlab.gg` |
| `/mp` | `mp1.dreamlab.gg` |
| `/s3` | `s3-assets.dreamlab.gg` |
| `/esm` | `esm.sh` |
| `/v135` | `esm.sh/v135` |
| `/stable` | `esm.sh/stable` |
| `/jsdelivr ` | `cdn.jsdelivr.net` |

Your final page should look like the following. Make sure to save!

<img src={UrlMappings} alt='Screenshot of the URL Mappings table filled in with the above data.' />

## Step 5: Test inside Discord

To test your activity inside of Discord, you must first enable Developer Mode to be able to see your activity.
This can be found in `User Settings -> App Settings -> Advanced` in the Discord Client.

Once enabled, you should be able to see your activity at the top of the list when starting an activity in any voice channel.
When starting an activity as a developer, only you will be able to join and interact with it.

While the Activity SDK is still in preview you will need to manually add any testers in the Discord Developer Portal.
This can be done in the **App Testers** section in your application settings. Anyone you add will receive an email from Discord
inviting them to test your app.
20 changes: 20 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
sidebar_position: 0.1
---

# Welcome to the Dreamlab Docs!


Dreamlab is your open-source game engine for creating and playing multiplayer games with your friends.

### What is Dreamlab?

Dreamlab empowers you to bring your game ideas to life with ease.

- **Multiplayer-First:** Every game you create in Dreamlab is multiplayer-ready by default. No complicated setups, no additional plugins—just instant multiplayer experiences at your fingertips.

- **Web-Based:** Dreamlab runs entirely in the browser. You can share your games with a link, and your friends can join in seconds—no downloads or installations required.

- **AI-Powered Creativity:** Leverage AI tools to generate unique assets, characters, and environments with just a few words.

We recommend you use the AI chatbot in the script editor to help you write code. It will use resources from this documentation.
8 changes: 8 additions & 0 deletions docs/ingredients/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Script Ingredients",
"position": 2.5,
"link": {
"type": "generated-index",
"description": "Examples of different functionality in Behavior scripts."
}
}
87 changes: 87 additions & 0 deletions docs/ingredients/behavior-structure.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import useBaseUrl from "@docusaurus/useBaseUrl";

# Behavior Structure
:::info
These docs can be queried by Dreamlab Assistant, our AI chatbot that helps you code your game.

<img
src={useBaseUrl("/img/scriptstab.png")}
style={{ width: "auto", maxHeight: "15rem" }}
alt="scripts tab location"
/>
Navigate to your "Scripts" tab and the Dreamlab Assistant will be available on
the right-hand side.

:::

```typescript
import { Behavior, Vector2, Vector2Adapter } from '@dreamlab/engine'
/*
In "@dreamlab/engine", a `Behavior` represents a modular piece of logic that can be attached to an entity.
This allows you to encapsulate functionality, such as movement, health management, or AI, in reusable components.
Key Components:
- **Lifecycle Methods:**
- `onInitialize`: Called once when the behavior is first attached to an entity, used for setup tasks.
- `onTick`: Called on every game tick, ideal for updating logic like movement or state changes.
- `onPreTick`, `onPostTick`, `onFrame`: Additional lifecycle hooks for more granular control over update timing.
- **Values:** Behaviors can have properties (values) that are synchronized across the network or exposed to
an inspector GUI. These values are defined using `defineValue` or `defineValues` methods and can be of various
types, including primitives and complex types with adapters.
- **Signals:** Behaviors can listen for signals (events) from the game or other entities and respond accordingly.
This is done using the `listen` method for subscribing to signals, and `fire` to emit them.
- **Destruction:** Behaviors can be destroyed manually using `destroy()` or automatically via the entity lifecycle.
This cleanup process ensures all listeners and values are properly disposed of.
The `Behavior` class is highly flexible, supporting complex game mechanics through a combination of values, signals,
and lifecycle hooks. It serves as the foundation for defining how entities behave in the game world.
If you want to get the width or height of the screen, you can use this.game.renderer.app.canvas.width / height.
this.game.renderer.app is a Pixi application. When making calls to pixi, you must import it as:
import * as PIXI from "@dreamlab/vendor/pixi.ts";
*/

// example Behavior that allows for WASD movement as well as a pattern for firing projectiles.
// this serves as an example for the general structure of a behavior
class Movement extends Behavior {
// the speed of the player
speed = 5.0
// example value
anotherValue = 42.0
// the current velocity of the player
velocity = Vector2.ZERO

#up = this.inputs.create('@movement/up', 'Move Up', 'KeyW')
#down = this.inputs.create('@movement/down', 'Move Down', 'KeyS')
#left = this.inputs.create('@movement/left', 'Move Left', 'KeyA')
#right = this.inputs.create('@movement/right', 'Move Right', 'KeyD')

// the setup method should ONLY be used for calls to defineValue. Anything else should go in onInitialize which will run when the behavior is spawned.
setup(): void {
// definevalue calls make the public class variables visible in the inspector GUI and also sync over the network
// define multiple values at once by passing them as more arguments. do not pass a list.
this.defineValues(Movement, 'speed', 'anotherValue')
this.defineValue(Movement, 'velocity', { type: Vector2Adapter })
}

onTick(): void {
const movement = new Vector2(0, 0)
const currentSpeed = this.speed

if (this.#up.held) movement.y += 1
if (this.#down.held) movement.y -= 1
if (this.#right.held) movement.x += 1
if (this.#left.held) movement.x -= 1

this.velocity = movement.normalize().mul((this.game.physics.tickDelta / 100) * currentSpeed)

const newPosition = this.entity.transform.position.add(this.velocity)
}
}

```
93 changes: 93 additions & 0 deletions docs/ingredients/character-controller.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import useBaseUrl from "@docusaurus/useBaseUrl";

# Character Controller
:::info
These docs can be queried by Dreamlab Assistant, our AI chatbot that helps you code your game.

<img
src={useBaseUrl("/img/scriptstab.png")}
style={{ width: "auto", maxHeight: "15rem" }}
alt="scripts tab location"
/>
Navigate to your "Scripts" tab and the Dreamlab Assistant will be available on
the right-hand side.

:::

```typescript
// This is an example of how to implement a platformer controller using the KinematicCharacterController

import { Behavior, EntityDestroyed, RectCollider, Vector2 } from '@dreamlab/engine'
import { KinematicCharacterController } from '@dreamlab/vendor/rapier.ts'

export default class PlatformMovement extends Behavior {
#collider: RectCollider = this.entity.cast(RectCollider)
#controller: KinematicCharacterController | undefined

speed = 10.0
jumpForce = 20.0
jumpAcceleration = 40
gravity = 90.0
maxJumpTime = 1 // Maximum duration the jump key affects the jump

#verticalVelocity = 0
#isGrounded = false
#jumpTimeCounter = 0

#up = this.inputs.create('@movement/up', 'Move Up', 'KeyW')
#down = this.inputs.create('@movement/down', 'Move Down', 'KeyS')
#left = this.inputs.create('@movement/left', 'Move Left', 'KeyA')
#right = this.inputs.create('@movement/right', 'Move Right', 'KeyD')
#jump = this.inputs.create('@movement/jump', 'Jump', 'Space')

setup() {
this.defineValues(PlatformMovement, 'speed', 'jumpForce', 'jumpAcceleration', 'gravity', 'maxJumpTime')
}

onInitialize(): void {
if (this.game.isClient()) {
this.#controller = this.game.physics.world.createCharacterController(0.01)
}

this.listen(this.entity, EntityDestroyed, () => {
if (this.#controller) this.game.physics.world.removeCharacterController(this.#controller)
})
}

onTick(): void {
if (!this.#controller) return

const deltaTime = this.game.physics.tickDelta / 1000 // Convert to seconds

let horizontalInput = 0
if (this.#right.held) horizontalInput += 1
if (this.#left.held) horizontalInput -= 1

const horizontalVelocity = horizontalInput * this.speed

// Jumping logic
if (this.#jump.pressed && this.#isGrounded) {
this.#verticalVelocity = this.jumpForce
this.#jumpTimeCounter = 0
}

if (this.#jump.held && this.#jumpTimeCounter < this.maxJumpTime) {
// Apply upward acceleration while the jump key is held
this.#verticalVelocity += this.jumpAcceleration * deltaTime
this.#jumpTimeCounter += deltaTime
}

// Create movement vector
const movement = new Vector2(horizontalVelocity * deltaTime, this.#verticalVelocity * deltaTime)

this.#controller.computeColliderMovement(this.#collider.collider, movement)
const corrected = this.#controller.computedMovement()

this.#isGrounded = this.#controller.computedGrounded()
if (!this.#isGrounded) this.#verticalVelocity -= this.gravity * deltaTime

this.entity.pos = this.entity.pos.add(corrected)
}
}

```
Loading

0 comments on commit d90da01

Please sign in to comment.