SwiftInk is, as the name suggests, a Swift port of the runtime engine for the ink scripting language by inkle.
For now, it should be assumed to be unstable!
Until a first version is complete, the code for SwiftInk will follow the C# engine very closely. This means that the official Running Your Ink documentation from inkle should be easily translatable into SwiftInk's API.
To fit Swift language conventions, SwiftInk uses pascalCase
for method names and
enumeration cases instead of CamelCase
as C# does.
Here's a basic "engine" for playing Ink scripts:
let story = try Story(jsonString)
while true {
print(try story.continueMaximally())
if !story.currentChoices.isEmpty {
for (i, choice) in s.currentChoices.enumerated() {
print("\(i): \(choice.text!)")
}
var playerChoice: Int? = nil
while playerChoice == nil {
playerChoice = Int(readLine() ?? "0")
}
try s.ChooseChoiceIndex(playerChoice!)
}
else {
print("Story complete!")
break
}
}
Like the original ink engine, SwiftInk is available under the MIT License.