Skip to content

Commit

Permalink
chore: add changes
Browse files Browse the repository at this point in the history
  • Loading branch information
spectrachrome committed Nov 20, 2023
1 parent 68d64b7 commit a122e04
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 20 deletions.
8 changes: 0 additions & 8 deletions app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ import {
} from 'vuex';
import CookieLaw from 'vue-cookie-law';
import { loadIndicatorData } from '@/utils';
import { createHexMap } from '@/plugins/minesweeper/index';

import axios from 'axios';
import { Wkt } from 'wicket';
Expand Down Expand Up @@ -268,13 +267,6 @@ export default {
}
});
this.setAreaFromQuery();

const { map } = getMapInstance('centerMap');
const loadendHandler = async () => {
await createHexMap(map);
map.un('loadend', loadendHandler); // Unregister the event handler after it's called once
};
map.on('loadend', loadendHandler);
},
methods: {
async checkComingSoon() {
Expand Down
1 change: 1 addition & 0 deletions app/src/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ module.exports = [
countDownTimer: '2020-06-25T13:30:00.000+02:00',
countDownMatch: ['eodashboard.org', 'www.eodashboard.org', 'eodash-trilateral.eox.at'],
enableStories: true,
minesweeperConfig: true,
},
{
id: 'gtif',
Expand Down
69 changes: 69 additions & 0 deletions app/src/components/map/Map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,40 @@
:center.sync="currentCenter"
mapControl
/>

<div>
<v-dialog width="500">
<template v-slot:activator="{ props }">
<v-btn
v-bind="props"
@click="toggleMinesweeper"
>
<span
:style="`font-size: 20px; filter: invert(28%) sepia(100%) hue-rotate(${minesweeper.isEnabled ? 60: -40}deg) saturate(3);`"

Check failure on line 154 in app/src/components/map/Map.vue

View workflow job for this annotation

GitHub Actions / deploy

This line has a length of 140. Maximum allowed is 100
>
💣
</span>
</v-btn>
</template>

<template v-slot:default="{ isActive }">
<v-card title="Dialog">
<v-card-text>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Check failure on line 164 in app/src/components/map/Map.vue

View workflow job for this annotation

GitHub Actions / deploy

This line has a length of 141. Maximum allowed is 100
</v-card-text>

<v-card-actions>
<v-spacer></v-spacer>

<v-btn
text="Close Dialog"
@click="isActive.value = false"
></v-btn>
</v-card-actions>
</v-card>
</template>
</v-dialog>
</div>
</div>
<div
v-if="$route.name !== 'demo'"
Expand Down Expand Up @@ -209,6 +243,7 @@ import {
findClosest,
} from '@/utils';
import getLocationCode from '../../mixins/getLocationCode';
import { createHexMap } from '@/plugins/minesweeper/index';

Check failure on line 246 in app/src/components/map/Map.vue

View workflow job for this annotation

GitHub Actions / deploy

`@/plugins/minesweeper/index` import should occur before import of `../../mixins/getLocationCode`
const geoJsonFormat = new GeoJSON({
});
Expand Down Expand Up @@ -288,6 +323,12 @@ export default {
viewZoomExtentFitId: null,
enableScrollyMode: false,
externallySuppliedTimeEntries: null,
minesweeper: {
isEnabled: true,
isLoaded: false,
// Layer IDs of the hex grid and board
uids: [],
}

Check failure on line 331 in app/src/components/map/Map.vue

View workflow job for this annotation

GitHub Actions / deploy

Missing trailing comma
};
},
computed: {
Expand Down Expand Up @@ -773,6 +814,15 @@ export default {
this.queryLink = new Link({ replace: true, params: ['x', 'y', 'z'] });
map.addInteraction(this.queryLink);
}
// Initialize Minesweeper game if options are present in the appConfig.
if (this.appConfig.minesweeperOptions) {
const loadendHandler = async () => {
this.minesweeper.uids = await createHexMap(map);
map.un('loadend', loadendHandler); // Unregister the event handler after it's called once
};
map.on('loadend', loadendHandler);
}
},
methods: {
convertDateForMsg(time) {
Expand Down Expand Up @@ -1054,6 +1104,25 @@ export default {
padding,
});
},
async toggleMinesweeper() {
let map = getMapInstance(this.mapId).map;

Check failure on line 1108 in app/src/components/map/Map.vue

View workflow job for this annotation

GitHub Actions / deploy

Use object destructuring

Check failure on line 1108 in app/src/components/map/Map.vue

View workflow job for this annotation

GitHub Actions / deploy

'map' is never reassigned. Use 'const' instead
if (this.minesweeper.isEnabled) {
for (const uid of this.minesweeper.uids) {

Check failure on line 1110 in app/src/components/map/Map.vue

View workflow job for this annotation

GitHub Actions / deploy

iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations
map.getLayers().getArray()
.filter(layer => {

Check failure on line 1112 in app/src/components/map/Map.vue

View workflow job for this annotation

GitHub Actions / deploy

Expected parentheses around arrow function argument
console.log(layer.get('ol_uid') === uid);
return layer.get('ol_uid') === uid

Check failure on line 1114 in app/src/components/map/Map.vue

View workflow job for this annotation

GitHub Actions / deploy

Missing semicolon
})
.forEach(layer => map.removeLayer(layer));

Check failure on line 1116 in app/src/components/map/Map.vue

View workflow job for this annotation

GitHub Actions / deploy

Expected parentheses around arrow function argument
}
this.minesweeper.isEnabled = false;
} else {
this.minesweeper.uids = await createHexMap(map);
this.minesweeper.isEnabled = true;
}
console.log(getMapInstance(this.mapId).map.getAllLayers());
}
},
beforeDestroy() {
if (this.mapId === 'centerMap') {
Expand Down
16 changes: 4 additions & 12 deletions app/src/plugins/minesweeper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ const setupGrid = (map) => {
});

const hex = new HexMap({ hexGrid: grid });
map.addLayer(new Image({ source: hex }));
let imageLayer = new Image({ source: hex });
map.addLayer(imageLayer);

return grid;
return [imageLayer.ol_uid, hex.ol_uid];
};

const updateTileVisuals = (x, y, grid, vectorSource, game) => {
Expand All @@ -37,8 +38,6 @@ const updateTileVisuals = (x, y, grid, vectorSource, game) => {
const feature = new Feature(new Polygon([hexagonVertices]));
const tile = game.get(x, y);

console.log(`Tile: ${tile.isMine ? '💣' : tile.adjacentMines}`);

// Assign a unique identifier to the feature
const featureId = `tile-${x}-${y}`;
feature.setId(featureId);
Expand Down Expand Up @@ -74,27 +73,20 @@ const handleMapClick = (e, game, grid, vectorSource) => {
e.preventDefault();

const { coordinate } = e;
console.log(coordinate);
// Get the axial coordinates of the clicked hexagon
const [q, r] = grid.coord2hex(coordinate);
const gameCoords = game.convertAxialToGameCoords(q, r);
const [x, y] = [gameCoords.x - 1, gameCoords.y];

console.log(`Got click: ${x}, ${y}`);

const revealedCoordsList = game.revealTile(x, y);

console.log(revealedCoordsList);

for (const [x, y] of revealedCoordsList) {
console.log('updating tile visuals');
updateTileVisuals(x, y, grid, vectorSource, game);
}
};

const getTileStyle = (tile) => {
let style;
console.log(tile);
if (tile.isRevealed === true) {
if (tile.isMine) {
style = new Style({
Expand All @@ -108,7 +100,7 @@ const getTileStyle = (tile) => {
});
} else {
style = new Style({
fill: new Fill({ color: '#777' }),
fill: new Fill({ color: 'rgba(0, 0, 0, 0.3)' }),
text: new Text({
text: tile.adjacentMines ? tile.adjacentMines.toString() : '0',
font: '20px Calibri,sans-serif',
Expand Down

0 comments on commit a122e04

Please sign in to comment.