RapidGameFramework
Reusable Godot managers for data-driven small games
Loading...
Searching...
No Matches
economy_manager.gd
Go to the documentation of this file.
1extends RefCounted
2
3
6
7var money := 0
8
9
10
11func set_money(value:int) -> void:
12 money = max(0, value)
13
14
15
16func add_money(amount:int) -> void:
17 set_money(money + amount)
18
19
20
21func can_spend(amount:int) -> bool:
22 return money >= amount
23
24
25
26func spend(amount:int) -> bool:
27 if amount < 0 or not can_spend(amount):
28 return false
29 money -= amount
30 return true
31
32
33
34func get_state() -> Dictionary:
35 return {"money": money}
36
37
38
39func apply_state(state:Dictionary, default_money:int = 350) -> void:
40 set_money(int(state.get("money", default_money)))
int
Return saveable economy state.