feat: scale village queries and enrich Jajce center
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
class_name SimulationPopulationView
|
||||
extends RefCounted
|
||||
|
||||
var all_by_id: Dictionary = {}
|
||||
var living_by_id: Dictionary = {}
|
||||
var starving_by_id: Dictionary = {}
|
||||
|
||||
|
||||
func _init(npcs: Array = []) -> void:
|
||||
rebuild(npcs)
|
||||
|
||||
|
||||
func rebuild(npcs: Array) -> void:
|
||||
all_by_id.clear()
|
||||
living_by_id.clear()
|
||||
starving_by_id.clear()
|
||||
for value in npcs:
|
||||
var npc := value as SimNPC
|
||||
if npc != null:
|
||||
refresh_npc(npc)
|
||||
|
||||
|
||||
func refresh_npc(npc: SimNPC) -> void:
|
||||
if npc == null:
|
||||
return
|
||||
all_by_id[npc.id] = npc
|
||||
if npc.is_dead:
|
||||
living_by_id.erase(npc.id)
|
||||
starving_by_id.erase(npc.id)
|
||||
return
|
||||
living_by_id[npc.id] = npc
|
||||
if npc.is_starving:
|
||||
starving_by_id[npc.id] = npc
|
||||
else:
|
||||
starving_by_id.erase(npc.id)
|
||||
|
||||
|
||||
func get_living(npc_id: int) -> SimNPC:
|
||||
return living_by_id.get(npc_id) as SimNPC
|
||||
|
||||
|
||||
func get_any(npc_id: int) -> SimNPC:
|
||||
return all_by_id.get(npc_id) as SimNPC
|
||||
|
||||
|
||||
func get_starving(npc_id: int) -> SimNPC:
|
||||
return starving_by_id.get(npc_id) as SimNPC
|
||||
|
||||
|
||||
func living_count() -> int:
|
||||
return living_by_id.size()
|
||||
|
||||
|
||||
func starving_count() -> int:
|
||||
return starving_by_id.size()
|
||||
@@ -0,0 +1 @@
|
||||
uid://btwlag4mpji24
|
||||
Reference in New Issue
Block a user