-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new character page and new currency (#192)
* chore: some color changes * feat: new character page and new currency * chore: some logic on form * feat: plugin for stream
- Loading branch information
1 parent
1596b5e
commit 9b017bb
Showing
26 changed files
with
1,150 additions
and
235 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
{ | ||
"eslint.experimental.useFlatConfig": true, | ||
|
||
"prettier.enable": false, | ||
"editor.formatOnSave": false, | ||
|
||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,85 @@ | ||
import type { WebSocketMessage } from '@hmbanan666/chat-game-api' | ||
import type { UnitsOnStream } from '$lib/game/types' | ||
import { browser } from '$app/environment' | ||
import { config } from '$lib/config' | ||
|
||
export class CustomWebSocketService { | ||
socket!: WebSocket | ||
messagesPerSecond = 0 | ||
kbitPerSecond = 0 | ||
game: UnitsOnStream | ||
|
||
constructor(game: UnitsOnStream) { | ||
this.game = game | ||
|
||
if (browser && this.game.options.isSocketOn) { | ||
this.#init() | ||
} | ||
} | ||
|
||
update() {} | ||
|
||
async #handleMessage(message: WebSocketMessage) { | ||
if (message.type === 'MESSAGE') { | ||
const { text, player } = message.data | ||
this.game.handleMessage({ text, playerId: player.id }) | ||
} | ||
// if (message.type === 'RAID_STARTED') { | ||
// this.game.audio.playSound('MARCHING_WITH_HORNS') | ||
// } | ||
// if (message.type === 'GROUP_FORM_STARTED') { | ||
// this.game.audio.playSound('MARCHING_WITH_HORNS') | ||
// } | ||
// if (message.type === 'MAIN_QUEST_STARTED') { | ||
// this.game.audio.playSound('MARCHING_WITH_HORNS') | ||
// } | ||
// if (message.type === 'SCENE_CHANGED') { | ||
// this.game.rebuildScene() | ||
// } | ||
// if (message.type === 'IDEA_CREATED') { | ||
// this.game.audio.playSound('YEAH') | ||
// } | ||
} | ||
|
||
#init() { | ||
this.socket = new WebSocket(config.websocketUrl ?? '', [this.game.id]) | ||
|
||
this.#setMessagesPerSecondHandler() | ||
|
||
this.socket.addEventListener('open', () => { | ||
this.socket.send(JSON.stringify({ type: 'GAME_HANDSHAKE', id: this.game.id, profileJWT: this.game.profileJWT })) | ||
}) | ||
|
||
this.socket.addEventListener('message', (event) => { | ||
const message = this.#parse(event.data.toString()) | ||
if (!message) { | ||
return | ||
} | ||
|
||
this.messagesPerSecond += 1 | ||
const bytes = JSON.stringify(message).length | ||
this.kbitPerSecond += Math.round((bytes * 8) / 1024) | ||
|
||
void this.#handleMessage(message) | ||
}) | ||
} | ||
|
||
#parse(message: string): WebSocketMessage | undefined { | ||
const parsed = JSON.parse(message) | ||
if (parsed) { | ||
return parsed as WebSocketMessage | ||
} | ||
|
||
return undefined | ||
} | ||
|
||
#setMessagesPerSecondHandler() { | ||
return setInterval(() => { | ||
// console.log( | ||
// `${this.messagesPerSecond} msg/s, ${this.kbitPerSecond} kbit/s`, | ||
// ) | ||
this.messagesPerSecond = 0 | ||
this.kbitPerSecond = 0 | ||
}, 1000) | ||
} | ||
} |
Oops, something went wrong.