Typed addon state без выдумывания новых save types
✅ Source verified 🧱 API layering pattern
Public API может дать typed convenience, не требуя от underlying game save container отдельного native representation для каждого C# type.
Political World показывает это на bool и float.
Bool поверх int
Заголовок раздела «Bool поверх int»Public contract:
GetKingdomBool(...)SetKingdomBool(...)Implementation:
false = 0true = 1Используется уже существующий collision-safe integer data path.
Float поверх string
Заголовок раздела «Float поверх string»Public contract:
GetKingdomFloat(...)SetKingdomFloat(...)Implementation:
float→ invariant round-trip text→ addon-private string storageRead:
float.TryParse( value, NumberStyles.Float, CultureInfo.InvariantCulture, out parsed)Write:
value.ToString("R", CultureInfo.InvariantCulture)Зачем InvariantCulture
Заголовок раздела «Зачем InvariantCulture»Без explicit culture float может сериализоваться по-разному в зависимости от locale:
1.251,25Save format не должен менять синтаксис только потому, что пользователь переключил language.
Зачем “R”
Заголовок раздела «Зачем “R”»Round-trip format нужен, чтобы parsed value можно было восстановить без лишней потери precision.
Typed facade и underlying representation
Заголовок раздела «Typed facade и underlying representation»Addon видит:
bool enabledfloat taxRatePersistence layer:
intstringЭто хорошее разделение.
Internal representation потом можно изменить, сохранив typed public contract.
Не обходите typed helper
Заголовок раздела «Не обходите typed helper»Если написать:
SetKingdomString(..., "tax_rate", someFloat.ToString())format/culture уже становятся вашей проблемой.
Если framework даёт:
SetKingdomFloat(...)лучше использовать его.
Общий вывод
Заголовок раздела «Общий вывод»Stable public API должен предоставлять semantic types, даже если storage построен на меньшем наборе primitive representations.