Skip to content

Commit

Permalink
(frontend) static map
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Alexandre35 committed Jun 26, 2024
1 parent ef1a0c1 commit c983869
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 7 deletions.
100 changes: 100 additions & 0 deletions travian/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions travian/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false"
},
"dependencies": {
"axios": "^1.7.2",
"pinia": "^2.1.6",
"vue": "^3.3.4",
"vue-router": "^4.2.4"
Expand Down
34 changes: 34 additions & 0 deletions travian/frontend/src/components/Map.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script setup>
import { ref, onMounted } from 'vue';
const mapData = ref([]);
onMounted(async () => {
try {
const { default: axios } = await import('axios');
const response = await axios.get('http://localhost:8000/get_map_data');
mapData.value = response.data;
} catch (error) {
console.error('Error fetching map data:', error);
}
});
</script>

<template>
<div class="map">
<div v-for="(row, rowIndex) in mapData" :key="rowIndex" class="map-row">
<div
v-for="(cell, colIndex) in row"
:key="colIndex"
class="map-cell"
:class="{ 'has-village': cell.hasVillage }"
>
<img v-if="cell.hasVillage" src="village_image_path" alt="Village" />
</div>
</div>
</div>
</template>

<style scoped>
/* Add your scoped styles */
</style>
17 changes: 10 additions & 7 deletions travian/frontend/src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import { createRouter, createWebHistory } from 'vue-router';
import HomeView from '../views/HomeView.vue';
import Map from '../components/Map.vue'; // Import the Map component

const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
Expand All @@ -12,12 +13,14 @@ const router = createRouter({
{
path: '/about',
name: 'about',
// route level code-splitting
// this generates a separate chunk (About.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import('../views/AboutView.vue')
},
{
path: '/map',
name: 'map',
component: Map // Add the Map component route
}
]
})
});

export default router
export default router;

0 comments on commit c983869

Please sign in to comment.