Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add More Example Games #20

Merged
merged 24 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
eda89ab
add option to re-create the default games if needed
amiantos Apr 5, 2023
11aae6b
reorganize buttons
amiantos Apr 5, 2023
b018902
rename button for clarity
amiantos Apr 5, 2023
82bbe2b
Merge master into more-default-books
amiantos Apr 5, 2023
378ebe8
Merge master into more-default-books
amiantos Apr 5, 2023
61cccf8
Merge master into more-default-books
amiantos Apr 5, 2023
280eab3
fix trailing whitespace that swiftlint didn't like
amiantos Apr 5, 2023
31eb0c6
add the beginning of a sample game
amiantos Apr 5, 2023
06f83ac
Merge master into more-default-books
amiantos Apr 6, 2023
241a3d1
fix cache maybe
amiantos Apr 6, 2023
e8031db
run swiftformat
amiantos Apr 6, 2023
cfccc28
remove mac catalyst option
amiantos Apr 6, 2023
35a318c
update settings according to warning
amiantos Apr 6, 2023
621d6ea
disable opening brace rule due to swiftformat
amiantos Apr 6, 2023
ff6e5a0
Merge master into more-default-books
amiantos Apr 6, 2023
9911979
update book
amiantos Apr 7, 2023
f370f39
turn catalyst back on
amiantos Apr 7, 2023
e09762c
add another sample book, "a pirate adventure"
amiantos Apr 7, 2023
baf85df
Merge master into more-default-books
amiantos Apr 7, 2023
682bce6
Merge master into more-default-books
amiantos Apr 10, 2023
396952e
remove unfinished defeat the dragon story
amiantos Apr 10, 2023
2ecdf9f
update a pirate adventure
amiantos Apr 10, 2023
32c3d12
change game name to Pirate Adventure so it's sorted under the intro book
amiantos Apr 10, 2023
96dc599
switch to cancelablealert
amiantos Apr 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ jobs:
- uses: actions/cache@v2
with:
path: .build/release/swiftformat
key: $-linting-swiftformat-$
key: linting-swiftformat-0.51.4
- name: Build nicklockwood/SwiftFormat
run: |
if [ -f ".build/release/swiftformat" ]; then
if ! [ -x "$(command -v swift-format)" ]; then
sudo cp -f .build/release/swiftformat /usr/local/bin/swiftformat
fi
else
git clone --depth 1 --branch master https://github.com/nicklockwood/SwiftFormat
git clone --depth 1 --branch 0.51.4 https://github.com/nicklockwood/SwiftFormat
cd SwiftFormat
swift build --disable-sandbox -c release
mv .build .. && cd ..
Expand Down
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
disabled_rules:
- trailing_comma
- opening_brace
opt_in_rules:
- empty_count
- empty_string
Expand Down
15 changes: 13 additions & 2 deletions GamebookEngine.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 53;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -42,6 +42,7 @@
44C522EB232F0B6D00E7AC95 /* GamePlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44C522EA232F0B6D00E7AC95 /* GamePlayer.swift */; };
44CB58C32326CFB6009E49D9 /* An Introduction to Gamebook Engine.gbook in Resources */ = {isa = PBXBuildFile; fileRef = 44CB58C22326CFB6009E49D9 /* An Introduction to Gamebook Engine.gbook */; };
44CB58C523286792009E49D9 /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44CB58C423286792009E49D9 /* Logging.swift */; };
44D767DF29DD537D001DFE82 /* Defeat the Dragon.gbook in Resources */ = {isa = PBXBuildFile; fileRef = 44D767DE29DD537D001DFE82 /* Defeat the Dragon.gbook */; };
B402FFEE2315FEFA00900020 /* MarkdownEditorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B402FFEC2315FEFA00900020 /* MarkdownEditorViewController.swift */; };
B402FFEF2315FEFA00900020 /* MarkdownEditorViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = B402FFED2315FEFA00900020 /* MarkdownEditorViewController.xib */; };
B402FFF22316055000900020 /* BRMarkdownParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = B402FFF12316055000900020 /* BRMarkdownParser.swift */; };
Expand Down Expand Up @@ -149,6 +150,7 @@
44C522EA232F0B6D00E7AC95 /* GamePlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GamePlayer.swift; sourceTree = "<group>"; };
44CB58C22326CFB6009E49D9 /* An Introduction to Gamebook Engine.gbook */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "An Introduction to Gamebook Engine.gbook"; sourceTree = "<group>"; };
44CB58C423286792009E49D9 /* Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = "<group>"; };
44D767DE29DD537D001DFE82 /* Defeat the Dragon.gbook */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "Defeat the Dragon.gbook"; sourceTree = "<group>"; };
B402FFEC2315FEFA00900020 /* MarkdownEditorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkdownEditorViewController.swift; sourceTree = "<group>"; };
B402FFED2315FEFA00900020 /* MarkdownEditorViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MarkdownEditorViewController.xib; sourceTree = "<group>"; };
B402FFF12316055000900020 /* BRMarkdownParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BRMarkdownParser.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -299,6 +301,7 @@
44CB58BF2326CDDB009E49D9 /* Built-in Gamebooks */ = {
isa = PBXGroup;
children = (
44D767DE29DD537D001DFE82 /* Defeat the Dragon.gbook */,
44CB58C22326CFB6009E49D9 /* An Introduction to Gamebook Engine.gbook */,
);
path = "Built-in Gamebooks";
Expand Down Expand Up @@ -550,8 +553,9 @@
B448874323063A0D000E2FDD /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 1100;
LastUpgradeCheck = 1420;
LastUpgradeCheck = 1430;
ORGANIZATIONNAME = "Brad Root";
TargetAttributes = {
4451A4B1232DCD36003D9FE9 = {
Expand Down Expand Up @@ -618,6 +622,7 @@
B4A13AD6230F6D24004929B8 /* PageEditorDecisionTableViewCell.xib in Resources */,
B448875623063A0E000E2FDD /* Assets.xcassets in Resources */,
B4A13AD2230F5B08004929B8 /* PlayDecisionTableViewCell.xib in Resources */,
44D767DF29DD537D001DFE82 /* Defeat the Dragon.gbook in Resources */,
44ADBA8723404BBB00855649 /* fileicon-ipad-64px.png in Resources */,
4407F51929DD22C800119893 /* LICENSE in Resources */,
B4F7C1492311AEB800EE055C /* PageEditorConsequenceTableViewCell.xib in Resources */,
Expand Down Expand Up @@ -927,6 +932,9 @@
);
PRODUCT_BUNDLE_IDENTIFIER = net.amiantos.BRGamebookEngine;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -949,6 +957,9 @@
);
PRODUCT_BUNDLE_IDENTIFIER = net.amiantos.BRGamebookEngine;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1430"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
LastUpgradeVersion = "1430"
wasCreatedForAppExtension = "YES"
version = "2.0">
<BuildAction
Expand Down
64 changes: 64 additions & 0 deletions GamebookEngine/Built-in Gamebooks/Defeat the Dragon.gbook
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name" : "Defeat the Dragon",
"uuid" : "4558BF56-B3BE-4223-95C2-AA3BA322AB7E",
"license" : "",
"about" : "You’ve been given a very important task by the mayor: defeat that dragon!",
"font" : "normal",
"author" : "Brad Root",
"pages" : [
{
"decisions" : [
{
"uuid" : "F5B74E7B-30AA-4A2C-87B4-D7502C611FEE",
"rules" : [

],
"content" : "Start your adventure!",
"match_style" : "match_all",
"destination_uuid" : "B5A7C12C-1165-46C3-8111-84ADEAA4BCC9"
}
],
"uuid" : "B17C8AE8-8069-4717-947F-5CF25DC25C69",
"type" : "first",
"content" : "# Introduction\n\nThis is a sample Gamebook that comes with Gamebook Engine. It’s meant to demonstrate how branching paths can create different outcomes.\n\nIn this short game, a few of your early decisions can have serious consequences later in the story.\n\nOnce you’ve found your way to the good ending, be sure to try to edit the Gamebook to add something new!"
},
{
"decisions" : [
{
"match_style" : "match_all",
"uuid" : "F1443240-BDD8-4695-99F1-1BB17AEA1D4C",
"content" : "Put on something nice",
"destination_uuid" : "B847757D-8F9B-4D06-83C8-B0F20BCDE160",
"rules" : [

]
},
{
"content" : "Just wear whatever is lying on the floor, who cares anyway, it’s just the stupid mayor",
"uuid" : "B04ADDDC-FE2F-40FF-A998-E5DD61FA8D44",
"rules" : [

],
"destination_uuid" : "0E63FD55-9539-4D2C-8D9C-8EB1432018E0",
"match_style" : "match_all"
}
],
"type" : "",
"content" : "# Chapter 1\n\nWhen you woke up this morning, you had no idea that your day was going to take you on a fantastic journey. Maybe a brief journey. But no doubt fantastic, through and through. But, first, let’s get you introduced to yourself.\n\nYou’re twelve, and no one takes you seriously. You really like chewing bubble gum and you’ve got a terrible habit of sticking it under any surface you’re near. Your mother has to go to the chiropractor to get her back adjusted because she is so often hunched over, scraping your chewed bubble gum off the furniture.\n\nIf you had any friends, no doubt the undersides of their furniture would be covered by the time you left. But I assure you, it’s not the gum that causes you to have no friends, though you sternly refuse to share a piece with anyone who asks, it’s that you’re rude and careless. With people, with objects, with money—and especially objects and money that aren’t yours, which is basically everything because, again, you’re twelve.\n\nWhen you open your eyes, lying in bed, the mid-afternoon sun streaming in through your bedroom window, making your hair mat itself to your forehead in a way that feels disgusting, you hear a faint breathing at your door. You find your mother standing there, white knuckles wrapped around a telephone receiver.\n\n“What did you do this time? My beautiful, horrible child!” Her face contorts as she shrieks.\n\nYou shrug.\n\n“The mayor just called. He said he needs you to slay a dragon. Do you know anything about that? How would you know anything about that! You’re just a child. A beautiful, horrible child, but just a child at that. Do you have any idea what I am saying to you right now?”\n\nYou stare at her and try to muster an expression but nothing really comes to you, so you just shrug again.\n\nFor a second your mother’s face becomes very red and you think her eyes might pop out of her head and there’s a faint creaking sound coming from her mouth like glass being ground between stone. But then she blinks a few times and everything seems to be just dandy.\n\n“Okay, well the mayor would like to see you urgently. Please get dressed and then we’ll be off. Please be sure to wear something nice for the Mayor.”",
"uuid" : "B5A7C12C-1165-46C3-8111-84ADEAA4BCC9"
},
{
"uuid" : "B847757D-8F9B-4D06-83C8-B0F20BCDE160",
"type" : "",
"content" : "A decision will lead to this new page..."
},
{
"type" : "",
"uuid" : "0E63FD55-9539-4D2C-8D9C-8EB1432018E0",
"content" : "A decision will lead to this new page..."
}
],
"attributes" : [

]
}
15 changes: 13 additions & 2 deletions GamebookEngine/Data/UserDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,22 @@ extension UserDefaults {

func createIntroGameIfNeeded() {
let status: Bool = bool(forKey: .createdIntro)
if !status, let introURL = Bundle.main.url(forResource: "An Introduction to Gamebook Engine", withExtension: "gbook"),
if !status {
createDefaultGames()
set(true, for: .createdIntro)
}
}

func createDefaultGames() {
createGameWithResourceName(resourceName: "An Introduction to Gamebook Engine")
createGameWithResourceName(resourceName: "Defeat the Dragon")
}

func createGameWithResourceName(resourceName: String) {
if let introURL = Bundle.main.url(forResource: resourceName, withExtension: "gbook"),
let jsonData = try? Data(contentsOf: introURL)
{
GameSerializer.standard.gameFromJSONData(jsonData, alert: false)
set(true, for: .createdIntro)
}
}

Expand Down
6 changes: 3 additions & 3 deletions GamebookEngine/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<false/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<string>LaunchScreen.storyboard</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand All @@ -69,8 +71,6 @@
</array>
<key>UISupportsDocumentBrowser</key>
<false/>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
Expand Down
33 changes: 29 additions & 4 deletions GamebookEngine/Views/Game List/GameListTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,27 @@ extension GameListTableViewController: GameListGameTableViewCellDelegate, UIDocu
actionSheet.view.tintColor = UIColor(named: "text") ?? .darkGray
}

@objc fileprivate func createDefaultGames() {
let alert = UIAlertController(
title: "Add example games?",
message: "Are you sure you want to add the example games to your library? This may duplicate the games if you already have them.",
preferredStyle: .alert
)

let okButton = UIAlertAction(title: "OK", style: .default) { _ in
UserDatabase.standard.createDefaultGames()
DispatchQueue.main.async {
self.fetchGames()
}
}
alert.addAction(okButton)

let cancelButton = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
alert.addAction(cancelButton)

present(alert, animated: true)
amiantos marked this conversation as resolved.
Show resolved Hide resolved
}

@objc fileprivate func fetchGames() {
GameDatabase.standard.fetchGames { games in
if let games = games {
Expand All @@ -181,16 +202,20 @@ extension GameListTableViewController: GameListGameTableViewCellDelegate, UIDocu
}

fileprivate func showFilePicker(_ sender: UIButton) {
let actionSheet = UIAlertController(title: "Add Game", message: nil, preferredStyle: .actionSheet)
let importAction = UIAlertAction(title: "Import from file", style: .default) { _ in
let actionSheet = UIAlertController(title: "Add game", message: nil, preferredStyle: .actionSheet)
let importAction = UIAlertAction(title: "Import game from file", style: .default) { _ in
self.importGame()
}
let createAction = UIAlertAction(title: "Create New", style: .default) { _ in
let createAction = UIAlertAction(title: "Create new game", style: .default) { _ in
self.createGame()
}
let createDefaultGamesAction = UIAlertAction(title: "Add example games", style: .default) { _ in
self.createDefaultGames()
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
actionSheet.addAction(importAction)
actionSheet.addAction(createAction)
actionSheet.addAction(importAction)
actionSheet.addAction(createDefaultGamesAction)
actionSheet.addAction(cancelAction)
actionSheet.popoverPresentationController?.sourceView = sender
actionSheet.popoverPresentationController?.sourceRect = CGRect(x: sender.frame.width / 2 - 3, y: sender.frame.height, width: 0, height: 0)
Expand Down