Skip to content

Commit

Permalink
Merge pull request #282 from RSamaium/v4.3.0
Browse files Browse the repository at this point in the history
V4.3.0
  • Loading branch information
RSamaium committed Jan 29, 2024
2 parents 35eb6d0 + 1292365 commit 50eb39b
Show file tree
Hide file tree
Showing 92 changed files with 27,486 additions and 1,485 deletions.
16 changes: 8 additions & 8 deletions docs/.vitepress/cache/deps/_metadata.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{
"hash": "52bfd73e",
"browserHash": "784c2801",
"hash": "1a35c785",
"browserHash": "06015c59",
"optimized": {
"vue": {
"src": "../../../node_modules/vue/dist/vue.runtime.esm-bundler.js",
"file": "vue.js",
"fileHash": "929fd058",
"fileHash": "89d026cc",
"needsInterop": false
},
"vitepress > @vue/devtools-api": {
"src": "../../../node_modules/@vue/devtools-api/lib/esm/index.js",
"file": "vitepress___@vue_devtools-api.js",
"fileHash": "e4854535",
"fileHash": "2645e713",
"needsInterop": false
},
"vitepress > @vueuse/integrations/useFocusTrap": {
"src": "../../../node_modules/@vueuse/integrations/useFocusTrap.mjs",
"file": "vitepress___@vueuse_integrations_useFocusTrap.js",
"fileHash": "42b2aa2c",
"fileHash": "4e2d43e4",
"needsInterop": false
},
"vitepress > mark.js/src/vanilla.js": {
"src": "../../../node_modules/mark.js/src/vanilla.js",
"file": "vitepress___mark__js_src_vanilla__js.js",
"fileHash": "0d6e6fc4",
"fileHash": "3ed8ef59",
"needsInterop": false
},
"vitepress > minisearch": {
"src": "../../../node_modules/minisearch/dist/es/index.js",
"file": "vitepress___minisearch.js",
"fileHash": "b20f55c8",
"fileHash": "b062852e",
"needsInterop": false
},
"@vue/theme": {
"src": "../../../node_modules/@vue/theme/src/index.ts",
"file": "@vue_theme.js",
"fileHash": "7bb8dba9",
"fileHash": "7db5d48e",
"needsInterop": false
}
},
Expand Down
12 changes: 11 additions & 1 deletion docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ const migrationMenu = [{
]
}]

const web3Menu = [{
text: 'Web3',
collapsed: false,
items: [
{ text: "Authentification with wallet", link: "/web3/auth" }
]
}]

const guideMenu = [{
text: 'Quick Start',
Expand Down Expand Up @@ -172,7 +179,8 @@ const guideMenu = [{
collapsed: false,
items: [
{ text: "Create Gui with React", link: "/gui/react" },
{ text: "Adding Tooltips to Your GUI", link: "/gui/react-tooltip" }
{ text: "Adding Tooltips to Your GUI", link: "/gui/react-tooltip" },
{ text: "Integrate in React App", link: "/gui/react-app"}
]
},
{
Expand Down Expand Up @@ -202,6 +210,7 @@ const guideMenu = [{
{ text: "Create Unit Tests", link: "/guide/unit-test" },
]
},
...web3Menu,
...migrationMenu
]

Expand Down Expand Up @@ -275,6 +284,7 @@ module.exports = {
'/advanced/': guideMenu,
'/plugins/': pluginMenu,
'/migration/': guideMenu,
'/web3/': guideMenu,
},
plugins: ['@vuepress/active-header-links'],
head: [
Expand Down
90 changes: 90 additions & 0 deletions docs/gui/react-app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Integrating RpgGame Component into a React App

This guide provides step-by-step instructions on how to insert an `RpgGame` component into a React application using ViteJS.

## Prerequisites

Ensure that you have a React application set up with ViteJS. Your `package.json` should include the following scripts:

```json
"scripts": {
"dev": "rpgjs dev",
"build": "rpgjs build"
}
```

## Step 1: Create the Game Directory

Create a new directory within your source folder:

```
src/game
```

## Step 2: Configure RPG Module

In your `rpg.toml` file, set the module root and disable autostart:

```toml
modulesRoot = './src/game'
autostart = false
```

> The `autostart` option prevents the engine from automatically searching for a div with the id `#rpg`. Instead, it will use the React component.
## Step 3: Import RpgGame Component

Import the `RpgGame` component from the RPGJS client package for React:

```javascript
import { RpgGame } from '@rpgjs/client/react';
```

## Step 4: Utilize RpgGame Component

Implement the `RpgGame` component with an `onReady` function:

```jsx
const onReady = ({ server, client }) => {
// server is an instance of RpgServerEngine or null
// client is an instance of RpgClientEngine
};

<RpgGame onReady={onReady} />
```

In MMORPG mode, `server` will be null. In RPG mode, you can access both client and server sides.

## Step 5: Advanced Configuration

To add modules via the React app, use the following setup:

```javascript
const [modules, setModules] = useState<any[]>([
{
server: {
player: {
onConnected(player) {
player.setHitbox(24, 24);
player.speed = 4;
player.setGraphic('hero');
}
}
},
client: {
engine: {
onStart() {
console.log('started')
}
}
}
}
]);

<RpgGame
onReady={onReady}
modules={modules}
/>
```

> In MMORPG mode, you only have access to the client API.
42 changes: 38 additions & 4 deletions docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,29 @@ The configuration and properties of RPGJS are defined using a JSON schema, which

Configuration properties related to the compiler.

- `type`: (*string*) The type of the RPG. Can be either "rpg" or "mmorpg".

- `modulesRoot`: (*string*) The root directory for modules. (since 4.3.0)

- `modules`: (*array*) List of modules to load.

Example:

```toml
modules = ["./main", "@rpgjs/gamepad"]
```

- `autostart`: (*boolean*) Finds the starting point selector and displays the game directly. (`true` by default). Since 4.3.0

If `false`, it can be loaded as follows:

```ts
import { RpgClientEngine, inject } from '@rpgjs/client';

const client = inject(RpgClientEngine)
await client.start()
```

- `compilerOptions`
- `alias`: (*object*) Aliases. Use aliases in Typescript imports
```toml
Expand All @@ -36,11 +59,11 @@ Configuration properties related to the compiler.
- `express`

Configuration properties related to the Express server.
Configuration properties related to the Express server.

- `static`: (*string*) Specifies the directory from which to serve static files.
> only for final files put into production
- `port`: (*integer*) The port number on which the Express server listens.
- `static`: (*string*) Specifies the directory from which to serve static files.
> only for final files put into production
- `port`: (*integer*) The port number on which the Express server listens.

Example:

Expand Down Expand Up @@ -69,6 +92,17 @@ Configuration properties for CORS middleware. Documentation: [cors](https://expr

Configuration properties for SocketIO middleware. Documentation: [socket.io](https://socket.io/docs/v4/server-initialization/)

- `socketIoClient`

All [SocketIO client configuration](https://socket.io/docs/v4/client-initialization/).

Example:

```toml
[socketIoClient]
withCredentials = true
```

- `spritesheetDirectories`: (*array*) Directories for spritesheets.

### `server`
Expand Down
7 changes: 6 additions & 1 deletion docs/guide/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This repository utilizes environment variables to configure various aspects of t
- Description: This environment variable specifies the current environment in which the RPGJS application is running. It can be set to either "development" or "production" mode.
- Usage: Set this variable to "development" when working on the application locally, and set it to "production" when deploying the game to a live server.

### 2. `VITE_SERVER_URL` (for build)
### `VITE_SERVER_URL` (for build)

- Description: This environment variable specifies the base URL for the server during the build process.
- Usage: Set this variable to the appropriate server URL before building the application.
Expand All @@ -20,6 +20,11 @@ Example:
VITE_SERVER_URL=https//world.rpgjs.dev npm run build
```

### `VITE_GAME_URL`

- Description: This environment variable specifies the base URL for the game


### 3. `RPG_TYPE`

- Description: This environment variable determines the type of the RPGJS application. It can be set to either "rpg" or "mmorpg" based on your desired type.
Expand Down
79 changes: 79 additions & 0 deletions docs/web3/auth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Authentification Integrating Web3 into RPGJS

::: warning
The module is not complete. Further developments are in progress
:::

## Overview

By following this guide, you'll be able to connect to a digital wallet like MetaMask and implement Web3 capabilities both on the client and server sides.

### Prerequisites
- Basic knowledge of RPGJS
- Familiarity with Web3 concepts
- MetaMask or similar digital wallet installed

## Frontend Integration

### Customization
You are free to customize the frontend as per your needs. However, an example is provided here for guidance.

### Example:

https://github.com/RSamaium/RPG-JS/tree/v4/packages/sample3

## Server-Side Integration

### Installation

Install the `@rpgjs/web3` plugin:

```bash
npx rpgjs add @rpgjs/web3
```

Ensure that the `@rpgjs/web3` module is the first in the list:

Example:
```toml
modules = [
'@rpgjs/web3',
'./main',
'@rpgjs/default-gui',
]
```

### Setting up Configuration

Add the following configurations:

```toml
[auth]
jwtSecret = 'mysecret'

[express.cors]
origin = '$ENV:VITE_GAME_URL'
credentials = true

[express.socketIo.cors]
origin = '$ENV:VITE_GAME_URL'
credentials = true

[socketIoClient]
withCredentials = true
```

## Usage

### Endpoints
The integration introduces two endpoints:

- `SERVER_URL + '/nonce'`
- `SERVER_URL + '/verify'`

These endpoints help in creating an HTTP-only cookie containing a JWT (JSON Web Token).

### API Utilization
This integration extends the `RpgPlayer` type with Web3 functionalities:

- `player.web3.walletAddress`: Allows access to the player's wallet address.
Loading

0 comments on commit 50eb39b

Please sign in to comment.