1.0.0 • Published 2 years ago

gamenet v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

gamenet

GameNetwork is a decentralized peer to peer state management store for making state save multiplayer game based on smnet.

demo

demo code

Install

# npm
npm i gamenet

# yarn
yarn add gamenet

Usage-Anywhere

TBA

Usage-React

import {GenericBoardGameState, useBoardGameNetwork} from 'gamenet'

//...
const App = () => {
<GameNetworkProvider reducer={myReducer} initialState={new GenericBoardGameState() /* or something extends this*/}>
  {/* your game GUI or room */}
  <SomeComponent/>
</GameNetworkProvider>
}

//...
const SomeComponent = () => {
  const { room, state, leave, isAdmin, myId, kick, ready, start } = useBoardGameNetwork()
// ...
}

API

interface UseGameNetwork {
  // join the room, name is player name, room is room name
  connect: (name: string, room: string) => Promise<void>

  // leave the room
  leave: () => Promise<void>

  // int enum, HOME=0, ROOM=1, GAME=2 
  gameAppState: GameAppState

  // sate stored in network
  state: GenericBoardGameState

  // room name
  room?: string

  // true if i am the host of game
  isAdmin: boolean

  // peerId of this point. hosting point has peerId same as networkName
  // please be aware that when the host gets disconnected,
  // one of the points will take up as the new host
  // myId of that point will change to networkName
  // (this is intended so other point can still reach to this network)
  myId?: string

  // kick other point having this peerId out of this network
  kick: (id: string) => Promise<void>

  // mark i am ready/ not ready
  ready: () => Promise<void>

  // start the game
  start: () => Promise<void>

  // general dispatch function
  dispatch: (action: GenericBoardGameAction) => Promise<void>
}
1.0.0

2 years ago

0.3.0

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago

0.0.4

4 years ago