60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import * as React from 'react'
|
|
|
|
import type { TalkNPC } from '@lastres/talk-npc'
|
|
import { StateGame } from '@lastres/components/game'
|
|
|
|
import OutputPacketTalk from '@lastres/output-packet/talk'
|
|
|
|
export interface TalkNPCComponentData {
|
|
npc: TalkNPC
|
|
websocket: WebSocket | null
|
|
key: string
|
|
setStateGame: (set: StateGame) => void
|
|
setNPCToSayWord: (set: TalkNPC | null) => void
|
|
}
|
|
|
|
export default function TalkNPCComponent (props: TalkNPCComponentData): JSX.Element {
|
|
const npc = props.npc
|
|
function onWordlesslyTalk (npc: TalkNPC): void {
|
|
if (props.websocket === null) {
|
|
return
|
|
}
|
|
new OutputPacketTalk(npc.identifier).send(props.websocket)
|
|
}
|
|
|
|
function onWantToSayWord (): void {
|
|
props.setStateGame(StateGame.SelectingWord)
|
|
props.setNPCToSayWord(npc)
|
|
}
|
|
|
|
function printAvatar (npc: TalkNPC): JSX.Element {
|
|
if (npc.icon === undefined) {
|
|
return <></>
|
|
}
|
|
return <div className="avatar">
|
|
<img src={npc.icon}/><div className="shadow"/>
|
|
</div>
|
|
}
|
|
|
|
return <div key={npc.identifier} className="talk-npc">
|
|
<div className="detail">
|
|
<div className="name-container">
|
|
{
|
|
printAvatar(npc)
|
|
}
|
|
<div className="name">
|
|
<p>{npc.name}</p>
|
|
</div>
|
|
</div>
|
|
<div className="buttons">
|
|
<button onClick={() => {
|
|
onWordlesslyTalk(npc)
|
|
}}>Hablar</button>
|
|
<button onClick={() => {
|
|
onWantToSayWord()
|
|
}}>Decir palabra</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|