Typed addon state without inventing new save types
✅ Source verified 🧱 API layering pattern
A public API can provide typed convenience without requiring the underlying game save container to expose a dedicated representation for every language type.
Political World demonstrates this with bool and float addon state.
Bool on top of int
Section titled “Bool on top of int”Public contract:
GetKingdomBool(...)SetKingdomBool(...)Implementation model:
false = 0true = 1This reuses the existing collision-safe integer data path.
Float on top of string
Section titled “Float on top of string”Public contract:
GetKingdomFloat(...)SetKingdomFloat(...)Implementation model:
float→ invariant round-trip text→ addon-private string storageRead:
float.TryParse( value, NumberStyles.Float, CultureInfo.InvariantCulture, out parsed)Write:
value.ToString("R", CultureInfo.InvariantCulture)Why invariant culture matters
Section titled “Why invariant culture matters”Without explicit culture, a float may serialize differently depending on machine/game locale.
For example:
1.251,25A save format should not silently change syntax because the user switched language.
Why “R” matters
Section titled “Why “R” matters”The round-trip format is intended to serialize a floating-point value so it can be parsed back without avoidable precision loss.
Typed facade vs underlying representation
Section titled “Typed facade vs underlying representation”Addon code sees:
bool enabledfloat taxRateThe persistence layer sees:
intstringThat separation is healthy.
The public API can later change its internal representation while preserving the typed public contract.
Do not bypass the typed helper
Section titled “Do not bypass the typed helper”If you write:
SetKingdomString(..., "tax_rate", someFloat.ToString())you have now made culture/format decisions yourself.
Prefer:
SetKingdomFloat(...)when the framework exposes it.
General lesson
Section titled “General lesson”A stable public API should expose semantic types even when storage is built from a smaller set of primitive representations.