Leftovers from previous PRs (#6725)

* Leftovers from #6698

* Leftovers from #6718

* Better naming
This commit is contained in:
Jack Rainy
2022-05-08 21:19:55 +03:00
committed by GitHub
parent 86d5011da1
commit d00b72806b
5 changed files with 12 additions and 7 deletions

View File

@ -601,6 +601,10 @@ Load from custom location =
Could not load game from custom location! =
Save to custom location =
Could not save game to custom location! =
Missing mods are downloaded successfully. =
Could not load the missing mods! =
Could not download mod list. =
Could not find a mod named "[modName]". =
# Options

View File

@ -866,7 +866,7 @@ class MapUnit {
clearEncampment(tile)
// Check whether any civilians without military units are there.
// Keep in mind that putInTile(), which calls this method,
// might has already placed your military unit in this tile.
// might have already placed your military unit in this tile.
val unguardedCivilian = tile.getUnguardedCivilian(this)
// Capture Enemy Civilian Unit if you move on top of it
if (isMilitary() && unguardedCivilian != null && civInfo.isAtWarWith(unguardedCivilian.civInfo)) {

View File

@ -145,10 +145,9 @@ open class TileInfo {
return null
}
/** Return null if military/air units on tile, or no civilian */
/** Return null if military on tile, or no civilian */
fun getUnguardedCivilian(attacker: MapUnit): MapUnit? {
if (militaryUnit != null && militaryUnit != attacker) return null
if (airUnits.isNotEmpty()) return null
if (civilianUnit != null) return civilianUnit!!
return null
}

View File

@ -220,7 +220,9 @@ object Github {
* @see <a href="https://docs.github.com/en/rest/reference/search#search-repositories">Github API doc</a>
*/
fun tryGetGithubReposWithTopic(amountPerPage:Int, page:Int, searchRequest: String = ""): RepoSearch? {
val link = "https://api.github.com/search/repositories?q=${searchRequest}topic:unciv-mod&sort:stars&per_page=$amountPerPage&page=$page"
// Add + here to separate the query text from its parameters
val searchText = if (searchRequest != "") "$searchRequest+" else ""
val link = "https://api.github.com/search/repositories?q=${searchText}topic:unciv-mod&sort:stars&per_page=$amountPerPage&page=$page"
var retries = 2
while (retries > 0) {
retries--

View File

@ -162,10 +162,10 @@ class LoadGameScreen(previousScreen:BaseScreen) : PickerScreen(disableScroll = t
try {
val mods = missingModsToLoad.replace(' ', '-').lowercase().splitToSequence(",-")
for (modName in mods) {
val repos = Github.tryGetGithubReposWithTopic(10, 1, "$modName+") // + is important here!
?: throw UncivShowableException("Could not download mod list")
val repos = Github.tryGetGithubReposWithTopic(10, 1, modName)
?: throw UncivShowableException("Could not download mod list.".tr())
val repo = repos.items.firstOrNull { it.name.lowercase() == modName }
?: throw UncivShowableException("The $modName is not found.")
?: throw UncivShowableException("Could not find a mod named \"[$modName]\".".tr())
val modFolder = Github.downloadAndExtract(
repo.html_url, repo.default_branch,
Gdx.files.local("mods")