|
|
@ -8,7 +8,8 @@ export default createStore({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
getters: {}, |
|
|
|
getters: {}, |
|
|
|
mutations: { |
|
|
|
mutations: { |
|
|
|
fetchUser(state) { |
|
|
|
fetchPlayer(state) { |
|
|
|
|
|
|
|
let vuex = this; |
|
|
|
let existingUserUuid = localStorage.getItem('farmfresh_uuid'); |
|
|
|
let existingUserUuid = localStorage.getItem('farmfresh_uuid'); |
|
|
|
|
|
|
|
|
|
|
|
if (existingUserUuid != null) { |
|
|
|
if (existingUserUuid != null) { |
|
|
@ -17,13 +18,48 @@ export default createStore({ |
|
|
|
).then((response) => { |
|
|
|
).then((response) => { |
|
|
|
if (response.data && response.data.uuid) { |
|
|
|
if (response.data && response.data.uuid) { |
|
|
|
state.player = response.data; |
|
|
|
state.player = response.data; |
|
|
|
|
|
|
|
vuex.commit('fetchInventory'); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
alert('User not found'); |
|
|
|
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'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
actions: {}, |
|
|
|
actions: {}, |
|
|
|
modules: {} |
|
|
|
modules: {} |
|
|
|
}) |
|
|
|
}); |
|
|
|