feat: add witnessed knowledge and wind ambience
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
class_name EconomicEventRecord
|
||||
extends RefCounted
|
||||
|
||||
const SCHEMA_VERSION := 1
|
||||
const SCHEMA_VERSION := 2
|
||||
const LEGACY_SCHEMA_VERSION := 1
|
||||
|
||||
var data: Dictionary
|
||||
|
||||
@@ -18,7 +19,8 @@ static func create(
|
||||
source_id: StringName,
|
||||
destination_id: StringName,
|
||||
item_id: StringName,
|
||||
amount: float
|
||||
amount: float,
|
||||
world_position: Vector3 = Vector3.ZERO
|
||||
) -> EconomicEventRecord:
|
||||
return EconomicEventRecord.new(
|
||||
{
|
||||
@@ -30,7 +32,8 @@ static func create(
|
||||
"source_id": String(source_id),
|
||||
"destination_id": String(destination_id),
|
||||
"item_id": String(item_id),
|
||||
"amount": amount
|
||||
"amount": amount,
|
||||
"world_position": [world_position.x, world_position.y, world_position.z]
|
||||
}
|
||||
)
|
||||
|
||||
@@ -41,7 +44,8 @@ static func create_narrative(
|
||||
tick: int,
|
||||
actor_id: int,
|
||||
source_id: StringName,
|
||||
action_display: String = ""
|
||||
action_display: String = "",
|
||||
world_position: Vector3 = Vector3.ZERO
|
||||
) -> EconomicEventRecord:
|
||||
return EconomicEventRecord.new(
|
||||
{
|
||||
@@ -54,13 +58,15 @@ static func create_narrative(
|
||||
"destination_id": "",
|
||||
"item_id": "",
|
||||
"amount": 0.0,
|
||||
"action_name": action_display
|
||||
"action_name": action_display,
|
||||
"world_position": [world_position.x, world_position.y, world_position.z]
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
static func from_dictionary(record_data: Dictionary) -> EconomicEventRecord:
|
||||
if int(record_data.get("schema_version", -1)) != SCHEMA_VERSION:
|
||||
var version := int(record_data.get("schema_version", -1))
|
||||
if version not in [LEGACY_SCHEMA_VERSION, SCHEMA_VERSION]:
|
||||
return null
|
||||
if not record_data.has_all(
|
||||
[
|
||||
@@ -75,6 +81,8 @@ static func from_dictionary(record_data: Dictionary) -> EconomicEventRecord:
|
||||
]
|
||||
):
|
||||
return null
|
||||
if version == SCHEMA_VERSION and not record_data.has("world_position"):
|
||||
return null
|
||||
var normalized := record_data.duplicate(true)
|
||||
normalized["schema_version"] = SCHEMA_VERSION
|
||||
normalized["event_id"] = int(record_data["event_id"])
|
||||
@@ -85,11 +93,13 @@ static func from_dictionary(record_data: Dictionary) -> EconomicEventRecord:
|
||||
normalized["destination_id"] = String(record_data["destination_id"])
|
||||
normalized["item_id"] = String(record_data["item_id"])
|
||||
normalized["amount"] = float(record_data["amount"])
|
||||
if (
|
||||
normalized["event_id"] < 0
|
||||
or normalized["tick"] < 0
|
||||
or normalized["event_type"].is_empty()
|
||||
):
|
||||
var saved_position = record_data.get("world_position", [0.0, 0.0, 0.0])
|
||||
if not saved_position is Array or saved_position.size() != 3:
|
||||
return null
|
||||
normalized["world_position"] = [
|
||||
float(saved_position[0]), float(saved_position[1]), float(saved_position[2])
|
||||
]
|
||||
if normalized["event_id"] < 0 or normalized["tick"] < 0 or normalized["event_type"].is_empty():
|
||||
return null
|
||||
return EconomicEventRecord.new(normalized)
|
||||
|
||||
@@ -98,6 +108,11 @@ func to_dictionary() -> Dictionary:
|
||||
return data.duplicate(true)
|
||||
|
||||
|
||||
func get_world_position() -> Vector3:
|
||||
var saved_position: Array = data["world_position"]
|
||||
return Vector3(float(saved_position[0]), float(saved_position[1]), float(saved_position[2]))
|
||||
|
||||
|
||||
func description(npc_names: Dictionary = {}) -> String:
|
||||
var actor_name: String = npc_names.get(int(data["actor_id"]), "Someone")
|
||||
var item: String = str(data["item_id"])
|
||||
|
||||
Reference in New Issue
Block a user