From 30188a1a76f58894b62f42e76dc57fffe51abc6f Mon Sep 17 00:00:00 2001 From: Sergiotarxz Date: Sun, 14 Jan 2024 04:18:14 +0100 Subject: [PATCH] Completed ability to choose a node as player. --- js-src/conquer/interface/select-team.ts | 33 ++++++++++++++- js-src/conquer/interface/self-player.ts | 9 ++--- js-src/conquer/map-node.ts | 4 ++ js-src/conquer/team.ts | 4 ++ lib/BurguillosInfo.pm | 1 + lib/BurguillosInfo/Controller/UserConquer.pm | 40 +++++++++++++++++++ .../Schema/Result/ConquerUser.pm | 1 + public/css/styles.css | 5 +++ public/css/styles.scss | 6 +++ public/js/bundle.js | 8 ++-- 10 files changed, 101 insertions(+), 10 deletions(-) diff --git a/js-src/conquer/interface/select-team.ts b/js-src/conquer/interface/select-team.ts index 1c0a14b..516955a 100644 --- a/js-src/conquer/interface/select-team.ts +++ b/js-src/conquer/interface/select-team.ts @@ -38,15 +38,46 @@ export default class SelectTeamUI extends AbstractTopBarInterface { const teamDiv = this.getNodeFromTemplateId('conquer-team-to-select-template') const nameParagraph = teamDiv.querySelector('p.conquer-name'); const descriptionParagraph = teamDiv.querySelector('p.conquer-description'); - if (!(nameParagraph instanceof HTMLParagraphElement) || !(descriptionParagraph instanceof HTMLParagraphElement)) { + const submit = teamDiv.querySelector('button.conquer-submit'); + if (!(nameParagraph instanceof HTMLParagraphElement) + || !(descriptionParagraph instanceof HTMLParagraphElement) + || !(submit instanceof HTMLButtonElement)) { Conquer.fail('Select team name inclusive or description container are not correctly defined in template.'); } nameParagraph.innerText = team.getName(); descriptionParagraph.innerText = team.getDescription(); nameParagraph.style.color = team.getColor(); + submit.addEventListener('click', async () => { + this.onSelectTeam(team); + }); this.getForm().append(teamDiv); } + private async onSelectTeam(team: ConquerTeam) { + const urlTeam = new URL('/conquer/user/team', + window.location.protocol + '//' + + window.location.hostname + ':' + + window.location.port); + const response = await fetch(urlTeam, { + method: 'POST', + body: JSON.stringify({ + team: team.getUUID(), + node: this.node.getUUID(), + }), + }); + let responseBody; + try { + responseBody = await response.json(); + if (response.status !== 200) { + console.error(responseBody.error); + return; + } + this.runCallbacks('close') + } catch (error) { + console.error('Error parsing json', error); + } + } + private getForm(): HTMLElement { if (this.form === null) { const form = this.getNodeFromTemplateId('conquer-select-team-list-template') diff --git a/js-src/conquer/interface/self-player.ts b/js-src/conquer/interface/self-player.ts index a568389..515606d 100644 --- a/js-src/conquer/interface/self-player.ts +++ b/js-src/conquer/interface/self-player.ts @@ -104,17 +104,16 @@ export default class SelfPlayerUI extends AbstractTopBarInterface { + ' ve al nodo más cercano para unirte a un equipo.'; return this.userTeamData; } + const spanText = document.createElement('span'); + spanText.innerText = 'Equipo: '; + element.append(spanText); const spanCircle = document.createElement('span'); spanCircle.classList.add('conquer-team-circle'); spanCircle.style.backgroundColor = team.getColor(); element.append(spanCircle); - const spanText = document.createElement('span'); - spanText.innerText = 'Perteneces al equipo: '; - element.append(spanText); const spanTeamName = document.createElement('span'); spanTeamName.style.color = team.getColor(); - spanTeamName.style.backgroundColor = 'white'; - spanTeamName.innerText = team.getName(); + spanTeamName.innerText = ' ' + team.getName(); element.append(spanTeamName); return this.userTeamData; } diff --git a/js-src/conquer/map-node.ts b/js-src/conquer/map-node.ts index 2ea58c7..d510806 100644 --- a/js-src/conquer/map-node.ts +++ b/js-src/conquer/map-node.ts @@ -111,6 +111,10 @@ export default class MapNode { return 'node-' + this.uuid; } + public getUUID(): string { + return this.uuid; + } + public getFeature(): Feature { if (this.feature === null) { this.feature = new Feature({ diff --git a/js-src/conquer/team.ts b/js-src/conquer/team.ts index 62b08f4..1f79803 100644 --- a/js-src/conquer/team.ts +++ b/js-src/conquer/team.ts @@ -17,6 +17,10 @@ export default class ConquerTeam { @JsonProperty() private color: string; + public getUUID(): string { + return this.uuid; + } + public getName(): string { return this.name; } diff --git a/lib/BurguillosInfo.pm b/lib/BurguillosInfo.pm index 21a4d22..8c2f00c 100644 --- a/lib/BurguillosInfo.pm +++ b/lib/BurguillosInfo.pm @@ -93,6 +93,7 @@ sub startup ($self) { $r->get('/conquer')->to('Conquer#index'); $r->put('/conquer/user')->to('UserConquer#create'); $r->get('/conquer/user/team')->to('UserConquer#getSelfTeam'); + $r->post('/conquer/user/team')->to('UserConquer#setTeamForUser'); $r->post('/conquer/user/coordinates')->to('UserConquer#setCoordinates'); $r->get('/conquer/team/')->to('ConquerTeam#get'); $r->put('/conquer/team')->to('ConquerTeam#put'); diff --git a/lib/BurguillosInfo/Controller/UserConquer.pm b/lib/BurguillosInfo/Controller/UserConquer.pm index 3ac3d1a..25b0a0a 100644 --- a/lib/BurguillosInfo/Controller/UserConquer.pm +++ b/lib/BurguillosInfo/Controller/UserConquer.pm @@ -21,6 +21,46 @@ my $username_maximum_chars = 15; my $password_minimum_chars = 8; my $password_maximum_chars = 4096; +sub setTeamForUser($self) { + my $user = $self->current_user; + if (!defined $user) { + return $self->_renderError(401, 'No estás loggeado.'); + } + my $input = $self->_expectJson; + if (!defined $input) { + return; + } + my $node_uuid = $input->{node}; + my $team_uuid = $input->{team}; + my $resultset_team = BurguillosInfo::Schema->Schema->resultset('ConquerTeam'); + my $resultset_node = BurguillosInfo::Schema->Schema->resultset('ConquerNode'); + my @teams = $resultset_team->search({uuid => $team_uuid}); + my @nodes = $resultset_node->search({uuid => $node_uuid}); + if (scalar @teams < 1) { + return $self->render(status => 404, json => { + error => 'No se encontró ese equipo.', + }); + } + if (scalar @nodes < 1) { + return $self->render(status => 404, json => { + error => 'No se encontró este nodo.', + }); + } + my $team = $teams[0]; + my $node = $nodes[0]; + if (!$node->is_near($user)) { + return $self->render(status => 400, json => { + error => 'Estás demasiado lejos del nodo.', + }); + } + $user = $user->get_from_storage; + $user->team_object($team); + $user->update; + return $self->render(json => { + ok => $JSON::true, + }); +} + sub get_self ($self) { my $user = $self->current_user; if ( !defined $user ) { diff --git a/lib/BurguillosInfo/Schema/Result/ConquerUser.pm b/lib/BurguillosInfo/Schema/Result/ConquerUser.pm index bea3831..274f476 100644 --- a/lib/BurguillosInfo/Schema/Result/ConquerUser.pm +++ b/lib/BurguillosInfo/Schema/Result/ConquerUser.pm @@ -83,6 +83,7 @@ sub serialize_to_owner ($self) { }; } __PACKAGE__->set_primary_key('uuid'); +__PACKAGE__->belongs_to('team_object', 'BurguillosInfo::Schema::Result::ConquerTeam', 'team'); __PACKAGE__->add_unique_constraint( "unique_constraint_username", ['username'] ); 1; diff --git a/public/css/styles.css b/public/css/styles.css index 94d997f..79e5e30 100644 --- a/public/css/styles.css +++ b/public/css/styles.css @@ -9,6 +9,11 @@ body { min-height: 100%; width: 100%; height: 100%; } + body span.conquer-team-circle { + display: inline-block; + aspect-ratio: 1 / 1; + height: 1rem; + border-radius: 50%; } body div.conquer-team-to-select { padding: 5px; border-radius: 5px; diff --git a/public/css/styles.scss b/public/css/styles.scss index 700ccd1..1f54087 100644 --- a/public/css/styles.scss +++ b/public/css/styles.scss @@ -17,6 +17,12 @@ html { } body { + span.conquer-team-circle { + display: inline-block; + aspect-ratio: 1 / 1; + height: 1rem; + border-radius: 50%; + } div.conquer-team-to-select { padding: 5px; border-radius: 5px; diff --git a/public/js/bundle.js b/public/js/bundle.js index 4b0aab1..8277675 100644 --- a/public/js/bundle.js +++ b/public/js/bundle.js @@ -177,7 +177,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ SelectTeamUI)\n/* harmony export */ });\n/* harmony import */ var _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @burguillosinfo/conquer */ \"./js-src/conquer/index.ts\");\n/* harmony import */ var _burguillosinfo_conquer_user__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/user */ \"./js-src/conquer/user.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_abstract_top_bar_interface__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/abstract-top-bar-interface */ \"./js-src/conquer/interface/abstract-top-bar-interface.ts\");\n/* harmony import */ var _burguillosinfo_conquer_team__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @burguillosinfo/conquer/team */ \"./js-src/conquer/team.ts\");\n\n\n\n\nclass SelectTeamUI extends _burguillosinfo_conquer_interface_abstract_top_bar_interface__WEBPACK_IMPORTED_MODULE_2__[\"default\"] {\n constructor(node) {\n super();\n this.form = null;\n this.node = node;\n }\n async run() {\n const user = await _burguillosinfo_conquer_user__WEBPACK_IMPORTED_MODULE_1__[\"default\"].getSelfUser();\n if (user === null) {\n this.runCallbacks('close');\n return;\n }\n this.user = user;\n await this.populateTeams();\n this.getForm().classList.remove('conquer-display-none');\n this.getMainNode().append(this.getForm());\n this.getMainNode().classList.remove('conquer-display-none');\n }\n async populateTeams() {\n const teams = await _burguillosinfo_conquer_team__WEBPACK_IMPORTED_MODULE_3__[\"default\"].getTeams();\n for (const team of teams) {\n this.populateTeam(team);\n }\n }\n populateTeam(team) {\n const teamDiv = this.getNodeFromTemplateId('conquer-team-to-select-template');\n const nameParagraph = teamDiv.querySelector('p.conquer-name');\n const descriptionParagraph = teamDiv.querySelector('p.conquer-description');\n if (!(nameParagraph instanceof HTMLParagraphElement) || !(descriptionParagraph instanceof HTMLParagraphElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Select team name inclusive or description container are not correctly defined in template.');\n }\n nameParagraph.innerText = team.getName();\n descriptionParagraph.innerText = team.getDescription();\n nameParagraph.style.color = team.getColor();\n this.getForm().append(teamDiv);\n }\n getForm() {\n if (this.form === null) {\n const form = this.getNodeFromTemplateId('conquer-select-team-list-template');\n this.form = form;\n }\n return this.form;\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/interface/select-team.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ SelectTeamUI)\n/* harmony export */ });\n/* harmony import */ var _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @burguillosinfo/conquer */ \"./js-src/conquer/index.ts\");\n/* harmony import */ var _burguillosinfo_conquer_user__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/user */ \"./js-src/conquer/user.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_abstract_top_bar_interface__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/abstract-top-bar-interface */ \"./js-src/conquer/interface/abstract-top-bar-interface.ts\");\n/* harmony import */ var _burguillosinfo_conquer_team__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @burguillosinfo/conquer/team */ \"./js-src/conquer/team.ts\");\n\n\n\n\nclass SelectTeamUI extends _burguillosinfo_conquer_interface_abstract_top_bar_interface__WEBPACK_IMPORTED_MODULE_2__[\"default\"] {\n constructor(node) {\n super();\n this.form = null;\n this.node = node;\n }\n async run() {\n const user = await _burguillosinfo_conquer_user__WEBPACK_IMPORTED_MODULE_1__[\"default\"].getSelfUser();\n if (user === null) {\n this.runCallbacks('close');\n return;\n }\n this.user = user;\n await this.populateTeams();\n this.getForm().classList.remove('conquer-display-none');\n this.getMainNode().append(this.getForm());\n this.getMainNode().classList.remove('conquer-display-none');\n }\n async populateTeams() {\n const teams = await _burguillosinfo_conquer_team__WEBPACK_IMPORTED_MODULE_3__[\"default\"].getTeams();\n for (const team of teams) {\n this.populateTeam(team);\n }\n }\n populateTeam(team) {\n const teamDiv = this.getNodeFromTemplateId('conquer-team-to-select-template');\n const nameParagraph = teamDiv.querySelector('p.conquer-name');\n const descriptionParagraph = teamDiv.querySelector('p.conquer-description');\n const submit = teamDiv.querySelector('button.conquer-submit');\n if (!(nameParagraph instanceof HTMLParagraphElement)\n || !(descriptionParagraph instanceof HTMLParagraphElement)\n || !(submit instanceof HTMLButtonElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Select team name inclusive or description container are not correctly defined in template.');\n }\n nameParagraph.innerText = team.getName();\n descriptionParagraph.innerText = team.getDescription();\n nameParagraph.style.color = team.getColor();\n submit.addEventListener('click', async () => {\n this.onSelectTeam(team);\n });\n this.getForm().append(teamDiv);\n }\n async onSelectTeam(team) {\n const urlTeam = new URL('/conquer/user/team', window.location.protocol + '//'\n + window.location.hostname + ':'\n + window.location.port);\n const response = await fetch(urlTeam, {\n method: 'POST',\n body: JSON.stringify({\n team: team.getUUID(),\n node: this.node.getUUID(),\n }),\n });\n let responseBody;\n try {\n responseBody = await response.json();\n if (response.status !== 200) {\n console.error(responseBody.error);\n return;\n }\n this.runCallbacks('close');\n }\n catch (error) {\n console.error('Error parsing json', error);\n }\n }\n getForm() {\n if (this.form === null) {\n const form = this.getNodeFromTemplateId('conquer-select-team-list-template');\n this.form = form;\n }\n return this.form;\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/interface/select-team.ts?"); /***/ }), @@ -188,7 +188,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ SelfPlayerUI)\n/* harmony export */ });\n/* harmony import */ var _burguillosinfo_conquer_user__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @burguillosinfo/conquer/user */ \"./js-src/conquer/user.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_abstract_top_bar_interface__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/abstract-top-bar-interface */ \"./js-src/conquer/interface/abstract-top-bar-interface.ts\");\n\n\nclass SelfPlayerUI extends _burguillosinfo_conquer_interface_abstract_top_bar_interface__WEBPACK_IMPORTED_MODULE_1__[\"default\"] {\n constructor(isExplorerModeEnabled) {\n super();\n this.selfPlayer = null;\n this.userWelcome = null;\n this.userTeamData = null;\n this.isExplorerModeEnabled = isExplorerModeEnabled;\n }\n async run() {\n const selfPlayerNode = this.getMainNode();\n const user = await _burguillosinfo_conquer_user__WEBPACK_IMPORTED_MODULE_0__[\"default\"].getSelfUser();\n if (user === null) {\n this.runCallbacks('close');\n return;\n }\n this.selfPlayer = user;\n this.populateWelcome();\n this.populateCreateNodeOption();\n this.populateToggleExplorerModeOption();\n this.populateCreateTeamButton();\n await this.populateUserTeamData();\n selfPlayerNode.classList.remove('conquer-display-none');\n }\n populateToggleExplorerModeOption() {\n const toggleExplorerModeButton = document.createElement('button');\n this.setTextToggleExplorerModeButton(toggleExplorerModeButton);\n toggleExplorerModeButton.addEventListener('click', () => {\n (() => {\n if (this.isExplorerModeEnabled) {\n this.runCallbacks('disable-explorer-mode');\n return;\n }\n this.runCallbacks('enable-explorer-mode');\n })();\n this.runCallbacks('close');\n });\n const toggleExplorerModeInterface = this.generateInterfaceElementCentered();\n toggleExplorerModeInterface.appendChild(toggleExplorerModeButton);\n this.getMainNode().appendChild(toggleExplorerModeInterface);\n }\n populateCreateTeamButton() {\n // Only admins can create teams.\n if (!this.selfPlayer?.isAdmin()) {\n return;\n }\n const createTeamButton = document.createElement('button');\n createTeamButton.innerText = 'Crea un nuevo equipo';\n createTeamButton.addEventListener('click', () => {\n this.runCallbacks('open-create-team');\n this.runCallbacks('close');\n });\n const createTeamButtonInterface = this.generateInterfaceElementCentered();\n createTeamButtonInterface.append(createTeamButton);\n this.getMainNode().appendChild(createTeamButtonInterface);\n }\n setTextToggleExplorerModeButton(button) {\n if (this.isExplorerModeEnabled) {\n button.innerText = 'Desactivar movimiento libre en el mapa.';\n return;\n }\n button.innerText = 'Activar movimiento libre en el mapa.';\n }\n populateCreateNodeOption() {\n // Only admins can create nodes.\n if (!this.selfPlayer?.isAdmin()) {\n return;\n }\n const createNodeButton = document.createElement('button');\n createNodeButton.innerText = 'Crear Nuevo Nodo';\n createNodeButton.addEventListener('click', () => {\n this.runCallbacks('createNodeStart');\n // We close because it is a sensible thing to do.\n this.runCallbacks('close');\n });\n const createNodeButtonInterface = this.generateInterfaceElementCentered();\n createNodeButtonInterface.appendChild(createNodeButton);\n this.getMainNode().appendChild(createNodeButtonInterface);\n }\n async getUserTeamData() {\n if (this.userTeamData !== null) {\n return this.userTeamData;\n }\n const element = document.createElement('p');\n this.userTeamData = element;\n if (this.selfPlayer === null) {\n throw new Error('User still not set');\n }\n const team = await this.selfPlayer.getTeam();\n if (team === null) {\n element.innerText = 'No tienes equipo aun,'\n + ' ve al nodo más cercano para unirte a un equipo.';\n return this.userTeamData;\n }\n const spanCircle = document.createElement('span');\n spanCircle.classList.add('conquer-team-circle');\n spanCircle.style.backgroundColor = team.getColor();\n element.append(spanCircle);\n const spanText = document.createElement('span');\n spanText.innerText = 'Perteneces al equipo: ';\n element.append(spanText);\n const spanTeamName = document.createElement('span');\n spanTeamName.style.color = team.getColor();\n spanTeamName.style.backgroundColor = 'white';\n spanTeamName.innerText = team.getName();\n element.append(spanTeamName);\n return this.userTeamData;\n }\n async populateUserTeamData() {\n const userTeamData = await this.getUserTeamData();\n const userTeamDataInterface = this.generateInterfaceElementCentered();\n userTeamDataInterface.append(userTeamData);\n this.getMainNode().append(userTeamDataInterface);\n }\n populateWelcome() {\n const userWelcome = this.getUserWelcome();\n const userWelcomeInterface = this.generateInterfaceElementCentered();\n userWelcomeInterface.appendChild(userWelcome);\n this.getMainNode().appendChild(userWelcomeInterface);\n }\n getUserWelcome() {\n if (this.userWelcome !== null) {\n return this.userWelcome;\n }\n const element = document.createElement('h2');\n if (this.selfPlayer === null) {\n throw new Error('User still not set');\n }\n element.innerText = `¡Hola, ${this.selfPlayer.getUsername()}!`;\n this.userWelcome = element;\n return this.userWelcome;\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/interface/self-player.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ SelfPlayerUI)\n/* harmony export */ });\n/* harmony import */ var _burguillosinfo_conquer_user__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @burguillosinfo/conquer/user */ \"./js-src/conquer/user.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_abstract_top_bar_interface__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/abstract-top-bar-interface */ \"./js-src/conquer/interface/abstract-top-bar-interface.ts\");\n\n\nclass SelfPlayerUI extends _burguillosinfo_conquer_interface_abstract_top_bar_interface__WEBPACK_IMPORTED_MODULE_1__[\"default\"] {\n constructor(isExplorerModeEnabled) {\n super();\n this.selfPlayer = null;\n this.userWelcome = null;\n this.userTeamData = null;\n this.isExplorerModeEnabled = isExplorerModeEnabled;\n }\n async run() {\n const selfPlayerNode = this.getMainNode();\n const user = await _burguillosinfo_conquer_user__WEBPACK_IMPORTED_MODULE_0__[\"default\"].getSelfUser();\n if (user === null) {\n this.runCallbacks('close');\n return;\n }\n this.selfPlayer = user;\n this.populateWelcome();\n this.populateCreateNodeOption();\n this.populateToggleExplorerModeOption();\n this.populateCreateTeamButton();\n await this.populateUserTeamData();\n selfPlayerNode.classList.remove('conquer-display-none');\n }\n populateToggleExplorerModeOption() {\n const toggleExplorerModeButton = document.createElement('button');\n this.setTextToggleExplorerModeButton(toggleExplorerModeButton);\n toggleExplorerModeButton.addEventListener('click', () => {\n (() => {\n if (this.isExplorerModeEnabled) {\n this.runCallbacks('disable-explorer-mode');\n return;\n }\n this.runCallbacks('enable-explorer-mode');\n })();\n this.runCallbacks('close');\n });\n const toggleExplorerModeInterface = this.generateInterfaceElementCentered();\n toggleExplorerModeInterface.appendChild(toggleExplorerModeButton);\n this.getMainNode().appendChild(toggleExplorerModeInterface);\n }\n populateCreateTeamButton() {\n // Only admins can create teams.\n if (!this.selfPlayer?.isAdmin()) {\n return;\n }\n const createTeamButton = document.createElement('button');\n createTeamButton.innerText = 'Crea un nuevo equipo';\n createTeamButton.addEventListener('click', () => {\n this.runCallbacks('open-create-team');\n this.runCallbacks('close');\n });\n const createTeamButtonInterface = this.generateInterfaceElementCentered();\n createTeamButtonInterface.append(createTeamButton);\n this.getMainNode().appendChild(createTeamButtonInterface);\n }\n setTextToggleExplorerModeButton(button) {\n if (this.isExplorerModeEnabled) {\n button.innerText = 'Desactivar movimiento libre en el mapa.';\n return;\n }\n button.innerText = 'Activar movimiento libre en el mapa.';\n }\n populateCreateNodeOption() {\n // Only admins can create nodes.\n if (!this.selfPlayer?.isAdmin()) {\n return;\n }\n const createNodeButton = document.createElement('button');\n createNodeButton.innerText = 'Crear Nuevo Nodo';\n createNodeButton.addEventListener('click', () => {\n this.runCallbacks('createNodeStart');\n // We close because it is a sensible thing to do.\n this.runCallbacks('close');\n });\n const createNodeButtonInterface = this.generateInterfaceElementCentered();\n createNodeButtonInterface.appendChild(createNodeButton);\n this.getMainNode().appendChild(createNodeButtonInterface);\n }\n async getUserTeamData() {\n if (this.userTeamData !== null) {\n return this.userTeamData;\n }\n const element = document.createElement('p');\n this.userTeamData = element;\n if (this.selfPlayer === null) {\n throw new Error('User still not set');\n }\n const team = await this.selfPlayer.getTeam();\n if (team === null) {\n element.innerText = 'No tienes equipo aun,'\n + ' ve al nodo más cercano para unirte a un equipo.';\n return this.userTeamData;\n }\n const spanText = document.createElement('span');\n spanText.innerText = 'Equipo: ';\n element.append(spanText);\n const spanCircle = document.createElement('span');\n spanCircle.classList.add('conquer-team-circle');\n spanCircle.style.backgroundColor = team.getColor();\n element.append(spanCircle);\n const spanTeamName = document.createElement('span');\n spanTeamName.style.color = team.getColor();\n spanTeamName.innerText = ' ' + team.getName();\n element.append(spanTeamName);\n return this.userTeamData;\n }\n async populateUserTeamData() {\n const userTeamData = await this.getUserTeamData();\n const userTeamDataInterface = this.generateInterfaceElementCentered();\n userTeamDataInterface.append(userTeamData);\n this.getMainNode().append(userTeamDataInterface);\n }\n populateWelcome() {\n const userWelcome = this.getUserWelcome();\n const userWelcomeInterface = this.generateInterfaceElementCentered();\n userWelcomeInterface.appendChild(userWelcome);\n this.getMainNode().appendChild(userWelcomeInterface);\n }\n getUserWelcome() {\n if (this.userWelcome !== null) {\n return this.userWelcome;\n }\n const element = document.createElement('h2');\n if (this.selfPlayer === null) {\n throw new Error('User still not set');\n }\n element.innerText = `¡Hola, ${this.selfPlayer.getUsername()}!`;\n this.userWelcome = element;\n return this.userWelcome;\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/interface/self-player.ts?"); /***/ }), @@ -210,7 +210,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! typescript-json-serializer */ \"./node_modules/typescript-json-serializer/dist/index.esm.js\");\n/* harmony import */ var ol_style_Style__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ol/style/Style */ \"./node_modules/ol/style/Style.js\");\n/* harmony import */ var ol_Feature__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ol/Feature */ \"./node_modules/ol/Feature.js\");\n/* harmony import */ var ol_style_Circle__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ol/style/Circle */ \"./node_modules/ol/style/Circle.js\");\n/* harmony import */ var ol_geom_Point__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ol/geom/Point */ \"./node_modules/ol/geom/Point.js\");\n/* harmony import */ var ol_style_Fill__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ol/style/Fill */ \"./node_modules/ol/style/Fill.js\");\n/* harmony import */ var ol_style_Stroke__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ol/style/Stroke */ \"./node_modules/ol/style/Stroke.js\");\n/* harmony import */ var _burguillosinfo_conquer_interface_node_view__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/node-view */ \"./js-src/conquer/interface/node-view.ts\");\n/* harmony import */ var _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer/serializer */ \"./js-src/conquer/serializer.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_select_team__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/select-team */ \"./js-src/conquer/interface/select-team.ts\");\nvar __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __metadata = (undefined && undefined.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};\nvar __param = (undefined && undefined.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};\nvar MapNode_1;\n\n\n\n\n\n\n\n\n\n\nlet MapNode = MapNode_1 = class MapNode {\n constructor(uuid, coordinate_1, coordinate_2, type, name, description, kind, is_near) {\n this.uuid = uuid;\n this.coordinate_1 = coordinate_1;\n this.coordinate_2 = coordinate_2;\n this.type = type;\n this.name = name;\n this.description = description;\n this.kind = kind;\n this.is_near = is_near;\n this.feature = null;\n this.callbacks = {};\n }\n async fetch() {\n const urlNode = new URL('/conquer/node/' + this.uuid, window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n const response = await fetch(urlNode);\n let responseBody;\n const errorThrow = new Error('Unable to fetch node updated.');\n try {\n responseBody = await response.json();\n }\n catch (error) {\n console.error('Error parseando json: ' + responseBody);\n console.error(error);\n throw errorThrow;\n }\n if (response.status !== 200) {\n console.error(responseBody.error);\n throw errorThrow;\n }\n const node = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_2__[\"default\"].deserialize(responseBody, MapNode_1);\n if (!(node instanceof MapNode_1)) {\n console.error('Unexpected JSON value for MapNode.');\n throw errorThrow;\n }\n return node;\n }\n click(interfaceManager) {\n const viewNodeInterface = new _burguillosinfo_conquer_interface_node_view__WEBPACK_IMPORTED_MODULE_1__[\"default\"](this);\n viewNodeInterface.on('close', () => {\n interfaceManager.remove(viewNodeInterface);\n });\n viewNodeInterface.on('update-nodes', () => {\n this.runCallbacks('update-nodes');\n });\n viewNodeInterface.on('open-select-team', () => {\n this.openSelectTeam(interfaceManager);\n });\n interfaceManager.push(viewNodeInterface);\n this.runCallbacks('click');\n }\n openSelectTeam(interfaceManager) {\n const selectTeamUI = new _burguillosinfo_conquer_interface_select_team__WEBPACK_IMPORTED_MODULE_3__[\"default\"](this);\n selectTeamUI.on('close', () => {\n interfaceManager.remove(selectTeamUI);\n });\n interfaceManager.push(selectTeamUI);\n }\n on(eventName, callback) {\n if (this.callbacks[eventName] === undefined) {\n this.callbacks[eventName] = [];\n }\n this.callbacks[eventName].push(callback);\n }\n runCallbacks(eventName) {\n const callbacks = this.callbacks[eventName];\n if (callbacks === undefined) {\n return;\n }\n for (const callback of callbacks) {\n callback();\n }\n }\n getType() {\n return this.type;\n }\n isNear() {\n return this.is_near;\n }\n getName() {\n return this.name;\n }\n getDescription() {\n return this.description;\n }\n getId() {\n return 'node-' + this.uuid;\n }\n getFeature() {\n if (this.feature === null) {\n this.feature = new ol_Feature__WEBPACK_IMPORTED_MODULE_4__[\"default\"]({\n geometry: new ol_geom_Point__WEBPACK_IMPORTED_MODULE_5__[\"default\"]([this.coordinate_1, this.coordinate_2]),\n type: 'node-' + this.uuid,\n });\n }\n return this.feature;\n }\n getStyle() {\n return new ol_style_Style__WEBPACK_IMPORTED_MODULE_6__[\"default\"]({\n image: new ol_style_Circle__WEBPACK_IMPORTED_MODULE_7__[\"default\"]({\n radius: 14,\n fill: new ol_style_Fill__WEBPACK_IMPORTED_MODULE_8__[\"default\"]({ color: 'white' }),\n stroke: new ol_style_Stroke__WEBPACK_IMPORTED_MODULE_9__[\"default\"]({\n color: 'gray',\n width: 2,\n })\n })\n });\n }\n};\nMapNode = MapNode_1 = __decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonObject)(),\n __param(0, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(1, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(2, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(3, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(4, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(5, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(6, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(7, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __metadata(\"design:paramtypes\", [String, Number, Number, String, String, String, String, Boolean])\n], MapNode);\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (MapNode);\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/map-node.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! typescript-json-serializer */ \"./node_modules/typescript-json-serializer/dist/index.esm.js\");\n/* harmony import */ var ol_style_Style__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ol/style/Style */ \"./node_modules/ol/style/Style.js\");\n/* harmony import */ var ol_Feature__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ol/Feature */ \"./node_modules/ol/Feature.js\");\n/* harmony import */ var ol_style_Circle__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ol/style/Circle */ \"./node_modules/ol/style/Circle.js\");\n/* harmony import */ var ol_geom_Point__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ol/geom/Point */ \"./node_modules/ol/geom/Point.js\");\n/* harmony import */ var ol_style_Fill__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ol/style/Fill */ \"./node_modules/ol/style/Fill.js\");\n/* harmony import */ var ol_style_Stroke__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ol/style/Stroke */ \"./node_modules/ol/style/Stroke.js\");\n/* harmony import */ var _burguillosinfo_conquer_interface_node_view__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/node-view */ \"./js-src/conquer/interface/node-view.ts\");\n/* harmony import */ var _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer/serializer */ \"./js-src/conquer/serializer.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_select_team__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/select-team */ \"./js-src/conquer/interface/select-team.ts\");\nvar __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __metadata = (undefined && undefined.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};\nvar __param = (undefined && undefined.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};\nvar MapNode_1;\n\n\n\n\n\n\n\n\n\n\nlet MapNode = MapNode_1 = class MapNode {\n constructor(uuid, coordinate_1, coordinate_2, type, name, description, kind, is_near) {\n this.uuid = uuid;\n this.coordinate_1 = coordinate_1;\n this.coordinate_2 = coordinate_2;\n this.type = type;\n this.name = name;\n this.description = description;\n this.kind = kind;\n this.is_near = is_near;\n this.feature = null;\n this.callbacks = {};\n }\n async fetch() {\n const urlNode = new URL('/conquer/node/' + this.uuid, window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n const response = await fetch(urlNode);\n let responseBody;\n const errorThrow = new Error('Unable to fetch node updated.');\n try {\n responseBody = await response.json();\n }\n catch (error) {\n console.error('Error parseando json: ' + responseBody);\n console.error(error);\n throw errorThrow;\n }\n if (response.status !== 200) {\n console.error(responseBody.error);\n throw errorThrow;\n }\n const node = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_2__[\"default\"].deserialize(responseBody, MapNode_1);\n if (!(node instanceof MapNode_1)) {\n console.error('Unexpected JSON value for MapNode.');\n throw errorThrow;\n }\n return node;\n }\n click(interfaceManager) {\n const viewNodeInterface = new _burguillosinfo_conquer_interface_node_view__WEBPACK_IMPORTED_MODULE_1__[\"default\"](this);\n viewNodeInterface.on('close', () => {\n interfaceManager.remove(viewNodeInterface);\n });\n viewNodeInterface.on('update-nodes', () => {\n this.runCallbacks('update-nodes');\n });\n viewNodeInterface.on('open-select-team', () => {\n this.openSelectTeam(interfaceManager);\n });\n interfaceManager.push(viewNodeInterface);\n this.runCallbacks('click');\n }\n openSelectTeam(interfaceManager) {\n const selectTeamUI = new _burguillosinfo_conquer_interface_select_team__WEBPACK_IMPORTED_MODULE_3__[\"default\"](this);\n selectTeamUI.on('close', () => {\n interfaceManager.remove(selectTeamUI);\n });\n interfaceManager.push(selectTeamUI);\n }\n on(eventName, callback) {\n if (this.callbacks[eventName] === undefined) {\n this.callbacks[eventName] = [];\n }\n this.callbacks[eventName].push(callback);\n }\n runCallbacks(eventName) {\n const callbacks = this.callbacks[eventName];\n if (callbacks === undefined) {\n return;\n }\n for (const callback of callbacks) {\n callback();\n }\n }\n getType() {\n return this.type;\n }\n isNear() {\n return this.is_near;\n }\n getName() {\n return this.name;\n }\n getDescription() {\n return this.description;\n }\n getId() {\n return 'node-' + this.uuid;\n }\n getUUID() {\n return this.uuid;\n }\n getFeature() {\n if (this.feature === null) {\n this.feature = new ol_Feature__WEBPACK_IMPORTED_MODULE_4__[\"default\"]({\n geometry: new ol_geom_Point__WEBPACK_IMPORTED_MODULE_5__[\"default\"]([this.coordinate_1, this.coordinate_2]),\n type: 'node-' + this.uuid,\n });\n }\n return this.feature;\n }\n getStyle() {\n return new ol_style_Style__WEBPACK_IMPORTED_MODULE_6__[\"default\"]({\n image: new ol_style_Circle__WEBPACK_IMPORTED_MODULE_7__[\"default\"]({\n radius: 14,\n fill: new ol_style_Fill__WEBPACK_IMPORTED_MODULE_8__[\"default\"]({ color: 'white' }),\n stroke: new ol_style_Stroke__WEBPACK_IMPORTED_MODULE_9__[\"default\"]({\n color: 'gray',\n width: 2,\n })\n })\n });\n }\n};\nMapNode = MapNode_1 = __decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonObject)(),\n __param(0, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(1, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(2, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(3, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(4, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(5, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(6, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(7, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __metadata(\"design:paramtypes\", [String, Number, Number, String, String, String, String, Boolean])\n], MapNode);\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (MapNode);\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/map-node.ts?"); /***/ }), @@ -243,7 +243,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @burguillosinfo/conquer/serializer */ \"./js-src/conquer/serializer.ts\");\n/* harmony import */ var typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! typescript-json-serializer */ \"./node_modules/typescript-json-serializer/dist/index.esm.js\");\n/* harmony import */ var _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer */ \"./js-src/conquer/index.ts\");\nvar __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __metadata = (undefined && undefined.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};\nvar ConquerTeam_1;\n\n\n\nlet ConquerTeam = ConquerTeam_1 = class ConquerTeam {\n getName() {\n return this.name;\n }\n getDescription() {\n return this.description;\n }\n getColor() {\n return this.color;\n }\n constructor(uuid, name, description, points, color) {\n this.kind = 'ConquerTeam';\n this.uuid = uuid;\n this.name = name;\n this.description = description;\n this.points = points;\n this.color = color;\n }\n static async getTeams() {\n const urlTeam = new URL('/conquer/teams', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n try {\n const response = await fetch(urlTeam);\n if (response.status !== 200) {\n throw new Error('Invalid response fetching teams.');\n }\n const teamData = await response.json();\n const teams = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].deserialize(teamData, ConquerTeam_1);\n if (teams === undefined || teams === null) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_2__[\"default\"].fail('Teams cannot be null, server error.');\n }\n if (!(teams instanceof Array)) {\n throw new Error('Unable to parse team.');\n }\n const teamsSanitized = [];\n for (const team of teams) {\n if (!(team instanceof ConquerTeam_1)) {\n console.error('Received null team from server, fix this error.');\n continue;\n }\n teamsSanitized.push(team);\n }\n return teamsSanitized;\n }\n catch (error) {\n console.error(error);\n throw new Error('Unable to fetch Teams.');\n }\n }\n static async getTeam(uuid) {\n const urlTeam = new URL('/conquer/team/' + uuid, window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n try {\n const response = await fetch(urlTeam);\n if (response.status !== 200) {\n throw new Error('Invalid response fetching team.');\n }\n const teamData = await response.json();\n let team = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].deserialize(teamData, ConquerTeam_1);\n if (team === undefined) {\n team = null;\n }\n if (!(team instanceof ConquerTeam_1)) {\n throw new Error('Unable to parse team.');\n }\n return team;\n }\n catch (error) {\n console.error(error);\n throw new Error('Unable to fetch Team.');\n }\n }\n static async getSelfTeam() {\n const urlTeam = new URL('/conquer/user/team', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n try {\n const response = await fetch(urlTeam);\n if (response.status !== 200) {\n throw new Error('Invalid response fetching team.');\n }\n const teamData = await response.json();\n let team = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].deserialize(teamData, ConquerTeam_1);\n if (team === undefined) {\n team = null;\n }\n if (team !== null && !(team instanceof ConquerTeam_1)) {\n throw new Error('Unable to parse team.');\n }\n return team;\n }\n catch (error) {\n console.error(error);\n throw new Error('Unable to fetch Team.');\n }\n }\n};\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerTeam.prototype, \"kind\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerTeam.prototype, \"uuid\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerTeam.prototype, \"name\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerTeam.prototype, \"description\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", Number)\n], ConquerTeam.prototype, \"points\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerTeam.prototype, \"color\", void 0);\nConquerTeam = ConquerTeam_1 = __decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonObject)(),\n __metadata(\"design:paramtypes\", [String, String, String, Number, String])\n], ConquerTeam);\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ConquerTeam);\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/team.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @burguillosinfo/conquer/serializer */ \"./js-src/conquer/serializer.ts\");\n/* harmony import */ var typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! typescript-json-serializer */ \"./node_modules/typescript-json-serializer/dist/index.esm.js\");\n/* harmony import */ var _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer */ \"./js-src/conquer/index.ts\");\nvar __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __metadata = (undefined && undefined.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};\nvar ConquerTeam_1;\n\n\n\nlet ConquerTeam = ConquerTeam_1 = class ConquerTeam {\n getUUID() {\n return this.uuid;\n }\n getName() {\n return this.name;\n }\n getDescription() {\n return this.description;\n }\n getColor() {\n return this.color;\n }\n constructor(uuid, name, description, points, color) {\n this.kind = 'ConquerTeam';\n this.uuid = uuid;\n this.name = name;\n this.description = description;\n this.points = points;\n this.color = color;\n }\n static async getTeams() {\n const urlTeam = new URL('/conquer/teams', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n try {\n const response = await fetch(urlTeam);\n if (response.status !== 200) {\n throw new Error('Invalid response fetching teams.');\n }\n const teamData = await response.json();\n const teams = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].deserialize(teamData, ConquerTeam_1);\n if (teams === undefined || teams === null) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_2__[\"default\"].fail('Teams cannot be null, server error.');\n }\n if (!(teams instanceof Array)) {\n throw new Error('Unable to parse team.');\n }\n const teamsSanitized = [];\n for (const team of teams) {\n if (!(team instanceof ConquerTeam_1)) {\n console.error('Received null team from server, fix this error.');\n continue;\n }\n teamsSanitized.push(team);\n }\n return teamsSanitized;\n }\n catch (error) {\n console.error(error);\n throw new Error('Unable to fetch Teams.');\n }\n }\n static async getTeam(uuid) {\n const urlTeam = new URL('/conquer/team/' + uuid, window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n try {\n const response = await fetch(urlTeam);\n if (response.status !== 200) {\n throw new Error('Invalid response fetching team.');\n }\n const teamData = await response.json();\n let team = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].deserialize(teamData, ConquerTeam_1);\n if (team === undefined) {\n team = null;\n }\n if (!(team instanceof ConquerTeam_1)) {\n throw new Error('Unable to parse team.');\n }\n return team;\n }\n catch (error) {\n console.error(error);\n throw new Error('Unable to fetch Team.');\n }\n }\n static async getSelfTeam() {\n const urlTeam = new URL('/conquer/user/team', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n try {\n const response = await fetch(urlTeam);\n if (response.status !== 200) {\n throw new Error('Invalid response fetching team.');\n }\n const teamData = await response.json();\n let team = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].deserialize(teamData, ConquerTeam_1);\n if (team === undefined) {\n team = null;\n }\n if (team !== null && !(team instanceof ConquerTeam_1)) {\n throw new Error('Unable to parse team.');\n }\n return team;\n }\n catch (error) {\n console.error(error);\n throw new Error('Unable to fetch Team.');\n }\n }\n};\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerTeam.prototype, \"kind\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerTeam.prototype, \"uuid\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerTeam.prototype, \"name\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerTeam.prototype, \"description\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", Number)\n], ConquerTeam.prototype, \"points\", void 0);\n__decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonProperty)(),\n __metadata(\"design:type\", String)\n], ConquerTeam.prototype, \"color\", void 0);\nConquerTeam = ConquerTeam_1 = __decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_1__.JsonObject)(),\n __metadata(\"design:paramtypes\", [String, String, String, Number, String])\n], ConquerTeam);\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ConquerTeam);\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/team.ts?"); /***/ }),