From da5935e5c8b45dc4f5e0d235bdbfbab4e548459d Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 1 Nov 2020 19:37:29 +0200 Subject: [PATCH] Stats unique can no longer crash badly defined mods --- core/src/com/unciv/models/ruleset/Unique.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/com/unciv/models/ruleset/Unique.kt b/core/src/com/unciv/models/ruleset/Unique.kt index 2e68f1deff..faa8427846 100644 --- a/core/src/com/unciv/models/ruleset/Unique.kt +++ b/core/src/com/unciv/models/ruleset/Unique.kt @@ -11,7 +11,11 @@ class Unique(val text:String){ val params = text.getPlaceholderParameters() /** This is so the heavy regex-based parsing is only activated once per unique, instead of every time it's called * - for instance, in the city screen, we call every tile unique for every tile, which can lead to ANRs */ - val stats = params.firstOrNull { Stats.isStats(it) }?.let { Stats.parse(it) } + val stats: Stats by lazy { + val firstStatParam = params.firstOrNull { Stats.isStats(it) } + if (firstStatParam == null) Stats() // So badly-defined stats don't crash the entire game + else Stats.parse(firstStatParam) + } } class UniqueMap:HashMap>() {