Skip to content

Meorge/SwiftInk

Repository files navigation

SwiftInk

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!

Documentation

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.

Differences from C# version

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
    }
}

License

Like the original ink engine, SwiftInk is available under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages