39 lines
1.5 KiB
GDScript
39 lines
1.5 KiB
GDScript
class_name OriginalRelationshipState
|
|
extends RefCounted
|
|
|
|
## Explicit facts only. Numeric values are not production initialization approval.
|
|
## No update, attack, reduction, threshold or route policy is defined here.
|
|
const FIELDS := ["subject_id", "protagonist_id", "rival_id", "affection", "lust", "netorare", "shield_current", "shield_max"]
|
|
var _payload: Dictionary = {}
|
|
|
|
|
|
static func from_snapshot(value: Variant) -> OriginalRelationshipState:
|
|
if not value is Dictionary or value.size() != FIELDS.size():
|
|
return null
|
|
for field: String in FIELDS:
|
|
if not value.has(field):
|
|
return null
|
|
for field: String in ["subject_id", "protagonist_id", "rival_id"]:
|
|
if not (value[field] is String or value[field] is StringName) or String(value[field]).is_empty():
|
|
return null
|
|
if value["subject_id"] == value["protagonist_id"] or value["subject_id"] == value["rival_id"] or value["protagonist_id"] == value["rival_id"]:
|
|
return null
|
|
for field: String in ["affection", "lust", "netorare", "shield_current", "shield_max"]:
|
|
if not (value[field] is int or value[field] is float):
|
|
return null
|
|
if value[field] is float and not is_finite(value[field]):
|
|
return null
|
|
if value["shield_max"] != value["affection"] or value["shield_current"] < 0 or value["shield_current"] > value["shield_max"]:
|
|
return null
|
|
var state := OriginalRelationshipState.new()
|
|
state._payload = value.duplicate(true)
|
|
return state
|
|
|
|
|
|
func create_snapshot() -> Dictionary:
|
|
return _payload.duplicate(true)
|
|
|
|
|
|
func subject_id() -> StringName:
|
|
return StringName(_payload.get("subject_id", ""))
|