This repository has been archived by the owner on Oct 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from atfinke/2020.08
2020.08
Showing
37 changed files
with
632 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// WKRDefaults.swift | ||
// WKRKit | ||
// | ||
// Created by Andrew Finke on 7/18/20. | ||
// Copyright © 2020 Andrew Finke. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
struct WKRDefaults { | ||
private static let fastlaneKey = "FASTLANE_SNAPSHOT" | ||
static var isFastlaneSnapshotInstance: Bool { | ||
get { | ||
return UserDefaults.standard.bool(forKey: fastlaneKey) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// | ||
// WKRLanguageHackery.swift | ||
// WKRKit | ||
// | ||
// Created by Andrew Finke on 7/17/20. | ||
// Copyright © 2020 Andrew Finke. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import os.log | ||
|
||
/// A terrible, terrible approach, but I don't want to spend much time on this. + code quality/arch doesn't matter to me that much anymore given I will no longer be working on this project in a few weeks | ||
internal class WKRLanguageHackery { | ||
|
||
// MARK: - Types- | ||
|
||
private struct WikiDataResponse: Decodable { | ||
struct Entity: Decodable { | ||
struct SiteLink: Decodable { | ||
let url: String | ||
} | ||
let sitelinks: [String: SiteLink] | ||
} | ||
|
||
private let entities: [String: Entity] | ||
func path(for language: String) -> String? { | ||
let site = "\(language).wikipedia.org/wiki" | ||
let urlString = entities | ||
.values | ||
.map { $0.sitelinks.values } | ||
.flatMap { $0 } | ||
.map { $0.url } | ||
.first(where: { $0.contains(site) }) | ||
|
||
guard let string = urlString else { | ||
return nil | ||
} | ||
|
||
let components = string.components(separatedBy: site) | ||
guard components.count == 2 else { | ||
return nil | ||
} | ||
|
||
return components[1] | ||
} | ||
} | ||
|
||
// MARK: - Properties | ||
|
||
static private let session: URLSession = { | ||
let config = URLSessionConfiguration.default | ||
config.timeoutIntervalForRequest = 2 | ||
config.timeoutIntervalForResource = 2 | ||
return URLSession(configuration: config) | ||
}() | ||
|
||
static let shared = WKRLanguageHackery() | ||
private var language = "en" | ||
|
||
var isEnglish: Bool { | ||
return language == "en" | ||
} | ||
|
||
// MARK: - Initalization - | ||
|
||
private init() {} | ||
|
||
// MARK: - Helpers - | ||
|
||
func configure(for settings: WKRGameSettings) { | ||
language = settings.language.code | ||
} | ||
|
||
var baseURLString: String { | ||
return WKRKitConstants.current.baseURLString.replacingOccurrences(of: "en", with: language) | ||
} | ||
|
||
var whatLinksHereURLString: String { | ||
return WKRKitConstants.current.whatLinksHereURLString.replacingOccurrences(of: "en", with: language) | ||
} | ||
|
||
var randomURLString: String { | ||
return WKRKitConstants.current.randomURLString.replacingOccurrences(of: "en", with: language) | ||
} | ||
|
||
var pageTitleStringToReplace: String { | ||
if language == "es" { | ||
return " - Wikipedia, la enciclopedia libre" | ||
} else if language == "fr" { | ||
return " — Wikipédia" | ||
} else if language == "de" { | ||
return " – Wikipedia" | ||
} else if language == "ru" { | ||
return " — Википедия" | ||
} else { | ||
return WKRKitConstants.current.pageTitleStringToReplace | ||
} | ||
} | ||
|
||
func adjustedPath(for path: String, completion: @escaping ((String?) -> Void)) { | ||
guard language != "en" else { | ||
completion(path) | ||
return | ||
} | ||
|
||
let adjustedPath = path.dropFirst() | ||
let urlString = "https://www.wikidata.org/w/api.php?action=wbgetentities&format=json&sites=enwiki&redirects=no&props=sitelinks%2Furls&titles=\(adjustedPath)" | ||
guard let url = URL(string: urlString) else { | ||
completion(nil) | ||
return | ||
} | ||
let task = WKRLanguageHackery.session.dataTask(with: url) { data, _, _ in | ||
if let data = data, let response = try? JSONDecoder().decode(WikiDataResponse.self, from: data) { | ||
let newPath = response.path(for: self.language) | ||
os_log("fetched adjusted path: %{public}s -> %{public}s", log: .articlesValidation, type: .info, path, newPath ?? "-") | ||
completion(newPath) | ||
} else { | ||
completion(nil) | ||
} | ||
} | ||
task.resume() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
...lers/Connect View Controllers/CustomRaceViewController/CustomRaceLanguageController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// | ||
// CustomRaceLanguageController.swift | ||
// WikiRaces | ||
// | ||
// Created by Andrew Finke on 7/17/20. | ||
// Copyright © 2020 Andrew Finke. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import WKRKit | ||
|
||
final class CustomRaceLanguageController: CustomRaceController { | ||
|
||
// MARK: - Types - | ||
|
||
private class Cell: UITableViewCell, UITextFieldDelegate { | ||
|
||
// MARK: - Properties - | ||
|
||
let textField = UITextField() | ||
static let reuseIdentifier = "reuseIdentifier" | ||
|
||
// MARK: - Initalization - | ||
|
||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | ||
super.init(style: style, reuseIdentifier: reuseIdentifier) | ||
textField.textAlignment = .right | ||
textField.returnKeyType = .done | ||
textField.delegate = self | ||
contentView.addSubview(textField) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: - View Life Cycle - | ||
|
||
override func layoutSubviews() { | ||
super.layoutSubviews() | ||
textField.frame = CGRect(origin: .zero, size: CGSize(width: 80, height: contentView.frame.height)) | ||
textField.center = CGPoint( | ||
x: contentView.frame.width - contentView.layoutMargins.right - textField.frame.width / 2, | ||
y: contentView.frame.height / 2) | ||
} | ||
|
||
// MARK: - UITextFieldDelegate - | ||
|
||
func textFieldShouldReturn(_ textField: UITextField) -> Bool { | ||
textField.resignFirstResponder() | ||
return true | ||
} | ||
} | ||
|
||
// MARK: - Properties - | ||
|
||
var language: WKRGameSettings.Language { | ||
didSet { | ||
didUpdate?(language) | ||
} | ||
} | ||
var didUpdate: ((WKRGameSettings.Language) -> Void)? | ||
private var textField: UITextField? | ||
|
||
// MARK: - Initalization - | ||
|
||
init(language: WKRGameSettings.Language) { | ||
self.language = language | ||
super.init(style: .grouped) | ||
title = "Language".uppercased() | ||
tableView.allowsSelection = false | ||
tableView.register(Cell.self, forCellReuseIdentifier: Cell.reuseIdentifier) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: - View Life Cycle - | ||
|
||
override func viewWillDisappear(_ animated: Bool) { | ||
super.viewWillDisappear(animated) | ||
if let text = textField?.text?.lowercased(), text != language.code { | ||
language = WKRGameSettings.Language(code: text) | ||
} | ||
} | ||
|
||
// MARK: - UITableViewDataSource - | ||
|
||
override func numberOfSections(in tableView: UITableView) -> Int { | ||
return 1 | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return 1 | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
guard let cell = tableView.dequeueReusableCell(withIdentifier: Cell.reuseIdentifier, | ||
for: indexPath) as? Cell else { | ||
fatalError() | ||
} | ||
switch indexPath.row { | ||
case 0: | ||
cell.textLabel?.text = "Language Code" | ||
cell.textField.text = language.code.lowercased() | ||
textField = cell.textField | ||
default: | ||
fatalError() | ||
} | ||
|
||
return cell | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { | ||
return """ | ||
Changing the Wikipedia language is highly experimental and not fully tested. | ||
Some aspects of the game may not work as expected when using any language other than the standard English Wikipedia (“en”). | ||
""" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,6 @@ extension GKMatchRequest { | |
} | ||
|
||
private static func publicRacePlayerGroup() -> Int { | ||
return 10 | ||
return 11 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters