Swiftfall 是一个用 Swift 编写的 Scryfall API 的封装。
Scryfall 是一个处理卡牌游戏《万智牌》信息的 API。
所有类型都是结构体 (Struct),可以通过 `Swiftfall.get*()` 来访问。
以下是一些可以调用的函数,它们将处理来自 Scryfall API 的信息。
Swiftfall.getCard(fuzzy:String) throws -> Card (模糊搜索)
Swiftfall.getCard(exact:String) throws -> Card (精确搜索)
Swiftfall.getCard(code: String, number: Int) throws -> Card (系列代码,ID 编号)
Swiftfall.getRandomCard() throws -> Card (随机卡牌)
... 以及更多!
例如。
import Swiftfall
do {
let card = try Swiftfall.getCard(exact:"Black Lotus")
print(card)
} catch {
print(error)
}
输出。
Name: Black Lotus
Cost: {0}
Type Line: Artifact
Oracle Text:
{T}, Sacrifice Black Lotus: Add three mana of any one color to your mana pool.
例如。
import Swiftfall
do {
let card = try Swiftfall.getCard(exact:"Jace, Vryn's Prodigy")
let faces = card.cardFaces
let front = faces![0]
let back = faces![1]
print(front)
print(back)
} catch {
print(error)
}
输出。
Name: Jace, Vryn's Prodigy
Cost: {1}{U}
Type Line: Legendary Creature — Human Wizard
Oracle Text:
{T}: Draw a card, then discard a card. If there are five or more cards in your graveyard, exile Jace, Vryn's Prodigy, then return him to the battlefield transformed under his owner's control.
Power: 0
Toughness: 2
Name: Jace, Telepath Unbound
Cost:
Type Line: Legendary Planeswalker — Jace
Oracle Text:
+1: Up to one target creature gets -2/-0 until your next turn.
−3: You may cast target instant or sorcery card from your graveyard this turn. If that card would be put into your graveyard this turn, exile it instead.
−9: You get an emblem with "Whenever you cast a spell, target opponent puts the top five cards of his or her library into his or her graveyard."
Loyalty: 5
Swiftfall.getCardList() throws -> CardList (第一页)
Swiftfall.getCardList(page:Int) throws -> CardList (加载指定页码)
例如。
import Swiftfall
do {
let cardlist = try Swiftfall.getCardList(page:0) // this is the same as .getCardList()
print(cardlist)
} catch {
print(error)
}
Swiftfall.getSet(code:String) throws -> Set (字符串必须是三个字母的代码)
例如。
import Swiftfall
do {
let set = try Swiftfall.getSet(code: "KTK")
print(set)
} catch {
print(error)
}
输出。
Name: Khans of Tarkir (ktk)
Block: Khans of Tarkir
Number of Cards: 269
Release Date: 2014-09-26
Set Type: expansion
Set.getCards() -> [CardList?] (一个 CardList 的数组,每个 CardList 包含一个系列的一部分)
例如。
import Swiftfall
do {
let set = try Swiftfall.getSet(code: "PRM")
let cards = set.getCards()
} catch {
print(error)
}
Swiftfall.getSetList() throws -> SetList (所有系列)
例如。
import Swiftfall
do {
let setlist = try Swiftfall.getSetList()
print(setlist)
} catch {
print(error)
}
Swiftfall.getRulingList(code:String,number:Int) throws -> RulingList
例如。
import Swiftfall
do {
let rulings = try Swiftfall.getRulingList(code: "ima", number: 65)
print(rulings)
} catch {
print(error)
}
要获取特定的裁定,必须首先获取裁定列表。
获得 RulingList 后,您可以调用 `.data[index: Int]`
例如。
import Swiftfall
do {
let rulings = try Swiftfall.getRulingList(code: "ima", number: 65)
let ruling = rulings.data[1]
print(ruling)
} catch {
print(error)
}
API 提供 Catalog 对象作为构建其他万智牌软件和理解卡牌对象字段可能值的辅助工具。 例如。
import Swiftfall
do {
let catalog = try Swiftfall.getCatalog(catalog: "land-types")
print(catalog)
} catch {
print(error)
}
输出。
Desert
Forest
Gate
Island
Lair
Locus
Mine
Mountain
Plains
Power-Plant
Swamp
Tower
Urza’s
测试允许我们快速检查特定场景,并以易于理解的方式确定问题。
例如。
func testRandomCard(){
do {
_ = try Swiftfall.getRandomCard()
} catch {
print(error)
XCTFail()
}
}
首先,创建一个可执行包。可执行文件默认包含一个 Hello World 函数。
$ mkdir MyExecutable
$ cd MyExecutable
$ swift package init --type executable
$ swift build
$ swift run
Hello, World!
接下来,
$ swift package generate-xcodeproj
然后,将 Swiftfall 设置为可执行文件的依赖项。
import PackageDescription
let package = Package(
name: "MyExecutable",
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url:"https://github.com/bmbowdish/Swiftfall.git", from: "1.2.0")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "MyExecutable",
dependencies: ["Swiftfall"]),
]
)
然后,运行
$ swift package generate-xcodeproj
现在你准备好使用 Swiftfall 了!
如果您有兴趣查看使用 Swiftfall 的项目,您可以查看
https://github.com/bmbowdish/Test-Swiftfall
card-names (卡牌名称)
word-bank (词库)
creature-types (生物类别)
planeswalker-types (鹏洛客类别)
land-types (地类别)
spell-types (咒语类别)
artifact-types (神器类别)
powers (力量)
toughnesses (防御力)
loyalties (忠诚)
watermarks (水印)