Skip to content

Commit

Permalink
Send requesting player
Browse files Browse the repository at this point in the history
  • Loading branch information
mduffin95 committed Apr 22, 2023
1 parent 7e85744 commit c5ff9a4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
45 changes: 27 additions & 18 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
import axios from "axios";

function getUrl() {
let url = process.env.VUE_APP_BACKEND_URL + ":" + process.env.VUE_APP_BACKEND_PORT;
console.log(url);
return url;
let url = process.env.VUE_APP_BACKEND_URL + ":" + process.env.VUE_APP_BACKEND_PORT;
console.log(url);
return url;
}

const axiosClient = axios.create({
baseURL: getUrl(),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
baseURL: getUrl(),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
}
});

export function sendDraft(id, territoryName) {
return axiosClient.post("/api/games/" + id + "/turn/draft", { territory: territoryName });
export function sendDraft(id, player, territoryName) {
const draftData = {
requestingPlayer: player,
territory: territoryName
}
return axiosClient.post("/api/games/" + id + "/turn/draft", draftData);
}

export function sendAttack(id, fromTerritory, toTerritory) {
const attack_data = {
from: fromTerritory,
to: toTerritory,
}
return axiosClient.post("/api/games/" + id + "/turn/attack", attack_data);
export function sendAttack(id, player, fromTerritory, toTerritory) {
const attack_data = {
requestingPlayer: player,
from: fromTerritory,
to: toTerritory,
}
return axiosClient.post("/api/games/" + id + "/turn/attack", attack_data);
}

export function sendMove(id, unitsToMove) {
return axiosClient.post("/api/games/" + id + "/turn/move", { units: unitsToMove })
export function sendMove(id, player, unitsToMove) {
const moveData = {
requestingPlayer: player,
units: unitsToMove
}
return axiosClient.post("/api/games/" + id + "/turn/move", moveData)
}

export { axiosClient }
14 changes: 8 additions & 6 deletions src/views/GamePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const clicked = (territory) => {
switch (store.model.phase) {
case "DRAFT":
case "ALLDRAFT":
sendDraft(route.params.id, territory.name);
sendDraft(route.params.id, store.playerName, territory.name);
break;
case "ATTACK":
attack(territory);
Expand All @@ -83,7 +83,7 @@ const attack = (territory) => {
store.lastSelected.player.name == currentPlayer &&
territory.player.name != currentPlayer
) {
sendAttack(route.params.id, store.lastSelected.name, territory.name);
sendAttack(route.params.id, store.playerName, store.lastSelected.name, territory.name);
store.lastSelected = null;
} else if (territory.player.name == currentPlayer) {
store.lastSelected = territory;
Expand Down Expand Up @@ -111,7 +111,7 @@ const fortify = (territory) => {
trapFocus: true,
events: {
"move-units": (units) =>
fortifyWithUnits(store.lastSelected.name, territory.name, units),
fortifyWithUnits(store.playerName, store.lastSelected.name, territory.name, units),
},
});
}
Expand All @@ -120,8 +120,9 @@ const fortify = (territory) => {
}
};
const fortifyWithUnits = (from, to, units) => {
const fortifyWithUnits = (player, from, to, units) => {
const fortify_data = {
requestingPlayer: player,
from: from,
to: to,
units: units,
Expand All @@ -138,7 +139,8 @@ const fortifyWithUnits = (from, to, units) => {
};
const move = (unitsToMove) => {
sendMove(route.params.id, unitsToMove)
const currentPlayer = store.model.currentPlayer;
sendMove(route.params.id, currentPlayer, unitsToMove)
// .then((response) => {
// store.model = response.data;
// })
Expand All @@ -164,7 +166,7 @@ const modal = (modalVM) => {
const endTurn = () => {
axiosClient
.post("/api/games/" + route.params.id + "/turn/end")
.post("/api/games/" + route.params.id + "/turn/end", { requestingPlayer: store.playerName })
.catch((error) => {
console.log(error);
});
Expand Down

0 comments on commit c5ff9a4

Please sign in to comment.