Skip to content

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.

Public contract:

GetKingdomBool(...)
SetKingdomBool(...)

Implementation model:

false = 0
true = 1

This reuses the existing collision-safe integer data path.

Public contract:

GetKingdomFloat(...)
SetKingdomFloat(...)

Implementation model:

float
→ invariant round-trip text
→ addon-private string storage

Read:

float.TryParse(
value,
NumberStyles.Float,
CultureInfo.InvariantCulture,
out parsed
)

Write:

value.ToString("R", CultureInfo.InvariantCulture)

Without explicit culture, a float may serialize differently depending on machine/game locale.

For example:

1.25
1,25

A save format should not silently change syntax because the user switched language.

The round-trip format is intended to serialize a floating-point value so it can be parsed back without avoidable precision loss.

Addon code sees:

bool enabled
float taxRate

The persistence layer sees:

int
string

That separation is healthy.

The public API can later change its internal representation while preserving the typed public contract.

If you write:

SetKingdomString(..., "tax_rate", someFloat.ToString())

you have now made culture/format decisions yourself.

Prefer:

SetKingdomFloat(...)

when the framework exposes it.

A stable public API should expose semantic types even when storage is built from a smaller set of primitive representations.