Add business pricing and closure controls with compatible digest optimization

This commit is contained in:
Takeshi
2026-09-09 12:04:12 +09:00
parent 071e338e82
commit b3b82ef03e
35 changed files with 2203 additions and 59 deletions
+16 -1
View File
@@ -2,6 +2,7 @@ class_name FacilityInstance
extends RefCounted
const ServiceInstanceType = preload("res://scripts/facility/service_instance.gd")
const FacilityPricingType = preload("res://scripts/facility/facility_pricing.gd")
## Values are deliberately ordered by operational priority.
enum State {
@@ -81,6 +82,8 @@ func configure(
access_available = bool(_value(options, &"access_available", true))
power_available = bool(_value(options, &"power_available", true))
operator_open = bool(_value(options, &"operator_open", true))
if _has_value(policy_current, &"business_open"):
operator_open = bool(_value(policy_current, &"business_open", operator_open))
var intervals := _parse_intervals(_value(options, &"opening_intervals", []))
if not intervals.is_empty():
opening_intervals = intervals
@@ -98,7 +101,8 @@ func is_valid() -> bool:
and base_service_minutes > 0 \
and staff_min >= 0 \
and staff_max >= staff_min \
and _intervals_are_valid(opening_intervals)
and _intervals_are_valid(opening_intervals) \
and bool(FacilityPricingType.validate_patch(policy_current)[&"valid"])
func set_opening_hours(open_minute_of_day: int, close_minute_of_day: int) -> bool:
@@ -144,6 +148,8 @@ func set_operational_conditions(conditions: Dictionary, absolute_minute: int) ->
power_available = bool(_value(conditions, &"power_available", power_available))
if _has_value(conditions, &"operator_open"):
operator_open = bool(_value(conditions, &"operator_open", operator_open))
if _has_value(policy_current, &"business_open"):
apply_policy_patch({&"business_open": operator_open})
if _has_value(conditions, &"active_staff_ids"):
active_staff_ids = _sorted_unique_names(_value(conditions, &"active_staff_ids", []))
if _has_value(conditions, &"degraded_reasons"):
@@ -218,6 +224,8 @@ func apply_policy_patch(patch: Dictionary) -> bool:
policy_current.erase(String(key))
policy_current[key] = _copy(value)
changed = true
if _has_value(patch, &"business_open"):
operator_open = bool(_value(patch, &"business_open", operator_open))
if changed:
policy_revision += 1
return changed
@@ -360,6 +368,13 @@ static func _snapshot_shapes_are_valid(snapshot: Dictionary) -> bool:
for field: StringName in dictionary_fields:
if not snapshot.get(field, null) is Dictionary:
return false
for field: StringName in [&"policy_current", &"policy_pending"]:
if not bool(FacilityPricingType.validate_patch(snapshot[field])[&"valid"]):
return false
var saved_policy: Dictionary = snapshot[&"policy_current"]
if _has_value(saved_policy, &"business_open") \
and _value(saved_policy, &"business_open", true) != snapshot.get(&"operator_open", true):
return false
return true