From 280025fa10f0a3b8b219bb1007d351a82a545c98 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Sun, 21 May 2023 12:35:57 +0300 Subject: [PATCH] Resolved #9416 - failure to get preview image no longer causes crash --- .../unciv/ui/screens/pickerscreens/GitHub.kt | 18 +++++++++++------- .../ui/screens/worldscreen/unit/UnitTable.kt | 2 +- docs/Modders/uniques.md | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/src/com/unciv/ui/screens/pickerscreens/GitHub.kt b/core/src/com/unciv/ui/screens/pickerscreens/GitHub.kt index 3423f99e70..fd8ebdbd03 100644 --- a/core/src/com/unciv/ui/screens/pickerscreens/GitHub.kt +++ b/core/src/com/unciv/ui/screens/pickerscreens/GitHub.kt @@ -252,15 +252,19 @@ object Github { return null } - fun tryGetPreviewImage(modUrl:String, defaultBranch: String): Pixmap?{ + fun tryGetPreviewImage(modUrl:String, defaultBranch: String): Pixmap? { val fileLocation = "$modUrl/$defaultBranch/preview" .replace("github.com", "raw.githubusercontent.com") - val file = download("$fileLocation.jpg") - ?: download("$fileLocation.png") - ?: return null - val byteArray = file.readBytes() - val buffer = ByteBuffer.allocateDirect(byteArray.size).put(byteArray).position(0) - return Pixmap(buffer) + try { + val file = download("$fileLocation.jpg") + ?: download("$fileLocation.png") + ?: return null + val byteArray = file.readBytes() + val buffer = ByteBuffer.allocateDirect(byteArray.size).put(byteArray).position(0) + return Pixmap(buffer) + } catch (ex: Exception) { + return null + } } class Tree { diff --git a/core/src/com/unciv/ui/screens/worldscreen/unit/UnitTable.kt b/core/src/com/unciv/ui/screens/worldscreen/unit/UnitTable.kt index 583e4a388a..31574ae8c3 100644 --- a/core/src/com/unciv/ui/screens/worldscreen/unit/UnitTable.kt +++ b/core/src/com/unciv/ui/screens/worldscreen/unit/UnitTable.kt @@ -192,7 +192,7 @@ class UnitTable(val worldScreen: WorldScreen) : Table() { } if (!unit.isCivilian()) { - unitDescriptionTable.add("XP".tr().toLabel().apply { + unitDescriptionTable.add("XP".toLabel().apply { onClick { if (selectedUnit == null) return@onClick worldScreen.game.pushScreen(PromotionPickerScreen(unit)) diff --git a/docs/Modders/uniques.md b/docs/Modders/uniques.md index 4d3a14f5bc..3f8519e304 100644 --- a/docs/Modders/uniques.md +++ b/docs/Modders/uniques.md @@ -1952,7 +1952,7 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl Applicable to: TriggerCondition -??? example "<upon adopting [policy]>" +??? example "<upon adopting [policy/belief]>" Example: "<upon adopting [Oligarchy]>" Applicable to: TriggerCondition