gamebookengine icon indicating copy to clipboard operation
gamebookengine copied to clipboard

Gamebook Library Cloud Backups

Open amiantos opened this issue 2 years ago • 7 comments

It would be nice if users could opt-in to storing their gamebook libraries securely in iCloud somehow. Maybe I can build something really simple like a mass export to a folder in iCloud. Or go all out and use CloudKit to store the Core Data DB in the cloud...? Maybe a little kooky but that would be the coolest.

It goes without saying it's important this cloud backup use iCloud for security and privacy purposes.

amiantos avatar Apr 06 '23 06:04 amiantos

I was curious how NetNewsWire handles iCloud syncing and it looks like it uses CloudKit https://github.com/Ranchero-Software/NetNewsWire/tree/main/Account/Sources/Account/CloudKit

Wonder if their implementation is the most straightforward way to implement CloudKit. Since GBE is already using core data in a fairly standard way, maybe using CloudKit for database syncing wouldn't be a big deal... only one way to find out I guess...

Docs: https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit

amiantos avatar Apr 11 '23 05:04 amiantos

Doesn't look like the core data store in GBE has any problem with CloudKit requirements: https://developer.apple.com/documentation/coredata/mirroring_a_core_data_store_with_cloudkit/creating_a_core_data_model_for_cloudkit#3191035

amiantos avatar Apr 11 '23 05:04 amiantos

Doesn't seem like it would be all that difficult. And once the database gets into iCloud, we could write a web app.

Now, that said, users need to be able to opt-in to this, not opt-out, as I do promote the privacy and disconnectedness of Gamebook Engine. I assume I should be able to set it up that way.

amiantos avatar Apr 11 '23 05:04 amiantos

Got blocked trying to generate a CloudKit schema.

CloudKit integration does not support ordered relationships. The following relationships are marked ordered: Game: pages Page: decisions

CloudKit integration requires that all attributes be optional, or have a default value set. The following attributes are marked non-optional but do not have a default value: Attribute: name Attribute: uuid Consequence: uuid Decision: content Decision: uuid Game: name Game: uuid Page: content Page: uuid Rule: uuid

CloudKit integration requires that all relationships be optional, the following are not: Attribute: game Consequence: page Decision: page Page: game Rule: decision

This might not be a big blocker. Pages don't need to be ordered in a game, literally no reason for that. And decisions... well... ordering seems like it might be important there though there is currently no way to actually reorder decisions on a page. If we want to keep ordered decisions, we can implement a displayOrder attribute easy enough.

"default value" is interesting, I wonder if default value can be an actual UUID in those cases. The other things have in-code defaults really.

And then the optional relationship thing... I mean... if an attribute doesn't have a game, if a consequence doesn't have a page, that's just bad data. But maybe it's not a big deal to consider those things optional.

Schema changes does mean migrations but maybe it's not a big deal...

amiantos avatar Apr 11 '23 06:04 amiantos

Another possibility is to set up a second core data store just to support syncing. Model would be super simple, local_uuid, game_json (the export of the game), sync_timestamp, and date_updated. I think with that we'd have enough to set up a decent document-based sync system.

amiantos avatar Apr 11 '23 06:04 amiantos

This doesn't have to be the solution--because I quite like my last comment's idea of essentially a document store using CloudKit--but taking that idea even further, does it not seem like Gamebook Engine could be something a bit more like, say, Pages? A productivity app? In the sense that it's acting on files. The fact that I'm loading the games into a database on the device and playing them off of that is an implementation detail. In reality it would make more sense if gamebooks lived in a Gamebook Engine specific folder in your documents or on your phone some where and you used gamebook engine to open them.

But I guess that interface is kind of lame deep down. There's no reason it can't work that way, though.

In reality Gamebook Engine is more like Books.app, where you drag files into it and then it does some hoodoo and changes the files all up into something it likes more and creates a database and syncs it to the cloud in its own way and so on.

amiantos avatar Apr 13 '23 05:04 amiantos

Idea of a document store backup is winning in my mind. And it should be essentially one-way where by default your books are uploaded to the sync database whenever they change, but it's not an automatic two-way sync. You can choose to overwrite your local book store with what is in the cloud if you want, but it's not going to overwrite a game while you're playing it. I was really overthinking the issue for a bit there.

amiantos avatar Apr 13 '23 05:04 amiantos