Adding refresh pj list on pj creation.

This commit is contained in:
Sergiotarxz 2023-06-22 21:54:28 +02:00
parent 12e6fb8524
commit de2cfae5a7
8 changed files with 68 additions and 25 deletions

View File

@ -1,7 +1,18 @@
import * as React from 'react' import * as React from 'react'
import PresentationItem from '@lastres/components/presentation-item'
import Presentation from '@lastres/components/presentation'
export interface BottomPanelProps {
websocket: WebSocket | null
}
export default function BottomPanel (): JSX.Element { export default function BottomPanel (): JSX.Element {
return ( return (
<> <Presentation>
</> <PresentationItem>
hola
</PresentationItem>
</Presentation>
) )
} }

View File

@ -73,6 +73,9 @@ export default function Game (props: GameProps): JSX.Element {
webSocket.onerror = (event) => { webSocket.onerror = (event) => {
console.log(event) console.log(event)
} }
webSocket.onclose = (event) => {
setWebsocket(null)
}
return webSocket return webSocket
} }
return websocket return websocket

View File

@ -1,22 +1,22 @@
import * as React from 'react' import * as React from 'react'
import { PJ } from '@lastres/pj' import type { PJ } from '@lastres/pj'
import { fetchMyPjs } from '@lastres/pj'
export interface PJCreationMenuProps { export interface PJCreationMenuProps {
error: string | null error: string | null
setSelectedPJ: (set: PJ | null) => void setSelectedPJ: (set: PJ | null) => void
setUserWantsToCreatePJ: (set: boolean) => void setUserWantsToCreatePJ: (set: boolean) => void
setError: (set: string | null) => void setError: (set: string | null) => void
setPJs: (set: PJ[] | null) => void
} }
export interface Race { export interface Race {
identifier: string; identifier: string
name_selection: string; name_selection: string
description: string; description: string
}
export interface Races {
[id: string]: Race
} }
export type Races = Record<string, Race>
export default function PJCreationMenu (props: PJCreationMenuProps): JSX.Element { export default function PJCreationMenu (props: PJCreationMenuProps): JSX.Element {
const longNameInputRef = React.useRef<HTMLInputElement>(null) const longNameInputRef = React.useRef<HTMLInputElement>(null)
@ -34,7 +34,7 @@ export default function PJCreationMenu (props: PJCreationMenuProps): JSX.Element
const data = await response.json() const data = await response.json()
if (statusCode !== 200) { if (statusCode !== 200) {
props.setError(data.error) props.setError(data.error)
return; return
} }
setPlayableRaces(data) setPlayableRaces(data)
props.setError(null) props.setError(null)
@ -75,10 +75,12 @@ export default function PJCreationMenu (props: PJCreationMenuProps): JSX.Element
} }
props.setError(null) props.setError(null)
props.setUserWantsToCreatePJ(false) props.setUserWantsToCreatePJ(false)
const pjs = await fetchMyPjs(props.setError)
props.setPJs(pjs)
}).catch((error) => { }).catch((error) => {
console.log(error) console.log(error)
props.setError('Imposible crear pj, no se pudo conectar al servidor.') props.setError('Imposible crear pj, no se pudo conectar al servidor.')
}); })
} }
function renderRaces (): JSX.Element[] { function renderRaces (): JSX.Element[] {
if (playableRaces !== null) { if (playableRaces !== null) {
@ -87,8 +89,7 @@ export default function PJCreationMenu (props: PJCreationMenuProps): JSX.Element
return <option key={i} value={playableRaces[item].identifier}> return <option key={i} value={playableRaces[item].identifier}>
{`${playableRaces[item].name_selection} (${playableRaces[item].description})`} {`${playableRaces[item].name_selection} (${playableRaces[item].description})`}
</option> </option>
} })
)
} }
return ([]) return ([])
} }

View File

@ -12,6 +12,7 @@ export default function PJListSelection (props: PJListSelectionProps): JSX.Eleme
if (pjs === null) { if (pjs === null) {
return ( return (
<> <>
<p>Aun no se han descargado los pjs, espera un segundo...</p>
</> </>
) )
} }

View File

@ -1,7 +1,8 @@
import * as React from 'react' import * as React from 'react'
import PJCreationMenu from '@lastres/components/pj-creation-menu' import PJCreationMenu from '@lastres/components/pj-creation-menu'
import PJListSelection from '@lastres/components/pj-list-selection' import PJListSelection from '@lastres/components/pj-list-selection'
import { PJ, fetchMyPjs } from '@lastres/pj' import { fetchMyPjs } from '@lastres/pj'
import type { PJ } from '@lastres/pj'
export interface PJSelectionMenuProps { export interface PJSelectionMenuProps {
setSelectedPJ: (set: PJ | null) => void setSelectedPJ: (set: PJ | null) => void
@ -22,12 +23,14 @@ export default function PJSelectionMenu (props: PJSelectionMenuProps): JSX.Eleme
setSelectedPJ={props.setSelectedPJ} setSelectedPJ={props.setSelectedPJ}
setUserWantsToCreatePJ={props.setUserWantsToCreatePJ} setUserWantsToCreatePJ={props.setUserWantsToCreatePJ}
error={props.error} error={props.error}
setError={props.setError}/> setError={props.setError}
setPJs={setPJs}/>
) )
} }
if (pjs === null) { if (pjs === null) {
fetchMyPjs(props.setError) fetchMyPjs(props.setError)
.then((pjs) => { setPJs(pjs) }) .then((pjs) => { setPJs(pjs) })
.catch((error) => { console.log(error) })
} }
return ( return (
<div className="pj-selection-menu"> <div className="pj-selection-menu">

View File

@ -31,6 +31,11 @@ sub frames_to_explore($self) {
return 7; return 7;
} }
## OVERRIDE
sub can_explore {
return 1;
}
sub _build_children($self) { sub _build_children($self) {
my $locations = $self->locations; my $locations = $self->locations;
my @locations = map { $locations->{$_} } keys %$locations; my @locations = map { $locations->{$_} } keys %$locations;

View File

@ -21,6 +21,26 @@ sub can_visit($self, $pj) {
return 1; return 1;
} }
## OVERRIDE
sub can_discover($self, $pj) {
return 1;
}
## OVERRIDE
sub chance_discover($self, $pj) {
return 50;
}
## OVERRIDE
sub allow_forced_discovery($self, $pj) {
return 1;
}
## OVERRIDE
sub order($self) {
return 1000;
}
## OVERRIDE (Always use $self->SUPER::on_team_arrival.) ## OVERRIDE (Always use $self->SUPER::on_team_arrival.)
sub on_team_arrival($self, $team) { sub on_team_arrival($self, $team) {
$team = $team->get_from_storage; $team = $team->get_from_storage;
@ -41,7 +61,6 @@ sub on_pj_arrival($self, $pj) {
$redis->publish( $redis->pj_subscription($pj), to_json({ command => 'update-location' })); $redis->publish( $redis->pj_subscription($pj), to_json({ command => 'update-location' }));
} }
sub show_intro ( $self, $pj ) { sub show_intro ( $self, $pj ) {
$pj->append_log_line( $pj->append_log_line(
[ [

File diff suppressed because one or more lines are too long