the merge project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.2 KiB

4 years ago
import {createStore} from 'vuex'
import axios from "axios";
4 years ago
export default createStore({
state: {
player: null,
4 years ago
inventory: []
},
getters: {},
mutations: {
fetchPlayer(state) {
let vuex = this;
let existingUserUuid = localStorage.getItem('farmfresh_uuid');
if (existingUserUuid != null) {
axios.get(
'http://api.luna-development.net/api/player/fetch/'+existingUserUuid
).then((response) => {
if (response.data && response.data.uuid) {
state.player = response.data;
vuex.commit('fetchInventory');
} else {
alert('User not found');
}
}).catch((error) => {
alert('User not found');
console.log(error);
});
}
},
fetchInventory(state) {
axios.get(
'http://api.luna-development.net/api/inventory/fetch/'+state.player.uuid
).then((response) => {
if (response.data.success) {
state.inventory = response.data.inventory;
}
});
},
createNewPlayer(state, userName) {
axios.post('http://api.luna-development.net/api/player/create', {
name: userName.trim(),
game_id: 1
}).then((response) => {
if (response.data.success) {
state.player = response.data.player;
localStorage.setItem('farmfresh_uuid', response.data.player.uuid);
}
});
},
destroyPlayer(state) {
axios.post('http://api.luna-development.net/api/player/destroy', {
name: state.player.name,
uuid: state.player.uuid
}).then((response) => {
if (response.data.success) {
state.player = null;
localStorage.removeItem('farmfresh_uuid');
}
});
}
},
4 years ago
actions: {},
modules: {}
});