Skip to content

Commit

Permalink
script entrypoint docs
Browse files Browse the repository at this point in the history
  • Loading branch information
luludotdev committed Feb 1, 2024
1 parent 6c21b32 commit c9400b2
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions pages/concepts/scripting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import { UnderConstruction } from '~/components/under-construction'

<UnderConstruction />

## TypeScript

{/* TODO: typescript info */}

- template is set up for TypeScript already
Dreamlab scripts are written in TypeScript and all new projects are created from one of our pre-made templates.
These templates are setup to work with Dreamlab correctly out of the box, so you don't need to worry about configuring anything yourself.

<Callout>
Although we **heavily** recommend using TypeScript, writing your scripts in
Expand All @@ -18,11 +15,46 @@ import { UnderConstruction } from '~/components/under-construction'

## Entrypoints

{/* TODO: entrypoints info */}
All scripts must implement three entrypoints for client code, server code, and level data. These are `client.ts`, `server.ts`, and `level.ts` respectively.
Client and Server entrypoints must export a single function named `init()` that has a single argument, a reference to the current Dreamlab game context.

Although not strictly required, we recommend defining another shared entrypoint that is called by both client and server `init()` functions that calls
any common code shared between client and server. A good example of such code would be [registering spawnable entities](./entities.mdx#registering).

<Callout>
All new projects created from our templates already have these entrypoints set
up correctly and are fully typed.
</Callout>

```ts filename="shared.ts"
import { InitShared } from '@dreamlab.gg/core/sdk'

export const sharedInit = async game => {
// ...
}
```

```ts filename="client.ts"
import { InitClient } from '@dreamlab.gg/core/sdk'
import { sharedInit } from './shared.ts'

export const init: InitClient = game => {
await sharedInit(game)

// ...
}
```

```ts filename="server.ts"
import type { InitServer } from '@dreamlab.gg/core/sdk'
import { sharedInit } from './shared.ts'

export const init: InitServer = game => {
await sharedInit(game)

- Client
- Server
- Level
// ...
}
```

## Imports

Expand Down

0 comments on commit c9400b2

Please sign in to comment.