From de2cfae5a7c152102f6583af7a717b0e55bc95b3 Mon Sep 17 00:00:00 2001 From: Sergiotarxz Date: Thu, 22 Jun 2023 21:54:28 +0200 Subject: [PATCH] Adding refresh pj list on pj creation. --- js-src/components/bottom-panel.tsx | 15 +++++++++++-- js-src/components/game.tsx | 3 +++ js-src/components/pj-creation-menu.tsx | 29 +++++++++++++------------ js-src/components/pj-list-selection.tsx | 1 + js-src/components/pj-selection-menu.tsx | 9 +++++--- lib/LasTres/Area.pm | 5 +++++ lib/LasTres/Location.pm | 21 +++++++++++++++++- public/js/bundle.js | 10 ++++----- 8 files changed, 68 insertions(+), 25 deletions(-) diff --git a/js-src/components/bottom-panel.tsx b/js-src/components/bottom-panel.tsx index cd6bb5e..4747d8a 100644 --- a/js-src/components/bottom-panel.tsx +++ b/js-src/components/bottom-panel.tsx @@ -1,7 +1,18 @@ 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 { return ( - <> - + + + hola + + ) } diff --git a/js-src/components/game.tsx b/js-src/components/game.tsx index 159a27b..7566ccf 100644 --- a/js-src/components/game.tsx +++ b/js-src/components/game.tsx @@ -73,6 +73,9 @@ export default function Game (props: GameProps): JSX.Element { webSocket.onerror = (event) => { console.log(event) } + webSocket.onclose = (event) => { + setWebsocket(null) + } return webSocket } return websocket diff --git a/js-src/components/pj-creation-menu.tsx b/js-src/components/pj-creation-menu.tsx index 9634225..b7a2dc4 100644 --- a/js-src/components/pj-creation-menu.tsx +++ b/js-src/components/pj-creation-menu.tsx @@ -1,22 +1,22 @@ import * as React from 'react' -import { PJ } from '@lastres/pj' +import type { PJ } from '@lastres/pj' +import { fetchMyPjs } from '@lastres/pj' export interface PJCreationMenuProps { error: string | null setSelectedPJ: (set: PJ | null) => void setUserWantsToCreatePJ: (set: boolean) => void setError: (set: string | null) => void + setPJs: (set: PJ[] | null) => void } export interface Race { - identifier: string; - name_selection: string; - description: string; -} -export interface Races { - [id: string]: Race + identifier: string + name_selection: string + description: string } +export type Races = Record export default function PJCreationMenu (props: PJCreationMenuProps): JSX.Element { const longNameInputRef = React.useRef(null) @@ -33,8 +33,8 @@ export default function PJCreationMenu (props: PJCreationMenuProps): JSX.Element const statusCode = response.status const data = await response.json() if (statusCode !== 200) { - props.setError(data.error) - return; + props.setError(data.error) + return } setPlayableRaces(data) props.setError(null) @@ -43,7 +43,7 @@ export default function PJCreationMenu (props: PJCreationMenuProps): JSX.Element props.setError('Imposible conectar al servidor para recibir las razas.') }) } - function createPJ(): void { + function createPJ (): void { if (longNameInputRef.current === null) { return } @@ -75,20 +75,21 @@ export default function PJCreationMenu (props: PJCreationMenuProps): JSX.Element } props.setError(null) props.setUserWantsToCreatePJ(false) + const pjs = await fetchMyPjs(props.setError) + props.setPJs(pjs) }).catch((error) => { console.log(error) props.setError('Imposible crear pj, no se pudo conectar al servidor.') - }); + }) } - function renderRaces(): JSX.Element[] { + function renderRaces (): JSX.Element[] { if (playableRaces !== null) { return Object.keys(playableRaces) .map((item, i) => { return - } - ) + }) } return ([]) } diff --git a/js-src/components/pj-list-selection.tsx b/js-src/components/pj-list-selection.tsx index 4503676..c267ed5 100644 --- a/js-src/components/pj-list-selection.tsx +++ b/js-src/components/pj-list-selection.tsx @@ -12,6 +12,7 @@ export default function PJListSelection (props: PJListSelectionProps): JSX.Eleme if (pjs === null) { return ( <> +

Aun no se han descargado los pjs, espera un segundo...

) } diff --git a/js-src/components/pj-selection-menu.tsx b/js-src/components/pj-selection-menu.tsx index 24e5f70..ce534bc 100644 --- a/js-src/components/pj-selection-menu.tsx +++ b/js-src/components/pj-selection-menu.tsx @@ -1,7 +1,8 @@ import * as React from 'react' import PJCreationMenu from '@lastres/components/pj-creation-menu' 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 { setSelectedPJ: (set: PJ | null) => void @@ -22,12 +23,14 @@ export default function PJSelectionMenu (props: PJSelectionMenuProps): JSX.Eleme setSelectedPJ={props.setSelectedPJ} setUserWantsToCreatePJ={props.setUserWantsToCreatePJ} error={props.error} - setError={props.setError}/> + setError={props.setError} + setPJs={setPJs}/> ) } if (pjs === null) { fetchMyPjs(props.setError) - .then((pjs)=> { setPJs(pjs) }) + .then((pjs) => { setPJs(pjs) }) + .catch((error) => { console.log(error) }) } return (
diff --git a/lib/LasTres/Area.pm b/lib/LasTres/Area.pm index 6bc50af..2124ae3 100644 --- a/lib/LasTres/Area.pm +++ b/lib/LasTres/Area.pm @@ -31,6 +31,11 @@ sub frames_to_explore($self) { return 7; } +## OVERRIDE +sub can_explore { + return 1; +} + sub _build_children($self) { my $locations = $self->locations; my @locations = map { $locations->{$_} } keys %$locations; diff --git a/lib/LasTres/Location.pm b/lib/LasTres/Location.pm index 591c846..c3dc523 100644 --- a/lib/LasTres/Location.pm +++ b/lib/LasTres/Location.pm @@ -21,6 +21,26 @@ sub can_visit($self, $pj) { 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.) sub on_team_arrival($self, $team) { $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' })); } - sub show_intro ( $self, $pj ) { $pj->append_log_line( [ diff --git a/public/js/bundle.js b/public/js/bundle.js index 19d0091..4ae655f 100644 --- a/public/js/bundle.js +++ b/public/js/bundle.js @@ -86,7 +86,7 @@ eval("\n\nif (false) {} else {\n module.exports = __webpack_require__(/*! ./cjs \********************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ BottomPanel)\n/* harmony export */ });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n\nfunction BottomPanel() {\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null));\n}\n\n\n//# sourceURL=webpack://LasTres/./js-src/components/bottom-panel.tsx?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ BottomPanel)\n/* harmony export */ });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _lastres_components_presentation_item__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @lastres/components/presentation-item */ \"./js-src/components/presentation-item.tsx\");\n/* harmony import */ var _lastres_components_presentation__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @lastres/components/presentation */ \"./js-src/components/presentation.tsx\");\n\n\n\nfunction BottomPanel() {\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_presentation__WEBPACK_IMPORTED_MODULE_2__[\"default\"], null,\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_presentation_item__WEBPACK_IMPORTED_MODULE_1__[\"default\"], null, \"hola\")));\n}\n\n\n//# sourceURL=webpack://LasTres/./js-src/components/bottom-panel.tsx?"); /***/ }), @@ -96,7 +96,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ Game)\n/* harmony export */ });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _lastres_components_upper_panel__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @lastres/components/upper-panel */ \"./js-src/components/upper-panel.tsx\");\n/* harmony import */ var _lastres_components_bottom_panel__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @lastres/components/bottom-panel */ \"./js-src/components/bottom-panel.tsx\");\n/* harmony import */ var _lastres_components_pj_selection_menu__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @lastres/components/pj-selection-menu */ \"./js-src/components/pj-selection-menu.tsx\");\n/* harmony import */ var _lastres_output_packet_init__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @lastres/output-packet/init */ \"./js-src/output-packet/init.ts\");\n/* harmony import */ var _lastres_output_packet_ping__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @lastres/output-packet/ping */ \"./js-src/output-packet/ping.ts\");\n/* harmony import */ var _lastres_input_packets__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @lastres/input-packets */ \"./js-src/input-packets.ts\");\n\n\n\n\n\n\n\nfunction Game(props) {\n const selectedPJ = props.selectedPJ;\n if (selectedPJ === null) {\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null,\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_pj_selection_menu__WEBPACK_IMPORTED_MODULE_3__[\"default\"], { setSelectedPJ: props.setSelectedPJ, userWantsToCreatePJ: props.userWantsToCreatePJ, setUserWantsToCreatePJ: props.setUserWantsToCreatePJ, error: props.error, setError: props.setError })));\n }\n const [websocket, setWebsocket] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const [teamPJs, setTeamPJs] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const [currentLocation, setCurrentLocation] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const [connectedLocations, setConnectedLocations] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const [logLines, setLogLines] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const [error, setError] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const [scrollLog, setScrollLog] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const logPresentationRef = react__WEBPACK_IMPORTED_MODULE_0__.useRef(null);\n window.setTimeout(() => {\n setWebsocket((websocket) => {\n if (websocket === null) {\n const locationProtocol = window.location.protocol;\n if (locationProtocol == null) {\n return null;\n }\n const protocol = locationProtocol.match(/https:/) != null ? 'wss' : 'ws';\n const webSocket = new WebSocket(`${protocol}://${window.location.host}/ws`);\n webSocket.onopen = () => {\n new _lastres_output_packet_init__WEBPACK_IMPORTED_MODULE_4__[\"default\"](selectedPJ.uuid).send(webSocket);\n let interval = 0;\n interval = window.setInterval(() => {\n if (webSocket.readyState === WebSocket.OPEN) {\n new _lastres_output_packet_ping__WEBPACK_IMPORTED_MODULE_5__[\"default\"]().send(webSocket);\n return;\n }\n window.clearInterval(interval);\n }, 250000);\n };\n const inputPackets = new _lastres_input_packets__WEBPACK_IMPORTED_MODULE_6__[\"default\"](setTeamPJs, setCurrentLocation, setConnectedLocations, logLines, setLogLines, setError, setScrollLog, logPresentationRef);\n webSocket.onmessage = (event) => {\n const packet = JSON.parse(event.data);\n inputPackets.handle(packet);\n };\n webSocket.onerror = (event) => {\n console.log(event);\n };\n return webSocket;\n }\n return websocket;\n });\n }, 100);\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null,\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_upper_panel__WEBPACK_IMPORTED_MODULE_1__[\"default\"], { teamPJs: teamPJs, currentLocation: currentLocation, connectedLocations: connectedLocations, logLines: logLines, websocket: websocket, logPresentationRef: logPresentationRef }),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_bottom_panel__WEBPACK_IMPORTED_MODULE_2__[\"default\"], null)));\n}\n\n\n//# sourceURL=webpack://LasTres/./js-src/components/game.tsx?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ Game)\n/* harmony export */ });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _lastres_components_upper_panel__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @lastres/components/upper-panel */ \"./js-src/components/upper-panel.tsx\");\n/* harmony import */ var _lastres_components_bottom_panel__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @lastres/components/bottom-panel */ \"./js-src/components/bottom-panel.tsx\");\n/* harmony import */ var _lastres_components_pj_selection_menu__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @lastres/components/pj-selection-menu */ \"./js-src/components/pj-selection-menu.tsx\");\n/* harmony import */ var _lastres_output_packet_init__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @lastres/output-packet/init */ \"./js-src/output-packet/init.ts\");\n/* harmony import */ var _lastres_output_packet_ping__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @lastres/output-packet/ping */ \"./js-src/output-packet/ping.ts\");\n/* harmony import */ var _lastres_input_packets__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @lastres/input-packets */ \"./js-src/input-packets.ts\");\n\n\n\n\n\n\n\nfunction Game(props) {\n const selectedPJ = props.selectedPJ;\n if (selectedPJ === null) {\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null,\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_pj_selection_menu__WEBPACK_IMPORTED_MODULE_3__[\"default\"], { setSelectedPJ: props.setSelectedPJ, userWantsToCreatePJ: props.userWantsToCreatePJ, setUserWantsToCreatePJ: props.setUserWantsToCreatePJ, error: props.error, setError: props.setError })));\n }\n const [websocket, setWebsocket] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const [teamPJs, setTeamPJs] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const [currentLocation, setCurrentLocation] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const [connectedLocations, setConnectedLocations] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const [logLines, setLogLines] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const [error, setError] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const [scrollLog, setScrollLog] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const logPresentationRef = react__WEBPACK_IMPORTED_MODULE_0__.useRef(null);\n window.setTimeout(() => {\n setWebsocket((websocket) => {\n if (websocket === null) {\n const locationProtocol = window.location.protocol;\n if (locationProtocol == null) {\n return null;\n }\n const protocol = locationProtocol.match(/https:/) != null ? 'wss' : 'ws';\n const webSocket = new WebSocket(`${protocol}://${window.location.host}/ws`);\n webSocket.onopen = () => {\n new _lastres_output_packet_init__WEBPACK_IMPORTED_MODULE_4__[\"default\"](selectedPJ.uuid).send(webSocket);\n let interval = 0;\n interval = window.setInterval(() => {\n if (webSocket.readyState === WebSocket.OPEN) {\n new _lastres_output_packet_ping__WEBPACK_IMPORTED_MODULE_5__[\"default\"]().send(webSocket);\n return;\n }\n window.clearInterval(interval);\n }, 250000);\n };\n const inputPackets = new _lastres_input_packets__WEBPACK_IMPORTED_MODULE_6__[\"default\"](setTeamPJs, setCurrentLocation, setConnectedLocations, logLines, setLogLines, setError, setScrollLog, logPresentationRef);\n webSocket.onmessage = (event) => {\n const packet = JSON.parse(event.data);\n inputPackets.handle(packet);\n };\n webSocket.onerror = (event) => {\n console.log(event);\n };\n webSocket.onclose = (event) => {\n setWebsocket(null);\n };\n return webSocket;\n }\n return websocket;\n });\n }, 100);\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null,\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_upper_panel__WEBPACK_IMPORTED_MODULE_1__[\"default\"], { teamPJs: teamPJs, currentLocation: currentLocation, connectedLocations: connectedLocations, logLines: logLines, websocket: websocket, logPresentationRef: logPresentationRef }),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_bottom_panel__WEBPACK_IMPORTED_MODULE_2__[\"default\"], null)));\n}\n\n\n//# sourceURL=webpack://LasTres/./js-src/components/game.tsx?"); /***/ }), @@ -136,7 +136,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ PJCreationMenu)\n/* harmony export */ });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n\nfunction PJCreationMenu(props) {\n const longNameInputRef = react__WEBPACK_IMPORTED_MODULE_0__.useRef(null);\n const shortNameInputRef = react__WEBPACK_IMPORTED_MODULE_0__.useRef(null);\n const nickInputRef = react__WEBPACK_IMPORTED_MODULE_0__.useRef(null);\n const raceSelectRef = react__WEBPACK_IMPORTED_MODULE_0__.useRef(null);\n const [playableRaces, setPlayableRaces] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n if (playableRaces === null) {\n fetch('/races/playable', {\n method: 'GET',\n mode: 'same-origin',\n cache: 'no-cache'\n }).then(async (response) => {\n const statusCode = response.status;\n const data = await response.json();\n if (statusCode !== 200) {\n props.setError(data.error);\n return;\n }\n setPlayableRaces(data);\n props.setError(null);\n }).catch((error) => {\n console.log(error);\n props.setError('Imposible conectar al servidor para recibir las razas.');\n });\n }\n function createPJ() {\n if (longNameInputRef.current === null) {\n return;\n }\n if (shortNameInputRef.current === null) {\n return;\n }\n if (nickInputRef.current === null) {\n return;\n }\n if (raceSelectRef.current === null || raceSelectRef.current.selectedOptions.length < 1) {\n return;\n }\n fetch('/pj/create', {\n method: 'POST',\n mode: 'same-origin',\n cache: 'no-cache',\n body: JSON.stringify({\n full_name: longNameInputRef.current.value,\n short_name: shortNameInputRef.current.value,\n nick: nickInputRef.current.value,\n race: raceSelectRef.current.selectedOptions[0].value\n })\n }).then(async (response) => {\n const statusCode = response.status;\n const data = await response.json();\n if (statusCode !== 200) {\n props.setError(data.error);\n return;\n }\n props.setError(null);\n props.setUserWantsToCreatePJ(false);\n }).catch((error) => {\n console.log(error);\n props.setError('Imposible crear pj, no se pudo conectar al servidor.');\n });\n }\n function renderRaces() {\n if (playableRaces !== null) {\n return Object.keys(playableRaces)\n .map((item, i) => {\n return react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"option\", { key: i, value: playableRaces[item].identifier }, `${playableRaces[item].name_selection} (${playableRaces[item].description})`);\n });\n }\n return ([]);\n }\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null,\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"login-container\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"login-contained\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"h1\", null, \"Crea tu personaje.\"),\n (props.error !== null\n ? (react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"p\", { style: { background: 'red' } }, props.error))\n : (react__WEBPACK_IMPORTED_MODULE_0__.createElement(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null))),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"login-form\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"label\", null, \"Nombre largo. (Se usar\\u00E1 en la historia en situaciones formales)\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"input\", { ref: longNameInputRef, type: \"text\" }),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"label\", null, \"Nombre corto. (Se usar\\u00E1 de forma coloquial)\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"input\", { ref: shortNameInputRef, type: \"text\" }),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"label\", null, \"Apodo. (Se usar\\u00E1 en las conversaciones m\\u00E1s distendidas)\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"input\", { ref: nickInputRef, type: \"text\" }),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"label\", null, \"Raza. (Determina tu localizaci\\u00F3n inicial y tus estad\\u00EDsticas)\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"select\", { ref: raceSelectRef }, renderRaces()),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"width-max-content align-self-end\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"button\", { onClick: createPJ }, \"Crear Personaje\")))))));\n}\n\n\n//# sourceURL=webpack://LasTres/./js-src/components/pj-creation-menu.tsx?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ PJCreationMenu)\n/* harmony export */ });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _lastres_pj__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @lastres/pj */ \"./js-src/pj.ts\");\n\n\nfunction PJCreationMenu(props) {\n const longNameInputRef = react__WEBPACK_IMPORTED_MODULE_0__.useRef(null);\n const shortNameInputRef = react__WEBPACK_IMPORTED_MODULE_0__.useRef(null);\n const nickInputRef = react__WEBPACK_IMPORTED_MODULE_0__.useRef(null);\n const raceSelectRef = react__WEBPACK_IMPORTED_MODULE_0__.useRef(null);\n const [playableRaces, setPlayableRaces] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n if (playableRaces === null) {\n fetch('/races/playable', {\n method: 'GET',\n mode: 'same-origin',\n cache: 'no-cache'\n }).then(async (response) => {\n const statusCode = response.status;\n const data = await response.json();\n if (statusCode !== 200) {\n props.setError(data.error);\n return;\n }\n setPlayableRaces(data);\n props.setError(null);\n }).catch((error) => {\n console.log(error);\n props.setError('Imposible conectar al servidor para recibir las razas.');\n });\n }\n function createPJ() {\n if (longNameInputRef.current === null) {\n return;\n }\n if (shortNameInputRef.current === null) {\n return;\n }\n if (nickInputRef.current === null) {\n return;\n }\n if (raceSelectRef.current === null || raceSelectRef.current.selectedOptions.length < 1) {\n return;\n }\n fetch('/pj/create', {\n method: 'POST',\n mode: 'same-origin',\n cache: 'no-cache',\n body: JSON.stringify({\n full_name: longNameInputRef.current.value,\n short_name: shortNameInputRef.current.value,\n nick: nickInputRef.current.value,\n race: raceSelectRef.current.selectedOptions[0].value\n })\n }).then(async (response) => {\n const statusCode = response.status;\n const data = await response.json();\n if (statusCode !== 200) {\n props.setError(data.error);\n return;\n }\n props.setError(null);\n props.setUserWantsToCreatePJ(false);\n const pjs = await (0,_lastres_pj__WEBPACK_IMPORTED_MODULE_1__.fetchMyPjs)(props.setError);\n props.setPJs(pjs);\n }).catch((error) => {\n console.log(error);\n props.setError('Imposible crear pj, no se pudo conectar al servidor.');\n });\n }\n function renderRaces() {\n if (playableRaces !== null) {\n return Object.keys(playableRaces)\n .map((item, i) => {\n return react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"option\", { key: i, value: playableRaces[item].identifier }, `${playableRaces[item].name_selection} (${playableRaces[item].description})`);\n });\n }\n return ([]);\n }\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null,\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"login-container\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"login-contained\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"h1\", null, \"Crea tu personaje.\"),\n (props.error !== null\n ? (react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"p\", { style: { background: 'red' } }, props.error))\n : (react__WEBPACK_IMPORTED_MODULE_0__.createElement(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null))),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"login-form\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"label\", null, \"Nombre largo. (Se usar\\u00E1 en la historia en situaciones formales)\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"input\", { ref: longNameInputRef, type: \"text\" }),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"label\", null, \"Nombre corto. (Se usar\\u00E1 de forma coloquial)\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"input\", { ref: shortNameInputRef, type: \"text\" }),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"label\", null, \"Apodo. (Se usar\\u00E1 en las conversaciones m\\u00E1s distendidas)\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"input\", { ref: nickInputRef, type: \"text\" }),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"label\", null, \"Raza. (Determina tu localizaci\\u00F3n inicial y tus estad\\u00EDsticas)\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"select\", { ref: raceSelectRef }, renderRaces()),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"width-max-content align-self-end\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"button\", { onClick: createPJ }, \"Crear Personaje\")))))));\n}\n\n\n//# sourceURL=webpack://LasTres/./js-src/components/pj-creation-menu.tsx?"); /***/ }), @@ -166,7 +166,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \*************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ PJListSelection)\n/* harmony export */ });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _lastres_components_pj_health_like_bar__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @lastres/components/pj-health-like-bar */ \"./js-src/components/pj-health-like-bar.tsx\");\n\n\nfunction PJListSelection(props) {\n const pjs = props.pjs;\n if (pjs === null) {\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null));\n }\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, pjs.map((item, i) => react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"a\", { onClick: () => {\n props.setSelectedPJ(item);\n }, href: \"#\", key: i },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"span\", null, item.full_name),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"span\", null, item.short_name),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"span\", null, item.nick),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"label\", { className: \"bar-container\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_pj_health_like_bar__WEBPACK_IMPORTED_MODULE_1__[\"default\"], { value: item.health, max: item.max_health })),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"label\", { className: \"bar-container\" },\n \"Mana\",\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_pj_health_like_bar__WEBPACK_IMPORTED_MODULE_1__[\"default\"], { value: item.mana, max: item.max_mana }))))));\n}\n\n\n//# sourceURL=webpack://LasTres/./js-src/components/pj-list-selection.tsx?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ PJListSelection)\n/* harmony export */ });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _lastres_components_pj_health_like_bar__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @lastres/components/pj-health-like-bar */ \"./js-src/components/pj-health-like-bar.tsx\");\n\n\nfunction PJListSelection(props) {\n const pjs = props.pjs;\n if (pjs === null) {\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null,\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"p\", null, \"Aun no se han descargado los pjs, espera un segundo...\")));\n }\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, pjs.map((item, i) => react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"a\", { onClick: () => {\n props.setSelectedPJ(item);\n }, href: \"#\", key: i },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"span\", null, item.full_name),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"span\", null, item.short_name),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"span\", null, item.nick),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"label\", { className: \"bar-container\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_pj_health_like_bar__WEBPACK_IMPORTED_MODULE_1__[\"default\"], { value: item.health, max: item.max_health })),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"label\", { className: \"bar-container\" },\n \"Mana\",\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_pj_health_like_bar__WEBPACK_IMPORTED_MODULE_1__[\"default\"], { value: item.mana, max: item.max_mana }))))));\n}\n\n\n//# sourceURL=webpack://LasTres/./js-src/components/pj-list-selection.tsx?"); /***/ }), @@ -176,7 +176,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac \*************************************************/ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ PJSelectionMenu)\n/* harmony export */ });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _lastres_components_pj_creation_menu__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @lastres/components/pj-creation-menu */ \"./js-src/components/pj-creation-menu.tsx\");\n/* harmony import */ var _lastres_components_pj_list_selection__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @lastres/components/pj-list-selection */ \"./js-src/components/pj-list-selection.tsx\");\n/* harmony import */ var _lastres_pj__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @lastres/pj */ \"./js-src/pj.ts\");\n\n\n\n\nfunction PJSelectionMenu(props) {\n const [pjs, setPJs] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const createPJ = () => {\n props.setUserWantsToCreatePJ(true);\n };\n if (props.userWantsToCreatePJ) {\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_pj_creation_menu__WEBPACK_IMPORTED_MODULE_1__[\"default\"], { setSelectedPJ: props.setSelectedPJ, setUserWantsToCreatePJ: props.setUserWantsToCreatePJ, error: props.error, setError: props.setError }));\n }\n if (pjs === null) {\n (0,_lastres_pj__WEBPACK_IMPORTED_MODULE_3__.fetchMyPjs)(props.setError)\n .then((pjs) => { setPJs(pjs); });\n }\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"pj-selection-menu\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"pj-selection-menu-container\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"h1\", null, \"L3TDE\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"h2\", null, \"Selecciona un Personaje\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"pj-list\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"a\", { onClick: createPJ, href: \"#\" }, \"Crear un nuevo personaje\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_pj_list_selection__WEBPACK_IMPORTED_MODULE_2__[\"default\"], { setSelectedPJ: props.setSelectedPJ, pjs: pjs })))));\n}\n\n\n//# sourceURL=webpack://LasTres/./js-src/components/pj-selection-menu.tsx?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ PJSelectionMenu)\n/* harmony export */ });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _lastres_components_pj_creation_menu__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @lastres/components/pj-creation-menu */ \"./js-src/components/pj-creation-menu.tsx\");\n/* harmony import */ var _lastres_components_pj_list_selection__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @lastres/components/pj-list-selection */ \"./js-src/components/pj-list-selection.tsx\");\n/* harmony import */ var _lastres_pj__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @lastres/pj */ \"./js-src/pj.ts\");\n\n\n\n\nfunction PJSelectionMenu(props) {\n const [pjs, setPJs] = react__WEBPACK_IMPORTED_MODULE_0__.useState(null);\n const createPJ = () => {\n props.setUserWantsToCreatePJ(true);\n };\n if (props.userWantsToCreatePJ) {\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_pj_creation_menu__WEBPACK_IMPORTED_MODULE_1__[\"default\"], { setSelectedPJ: props.setSelectedPJ, setUserWantsToCreatePJ: props.setUserWantsToCreatePJ, error: props.error, setError: props.setError, setPJs: setPJs }));\n }\n if (pjs === null) {\n (0,_lastres_pj__WEBPACK_IMPORTED_MODULE_3__.fetchMyPjs)(props.setError)\n .then((pjs) => { setPJs(pjs); })\n .catch((error) => { console.log(error); });\n }\n return (react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"pj-selection-menu\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"pj-selection-menu-container\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"h1\", null, \"L3TDE\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"h2\", null, \"Selecciona un Personaje\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"div\", { className: \"pj-list\" },\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(\"a\", { onClick: createPJ, href: \"#\" }, \"Crear un nuevo personaje\"),\n react__WEBPACK_IMPORTED_MODULE_0__.createElement(_lastres_components_pj_list_selection__WEBPACK_IMPORTED_MODULE_2__[\"default\"], { setSelectedPJ: props.setSelectedPJ, pjs: pjs })))));\n}\n\n\n//# sourceURL=webpack://LasTres/./js-src/components/pj-selection-menu.tsx?"); /***/ }),