feat: add witnessed knowledge and wind ambience
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
class_name NPCStateRecord
|
||||
extends RefCounted
|
||||
|
||||
const SCHEMA_VERSION := 3
|
||||
const SCHEMA_VERSION := 4
|
||||
const LEGACY_SCHEMA_VERSION := 1
|
||||
const PREVIOUS_SCHEMA_VERSION := 2
|
||||
const RELATIONSHIP_LEGACY_SCHEMA_VERSION := 3
|
||||
|
||||
var data: Dictionary
|
||||
|
||||
@@ -46,7 +47,6 @@ static func capture(npc: SimNPC) -> NPCStateRecord:
|
||||
"last_task": String(npc.last_task),
|
||||
"random_seed": str(npc.random_source.seed),
|
||||
"random_state": str(npc.random_source.state),
|
||||
"familiarity": _sorted_familiarity(npc.familiarity),
|
||||
"mourning_ticks": npc.mourning_ticks
|
||||
}
|
||||
)
|
||||
@@ -54,7 +54,10 @@ static func capture(npc: SimNPC) -> NPCStateRecord:
|
||||
|
||||
static func from_dictionary(record_data: Dictionary) -> NPCStateRecord:
|
||||
var version := int(record_data.get("schema_version", -1))
|
||||
if version in [LEGACY_SCHEMA_VERSION, PREVIOUS_SCHEMA_VERSION]:
|
||||
if (
|
||||
version
|
||||
in [LEGACY_SCHEMA_VERSION, PREVIOUS_SCHEMA_VERSION, RELATIONSHIP_LEGACY_SCHEMA_VERSION]
|
||||
):
|
||||
record_data = _migrate_legacy(record_data, version)
|
||||
elif version != SCHEMA_VERSION:
|
||||
return null
|
||||
@@ -116,7 +119,9 @@ static func _migrate_legacy(legacy_data: Dictionary, version: int) -> Dictionary
|
||||
if version == LEGACY_SCHEMA_VERSION:
|
||||
migrated["travel_target_position"] = legacy_data.get("position", [0.0, 0.0, 0.0])
|
||||
migrated["has_travel_target"] = false
|
||||
migrated["inventory"] = {}
|
||||
if version in [LEGACY_SCHEMA_VERSION, PREVIOUS_SCHEMA_VERSION]:
|
||||
migrated["inventory"] = {}
|
||||
migrated.erase("familiarity")
|
||||
return migrated
|
||||
|
||||
|
||||
@@ -141,9 +146,7 @@ func restore(debug_logs: bool) -> SimNPC:
|
||||
float(saved_position[0]), float(saved_position[1]), float(saved_position[2])
|
||||
)
|
||||
var saved_home: Array = data.get("home_position", saved_position)
|
||||
npc.home_position = Vector3(
|
||||
float(saved_home[0]), float(saved_home[1]), float(saved_home[2])
|
||||
)
|
||||
npc.home_position = Vector3(float(saved_home[0]), float(saved_home[1]), float(saved_home[2]))
|
||||
npc.is_starving = bool(data["is_starving"])
|
||||
npc.starvation_ticks = int(data["starvation_ticks"])
|
||||
npc.starvation_death_threshold = int(data["starvation_death_threshold"])
|
||||
@@ -162,28 +165,9 @@ func restore(debug_logs: bool) -> SimNPC:
|
||||
npc.last_task = StringName(data["last_task"])
|
||||
npc.random_source.state = String(data["random_state"]).to_int()
|
||||
npc.debug_logs = debug_logs
|
||||
var saved_familiarity = data.get("familiarity", {})
|
||||
if saved_familiarity is Array:
|
||||
for pair in saved_familiarity:
|
||||
var pair_dict: Dictionary = pair
|
||||
npc.familiarity[int(pair_dict["id"])] = float(pair_dict["score"])
|
||||
elif saved_familiarity is Dictionary:
|
||||
npc.familiarity = saved_familiarity.duplicate(true)
|
||||
npc.mourning_ticks = int(data.get("mourning_ticks", 0))
|
||||
return npc
|
||||
|
||||
|
||||
func to_dictionary() -> Dictionary:
|
||||
return data.duplicate(true)
|
||||
|
||||
|
||||
static func _sorted_familiarity(familiarity: Dictionary) -> Array:
|
||||
var pairs: Array[Dictionary] = []
|
||||
for key in familiarity:
|
||||
pairs.append({"id": int(key), "score": float(familiarity[key])})
|
||||
pairs.sort_custom(_familiarity_sort)
|
||||
return pairs
|
||||
|
||||
|
||||
static func _familiarity_sort(a: Dictionary, b: Dictionary) -> bool:
|
||||
return int(a["id"]) < int(b["id"])
|
||||
|
||||
Reference in New Issue
Block a user