Hi folks,
Moonring does a lot of copying of directories to enable the save-game functionality, and to create backups.
My levels are held as .pngs, the level data is held as .csvs and the player data is held as a serialised .sav file.
I literally backup a directory from my game's 'level' directory (held as part of the .love file) to a location in the LOVE save directory.
As far as I can tell, Love2D lacks any form of file copy, so I have to load in every piece of data, decode it, recode it and save it again! This seems more than a bit ridiculous. What am I missing here?
Any help much appreciated... both by me and a ton of new players!
- Dene
Copying a file from a local directory to the LOVE save directory
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Party member
- Posts: 548
- Joined: Wed Oct 05, 2016 11:53 am
Re: Copying a file from a local directory to the LOVE save directory
You could potentially use os.execute, and run some copy commands to transfer those files over. These commands may be platform specifc, like using robocopy on windows. This method may flash a command prompt on users' screens, but if you mean to do the file transfers as a one-time thing (eg. when first launching the game), it might not be so bad.
There's probably better approaches with FFI, but above is what I've used personally when I've needed to copy files back and forth in bulk.
Out of curiosity though, what's the purpose behind copying the level data over to the save file folder?
There's probably better approaches with FFI, but above is what I've used personally when I've needed to copy files back and forth in bulk.
Out of curiosity though, what's the purpose behind copying the level data over to the save file folder?
- slime
- Solid Snayke
- Posts: 3162
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Copying a file from a local directory to the LOVE save directory
Something like this will copy a file without doing any decoding or encoding, only reading and writing:
It will load the whole file into memory at once, but you can avoid that if you want by using a File object and copying a chunk at a time.
However, love.filesystem is designed to transparently handle situations where you have initial data shipped with the game that might be replaced by saved data later. If something exists in the same relative path in the game's source directory (.love) as it does in the game's save directory, then by default love will prioritize reading from the save directory's version of the file instead of the source directory - which means (for example) you can have a default settings file shipped with the game, and save a modified version to the same relative path when a user modifies their settings and everything will work without needing to manage a separate relative path for the default settings versus modified ones. That behaviour can be changed in love.conf or love.filesystem.setIdentity.
That being said, I wouldn't think you'd need to do any copying at all of levels (those png files), but I don't have a full understanding of what your game does with levels.
Code: Select all
local data = love.filesystem.read(readpath)
love.filesystem.write(writepath, data)
However, love.filesystem is designed to transparently handle situations where you have initial data shipped with the game that might be replaced by saved data later. If something exists in the same relative path in the game's source directory (.love) as it does in the game's save directory, then by default love will prioritize reading from the save directory's version of the file instead of the source directory - which means (for example) you can have a default settings file shipped with the game, and save a modified version to the same relative path when a user modifies their settings and everything will work without needing to manage a separate relative path for the default settings versus modified ones. That behaviour can be changed in love.conf or love.filesystem.setIdentity.
That being said, I wouldn't think you'd need to do any copying at all of levels (those png files), but I don't have a full understanding of what your game does with levels.
Who is online
Users browsing this forum: Google [Bot] and 0 guests