80 lines
2.1 KiB
GDScript
80 lines
2.1 KiB
GDScript
class_name KnownEventStateRecord
|
|
extends RefCounted
|
|
|
|
const SCHEMA_VERSION := 2
|
|
const NO_SOURCE_NPC_ID := -1
|
|
|
|
const VALID_ACQUISITION_METHODS := [
|
|
SimulationIds.KNOWLEDGE_ACQUISITION_PERFORMED,
|
|
SimulationIds.KNOWLEDGE_ACQUISITION_WITNESSED,
|
|
SimulationIds.KNOWLEDGE_ACQUISITION_COMMUNICATED,
|
|
SimulationIds.KNOWLEDGE_ACQUISITION_LEGACY,
|
|
]
|
|
|
|
var data: Dictionary
|
|
|
|
|
|
func _init(record_data: Dictionary = {}) -> void:
|
|
data = record_data.duplicate(true)
|
|
|
|
|
|
static func create(
|
|
knower_id: int,
|
|
event_id: int,
|
|
acquisition_method: StringName = SimulationIds.KNOWLEDGE_ACQUISITION_LEGACY,
|
|
source_npc_id: int = NO_SOURCE_NPC_ID
|
|
) -> KnownEventStateRecord:
|
|
return (
|
|
KnownEventStateRecord
|
|
. new(
|
|
{
|
|
"schema_version": SCHEMA_VERSION,
|
|
"knower_id": knower_id,
|
|
"event_id": event_id,
|
|
"acquisition_method": String(acquisition_method),
|
|
"source_npc_id": source_npc_id,
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
static func from_dictionary(record_data: Dictionary) -> KnownEventStateRecord:
|
|
if int(record_data.get("schema_version", -1)) != SCHEMA_VERSION:
|
|
return null
|
|
if not record_data.has_all(["knower_id", "event_id", "acquisition_method", "source_npc_id"]):
|
|
return null
|
|
var knower_id := int(record_data["knower_id"])
|
|
var event_id := int(record_data["event_id"])
|
|
var acquisition_method := StringName(record_data["acquisition_method"])
|
|
var source_npc_id := int(record_data["source_npc_id"])
|
|
if knower_id < 0 or event_id < 0:
|
|
return null
|
|
if acquisition_method not in VALID_ACQUISITION_METHODS:
|
|
return null
|
|
if acquisition_method == SimulationIds.KNOWLEDGE_ACQUISITION_COMMUNICATED:
|
|
if source_npc_id < 0 or source_npc_id == knower_id:
|
|
return null
|
|
elif source_npc_id != NO_SOURCE_NPC_ID:
|
|
return null
|
|
return create(knower_id, event_id, acquisition_method, source_npc_id)
|
|
|
|
|
|
func get_knower_id() -> int:
|
|
return int(data["knower_id"])
|
|
|
|
|
|
func get_event_id() -> int:
|
|
return int(data["event_id"])
|
|
|
|
|
|
func get_acquisition_method() -> StringName:
|
|
return StringName(data["acquisition_method"])
|
|
|
|
|
|
func get_source_npc_id() -> int:
|
|
return int(data["source_npc_id"])
|
|
|
|
|
|
func to_dictionary() -> Dictionary:
|
|
return data.duplicate(true)
|