|
|
|
@ -5,17 +5,19 @@ import {ItemTypes} from "@/data/ItemTypes";
@@ -5,17 +5,19 @@ import {ItemTypes} from "@/data/ItemTypes";
|
|
|
|
|
import createPersistedState from "vuex-persistedstate"; |
|
|
|
|
import ItemService from "@/services/ItemService"; |
|
|
|
|
import iziToast from "izitoast"; |
|
|
|
|
import AnimalService from "@/services/AnimalService"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default createStore({ |
|
|
|
|
state: { |
|
|
|
|
initialized: null, |
|
|
|
|
tickBeat: false, |
|
|
|
|
player: { |
|
|
|
|
// TODO: ADD PLAYER INTRODUCTION
|
|
|
|
|
name: 'Franz', |
|
|
|
|
money: 1_000, |
|
|
|
|
unlocked: { |
|
|
|
|
fields: 48 |
|
|
|
|
fields: 10 |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
time: { |
|
|
|
@ -33,7 +35,59 @@ export default createStore({
@@ -33,7 +35,59 @@ export default createStore({
|
|
|
|
|
selections: { |
|
|
|
|
field: null, |
|
|
|
|
item: null |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
animals: [ |
|
|
|
|
{ |
|
|
|
|
id: 1, |
|
|
|
|
name: 'Nugget', |
|
|
|
|
position: { |
|
|
|
|
facing: 'left', |
|
|
|
|
moving: false, |
|
|
|
|
x: 20, |
|
|
|
|
y: 20 |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
id: 1, |
|
|
|
|
name: 'Nugget', |
|
|
|
|
position: { |
|
|
|
|
facing: 'left', |
|
|
|
|
moving: false, |
|
|
|
|
x: 20, |
|
|
|
|
y: 20 |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
id: 1, |
|
|
|
|
name: 'Nugget', |
|
|
|
|
position: { |
|
|
|
|
facing: 'left', |
|
|
|
|
moving: false, |
|
|
|
|
x: 20, |
|
|
|
|
y: 20 |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
id: 1, |
|
|
|
|
name: 'Nugget', |
|
|
|
|
position: { |
|
|
|
|
facing: 'left', |
|
|
|
|
moving: false, |
|
|
|
|
x: 20, |
|
|
|
|
y: 20 |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
id: 1, |
|
|
|
|
name: 'Nugget', |
|
|
|
|
position: { |
|
|
|
|
facing: 'left', |
|
|
|
|
moving: false, |
|
|
|
|
x: 20, |
|
|
|
|
y: 20 |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
getters: { |
|
|
|
|
selectedField(state) { |
|
|
|
@ -90,6 +144,12 @@ export default createStore({
@@ -90,6 +144,12 @@ export default createStore({
|
|
|
|
|
item.quantity = inventoryItem.quantity; |
|
|
|
|
return item; |
|
|
|
|
}) ?? []; |
|
|
|
|
}, |
|
|
|
|
getAnimalsWithAnimalData(state) { |
|
|
|
|
return state.animals.map((animal) => { |
|
|
|
|
animal.data = AnimalService.getAnimalByID(animal.id) |
|
|
|
|
return animal; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
mutations: { |
|
|
|
@ -105,6 +165,7 @@ export default createStore({
@@ -105,6 +165,7 @@ export default createStore({
|
|
|
|
|
this.commit('generateField'); |
|
|
|
|
}, |
|
|
|
|
updateTimestamp(state) { |
|
|
|
|
state.tickBeat = !state.tickBeat; |
|
|
|
|
state.time.stamp = moment().format('H:mm:ss') |
|
|
|
|
}, |
|
|
|
|
generateField(state) { |
|
|
|
@ -150,6 +211,11 @@ export default createStore({
@@ -150,6 +211,11 @@ export default createStore({
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
iziToast.success({ |
|
|
|
|
title: 'Harvested '+productFromSeed.name, |
|
|
|
|
image: productFromSeed.icon |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
this.commit('addItemToInventory', { |
|
|
|
|
item: productFromSeed, |
|
|
|
|
quantity: 1 |
|
|
|
@ -264,6 +330,37 @@ export default createStore({
@@ -264,6 +330,37 @@ export default createStore({
|
|
|
|
|
}, |
|
|
|
|
toggleGrouping(state) { |
|
|
|
|
state.groupInventory = !state.groupInventory; |
|
|
|
|
}, |
|
|
|
|
doAnimalMovement(state) { |
|
|
|
|
state.animals.forEach((animal) => { |
|
|
|
|
animal.position.moving = false; |
|
|
|
|
let moveChance = Math.random(); |
|
|
|
|
// console.log(moveChance)
|
|
|
|
|
// console.log(animal.position.x+'|'+animal.position.y)
|
|
|
|
|
|
|
|
|
|
if (moveChance > 0.6) { |
|
|
|
|
animal.position.moving = true; |
|
|
|
|
let randomX = Math.random() * 5 - 2.0; |
|
|
|
|
let randomY = Math.random() * 5 - 2.0; |
|
|
|
|
// console.log(randomX+'|'+randomY)
|
|
|
|
|
let newX = Math.floor(Number(animal.position.x) + Number(randomX)); |
|
|
|
|
let newY = Math.floor(Number(animal.position.y) + Number(randomY)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
animal.position.x = (newX > 0 ? (newX < 60 ? newX: 60) : 0); |
|
|
|
|
animal.position.y = (newY > 0 ? (newY < 70 ? newY: 70) : 0); |
|
|
|
|
|
|
|
|
|
animal.position.facing = randomY > 0 ? 'right' : 'left'; |
|
|
|
|
// console.debug('lazy chicken did move')
|
|
|
|
|
} else { |
|
|
|
|
// console.debug('lazy chicken did not move')
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
animal.position.moving = false; |
|
|
|
|
}, 500) |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
actions: {}, |
|
|
|
|