-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathplayer.js
47 lines (43 loc) · 1.1 KB
/
player.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Player {
constructor() {
// Just for the idb primary key.
this.id = 1
this.inventory = {}
this.maxInventory = 100
this.pets = {}
this.cropImages = {}
this.cropTimes = {}
this.animalItems = {}
this.currentPerkset = null
this.perksets = null
this.settings = {}
this.perks = {}
this.farmSupply = {}
this.perksByPerkset = {}
this.orchard = null
this.vineyard = null
this.cellar = null
}
async load(db) {
const data = await db.get("player", this.id)
if (data !== null) {
Object.assign(this, data)
}
}
async save(db) {
await db.put("player", this)
}
perkValue(perks) {
let total = 0
for (const [key, value] of Object.entries(perks)) {
if (this.perks[key] || this.farmSupply[key]) {
total += value
}
}
return total
}
}
export const setupPlayer = async state => {
state.player = new Player()
await state.player.load(state.db)
}