-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
RSamaium
committed
Dec 8, 2023
1 parent
4ddccd3
commit a617bfd
Showing
7 changed files
with
94 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import { room } from '@rpgjs/client' | ||
import { RpgReactContext, useObjects, useCurrentPlayer } from '@rpgjs/client/react' | ||
import { useContext } from 'react' | ||
import { useContext, useEffect } from 'react' | ||
|
||
export default function Test({ gold }) { | ||
const player = useCurrentPlayer() | ||
return <>{player?.position?.x}</> | ||
const { rpgCurrentPlayer } = useContext(RpgReactContext) | ||
|
||
useEffect(() => { | ||
rpgCurrentPlayer.subscribe(({ object }) => { | ||
console.log('frontend', object.items); | ||
}) | ||
}, []) | ||
|
||
return <>test</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { _beforeEach } from './beforeEach' | ||
import { clear } from '@rpgjs/testing' | ||
import { RpgPlayer, RpgMap, MapData, RpgModule, RpgServer } from '@rpgjs/server' | ||
import { beforeEach, test, afterEach, expect, describe, vi } from 'vitest' | ||
|
||
let client, fixture, playerId, server | ||
let player: RpgPlayer | ||
|
||
beforeEach(async () => { | ||
const ret = await _beforeEach() | ||
client = ret.client | ||
player = ret.player | ||
fixture = ret.fixture | ||
server = ret.server | ||
playerId = ret.playerId | ||
}) | ||
|
||
describe('Test props', () => { | ||
test('sync props', async () => { | ||
clear() | ||
|
||
@RpgModule<RpgServer>({ | ||
player: { | ||
props: { | ||
bronze: Number | ||
}, | ||
onJoinMap(player, map) { | ||
player['bronze'] = 100 | ||
}, | ||
} | ||
}) | ||
class RpgServerModule {} | ||
|
||
const { server, client } = await _beforeEach([{ | ||
server: RpgServerModule | ||
}]) | ||
|
||
await server.send() | ||
|
||
expect(client.player.bronze).toEqual(100) | ||
}) | ||
}) | ||
|
||
// https://community.rpgjs.dev/d/244-playeradditem-bug | ||
test('change map before, sync player', async () => { | ||
const sceneMap = server.sceneMap | ||
|
||
@MapData({ | ||
id: 'myid', | ||
file: require('./fixtures/maps/map.tmx') | ||
}) | ||
class SampleMap extends RpgMap { } | ||
|
||
sceneMap.createDynamicMap(SampleMap) | ||
|
||
await player.changeMap('myid') | ||
|
||
player.gold += 100 | ||
|
||
await server.send() | ||
|
||
expect(client.player.gold).toEqual(player.gold) | ||
}) | ||
|
||
afterEach(() => { | ||
clear() | ||
}) |