|
|
|
|
import {createStore} from 'vuex'
|
|
|
|
|
import moment from "moment";
|
|
|
|
|
import getSeason from "@/tools/getSeason";
|
|
|
|
|
import ItemTypes from "@/data/itemTypes";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default createStore({
|
|
|
|
|
state: {
|
|
|
|
|
player: null,
|
|
|
|
|
unlocked: {
|
|
|
|
|
fields: 48
|
|
|
|
|
},
|
|
|
|
|
time: {
|
|
|
|
|
stamp: null,
|
|
|
|
|
week: null,
|
|
|
|
|
season: null,
|
|
|
|
|
weekday: null,
|
|
|
|
|
weekdayNr: null
|
|
|
|
|
},
|
|
|
|
|
inventory: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Wheat seeds',
|
|
|
|
|
type: ItemTypes.Seeds,
|
|
|
|
|
cropID: 1,
|
|
|
|
|
count: 0
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
cropField: [],
|
|
|
|
|
selections: {
|
|
|
|
|
field: null,
|
|
|
|
|
item: null
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getters: {
|
|
|
|
|
selectedField(state) {
|
|
|
|
|
return state.cropField.filter(function (field) {
|
|
|
|
|
return field.id === state.selections.field;
|
|
|
|
|
})[0];
|
|
|
|
|
},
|
|
|
|
|
seeds(state) {
|
|
|
|
|
return state.inventory.filter(function (item) {
|
|
|
|
|
return item.type === ItemTypes.Seeds;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
mutations: {
|
|
|
|
|
initialize(state) {
|
|
|
|
|
state.time.week = moment().week();
|
|
|
|
|
state.time.season = getSeason(state.time.week);
|
|
|
|
|
state.time.weekday = moment().weekday();
|
|
|
|
|
state.time.weekdayNr = moment().format('dddd');
|
|
|
|
|
|
|
|
|
|
this.commit('generateField');
|
|
|
|
|
},
|
|
|
|
|
updateTimestamp(state) {
|
|
|
|
|
state.time.stamp = moment().format('H:mm:ss')
|
|
|
|
|
},
|
|
|
|
|
generateField(state) {
|
|
|
|
|
let fieldIndex = 0;
|
|
|
|
|
|
|
|
|
|
while(state.cropField.length < state.unlocked.fields) {
|
|
|
|
|
fieldIndex++;
|
|
|
|
|
|
|
|
|
|
state.cropField.push({
|
|
|
|
|
id: fieldIndex
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
selectField(state, id) {
|
|
|
|
|
console.debug('select field with id '+id)
|
|
|
|
|
state.selections.field = id;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
actions: {},
|
|
|
|
|
modules: {}
|
|
|
|
|
});
|