From ed48de1c385798273270abfae5b8d1ad50b8a8ca Mon Sep 17 00:00:00 2001 From: Sergiotarxz Date: Sat, 13 Jan 2024 19:59:11 +0100 Subject: [PATCH] Creating the create team interface. --- js-src/conquer/index.ts | 13 ++- js-src/conquer/interface/login.ts | 1 - js-src/conquer/interface/new-team.ts | 97 +++++++++++++++++++ js-src/conquer/interface/self-player.ts | 18 ++++ js-src/conquer/map-node.ts | 2 - public/js/bundle.js | 19 +++- .../_new-team-form-creation-template.html.ep | 18 ++++ templates/conquer/index.html.ep | 2 + 8 files changed, 162 insertions(+), 8 deletions(-) create mode 100644 js-src/conquer/interface/new-team.ts create mode 100644 templates/conquer/_new-team-form-creation-template.html.ep diff --git a/js-src/conquer/index.ts b/js-src/conquer/index.ts index 085a231..75fef9c 100644 --- a/js-src/conquer/index.ts +++ b/js-src/conquer/index.ts @@ -21,6 +21,7 @@ import CreateNode from '@burguillosinfo/conquer/create-node' import MapState from '@burguillosinfo/conquer/map-state' import MapNode from '@burguillosinfo/conquer/map-node' import NewNodeUI from '@burguillosinfo/conquer/interface/new-node' +import NewTeamUI from '@burguillosinfo/conquer/interface/new-team' import WebSocket from '@burguillosinfo/conquer/websocket' import JsonSerializer from '@burguillosinfo/conquer/serializer'; @@ -182,7 +183,6 @@ export default class Conquer { this.interfaceManager.remove(selfPlayerUI) }) selfPlayerUI.on('enable-explorer-mode', () => { - console.log('hola') this.addState(MapState.FREE_MOVE); this.addState(MapState.FREE_ROTATION); }); @@ -194,10 +194,21 @@ export default class Conquer { this.addState(MapState.CREATE_NODE) this.removeState(MapState.NORMAL) }) + selfPlayerUI.on('open-create-team', () => { + this.onOpenCreateTeam(); + }); this.interfaceManager.push(selfPlayerUI) this.selfPlayerUI = selfPlayerUI } + private onOpenCreateTeam(): void { + const newTeamUI = new NewTeamUI(); + newTeamUI.on('close', () => { + this.interfaceManager.remove(newTeamUI); + }); + this.interfaceManager.push(newTeamUI); + } + private isFeatureEnabledMap: Record = {} async onClickFeature(feature: Feature): Promise { diff --git a/js-src/conquer/interface/login.ts b/js-src/conquer/interface/login.ts index bcc55d3..c727d74 100644 --- a/js-src/conquer/interface/login.ts +++ b/js-src/conquer/interface/login.ts @@ -150,7 +150,6 @@ export default class LoginUI extends ConquerInterface { Conquer.fail('Unable to find the submit button for the login.') } this.conquerLoginSubmit = conquerLoginSubmit - console.log(this.conquerLoginSubmit.parentNode?.parentNode) this.conquerLoginSubmit.addEventListener('click', (event: Event) => { event.preventDefault() const username = this.conquerLoginUsername.value diff --git a/js-src/conquer/interface/new-team.ts b/js-src/conquer/interface/new-team.ts new file mode 100644 index 0000000..fc94e5e --- /dev/null +++ b/js-src/conquer/interface/new-team.ts @@ -0,0 +1,97 @@ +import AbstractTopBarInterface from '@burguillosinfo/conquer/interface/abstract-top-bar-interface' +import Conquer from '@burguillosinfo/conquer' + +export default class NewTeamUI extends AbstractTopBarInterface { + public getSubmitButton(): HTMLElement { + const submitButton = this.getMainNode().querySelector('button.new-team-form-submit') + if (submitButton === null || !(submitButton instanceof HTMLElement)) { + Conquer.fail('SubmitButton is null'); + } + return submitButton; + } + public getErrorElement(): HTMLElement { + const errorElement = this.getMainNode().querySelector('p.conquer-error'); + if (errorElement === null || !(errorElement instanceof HTMLElement)) { + Conquer.fail('No error element set'); + } + return errorElement; + } + public getInputTeamName(): HTMLInputElement { + const teamName = this.getMainNode().querySelector('input.conquer-team-name'); + if (teamName === null || !(teamName instanceof HTMLInputElement)) { + Conquer.fail('TeamName is null'); + } + return teamName; + } + public getInputTeamColor(): HTMLInputElement { + const teamColor = this.getMainNode().querySelector('input.conquer-team-color'); + if (teamColor === null || !(teamColor instanceof HTMLInputElement)) { + Conquer.fail('TeamColor is null'); + } + return teamColor; + } + public getTextareaTeamDescription(): HTMLTextAreaElement { + const teamDescription = this.getMainNode().querySelector('textarea.conquer-team-description') + if (teamDescription === null || !(teamDescription instanceof HTMLTextAreaElement)) { + Conquer.fail('TeamDescription is null'); + } + return teamDescription + } + + constructor() { + super() + } + + public run() { + const mainNode = this.getMainNode() + const form = this.getNodeFromTemplateId('conquer-new-team-form-creation-template') + mainNode.append(form) + this.getSubmitButton().addEventListener('click', (event) => { + event.preventDefault(); + this.onSubmit(); + }); + form.classList.remove('conquer-display-none') + mainNode.classList.remove('conquer-display-none') + } + + private setError(error: string): void { + const errorElement = this.getErrorElement(); + errorElement.classList.remove('conquer-display-none') + errorElement.innerText = error + } + + private onSubmit(): void { + const inputTeamName = this.getInputTeamName(); + const textareaTeamDescription = this.getTextareaTeamDescription(); + const inputTeamColor = this.getInputTeamColor(); + const name = inputTeamName.value; + const description = textareaTeamDescription.value; + const color = inputTeamColor.value; + if (name.length < 5) { + this.setError('Todos los equipos deben tener un nombre mayor a 4 caracteres.'); + return; + } + const urlTeam = new URL('/conquer/team', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port) + fetch(urlTeam, { + method: 'PUT', + body: JSON.stringify({ + description : description, + name : name, + color : color, + }), + }).then(async (res) => { + let responseBody; + try { + responseBody = await res.json(); + } catch (error) { + this.setError( 'Respuesta erronea del servidor.'); + return; + } + if (res.status !== 200) { + this.setError(responseBody.error); + return; + } + this.runCallbacks('close') + }); + } +} diff --git a/js-src/conquer/interface/self-player.ts b/js-src/conquer/interface/self-player.ts index fabe848..451efe8 100644 --- a/js-src/conquer/interface/self-player.ts +++ b/js-src/conquer/interface/self-player.ts @@ -33,6 +33,7 @@ export default class SelfPlayerUI extends AbstractTopBarInterface { this.populateWelcome() this.populateCreateNodeOption() this.populateToggleExplorerModeOption(); + this.populateCreateTeamButton(); await this.populateUserTeamData(); selfPlayerNode.classList.remove('conquer-display-none') } @@ -56,6 +57,22 @@ export default class SelfPlayerUI extends AbstractTopBarInterface { } + private populateCreateTeamButton(): void { + // Only admins can create teams. + if (!this.selfPlayer?.isAdmin()) { + return; + } + const createTeamButton = document.createElement('button'); + createTeamButton.innerText = 'Crea un nuevo equipo'; + createTeamButton.addEventListener('click', () => { + this.runCallbacks('open-create-team'); + this.runCallbacks('close'); + }); + const createTeamButtonInterface = this.generateInterfaceElementCentered() + createTeamButtonInterface.append(createTeamButton); + this.getMainNode().appendChild(createTeamButtonInterface); + } + private setTextToggleExplorerModeButton(button: HTMLElement): void { if (this.isExplorerModeEnabled) { button.innerText = 'Desactivar movimiento libre en el mapa.'; @@ -65,6 +82,7 @@ export default class SelfPlayerUI extends AbstractTopBarInterface { } private populateCreateNodeOption() { + // Only admins can create nodes. if (!this.selfPlayer?.isAdmin()) { return } diff --git a/js-src/conquer/map-node.ts b/js-src/conquer/map-node.ts index 1e25638..e86bfd6 100644 --- a/js-src/conquer/map-node.ts +++ b/js-src/conquer/map-node.ts @@ -101,8 +101,6 @@ export default class MapNode { public getFeature(): Feature { if (this.feature === null) { - console.log(this.coordinate_1); - console.log(this.coordinate_2); this.feature = new Feature({ geometry: new Point([this.coordinate_1, this.coordinate_2]), type: 'node-' + this.uuid, diff --git a/public/js/bundle.js b/public/js/bundle.js index e5a8894..d185440 100644 --- a/public/js/bundle.js +++ b/public/js/bundle.js @@ -89,7 +89,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 */ Conquer)\n/* harmony export */ });\n/* harmony import */ var ol_Map__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ol/Map */ \"./node_modules/ol/Map.js\");\n/* harmony import */ var ol_MapBrowserEvent__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ol/MapBrowserEvent */ \"./node_modules/ol/MapBrowserEvent.js\");\n/* harmony import */ var ol_View__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ol/View */ \"./node_modules/ol/View.js\");\n/* harmony import */ var ol_proj_Projection_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ol/proj/Projection.js */ \"./node_modules/ol/proj/Projection.js\");\n/* harmony import */ var ol_layer_Tile__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ol/layer/Tile */ \"./node_modules/ol/layer/Tile.js\");\n/* harmony import */ var ol_source_OSM__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ol/source/OSM */ \"./node_modules/ol/source/OSM.js\");\n/* harmony import */ var ol_proj__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ol/proj */ \"./node_modules/ol/proj.js\");\n/* harmony import */ var ol_Feature__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ol/Feature */ \"./node_modules/ol/Feature.js\");\n/* harmony import */ var ol_geom_Point__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ol/geom/Point */ \"./node_modules/ol/geom/Point.js\");\n/* harmony import */ var ol_layer_Vector__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ol/layer/Vector */ \"./node_modules/ol/layer/Vector.js\");\n/* harmony import */ var ol_source_Vector__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ol/source/Vector */ \"./node_modules/ol/source/Vector.js\");\n/* harmony import */ var ol_style_Stroke__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ol/style/Stroke */ \"./node_modules/ol/style/Stroke.js\");\n/* harmony import */ var ol_style_Fill__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ol/style/Fill */ \"./node_modules/ol/style/Fill.js\");\n/* harmony import */ var ol_style_Circle__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ol/style/Circle */ \"./node_modules/ol/style/Circle.js\");\n/* harmony import */ var ol_style_Style__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ol/style/Style */ \"./node_modules/ol/style/Style.js\");\n/* harmony import */ var _burguillosinfo_conquer_login__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/login */ \"./js-src/conquer/login.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_manager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer/interface-manager */ \"./js-src/conquer/interface-manager.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_self_player__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/self-player */ \"./js-src/conquer/interface/self-player.ts\");\n/* harmony import */ var _burguillosinfo_conquer_create_node__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @burguillosinfo/conquer/create-node */ \"./js-src/conquer/create-node.ts\");\n/* harmony import */ var _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @burguillosinfo/conquer/map-state */ \"./js-src/conquer/map-state.ts\");\n/* harmony import */ var _burguillosinfo_conquer_map_node__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @burguillosinfo/conquer/map-node */ \"./js-src/conquer/map-node.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_new_node__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/new-node */ \"./js-src/conquer/interface/new-node.ts\");\n/* harmony import */ var _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! @burguillosinfo/conquer/serializer */ \"./js-src/conquer/serializer.ts\");\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nclass Conquer {\n getServerNodes() {\n return this.serverNodes;\n }\n getState() {\n return this.state;\n }\n setState(state) {\n this.state = state;\n this.refreshState();\n }\n removeState(state) {\n this.state &= ~state;\n this.refreshState();\n }\n addState(state) {\n this.state |= state;\n this.refreshState();\n }\n refreshState() {\n this.createNodeObject.refreshState();\n return;\n }\n static start() {\n const conquerContainer = document.querySelector(\".conquer-container\");\n if (conquerContainer === null || !(conquerContainer instanceof HTMLDivElement)) {\n Conquer.fail('.conquer-container is not a div.');\n }\n const conquer = new Conquer(conquerContainer);\n conquer.run();\n }\n setCenterDisplaced(lat, lon) {\n if (this.firstSetCenter || !(this.state & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE)) {\n this.coordinate_1 = lon;\n this.coordinate_2 = lat;\n const olCoordinates = this.realCoordinatesToOl(lat, lon);\n const size = this.map.getSize();\n if (size === undefined) {\n return;\n }\n this.map.getView().centerOn(olCoordinates, size, [size[0] / 2, size[1] - 60]);\n this.firstSetCenter = false;\n }\n }\n static fail(error) {\n alert('Error de interfaz');\n throw new Error(error);\n }\n isStateCreatingNode() {\n return !!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].CREATE_NODE);\n }\n isStateSelectWhereToCreateNode() {\n return !!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].SELECT_WHERE_TO_CREATE_NODE);\n }\n async onClickWhereToCreateNode(event) {\n if (!(event instanceof ol_MapBrowserEvent__WEBPACK_IMPORTED_MODULE_9__[\"default\"])) {\n return;\n }\n const pixel = event.pixel;\n const coordinates = this.map.getCoordinateFromPixel(pixel);\n const newNodeUI = new _burguillosinfo_conquer_interface_new_node__WEBPACK_IMPORTED_MODULE_7__[\"default\"](coordinates);\n const oldState = this.getState();\n newNodeUI.on('close', () => {\n this.interfaceManager.remove(newNodeUI);\n this.setState(oldState);\n });\n this.interfaceManager.push(newNodeUI);\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].SELECT_WHERE_TO_CREATE_NODE);\n // const style = new Style({\n // image: new CircleStyle({\n // radius: 14,\n // fill: new Fill({color: 'white'}),\n // stroke: new Stroke({\n // color: 'gray',\n // width: 2,\n // })\n // })\n // })\n // const mapNode = new MapNode(style, feature, `server-node-${++this.createNodeCounter}`)\n // this.getServerNodes()[mapNode.getId()] = mapNode\n // this.refreshLayers()\n }\n isStateFillingFormCreateNode() {\n return !!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FILLING_FORM_CREATE_NODE);\n }\n async onClickMap(event) {\n if (this.isStateCreatingNode() && this.isStateSelectWhereToCreateNode()) {\n this.onClickWhereToCreateNode(event);\n }\n if (!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL)) {\n return;\n }\n if (this.vectorLayer === null) {\n return;\n }\n if (!(event instanceof ol_MapBrowserEvent__WEBPACK_IMPORTED_MODULE_9__[\"default\"])) {\n return;\n }\n if (event.dragging) {\n return;\n }\n const pixel = event.pixel;\n const features = this.map.getFeaturesAtPixel(pixel);\n const feature = features.length ? features[0] : undefined;\n if (feature === undefined) {\n return;\n }\n if (!(feature instanceof ol_Feature__WEBPACK_IMPORTED_MODULE_10__[\"default\"])) {\n return;\n }\n this.onClickFeature(feature);\n }\n async onClickSelf() {\n if (!(this.state & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL)) {\n return;\n }\n const selfPlayerUI = new _burguillosinfo_conquer_interface_self_player__WEBPACK_IMPORTED_MODULE_3__[\"default\"](!!(this.getState() & (_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE | _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION)));\n selfPlayerUI.on('close', () => {\n this.interfaceManager.remove(selfPlayerUI);\n });\n selfPlayerUI.on('enable-explorer-mode', () => {\n console.log('hola');\n this.addState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE);\n this.addState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION);\n });\n selfPlayerUI.on('disable-explorer-mode', () => {\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE);\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION);\n });\n selfPlayerUI.on('createNodeStart', () => {\n this.addState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].CREATE_NODE);\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL);\n });\n this.interfaceManager.push(selfPlayerUI);\n this.selfPlayerUI = selfPlayerUI;\n }\n async onClickFeature(feature) {\n if (this.isFeatureEnabledMap[feature.getProperties().type] === undefined) {\n this.isFeatureEnabledMap[feature.getProperties().type] = true;\n }\n if (!this.isFeatureEnabledMap[feature.getProperties().type]) {\n return;\n }\n this.isFeatureEnabledMap[feature.getProperties().type] = false;\n window.setTimeout(() => {\n this.isFeatureEnabledMap[feature.getProperties().type] = true;\n }, 100);\n const candidateNode = this.getServerNodes()[feature.getProperties().type];\n if (candidateNode !== undefined) {\n candidateNode.click(this.interfaceManager);\n return;\n }\n if (feature === this.currentPositionFeature) {\n this.onClickSelf();\n return;\n }\n }\n async onLoginSuccess() {\n this.clearIntervalSendCoordinates();\n this.createIntervalSendCoordinates();\n this.clearIntervalPollNearbyNodes();\n this.createIntervalPollNearbyNodes();\n }\n clearIntervalPollNearbyNodes() {\n if (this.intervalPollNearbyNodes !== null) {\n window.clearInterval(this.intervalPollNearbyNodes);\n this.intervalPollNearbyNodes = null;\n }\n }\n async getNearbyNodes() {\n const urlNodes = new URL('/conquer/node/near', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n let response;\n try {\n response = await fetch(urlNodes);\n }\n catch (error) {\n console.error(error);\n return;\n }\n let responseBody;\n try {\n responseBody = await response.json();\n }\n catch (error) {\n console.error('Error parseando json: ' + responseBody);\n console.error(error);\n return;\n }\n if (response.status !== 200) {\n console.error(responseBody.error);\n return;\n }\n const serverNodes = {};\n const nodes = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_8__[\"default\"].deserialize(responseBody, _burguillosinfo_conquer_map_node__WEBPACK_IMPORTED_MODULE_6__[\"default\"]);\n if (!(nodes instanceof Array)) {\n console.error('Received null instead of node list.');\n return;\n }\n for (const node of nodes) {\n if (!(node instanceof _burguillosinfo_conquer_map_node__WEBPACK_IMPORTED_MODULE_6__[\"default\"])) {\n console.error('Received node is not a MapNode.');\n continue;\n }\n node.on('update-nodes', async () => {\n await this.sendCoordinatesToServer();\n this.getNearbyNodes();\n });\n serverNodes[node.getId()] = node;\n }\n this.serverNodes = serverNodes;\n this.refreshLayers();\n }\n createIntervalPollNearbyNodes() {\n this.getNearbyNodes();\n this.intervalPollNearbyNodes = window.setInterval(() => {\n this.getNearbyNodes();\n }, 40000);\n }\n createIntervalSendCoordinates() {\n this.intervalSendCoordinates = window.setInterval(() => {\n this.sendCoordinatesToServer();\n }, 40000);\n }\n async sendCoordinatesToServer() {\n const urlLog = new URL('/conquer/user/coordinates', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n let res;\n try {\n res = await fetch(urlLog, {\n method: 'POST',\n body: JSON.stringify([\n this.coordinate_1,\n this.coordinate_2,\n ])\n });\n }\n catch (error) {\n console.error(error);\n return;\n }\n let responseBody;\n try {\n responseBody = await res.json();\n }\n catch (error) {\n console.error('Error parseando json: ' + responseBody);\n console.error(error);\n return;\n }\n if (res.status !== 200) {\n console.error(responseBody.error);\n }\n }\n runPreStartState() {\n const createNodeObject = new _burguillosinfo_conquer_create_node__WEBPACK_IMPORTED_MODULE_4__[\"default\"](this);\n this.createNodeObject = createNodeObject;\n const interfaceManager = new _burguillosinfo_conquer_interface_manager__WEBPACK_IMPORTED_MODULE_2__[\"default\"]();\n this.interfaceManager = interfaceManager;\n const conquerLogin = new _burguillosinfo_conquer_login__WEBPACK_IMPORTED_MODULE_1__[\"default\"](interfaceManager);\n conquerLogin.on('login', () => {\n this.onLoginSuccess();\n });\n conquerLogin.on('logout', () => {\n this.onLogout();\n });\n conquerLogin.start();\n this.conquerLogin = conquerLogin;\n }\n onLogout() {\n this.clearIntervalSendCoordinates();\n this.clearIntervalPollNearbyNodes();\n }\n clearIntervalSendCoordinates() {\n if (this.intervalSendCoordinates !== null) {\n window.clearInterval(this.intervalSendCoordinates);\n this.intervalSendCoordinates = null;\n }\n }\n async run() {\n this.runPreStartState();\n this.setState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL);\n const conquerContainer = this.conquerContainer;\n //layer.on('prerender', (evt) => {\n // // return\n // if (evt.context) {\n // const context = evt.context as CanvasRenderingContext2D\n // context.filter = 'grayscale(80%) invert(100%) '\n // context.globalCompositeOperation = 'source-over'\n // }\n //})\n //layer.on('postrender', (evt) => {\n // if (evt.context) {\n // const context = evt.context as CanvasRenderingContext2D\n // context.filter = 'none'\n // }\n //})\n ol_proj__WEBPACK_IMPORTED_MODULE_0__.useGeographic();\n const osm = new ol_source_OSM__WEBPACK_IMPORTED_MODULE_11__[\"default\"]();\n osm.setUrls([`${window.location.protocol}//${window.location.hostname}:${window.location.port}/conquer/tile/{z}/{x}/{y}.png`]);\n this.map = new ol_Map__WEBPACK_IMPORTED_MODULE_12__[\"default\"]({\n target: conquerContainer,\n layers: [\n new ol_layer_Tile__WEBPACK_IMPORTED_MODULE_13__[\"default\"]({\n source: osm\n })\n ],\n view: new ol_View__WEBPACK_IMPORTED_MODULE_14__[\"default\"]({\n zoom: 19,\n maxZoom: 22,\n }),\n });\n this.setLocationChangeTriggers();\n this.setRotationChangeTriggers();\n }\n setRotationChangeTriggers() {\n if (window.DeviceOrientationEvent) {\n window.addEventListener(\"deviceorientation\", (event) => {\n if (event.alpha !== null && event.beta !== null && event.gamma !== null) {\n this.onRotate(event.alpha, event.beta, event.gamma);\n }\n }, true);\n }\n }\n addCurrentLocationMarkerToMap(currentLatitude, currentLongitude) {\n const currentPositionFeature = new ol_Feature__WEBPACK_IMPORTED_MODULE_10__[\"default\"]({\n type: 'currentPositionFeature',\n geometry: new ol_geom_Point__WEBPACK_IMPORTED_MODULE_15__[\"default\"](this.realCoordinatesToOl(currentLatitude, currentLongitude))\n });\n this.currentPositionFeature = currentPositionFeature;\n }\n processLocation(location) {\n this.currentLatitude = location.coords.latitude;\n this.currentLongitude = location.coords.longitude;\n if (location.coords.heading !== null && (this.alpha != 0 || this.beta != 0 || this.gamma != 0) && !this.disableSetRotationOffset) {\n this.disableSetRotationOffset = true;\n this.heading = location.coords.heading;\n this.rotationOffset = this.compassHeading(this.alpha, this.beta, this.gamma) + (location.coords.heading * Math.PI * 2) / 360;\n }\n this.setCenterDisplaced(this.currentLatitude, this.currentLongitude);\n this.addCurrentLocationMarkerToMap(this.currentLatitude, this.currentLongitude);\n this.refreshLayers();\n }\n async refreshLayers() {\n if (this.currentPositionFeature === null) {\n return;\n }\n const styles = {\n currentPositionFeature: new ol_style_Style__WEBPACK_IMPORTED_MODULE_16__[\"default\"]({\n image: new ol_style_Circle__WEBPACK_IMPORTED_MODULE_17__[\"default\"]({\n radius: 14,\n fill: new ol_style_Fill__WEBPACK_IMPORTED_MODULE_18__[\"default\"]({ color: 'white' }),\n stroke: new ol_style_Stroke__WEBPACK_IMPORTED_MODULE_19__[\"default\"]({\n color: 'blue',\n width: 2,\n })\n })\n })\n };\n const features = [this.currentPositionFeature];\n for (const key in this.getServerNodes()) {\n styles[key] = this.getServerNodes()[key].getStyle();\n features.push(this.getServerNodes()[key].getFeature());\n }\n const vectorLayer = new ol_layer_Vector__WEBPACK_IMPORTED_MODULE_20__[\"default\"]({\n source: new ol_source_Vector__WEBPACK_IMPORTED_MODULE_21__[\"default\"]({\n features: features\n }),\n });\n if (this.vectorLayer !== null) {\n this.map.removeLayer(this.vectorLayer);\n this.vectorLayer = null;\n }\n vectorLayer.setStyle((feature) => {\n return styles[feature.getProperties().type];\n });\n this.map.addLayer(vectorLayer);\n this.vectorLayer = vectorLayer;\n this.map.on('click', (event) => {\n this.onClickMap(event);\n });\n }\n setLocationChangeTriggers() {\n window.setInterval(() => {\n this.disableSetRotationOffset = false;\n }, 10000);\n this.currentPositionFeature = null;\n window.setTimeout(() => {\n window.setInterval(() => {\n navigator.geolocation.getCurrentPosition((location) => {\n this.processLocation(location);\n }, () => {\n return;\n }, {\n enableHighAccuracy: true,\n });\n }, 3000);\n }, 1000);\n // const initialLatitude = 37.58237\n //const initialLongitude = -5.96766\n const initialLongitude = 2.500845037550267;\n const initialLatitude = 48.81050698635832;\n this.setCenterDisplaced(initialLatitude, initialLongitude);\n this.addCurrentLocationMarkerToMap(initialLatitude, initialLongitude);\n this.refreshLayers();\n navigator.geolocation.watchPosition((location) => {\n this.processLocation(location);\n }, (err) => {\n return;\n }, {\n enableHighAccuracy: true,\n });\n }\n realCoordinatesToOl(lat, lon) {\n return ol_proj__WEBPACK_IMPORTED_MODULE_0__.transform([lon, lat], new ol_proj_Projection_js__WEBPACK_IMPORTED_MODULE_22__[\"default\"]({ code: \"WGS84\" }), new ol_proj_Projection_js__WEBPACK_IMPORTED_MODULE_22__[\"default\"]({ code: \"EPSG:900913\" }));\n }\n compassHeading(alpha, beta, gamma) {\n const alphaRad = alpha * (Math.PI / 180);\n return alphaRad;\n }\n logToServer(logValue) {\n const urlLog = new URL('/conquer/log', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n urlLog.searchParams.append('log', logValue);\n fetch(urlLog).then(() => {\n return;\n }).catch((error) => {\n console.error(error);\n });\n }\n onRotate(alpha, beta, gamma) {\n if (this.enabledOnRotate) {\n this.alpha = alpha;\n this.beta = beta;\n this.gamma = gamma;\n this.enabledOnRotate = false;\n if (this.firstSetRotation || !(this.state & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION)) {\n this.map.getView().setRotation((this.compassHeading(alpha, beta, gamma) - this.rotationOffset));\n this.firstSetRotation = false;\n }\n window.setTimeout(() => {\n this.enabledOnRotate = true;\n }, 10);\n }\n this.setCenterDisplaced(this.currentLatitude, this.currentLongitude);\n }\n constructor(conquerContainer) {\n this.intervalSendCoordinates = null;\n this.rotationOffset = 0;\n this.heading = 0;\n this.disableSetRotationOffset = false;\n this.vectorLayer = null;\n this.alpha = 0;\n this.beta = 0;\n this.gamma = 0;\n this.selfPlayerUI = null;\n this.firstSetCenter = true;\n this.firstSetRotation = true;\n this.state = _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NOTHING;\n this.serverNodes = {};\n this.coordinate_1 = 0;\n this.coordinate_2 = 0;\n this.createNodeCounter = 0;\n this.isFeatureEnabledMap = {};\n this.intervalPollNearbyNodes = null;\n this.enabledOnRotate = true;\n this.conquerContainer = conquerContainer;\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/index.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ Conquer)\n/* harmony export */ });\n/* harmony import */ var ol_Map__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ol/Map */ \"./node_modules/ol/Map.js\");\n/* harmony import */ var ol_MapBrowserEvent__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ol/MapBrowserEvent */ \"./node_modules/ol/MapBrowserEvent.js\");\n/* harmony import */ var ol_View__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ol/View */ \"./node_modules/ol/View.js\");\n/* harmony import */ var ol_proj_Projection_js__WEBPACK_IMPORTED_MODULE_23__ = __webpack_require__(/*! ol/proj/Projection.js */ \"./node_modules/ol/proj/Projection.js\");\n/* harmony import */ var ol_layer_Tile__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ol/layer/Tile */ \"./node_modules/ol/layer/Tile.js\");\n/* harmony import */ var ol_source_OSM__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ol/source/OSM */ \"./node_modules/ol/source/OSM.js\");\n/* harmony import */ var ol_proj__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ol/proj */ \"./node_modules/ol/proj.js\");\n/* harmony import */ var ol_Feature__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ol/Feature */ \"./node_modules/ol/Feature.js\");\n/* harmony import */ var ol_geom_Point__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ol/geom/Point */ \"./node_modules/ol/geom/Point.js\");\n/* harmony import */ var ol_layer_Vector__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ol/layer/Vector */ \"./node_modules/ol/layer/Vector.js\");\n/* harmony import */ var ol_source_Vector__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ol/source/Vector */ \"./node_modules/ol/source/Vector.js\");\n/* harmony import */ var ol_style_Stroke__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ol/style/Stroke */ \"./node_modules/ol/style/Stroke.js\");\n/* harmony import */ var ol_style_Fill__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ol/style/Fill */ \"./node_modules/ol/style/Fill.js\");\n/* harmony import */ var ol_style_Circle__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ol/style/Circle */ \"./node_modules/ol/style/Circle.js\");\n/* harmony import */ var ol_style_Style__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ol/style/Style */ \"./node_modules/ol/style/Style.js\");\n/* harmony import */ var _burguillosinfo_conquer_login__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/login */ \"./js-src/conquer/login.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_manager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer/interface-manager */ \"./js-src/conquer/interface-manager.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_self_player__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/self-player */ \"./js-src/conquer/interface/self-player.ts\");\n/* harmony import */ var _burguillosinfo_conquer_create_node__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @burguillosinfo/conquer/create-node */ \"./js-src/conquer/create-node.ts\");\n/* harmony import */ var _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @burguillosinfo/conquer/map-state */ \"./js-src/conquer/map-state.ts\");\n/* harmony import */ var _burguillosinfo_conquer_map_node__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @burguillosinfo/conquer/map-node */ \"./js-src/conquer/map-node.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_new_node__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/new-node */ \"./js-src/conquer/interface/new-node.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_new_team__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/new-team */ \"./js-src/conquer/interface/new-team.ts\");\n/* harmony import */ var _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! @burguillosinfo/conquer/serializer */ \"./js-src/conquer/serializer.ts\");\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nclass Conquer {\n getServerNodes() {\n return this.serverNodes;\n }\n getState() {\n return this.state;\n }\n setState(state) {\n this.state = state;\n this.refreshState();\n }\n removeState(state) {\n this.state &= ~state;\n this.refreshState();\n }\n addState(state) {\n this.state |= state;\n this.refreshState();\n }\n refreshState() {\n this.createNodeObject.refreshState();\n return;\n }\n static start() {\n const conquerContainer = document.querySelector(\".conquer-container\");\n if (conquerContainer === null || !(conquerContainer instanceof HTMLDivElement)) {\n Conquer.fail('.conquer-container is not a div.');\n }\n const conquer = new Conquer(conquerContainer);\n conquer.run();\n }\n setCenterDisplaced(lat, lon) {\n if (this.firstSetCenter || !(this.state & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE)) {\n this.coordinate_1 = lon;\n this.coordinate_2 = lat;\n const olCoordinates = this.realCoordinatesToOl(lat, lon);\n const size = this.map.getSize();\n if (size === undefined) {\n return;\n }\n this.map.getView().centerOn(olCoordinates, size, [size[0] / 2, size[1] - 60]);\n this.firstSetCenter = false;\n }\n }\n static fail(error) {\n alert('Error de interfaz');\n throw new Error(error);\n }\n isStateCreatingNode() {\n return !!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].CREATE_NODE);\n }\n isStateSelectWhereToCreateNode() {\n return !!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].SELECT_WHERE_TO_CREATE_NODE);\n }\n async onClickWhereToCreateNode(event) {\n if (!(event instanceof ol_MapBrowserEvent__WEBPACK_IMPORTED_MODULE_10__[\"default\"])) {\n return;\n }\n const pixel = event.pixel;\n const coordinates = this.map.getCoordinateFromPixel(pixel);\n const newNodeUI = new _burguillosinfo_conquer_interface_new_node__WEBPACK_IMPORTED_MODULE_7__[\"default\"](coordinates);\n const oldState = this.getState();\n newNodeUI.on('close', () => {\n this.interfaceManager.remove(newNodeUI);\n this.setState(oldState);\n });\n this.interfaceManager.push(newNodeUI);\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].SELECT_WHERE_TO_CREATE_NODE);\n // const style = new Style({\n // image: new CircleStyle({\n // radius: 14,\n // fill: new Fill({color: 'white'}),\n // stroke: new Stroke({\n // color: 'gray',\n // width: 2,\n // })\n // })\n // })\n // const mapNode = new MapNode(style, feature, `server-node-${++this.createNodeCounter}`)\n // this.getServerNodes()[mapNode.getId()] = mapNode\n // this.refreshLayers()\n }\n isStateFillingFormCreateNode() {\n return !!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FILLING_FORM_CREATE_NODE);\n }\n async onClickMap(event) {\n if (this.isStateCreatingNode() && this.isStateSelectWhereToCreateNode()) {\n this.onClickWhereToCreateNode(event);\n }\n if (!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL)) {\n return;\n }\n if (this.vectorLayer === null) {\n return;\n }\n if (!(event instanceof ol_MapBrowserEvent__WEBPACK_IMPORTED_MODULE_10__[\"default\"])) {\n return;\n }\n if (event.dragging) {\n return;\n }\n const pixel = event.pixel;\n const features = this.map.getFeaturesAtPixel(pixel);\n const feature = features.length ? features[0] : undefined;\n if (feature === undefined) {\n return;\n }\n if (!(feature instanceof ol_Feature__WEBPACK_IMPORTED_MODULE_11__[\"default\"])) {\n return;\n }\n this.onClickFeature(feature);\n }\n async onClickSelf() {\n if (!(this.state & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL)) {\n return;\n }\n const selfPlayerUI = new _burguillosinfo_conquer_interface_self_player__WEBPACK_IMPORTED_MODULE_3__[\"default\"](!!(this.getState() & (_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE | _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION)));\n selfPlayerUI.on('close', () => {\n this.interfaceManager.remove(selfPlayerUI);\n });\n selfPlayerUI.on('enable-explorer-mode', () => {\n this.addState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE);\n this.addState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION);\n });\n selfPlayerUI.on('disable-explorer-mode', () => {\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE);\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION);\n });\n selfPlayerUI.on('createNodeStart', () => {\n this.addState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].CREATE_NODE);\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL);\n });\n selfPlayerUI.on('open-create-team', () => {\n this.onOpenCreateTeam();\n });\n this.interfaceManager.push(selfPlayerUI);\n this.selfPlayerUI = selfPlayerUI;\n }\n onOpenCreateTeam() {\n const newTeamUI = new _burguillosinfo_conquer_interface_new_team__WEBPACK_IMPORTED_MODULE_8__[\"default\"]();\n newTeamUI.on('close', () => {\n this.interfaceManager.remove(newTeamUI);\n });\n this.interfaceManager.push(newTeamUI);\n }\n async onClickFeature(feature) {\n if (this.isFeatureEnabledMap[feature.getProperties().type] === undefined) {\n this.isFeatureEnabledMap[feature.getProperties().type] = true;\n }\n if (!this.isFeatureEnabledMap[feature.getProperties().type]) {\n return;\n }\n this.isFeatureEnabledMap[feature.getProperties().type] = false;\n window.setTimeout(() => {\n this.isFeatureEnabledMap[feature.getProperties().type] = true;\n }, 100);\n const candidateNode = this.getServerNodes()[feature.getProperties().type];\n if (candidateNode !== undefined) {\n candidateNode.click(this.interfaceManager);\n return;\n }\n if (feature === this.currentPositionFeature) {\n this.onClickSelf();\n return;\n }\n }\n async onLoginSuccess() {\n this.clearIntervalSendCoordinates();\n this.createIntervalSendCoordinates();\n this.clearIntervalPollNearbyNodes();\n this.createIntervalPollNearbyNodes();\n }\n clearIntervalPollNearbyNodes() {\n if (this.intervalPollNearbyNodes !== null) {\n window.clearInterval(this.intervalPollNearbyNodes);\n this.intervalPollNearbyNodes = null;\n }\n }\n async getNearbyNodes() {\n const urlNodes = new URL('/conquer/node/near', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n let response;\n try {\n response = await fetch(urlNodes);\n }\n catch (error) {\n console.error(error);\n return;\n }\n let responseBody;\n try {\n responseBody = await response.json();\n }\n catch (error) {\n console.error('Error parseando json: ' + responseBody);\n console.error(error);\n return;\n }\n if (response.status !== 200) {\n console.error(responseBody.error);\n return;\n }\n const serverNodes = {};\n const nodes = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_9__[\"default\"].deserialize(responseBody, _burguillosinfo_conquer_map_node__WEBPACK_IMPORTED_MODULE_6__[\"default\"]);\n if (!(nodes instanceof Array)) {\n console.error('Received null instead of node list.');\n return;\n }\n for (const node of nodes) {\n if (!(node instanceof _burguillosinfo_conquer_map_node__WEBPACK_IMPORTED_MODULE_6__[\"default\"])) {\n console.error('Received node is not a MapNode.');\n continue;\n }\n node.on('update-nodes', async () => {\n await this.sendCoordinatesToServer();\n this.getNearbyNodes();\n });\n serverNodes[node.getId()] = node;\n }\n this.serverNodes = serverNodes;\n this.refreshLayers();\n }\n createIntervalPollNearbyNodes() {\n this.getNearbyNodes();\n this.intervalPollNearbyNodes = window.setInterval(() => {\n this.getNearbyNodes();\n }, 40000);\n }\n createIntervalSendCoordinates() {\n this.intervalSendCoordinates = window.setInterval(() => {\n this.sendCoordinatesToServer();\n }, 40000);\n }\n async sendCoordinatesToServer() {\n const urlLog = new URL('/conquer/user/coordinates', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n let res;\n try {\n res = await fetch(urlLog, {\n method: 'POST',\n body: JSON.stringify([\n this.coordinate_1,\n this.coordinate_2,\n ])\n });\n }\n catch (error) {\n console.error(error);\n return;\n }\n let responseBody;\n try {\n responseBody = await res.json();\n }\n catch (error) {\n console.error('Error parseando json: ' + responseBody);\n console.error(error);\n return;\n }\n if (res.status !== 200) {\n console.error(responseBody.error);\n }\n }\n runPreStartState() {\n const createNodeObject = new _burguillosinfo_conquer_create_node__WEBPACK_IMPORTED_MODULE_4__[\"default\"](this);\n this.createNodeObject = createNodeObject;\n const interfaceManager = new _burguillosinfo_conquer_interface_manager__WEBPACK_IMPORTED_MODULE_2__[\"default\"]();\n this.interfaceManager = interfaceManager;\n const conquerLogin = new _burguillosinfo_conquer_login__WEBPACK_IMPORTED_MODULE_1__[\"default\"](interfaceManager);\n conquerLogin.on('login', () => {\n this.onLoginSuccess();\n });\n conquerLogin.on('logout', () => {\n this.onLogout();\n });\n conquerLogin.start();\n this.conquerLogin = conquerLogin;\n }\n onLogout() {\n this.clearIntervalSendCoordinates();\n this.clearIntervalPollNearbyNodes();\n }\n clearIntervalSendCoordinates() {\n if (this.intervalSendCoordinates !== null) {\n window.clearInterval(this.intervalSendCoordinates);\n this.intervalSendCoordinates = null;\n }\n }\n async run() {\n this.runPreStartState();\n this.setState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL);\n const conquerContainer = this.conquerContainer;\n //layer.on('prerender', (evt) => {\n // // return\n // if (evt.context) {\n // const context = evt.context as CanvasRenderingContext2D\n // context.filter = 'grayscale(80%) invert(100%) '\n // context.globalCompositeOperation = 'source-over'\n // }\n //})\n //layer.on('postrender', (evt) => {\n // if (evt.context) {\n // const context = evt.context as CanvasRenderingContext2D\n // context.filter = 'none'\n // }\n //})\n ol_proj__WEBPACK_IMPORTED_MODULE_0__.useGeographic();\n const osm = new ol_source_OSM__WEBPACK_IMPORTED_MODULE_12__[\"default\"]();\n osm.setUrls([`${window.location.protocol}//${window.location.hostname}:${window.location.port}/conquer/tile/{z}/{x}/{y}.png`]);\n this.map = new ol_Map__WEBPACK_IMPORTED_MODULE_13__[\"default\"]({\n target: conquerContainer,\n layers: [\n new ol_layer_Tile__WEBPACK_IMPORTED_MODULE_14__[\"default\"]({\n source: osm\n })\n ],\n view: new ol_View__WEBPACK_IMPORTED_MODULE_15__[\"default\"]({\n zoom: 19,\n maxZoom: 22,\n }),\n });\n this.setLocationChangeTriggers();\n this.setRotationChangeTriggers();\n }\n setRotationChangeTriggers() {\n if (window.DeviceOrientationEvent) {\n window.addEventListener(\"deviceorientation\", (event) => {\n if (event.alpha !== null && event.beta !== null && event.gamma !== null) {\n this.onRotate(event.alpha, event.beta, event.gamma);\n }\n }, true);\n }\n }\n addCurrentLocationMarkerToMap(currentLatitude, currentLongitude) {\n const currentPositionFeature = new ol_Feature__WEBPACK_IMPORTED_MODULE_11__[\"default\"]({\n type: 'currentPositionFeature',\n geometry: new ol_geom_Point__WEBPACK_IMPORTED_MODULE_16__[\"default\"](this.realCoordinatesToOl(currentLatitude, currentLongitude))\n });\n this.currentPositionFeature = currentPositionFeature;\n }\n processLocation(location) {\n this.currentLatitude = location.coords.latitude;\n this.currentLongitude = location.coords.longitude;\n if (location.coords.heading !== null && (this.alpha != 0 || this.beta != 0 || this.gamma != 0) && !this.disableSetRotationOffset) {\n this.disableSetRotationOffset = true;\n this.heading = location.coords.heading;\n this.rotationOffset = this.compassHeading(this.alpha, this.beta, this.gamma) + (location.coords.heading * Math.PI * 2) / 360;\n }\n this.setCenterDisplaced(this.currentLatitude, this.currentLongitude);\n this.addCurrentLocationMarkerToMap(this.currentLatitude, this.currentLongitude);\n this.refreshLayers();\n }\n async refreshLayers() {\n if (this.currentPositionFeature === null) {\n return;\n }\n const styles = {\n currentPositionFeature: new ol_style_Style__WEBPACK_IMPORTED_MODULE_17__[\"default\"]({\n image: new ol_style_Circle__WEBPACK_IMPORTED_MODULE_18__[\"default\"]({\n radius: 14,\n fill: new ol_style_Fill__WEBPACK_IMPORTED_MODULE_19__[\"default\"]({ color: 'white' }),\n stroke: new ol_style_Stroke__WEBPACK_IMPORTED_MODULE_20__[\"default\"]({\n color: 'blue',\n width: 2,\n })\n })\n })\n };\n const features = [this.currentPositionFeature];\n for (const key in this.getServerNodes()) {\n styles[key] = this.getServerNodes()[key].getStyle();\n features.push(this.getServerNodes()[key].getFeature());\n }\n const vectorLayer = new ol_layer_Vector__WEBPACK_IMPORTED_MODULE_21__[\"default\"]({\n source: new ol_source_Vector__WEBPACK_IMPORTED_MODULE_22__[\"default\"]({\n features: features\n }),\n });\n if (this.vectorLayer !== null) {\n this.map.removeLayer(this.vectorLayer);\n this.vectorLayer = null;\n }\n vectorLayer.setStyle((feature) => {\n return styles[feature.getProperties().type];\n });\n this.map.addLayer(vectorLayer);\n this.vectorLayer = vectorLayer;\n this.map.on('click', (event) => {\n this.onClickMap(event);\n });\n }\n setLocationChangeTriggers() {\n window.setInterval(() => {\n this.disableSetRotationOffset = false;\n }, 10000);\n this.currentPositionFeature = null;\n window.setTimeout(() => {\n window.setInterval(() => {\n navigator.geolocation.getCurrentPosition((location) => {\n this.processLocation(location);\n }, () => {\n return;\n }, {\n enableHighAccuracy: true,\n });\n }, 3000);\n }, 1000);\n // const initialLatitude = 37.58237\n //const initialLongitude = -5.96766\n const initialLongitude = 2.500845037550267;\n const initialLatitude = 48.81050698635832;\n this.setCenterDisplaced(initialLatitude, initialLongitude);\n this.addCurrentLocationMarkerToMap(initialLatitude, initialLongitude);\n this.refreshLayers();\n navigator.geolocation.watchPosition((location) => {\n this.processLocation(location);\n }, (err) => {\n return;\n }, {\n enableHighAccuracy: true,\n });\n }\n realCoordinatesToOl(lat, lon) {\n return ol_proj__WEBPACK_IMPORTED_MODULE_0__.transform([lon, lat], new ol_proj_Projection_js__WEBPACK_IMPORTED_MODULE_23__[\"default\"]({ code: \"WGS84\" }), new ol_proj_Projection_js__WEBPACK_IMPORTED_MODULE_23__[\"default\"]({ code: \"EPSG:900913\" }));\n }\n compassHeading(alpha, beta, gamma) {\n const alphaRad = alpha * (Math.PI / 180);\n return alphaRad;\n }\n logToServer(logValue) {\n const urlLog = new URL('/conquer/log', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n urlLog.searchParams.append('log', logValue);\n fetch(urlLog).then(() => {\n return;\n }).catch((error) => {\n console.error(error);\n });\n }\n onRotate(alpha, beta, gamma) {\n if (this.enabledOnRotate) {\n this.alpha = alpha;\n this.beta = beta;\n this.gamma = gamma;\n this.enabledOnRotate = false;\n if (this.firstSetRotation || !(this.state & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION)) {\n this.map.getView().setRotation((this.compassHeading(alpha, beta, gamma) - this.rotationOffset));\n this.firstSetRotation = false;\n }\n window.setTimeout(() => {\n this.enabledOnRotate = true;\n }, 10);\n }\n this.setCenterDisplaced(this.currentLatitude, this.currentLongitude);\n }\n constructor(conquerContainer) {\n this.intervalSendCoordinates = null;\n this.rotationOffset = 0;\n this.heading = 0;\n this.disableSetRotationOffset = false;\n this.vectorLayer = null;\n this.alpha = 0;\n this.beta = 0;\n this.gamma = 0;\n this.selfPlayerUI = null;\n this.firstSetCenter = true;\n this.firstSetRotation = true;\n this.state = _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NOTHING;\n this.serverNodes = {};\n this.coordinate_1 = 0;\n this.coordinate_2 = 0;\n this.createNodeCounter = 0;\n this.isFeatureEnabledMap = {};\n this.intervalPollNearbyNodes = null;\n this.enabledOnRotate = true;\n this.conquerContainer = conquerContainer;\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/index.ts?"); /***/ }), @@ -133,7 +133,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 */ LoginUI)\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_interface__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/interface */ \"./js-src/conquer/interface.ts\");\n\n\nclass LoginUI extends _burguillosinfo_conquer_interface__WEBPACK_IMPORTED_MODULE_1__[\"default\"] {\n constructor(conquerLogin) {\n super();\n this.conquerLogin = conquerLogin;\n }\n run() {\n this.conquerLogin.on('login', () => {\n this.runCallbacks('close');\n });\n this.storeRegisterElements();\n this.storeLoginElements();\n }\n getLoginDiv() {\n const element = this.getNodes()[1];\n if (element === undefined || !(element instanceof HTMLDivElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Login is not a div.');\n }\n return element;\n }\n getOverlayDiv() {\n const element = this.getNodes()[0];\n if (element === undefined || !(element instanceof HTMLDivElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Overlay transparent is not a div.');\n }\n return element;\n }\n getRegisterDiv() {\n const element = this.getNodes()[2];\n if (element === undefined || !(element instanceof HTMLDivElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Register is not a div.');\n }\n return element;\n }\n generateNodes() {\n const resultArray = [];\n const overlay = this.getNodeFromTemplateId('conquer-overlay-transparent-template');\n overlay.classList.remove('conquer-display-none');\n resultArray.push(overlay);\n const login = this.getNodeFromTemplateId('conquer-login-template');\n login.classList.remove('conquer-display-none');\n if (!(login instanceof HTMLDivElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Login is required to be a Div.');\n }\n resultArray.push(login);\n const register = this.getNodeFromTemplateId('conquer-register-template');\n resultArray.push(register);\n return resultArray;\n }\n async storeRegisterElements() {\n const registerElement = this.getRegisterDiv();\n const conquerRegisterGoToLogin = registerElement.querySelector('.conquer-register-go-to-login');\n if (conquerRegisterGoToLogin === null || !(conquerRegisterGoToLogin instanceof HTMLAnchorElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Link to go to login from register is invalid.');\n }\n this.conquerRegisterGoToLogin = conquerRegisterGoToLogin;\n this.conquerRegisterGoToLogin.addEventListener('click', () => {\n this.goToLogin();\n });\n const conquerRegisterUsername = registerElement.querySelector('.conquer-register-username');\n if (conquerRegisterUsername === null || !(conquerRegisterUsername instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No username field in conquer register.');\n }\n this.conquerRegisterUsername = conquerRegisterUsername;\n const conquerRegisterPassword = registerElement.querySelector('.conquer-register-password');\n if (conquerRegisterPassword === null || !(conquerRegisterPassword instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No password field in conquer register.');\n }\n this.conquerRegisterPassword = conquerRegisterPassword;\n const conquerRegisterRepeatPassword = registerElement.querySelector('.conquer-register-repeat-password');\n if (conquerRegisterRepeatPassword === null || !(conquerRegisterRepeatPassword instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No repeat password field in conquer register.');\n }\n this.conquerRegisterRepeatPassword = conquerRegisterRepeatPassword;\n const conquerRegisterSubmit = registerElement.querySelector('.conquer-register-submit');\n if (conquerRegisterSubmit === null || !(conquerRegisterSubmit instanceof HTMLButtonElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No register submit button found.');\n }\n this.conquerRegisterSubmit = conquerRegisterSubmit;\n this.conquerRegisterSubmit.addEventListener('click', (event) => {\n event.preventDefault();\n const username = this.conquerRegisterUsername.value;\n const password = this.conquerRegisterPassword.value;\n const repeatPassword = this.conquerRegisterRepeatPassword.value;\n this.conquerLogin.onRegisterRequest(this, username, password, repeatPassword);\n });\n const conquerRegisterError = registerElement.querySelector('.conquer-register-error');\n if (conquerRegisterError === null || !(conquerRegisterError instanceof HTMLParagraphElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find the conquer error element.');\n }\n this.conquerRegisterError = conquerRegisterError;\n }\n storeLoginElements() {\n const loginElement = this.getLoginDiv();\n const conquerLoginGoToRegister = loginElement.querySelector('.conquer-login-go-to-register');\n if (conquerLoginGoToRegister === null || !(conquerLoginGoToRegister instanceof HTMLAnchorElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Link to go to register from login is invalid.');\n }\n this.conquerLoginGoToRegister = conquerLoginGoToRegister;\n this.conquerLoginGoToRegister.addEventListener('click', () => {\n this.goToRegister();\n });\n const conquerLoginError = loginElement.querySelector('.conquer-login-error');\n if (conquerLoginError === null || !(conquerLoginError instanceof HTMLParagraphElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login error.');\n }\n this.conquerLoginError = conquerLoginError;\n const conquerLoginSuccess = loginElement.querySelector('.conquer-login-success');\n if (conquerLoginSuccess === null || !(conquerLoginSuccess instanceof HTMLParagraphElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login success.');\n }\n this.conquerLoginSuccess = conquerLoginSuccess;\n const conquerLoginUsername = loginElement.querySelector('.conquer-login-username');\n if (conquerLoginUsername === null || !(conquerLoginUsername instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login username field.');\n }\n this.conquerLoginUsername = conquerLoginUsername;\n const conquerLoginPassword = loginElement.querySelector('.conquer-login-password');\n if (conquerLoginPassword === null || !(conquerLoginPassword instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login password field.');\n }\n this.conquerLoginPassword = conquerLoginPassword;\n const conquerLoginSubmit = loginElement.querySelector('.conquer-login-submit');\n if (conquerLoginSubmit === null || !(conquerLoginSubmit instanceof HTMLButtonElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find the submit button for the login.');\n }\n this.conquerLoginSubmit = conquerLoginSubmit;\n console.log(this.conquerLoginSubmit.parentNode?.parentNode);\n this.conquerLoginSubmit.addEventListener('click', (event) => {\n event.preventDefault();\n const username = this.conquerLoginUsername.value;\n const password = this.conquerLoginPassword.value;\n this.conquerLogin.onLoginRequested(this, username, password);\n });\n }\n async goToRegister() {\n await this.removeLoginRegisterCombo();\n const registerElement = this.getRegisterDiv();\n registerElement.classList.remove('conquer-display-none');\n }\n async removeLoginRegisterCombo() {\n const registerElement = this.getRegisterDiv();\n const overlayElement = this.getOverlayDiv();\n overlayElement.classList.add('conquer-display-none');\n const loginElement = this.getLoginDiv();\n loginElement.classList.add('conquer-display-none');\n registerElement.classList.add('conquer-display-none');\n }\n async addNewLoginSuccessText(message) {\n this.unsetLoginAndRegisterErrors();\n this.conquerLoginSuccess.innerText = message;\n this.conquerLoginSuccess.classList.remove('conquer-display-none');\n }\n async addNewLoginError(error) {\n this.unsetLoginAndRegisterErrors();\n this.conquerLoginSuccess.classList.add('conquer-display-none');\n this.conquerLoginError.innerText = error;\n this.conquerLoginError.classList.remove('conquer-display-none');\n }\n async addNewRegisterError(error) {\n this.unsetLoginAndRegisterErrors();\n this.conquerLoginSuccess.classList.add('conquer-display-none');\n this.conquerRegisterError.innerText = error;\n this.conquerRegisterError.classList.remove('conquer-display-none');\n }\n async unsetLoginAndRegisterErrors() {\n this.conquerRegisterError.classList.add('conquer-display-none');\n this.conquerLoginError.classList.add('conquer-display-none');\n }\n async goToLogin() {\n await this.removeLoginRegisterCombo();\n const loginElement = this.getLoginDiv();\n loginElement.classList.remove('conquer-display-none');\n }\n async addNewLoginRegisterError(message) {\n this.addNewRegisterError(message);\n this.addNewLoginError(message);\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/interface/login.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ LoginUI)\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_interface__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/interface */ \"./js-src/conquer/interface.ts\");\n\n\nclass LoginUI extends _burguillosinfo_conquer_interface__WEBPACK_IMPORTED_MODULE_1__[\"default\"] {\n constructor(conquerLogin) {\n super();\n this.conquerLogin = conquerLogin;\n }\n run() {\n this.conquerLogin.on('login', () => {\n this.runCallbacks('close');\n });\n this.storeRegisterElements();\n this.storeLoginElements();\n }\n getLoginDiv() {\n const element = this.getNodes()[1];\n if (element === undefined || !(element instanceof HTMLDivElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Login is not a div.');\n }\n return element;\n }\n getOverlayDiv() {\n const element = this.getNodes()[0];\n if (element === undefined || !(element instanceof HTMLDivElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Overlay transparent is not a div.');\n }\n return element;\n }\n getRegisterDiv() {\n const element = this.getNodes()[2];\n if (element === undefined || !(element instanceof HTMLDivElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Register is not a div.');\n }\n return element;\n }\n generateNodes() {\n const resultArray = [];\n const overlay = this.getNodeFromTemplateId('conquer-overlay-transparent-template');\n overlay.classList.remove('conquer-display-none');\n resultArray.push(overlay);\n const login = this.getNodeFromTemplateId('conquer-login-template');\n login.classList.remove('conquer-display-none');\n if (!(login instanceof HTMLDivElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Login is required to be a Div.');\n }\n resultArray.push(login);\n const register = this.getNodeFromTemplateId('conquer-register-template');\n resultArray.push(register);\n return resultArray;\n }\n async storeRegisterElements() {\n const registerElement = this.getRegisterDiv();\n const conquerRegisterGoToLogin = registerElement.querySelector('.conquer-register-go-to-login');\n if (conquerRegisterGoToLogin === null || !(conquerRegisterGoToLogin instanceof HTMLAnchorElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Link to go to login from register is invalid.');\n }\n this.conquerRegisterGoToLogin = conquerRegisterGoToLogin;\n this.conquerRegisterGoToLogin.addEventListener('click', () => {\n this.goToLogin();\n });\n const conquerRegisterUsername = registerElement.querySelector('.conquer-register-username');\n if (conquerRegisterUsername === null || !(conquerRegisterUsername instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No username field in conquer register.');\n }\n this.conquerRegisterUsername = conquerRegisterUsername;\n const conquerRegisterPassword = registerElement.querySelector('.conquer-register-password');\n if (conquerRegisterPassword === null || !(conquerRegisterPassword instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No password field in conquer register.');\n }\n this.conquerRegisterPassword = conquerRegisterPassword;\n const conquerRegisterRepeatPassword = registerElement.querySelector('.conquer-register-repeat-password');\n if (conquerRegisterRepeatPassword === null || !(conquerRegisterRepeatPassword instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No repeat password field in conquer register.');\n }\n this.conquerRegisterRepeatPassword = conquerRegisterRepeatPassword;\n const conquerRegisterSubmit = registerElement.querySelector('.conquer-register-submit');\n if (conquerRegisterSubmit === null || !(conquerRegisterSubmit instanceof HTMLButtonElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('No register submit button found.');\n }\n this.conquerRegisterSubmit = conquerRegisterSubmit;\n this.conquerRegisterSubmit.addEventListener('click', (event) => {\n event.preventDefault();\n const username = this.conquerRegisterUsername.value;\n const password = this.conquerRegisterPassword.value;\n const repeatPassword = this.conquerRegisterRepeatPassword.value;\n this.conquerLogin.onRegisterRequest(this, username, password, repeatPassword);\n });\n const conquerRegisterError = registerElement.querySelector('.conquer-register-error');\n if (conquerRegisterError === null || !(conquerRegisterError instanceof HTMLParagraphElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find the conquer error element.');\n }\n this.conquerRegisterError = conquerRegisterError;\n }\n storeLoginElements() {\n const loginElement = this.getLoginDiv();\n const conquerLoginGoToRegister = loginElement.querySelector('.conquer-login-go-to-register');\n if (conquerLoginGoToRegister === null || !(conquerLoginGoToRegister instanceof HTMLAnchorElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Link to go to register from login is invalid.');\n }\n this.conquerLoginGoToRegister = conquerLoginGoToRegister;\n this.conquerLoginGoToRegister.addEventListener('click', () => {\n this.goToRegister();\n });\n const conquerLoginError = loginElement.querySelector('.conquer-login-error');\n if (conquerLoginError === null || !(conquerLoginError instanceof HTMLParagraphElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login error.');\n }\n this.conquerLoginError = conquerLoginError;\n const conquerLoginSuccess = loginElement.querySelector('.conquer-login-success');\n if (conquerLoginSuccess === null || !(conquerLoginSuccess instanceof HTMLParagraphElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login success.');\n }\n this.conquerLoginSuccess = conquerLoginSuccess;\n const conquerLoginUsername = loginElement.querySelector('.conquer-login-username');\n if (conquerLoginUsername === null || !(conquerLoginUsername instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login username field.');\n }\n this.conquerLoginUsername = conquerLoginUsername;\n const conquerLoginPassword = loginElement.querySelector('.conquer-login-password');\n if (conquerLoginPassword === null || !(conquerLoginPassword instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find conquer login password field.');\n }\n this.conquerLoginPassword = conquerLoginPassword;\n const conquerLoginSubmit = loginElement.querySelector('.conquer-login-submit');\n if (conquerLoginSubmit === null || !(conquerLoginSubmit instanceof HTMLButtonElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_0__[\"default\"].fail('Unable to find the submit button for the login.');\n }\n this.conquerLoginSubmit = conquerLoginSubmit;\n this.conquerLoginSubmit.addEventListener('click', (event) => {\n event.preventDefault();\n const username = this.conquerLoginUsername.value;\n const password = this.conquerLoginPassword.value;\n this.conquerLogin.onLoginRequested(this, username, password);\n });\n }\n async goToRegister() {\n await this.removeLoginRegisterCombo();\n const registerElement = this.getRegisterDiv();\n registerElement.classList.remove('conquer-display-none');\n }\n async removeLoginRegisterCombo() {\n const registerElement = this.getRegisterDiv();\n const overlayElement = this.getOverlayDiv();\n overlayElement.classList.add('conquer-display-none');\n const loginElement = this.getLoginDiv();\n loginElement.classList.add('conquer-display-none');\n registerElement.classList.add('conquer-display-none');\n }\n async addNewLoginSuccessText(message) {\n this.unsetLoginAndRegisterErrors();\n this.conquerLoginSuccess.innerText = message;\n this.conquerLoginSuccess.classList.remove('conquer-display-none');\n }\n async addNewLoginError(error) {\n this.unsetLoginAndRegisterErrors();\n this.conquerLoginSuccess.classList.add('conquer-display-none');\n this.conquerLoginError.innerText = error;\n this.conquerLoginError.classList.remove('conquer-display-none');\n }\n async addNewRegisterError(error) {\n this.unsetLoginAndRegisterErrors();\n this.conquerLoginSuccess.classList.add('conquer-display-none');\n this.conquerRegisterError.innerText = error;\n this.conquerRegisterError.classList.remove('conquer-display-none');\n }\n async unsetLoginAndRegisterErrors() {\n this.conquerRegisterError.classList.add('conquer-display-none');\n this.conquerLoginError.classList.add('conquer-display-none');\n }\n async goToLogin() {\n await this.removeLoginRegisterCombo();\n const loginElement = this.getLoginDiv();\n loginElement.classList.remove('conquer-display-none');\n }\n async addNewLoginRegisterError(message) {\n this.addNewRegisterError(message);\n this.addNewLoginError(message);\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/interface/login.ts?"); /***/ }), @@ -148,6 +148,17 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ }), +/***/ "./js-src/conquer/interface/new-team.ts": +/*!**********************************************!*\ + !*** ./js-src/conquer/interface/new-team.ts ***! + \**********************************************/ +/***/ ((__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 */ NewTeamUI)\n/* harmony export */ });\n/* harmony import */ var _burguillosinfo_conquer_interface_abstract_top_bar_interface__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/abstract-top-bar-interface */ \"./js-src/conquer/interface/abstract-top-bar-interface.ts\");\n/* harmony import */ var _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer */ \"./js-src/conquer/index.ts\");\n\n\nclass NewTeamUI extends _burguillosinfo_conquer_interface_abstract_top_bar_interface__WEBPACK_IMPORTED_MODULE_0__[\"default\"] {\n getSubmitButton() {\n const submitButton = this.getMainNode().querySelector('button.new-team-form-submit');\n if (submitButton === null || !(submitButton instanceof HTMLElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_1__[\"default\"].fail('SubmitButton is null');\n }\n return submitButton;\n }\n getErrorElement() {\n const errorElement = this.getMainNode().querySelector('p.conquer-error');\n if (errorElement === null || !(errorElement instanceof HTMLElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_1__[\"default\"].fail('No error element set');\n }\n return errorElement;\n }\n getInputTeamName() {\n const teamName = this.getMainNode().querySelector('input.conquer-team-name');\n if (teamName === null || !(teamName instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_1__[\"default\"].fail('TeamName is null');\n }\n return teamName;\n }\n getInputTeamColor() {\n const teamColor = this.getMainNode().querySelector('input.conquer-team-color');\n if (teamColor === null || !(teamColor instanceof HTMLInputElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_1__[\"default\"].fail('TeamColor is null');\n }\n return teamColor;\n }\n getTextareaTeamDescription() {\n const teamDescription = this.getMainNode().querySelector('textarea.conquer-team-description');\n if (teamDescription === null || !(teamDescription instanceof HTMLTextAreaElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_1__[\"default\"].fail('TeamDescription is null');\n }\n return teamDescription;\n }\n constructor() {\n super();\n }\n run() {\n const mainNode = this.getMainNode();\n const form = this.getNodeFromTemplateId('conquer-new-team-form-creation-template');\n mainNode.append(form);\n this.getSubmitButton().addEventListener('click', (event) => {\n event.preventDefault();\n this.onSubmit();\n });\n form.classList.remove('conquer-display-none');\n mainNode.classList.remove('conquer-display-none');\n }\n setError(error) {\n const errorElement = this.getErrorElement();\n errorElement.classList.remove('conquer-display-none');\n errorElement.innerText = error;\n }\n onSubmit() {\n const inputTeamName = this.getInputTeamName();\n const textareaTeamDescription = this.getTextareaTeamDescription();\n const inputTeamColor = this.getInputTeamColor();\n const name = inputTeamName.value;\n const description = textareaTeamDescription.value;\n const color = inputTeamColor.value;\n if (name.length < 5) {\n this.setError('Todos los equipos deben tener un nombre mayor a 4 caracteres.');\n return;\n }\n const urlTeam = new URL('/conquer/team', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n fetch(urlTeam, {\n method: 'PUT',\n body: JSON.stringify({\n description: description,\n name: name,\n color: color,\n }),\n }).then(async (res) => {\n let responseBody;\n try {\n responseBody = await res.json();\n }\n catch (error) {\n this.setError('Respuesta erronea del servidor.');\n return;\n }\n if (res.status !== 200) {\n this.setError(responseBody.error);\n return;\n }\n this.runCallbacks('close');\n });\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/interface/new-team.ts?"); + +/***/ }), + /***/ "./js-src/conquer/interface/node-view.ts": /*!***********************************************!*\ !*** ./js-src/conquer/interface/node-view.ts ***! @@ -166,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 */ 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 generateNodes() {\n const player = this.getNodeFromTemplateId('conquer-interface-with-top-bar-template');\n return [player];\n }\n generateInterfaceElementCentered() {\n return this.getNodeFromTemplateId('conquer-interface-element-padded-template');\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 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 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 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 generateNodes() {\n const player = this.getNodeFromTemplateId('conquer-interface-with-top-bar-template');\n return [player];\n }\n generateInterfaceElementCentered() {\n return this.getNodeFromTemplateId('conquer-interface-element-padded-template');\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?"); /***/ }), @@ -188,7 +199,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_5__ = __webpack_require__(/*! ol/style/Style */ \"./node_modules/ol/style/Style.js\");\n/* harmony import */ var ol_Feature__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ol/Feature */ \"./node_modules/ol/Feature.js\");\n/* harmony import */ var ol_style_Circle__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ol/style/Circle */ \"./node_modules/ol/style/Circle.js\");\n/* harmony import */ var ol_geom_Point__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ol/geom/Point */ \"./node_modules/ol/geom/Point.js\");\n/* harmony import */ var ol_style_Fill__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ol/style/Fill */ \"./node_modules/ol/style/Fill.js\");\n/* harmony import */ var ol_style_Stroke__WEBPACK_IMPORTED_MODULE_8__ = __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\");\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\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 interfaceManager.push(viewNodeInterface);\n this.runCallbacks('click');\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 console.log(this.coordinate_1);\n console.log(this.coordinate_2);\n this.feature = new ol_Feature__WEBPACK_IMPORTED_MODULE_3__[\"default\"]({\n geometry: new ol_geom_Point__WEBPACK_IMPORTED_MODULE_4__[\"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_5__[\"default\"]({\n image: new ol_style_Circle__WEBPACK_IMPORTED_MODULE_6__[\"default\"]({\n radius: 14,\n fill: new ol_style_Fill__WEBPACK_IMPORTED_MODULE_7__[\"default\"]({ color: 'white' }),\n stroke: new ol_style_Stroke__WEBPACK_IMPORTED_MODULE_8__[\"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_5__ = __webpack_require__(/*! ol/style/Style */ \"./node_modules/ol/style/Style.js\");\n/* harmony import */ var ol_Feature__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ol/Feature */ \"./node_modules/ol/Feature.js\");\n/* harmony import */ var ol_style_Circle__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ol/style/Circle */ \"./node_modules/ol/style/Circle.js\");\n/* harmony import */ var ol_geom_Point__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ol/geom/Point */ \"./node_modules/ol/geom/Point.js\");\n/* harmony import */ var ol_style_Fill__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ol/style/Fill */ \"./node_modules/ol/style/Fill.js\");\n/* harmony import */ var ol_style_Stroke__WEBPACK_IMPORTED_MODULE_8__ = __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\");\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\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 interfaceManager.push(viewNodeInterface);\n this.runCallbacks('click');\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_3__[\"default\"]({\n geometry: new ol_geom_Point__WEBPACK_IMPORTED_MODULE_4__[\"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_5__[\"default\"]({\n image: new ol_style_Circle__WEBPACK_IMPORTED_MODULE_6__[\"default\"]({\n radius: 14,\n fill: new ol_style_Fill__WEBPACK_IMPORTED_MODULE_7__[\"default\"]({ color: 'white' }),\n stroke: new ol_style_Stroke__WEBPACK_IMPORTED_MODULE_8__[\"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?"); /***/ }), diff --git a/templates/conquer/_new-team-form-creation-template.html.ep b/templates/conquer/_new-team-form-creation-template.html.ep new file mode 100644 index 0000000..7d9a8d4 --- /dev/null +++ b/templates/conquer/_new-team-form-creation-template.html.ep @@ -0,0 +1,18 @@ +
+
+

+ + + + +
+ +
+
+
+ diff --git a/templates/conquer/index.html.ep b/templates/conquer/index.html.ep index e1f4829..228ade2 100644 --- a/templates/conquer/index.html.ep +++ b/templates/conquer/index.html.ep @@ -15,6 +15,7 @@ %= include 'conquer/_interface-with-top-bar-template'; %= include 'conquer/_login-template'; %= include 'conquer/_register-template'; +%= include 'conquer/_new-team-form-creation-template';

Vista de nodo.

@@ -22,6 +23,7 @@

+