Skip to content

Commit

Permalink
add vite game url env
Browse files Browse the repository at this point in the history
  • Loading branch information
RSamaium committed Jan 28, 2024
1 parent 6277f1b commit e0b3157
Show file tree
Hide file tree
Showing 16 changed files with 5,352 additions and 83 deletions.
10 changes: 6 additions & 4 deletions docs/guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ 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.
Expand Down Expand Up @@ -57,11 +59,11 @@ await client.start()
- `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
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
2 changes: 2 additions & 0 deletions packages/compiler/src/build/vite-plugin-config.toml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,11 @@ export default function configTomlPlugin(options: ClientBuildConfigOptions = {},
async load(id: string) {
const { env } = process
const serverUrl = env.VITE_SERVER_URL
const gameUrl = env.VITE_GAME_URL
const envsString = `{
VITE_BUILT: ${env.VITE_BUILT},
VITE_SERVER_URL: ${serverUrl ? "'" + serverUrl + "'" : 'undefined'},
VITE_GAME_URL: ${gameUrl ? "'" + gameUrl + "'" : 'undefined'},
VITE_RPG_TYPE: '${options.type ?? 'mmorpg'}',
VITE_ASSETS_PATH: '${env.VITE_ASSETS_PATH ?? ''}',
VITE_REACT: ${env.VITE_REACT},
Expand Down
4 changes: 3 additions & 1 deletion packages/compiler/src/serve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export async function devMode(options: DevOptions = {}) {
port: 3000
})
}

const isRpg = process.env.RPG_TYPE == 'rpg'
process.env.NODE_ENV = 'development'
process.env.VITE_GAME_URL ??= `http://localhost:${options.port}`
const cwd = process.cwd()

const colorUrl = (url: string) =>
Expand Down Expand Up @@ -73,6 +74,7 @@ export async function devMode(options: DevOptions = {}) {
const { runner, server: serverSide, files, node } = await runServer()
console.log(` ${colors.green('➜')} ${colors.bold('Mode')}: ${colorUrl('MMORPG')}`)
server.printUrls()

console.log(` ${colors.dim('➜')} ${colors.dim('Server')}: ${colors.dim(`http://localhost:${serverPort}/`)}`)
restartViteServer(server, async () => {
await hmr.handleMessage(runner, serverSide.emitter, [], {
Expand Down
8 changes: 7 additions & 1 deletion packages/plugins/auth/src/server/web3/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ export function playerWeb3VerifyHandler(authConfig: AuthConfig) {
try {
const server = inject(RpgServerEngine)

z.object({
const schema = z.object({
message: z.object({
nonce: z.string(),
}),
signature: z.string()
}).strict()

schema.parse(req.body)

const { message, signature }: { message: Message, signature: string } = req.body
const jwtSecret = authConfig.jwtSecret

Expand Down Expand Up @@ -61,6 +63,10 @@ export function playerWeb3VerifyHandler(authConfig: AuthConfig) {
}).send(result)

} catch (error) {
if (error instanceof z.ZodError) {
res.status(400).send(error.errors)
return
}
next(error)
}
}
Expand Down
11 changes: 8 additions & 3 deletions packages/sample3/rpg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ autostart = false
jwtSecret = 'mysecret'

[express.cors]
origin = 'http://localhost:3000'
origin = '$ENV:VITE_GAME_URL'
credentials = true

[express.socketIo.cors]
origin = "http://localhost:3000"
origin = '$ENV:VITE_GAME_URL'
credentials = true

[socketIoClient]
withCredentials = true
withCredentials = true

[start]
map = './src/game/main/maps/map'
graphic = 'male'
hitbox = [32, 32]
1 change: 0 additions & 1 deletion packages/sample3/src/assets/react.svg

This file was deleted.

Binary file removed packages/sample3/src/game/main/characters/ev1.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed packages/sample3/src/game/main/characters/hero.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 6 additions & 71 deletions packages/sample3/src/game/main/characters/spritesheet.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,8 @@
import { Spritesheet, Presets } from '@rpgjs/client'

import { Animation, Spritesheet, Direction } from '@rpgjs/client'
const { RMSpritesheet } = Presets

const LPCSpritesheetPreset = () => {
const frameY = (direction: Direction) => {
return {
[Direction.Down]: 2,
[Direction.Left]: 1,
[Direction.Right]: 3,
[Direction.Up]: 0
}[direction]
}

const stand = (direction: Direction) => [{ time: 0, frameX: 0, frameY: frameY(direction) }]
const anim = (direction: Direction, framesWidth: number, speed: number = 5) => {
const array: any = []
for (let i = 0; i < framesWidth; i++) {
array.push({ time: i * speed, frameX: i, frameY: frameY(direction) })
}
return array
}

const ratio = 1.5

return {
rectWidth: 64 * ratio,
rectHeight: 64 * ratio,
spriteRealSize: {
width: 48 * ratio,
height: 52 * ratio,
},
framesWidth: 6,
framesHeight: 4,
textures: {
[Animation.Stand]: {
offset: {
x: 0,
y: 512 * ratio,
},
animations: (direction: Direction) => [stand(direction)]
},
[Animation.Walk]: {
offset: {
x: 0,
y: 512 * ratio,
},
framesWidth: 9,
framesHeight: 4,
animations: (direction: Direction) => [anim(direction, 9)]
},
[Animation.Attack]: {
offset: {
x: 0,
y: 768 * ratio,
},
framesWidth: 6,
framesHeight: 4,
animations: (direction: Direction) => [anim(direction, 6, 3)]
},
[Animation.Skill]: {
framesWidth: 7,
framesHeight: 4,
animations: (direction: Direction) => [anim(direction, 7, 3)]
}
},
}
}

@Spritesheet({
...LPCSpritesheetPreset(),
})
export default class LPCSpritesheet {
}
@Spritesheet(
RMSpritesheet(3, 4)
)
export default class Characters { }
Binary file added packages/sample3/src/game/main/maps/base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e0b3157

Please sign in to comment.