RapidGameFramework
Reusable Godot managers for data-driven small games
Loading...
Searching...
No Matches
collection_manager.gd
Go to the documentation of this file.
1extends RefCounted
2
3
8
9var discovered_card_ids := []
10
11
12
13func mark_discovered(card_id) -> void:
14 var id = str(card_id)
15 if id != "" and not discovered_card_ids.has(id):
16 discovered_card_ids.append(id)
17
18
19
20func mark_cards_discovered(ids:Array) -> void:
21 for id in ids:
22 mark_discovered(id)
23
24
25
26func mark_inventory_discovered(inventory_manager) -> void:
27 mark_cards_discovered(inventory_manager.get_card_ids())
28
29
30
31func has_discovered(card_id) -> bool:
32 return discovered_card_ids.has(str(card_id))
33
34
35
36func discovered_count() -> int:
37 return discovered_card_ids.size()
38
39
40
41func is_collection_complete(all_ids:Array) -> bool:
42 for id in all_ids:
43 if str(id) != "" and not has_discovered(id):
44 return false
45 return not all_ids.is_empty()
46
47
48
49func get_card_status(card_id, inventory_manager) -> String:
50 if inventory_manager.count_card(card_id) > 0:
51 return "owned"
52 if has_discovered(card_id):
53 return "discovered"
54 return "unknown"
55
56
57
58func get_state() -> Dictionary:
59 return {"discovered_card_ids": discovered_card_ids.duplicate()}
60
61
62
63func apply_state(state:Dictionary) -> void:
64 discovered_card_ids.clear()
65 for id in state.get("discovered_card_ids", []):
66 mark_discovered(id)