Posted August 24, 2019 by Drillur
#lored #update #patch #marshalls #exporting save #base64 #importing save
LORED 1.2
:D
All of this can be read at the patch notes.
You can now export and import saves! ... on desktop.
Now only the MALIGNANCY LORED can produce malignancy.
The malignant upgrade aw <3 now correctly increases the price of the COAL LORED as if it had been bought.
Added a few malignant and (very expensive) normal upgrades.
LOREDs that are offloading their resources so the target LORED can continue to work will now attempt to keep 4x what the target LORED requires to work.
Fixed a bug where the bottom half of the IRON and COPPER LORED buy buttons were blocked by a spooky ghost.
If the player does not buy the COAL LORED within 15 seconds of beginning the game, display a tip that tells them to click the button.
Add floating numbers for resource gains!
Replace the colored status indicators with little animations, or at least a dot in a better place.
This has been a nightmare, but exporting the entire save came down to one little line of code:
OS.set_clipboard(save.game_version + "/n" + Marshalls.variant_to_base64(save.data))
OS.set_clipboard() will write any string to the user's clipboard, so anything inside the () has to be a string.
(By the way, save is a class I made that has two variables: game_version, a string, and data, a dictionary.)
save.game_version is a string that equals "1.2". I didn't want to translate this to base64 because I don't care. If the player changes it, it might break something, so it's at their own risk.
"/n" creates a new line and is important when importing a save.
Marshalls.variant_to_base64() will translate any variable into base64, I think. That's what the Godot documentation says, anyway. There's also Marshalls.utf8_to_base64(), which translates a string into base64. I wouldn't use the variant method if you're just translating a string--the two methods must exist for a reason. save.data is a dictionary with all of the save information in it, so that's why I used the variant method.
So after that line, the user's clipboard looks something like this:
1.2
SnAAAAKJDNTKAMMAAAKEOTNGNFNWKAAAJJRSGBBBACEVEAKEDAAKEurLem
but much longer. There are a lot of A's in base64.
Once the proper text is on the clipboard, you can then import the info to any website or platform the game is on using OS.get_clipboard().
Since I want to get two variables out of the clipboard--game_version and data--I need to use split()[] which looks for a string and returns what comes before the x instance of it. I want to find "/n" and get the first instance of it, so I'd write split("/n")[0]. Here's the actual line:
save.game_version = OS.get_clipboard().split("/n")[0]
This will equal "1.2". OS.get_clipboard() gets the entire clipboard, but then split("/n")[0] cuts it down to what comes before the first line, or "/n".
The rest of the clipboard is in base64, so we will need to translate it back to real text so the game can load it.
It's pretty easy, and I won't even need to explain it since you already know all you need to! Here it is (for the save.data dictionary):
save.data = Marshalls.base64_to_variant(OS.get_clipboard().split("/n")[1])