mirror of
https://github.com/neon443/CookieSwifter.git
synced 2026-03-11 07:09:11 +00:00
forgot to start timer on init lollll
This commit is contained in:
@@ -72,17 +72,22 @@ class CookieGame: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
//FLAG: DONT REMOVE
|
||||||
|
//im so stupid
|
||||||
|
startTimer()
|
||||||
loadSavedGames()
|
loadSavedGames()
|
||||||
}
|
}
|
||||||
|
|
||||||
func startTimer() {
|
func startTimer() {
|
||||||
if timer == nil {
|
if timer == nil {
|
||||||
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
|
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
|
||||||
|
DispatchQueue.main.async {
|
||||||
self.cookies += self.cps
|
self.cookies += self.cps
|
||||||
self.checkAchievements()
|
self.checkAchievements()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func buyItem(at index: Int, quantity: Int) {
|
func buyItem(at index: Int, quantity: Int) {
|
||||||
let cost = totalCost(of: index, quantity: quantity)
|
let cost = totalCost(of: index, quantity: quantity)
|
||||||
@@ -110,13 +115,19 @@ class CookieGame: ObservableObject {
|
|||||||
for i in items.indices {
|
for i in items.indices {
|
||||||
items[i].cps *= 2
|
items[i].cps *= 2
|
||||||
}
|
}
|
||||||
|
cps = items.reduce(0) { $0 + $1.cps * $1.count }
|
||||||
} else if upgrade.appliesTo == "Temporary" {
|
} else if upgrade.appliesTo == "Temporary" {
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 30) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 30) {
|
||||||
self.cps /= 3
|
self.cps /= 3
|
||||||
}
|
}
|
||||||
cps *= 3
|
cps *= 3
|
||||||
} else if let itemIndex = items.firstIndex(where: { $0.name == upgrade.appliesTo }) {
|
} else if let itemIndex = items.firstIndex(where: { $0.name == upgrade.appliesTo }) {
|
||||||
items[itemIndex].cps = Int(Double(items[itemIndex].cps) * (upgrade.name.contains("Efficiency") ? 1.5 : 2))
|
var item = items[itemIndex]
|
||||||
|
if upgrade.name.contains("Efficien") {
|
||||||
|
item.cps = Int(Double(item.cps) * 1.5)
|
||||||
|
} else {
|
||||||
|
item.cps *= 2
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cookies -= upgrade.cost
|
cookies -= upgrade.cost
|
||||||
|
|||||||
Reference in New Issue
Block a user