Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/farm.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,39 @@ const visitHarvestAll = async (state, page, url) => {
state.preHarvestInventory = undefined
}

const parseAnimalItems = (state, page) => {
let itemNames = []
switch(state.lastView) {
case "coop":
itemNames = ["Eggs", "Feathers"]
break
case "pasture":
itemNames = ["Milk"]
break
case "raptors":
itemNames = ["Antlers", "Bobs"]
break
}
const animalItems = {}
const parser = new DOMParser()
const dom = parser.parseFromString(page, "text/html")
const items = dom.querySelectorAll(".card-content-inner > strong")
for (let i = 0; i < itemNames.length; i++) {
animalItems[itemNames[i]] = items[i].textContent
}
return animalItems
}

const visitCoop = async (state, page, url) => {
state.lastView = "coop"
state.player.animalItems["Chickens"] = parseAnimalItems(state, page)
await state.player.save(state.db)
}

const visitPasture = async (state, page, url) => {
state.lastView = "pasture"
state.player.animalItems["Cows"] = parseAnimalItems(state, page)
await state.player.save(state.db)
}

const visitPigPen = async (state, page, url) => {
Expand All @@ -130,6 +157,8 @@ const visitPigPen = async (state, page, url) => {

const visitPen = async (state, page, url) => {
state.lastView = "raptors"
state.player.animalItems["Raptors"] = parseAnimalItems(state, page)
await state.player.save(state.db)
}

const visitHab = async (state, page, url) => {
Expand Down
1 change: 1 addition & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Player {
this.pets = {}
this.cropImages = {}
this.cropTimes = {}
this.animalItems = {}
this.currentPerkset = null
this.perksets = null
this.settings = {}
Expand Down