Is there a way of saving and loading files from anywhere?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Darlex
Party member
Posts: 128
Joined: Sun Sep 24, 2017 10:02 am
Location: Chile
Contact:

Is there a way of saving and loading files from anywhere?

Post by Darlex »

Is there a way of saving and loading files from anywhere? Like "C:\users\darlex\Desktop\project1" or "\home\darlex\desktop\project1"?
Im trying to do a game editor thing but i dont know how to do that :/
Hi! I wish you have an amazing day!
User avatar
Rehtinor
Prole
Posts: 7
Joined: Fri Apr 19, 2019 5:35 pm

Re: Is there a way of saving and loading files from anywhere?

Post by Rehtinor »

I'd suggest the IO library: https://www.lua.org/pil/21.2.2.html
Last edited by Rehtinor on Sat May 04, 2019 11:22 pm, edited 1 time in total.
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Is there a way of saving and loading files from anywhere?

Post by zorg »

Not easily; löve by default doesn't support that (with the exception of dragging folders and files), but there are a few solutions;
You can either use an external lib like luafilesystem and sacrifice it working with any constructors löve gives you (since they still depend on PhysFS that love.filesystem uses), or you can use my library that for now, allows loading from anywhere: love-fml on github. (and yes, my lib can take care of OS-specific differences in a neat way, so you don't have to worry about that)
Last edited by zorg on Sun May 05, 2019 11:43 am, edited 1 time in total.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Is there a way of saving and loading files from anywhere?

Post by Ref »

As posted before, you could always do the following.

Code: Select all

-- ***** Load/Save from Anywhere on Computer *****
-- To use, wrap 'filename' with 'mount'.
-- 				for  filename =  'D:/Scripts/Love/test.png'
-- Load Example:			love.graphics.newImage( mount( filename ) )
-- Save Example:			id:encode('png', mount( filename ) )
-- 				for dir = 'D:/Scripts/Love'
-- Files in Directory:	files = love.filesystem.getDirectoryItems( mount( dir ) )
--	Create Directory:	love.filesystem.createDirectory( mount( savedir ) )

mount = function( name )
	local ffi = require( 'ffi' )
	local lv		= ffi.load( 'love' )
	ffi.cdef[[ int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath); ]];
	ffi.cdef[[ int PHYSFS_setWriteDir(const char *newDir); ]]
	local file	= name:match( "^.+/(.+)$" )			-- filename
	local path	= string.sub( name, 1, -(#file+1) )	-- path without filename
	lv.PHYSFS_setWriteDir( path )
	lv.PHYSFS_mount( path, nil, 0 )
	return file
	end
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Is there a way of saving and loading files from anywhere?

Post by ivan »

Darlex wrote: Sat May 04, 2019 10:29 pm Is there a way of saving and loading files from anywhere? Like "C:\users\darlex\Desktop\project1" or "\home\darlex\desktop\project1"?
"C:\" is a Windows thing and it won't work across platforms.
You want your game to work on any device, right?
Darlex wrote: Sat May 04, 2019 10:29 pm Im trying to do a game editor thing but i dont know how to do that :/
Just save the maps to the appData folder and you should be fine.
Darlex
Party member
Posts: 128
Joined: Sun Sep 24, 2017 10:02 am
Location: Chile
Contact:

Re: Is there a way of saving and loading files from anywhere?

Post by Darlex »

ivan wrote: Sun May 05, 2019 4:22 am
Darlex wrote: Sat May 04, 2019 10:29 pm Is there a way of saving and loading files from anywhere? Like "C:\users\darlex\Desktop\project1" or "\home\darlex\desktop\project1"?
"C:\" is a Windows thing and it won't work across platforms.
You want your game to work on any device, right?
Darlex wrote: Sat May 04, 2019 10:29 pm Im trying to do a game editor thing but i dont know how to do that :/
Just save the maps to the appData folder and you should be fine.
Im trying to do a game/map editor and the fact of saving everything in the appdata thing is tedious.
I want to give that sensation of comfort of saving and loading files from anywhere to anywhere.
Like tilesheets, lua files and etcetera
Hi! I wish you have an amazing day!
Darlex
Party member
Posts: 128
Joined: Sun Sep 24, 2017 10:02 am
Location: Chile
Contact:

Re: Is there a way of saving and loading files from anywhere?

Post by Darlex »

Ref wrote: Sun May 05, 2019 12:34 am As posted before, you could always do the following.

Code: Select all

-- ***** Load/Save from Anywhere on Computer *****
-- To use, wrap 'filename' with 'mount'.
-- 				for  filename =  'D:/Scripts/Love/test.png'
-- Load Example:			love.graphics.newImage( mount( filename ) )
-- Save Example:			id:encode('png', mount( filename ) )
-- 				for dir = 'D:/Scripts/Love'
-- Files in Directory:	files = love.filesystem.getDirectoryItems( mount( dir ) )
--	Create Directory:	love.filesystem.createDirectory( mount( savedir ) )

mount = function( name )
	local ffi = require( 'ffi' )
	local lv		= ffi.load( 'love' )
	ffi.cdef[[ int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath); ]];
	ffi.cdef[[ int PHYSFS_setWriteDir(const char *newDir); ]]
	local file	= name:match( "^.+/(.+)$" )			-- filename
	local path	= string.sub( name, 1, -(#file+1) )	-- path without filename
	lv.PHYSFS_setWriteDir( path )
	lv.PHYSFS_mount( path, nil, 0 )
	return file
	end
Wow, that's useful! Thanks!
But... Does work with unix-like systems? ("/home/darlex/desktop/project1/")
Hi! I wish you have an amazing day!
Darlex
Party member
Posts: 128
Joined: Sun Sep 24, 2017 10:02 am
Location: Chile
Contact:

Re: Is there a way of saving and loading files from anywhere?

Post by Darlex »

zorg wrote: Sat May 04, 2019 11:14 pm Not easily; löve by default doesn't support that (with the exception of dragging folders and files), but there are a few solutions;
You can either use an external lib like luafilesystem and sacrifice it working with any constructors löve gives you (since they still depend on PhysFS that love.filesystem uses), or you can use my library that for now, allows loading from anywhere: love-fml on github. (and yes, my lib can take care of OS-specific differences in a neat way, so you don't have to worry about that)
Thanks! but is a little complex to me. (yes. im retarded)
Hi! I wish you have an amazing day!
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Is there a way of saving and loading files from anywhere?

Post by ivan »

Darlex wrote: Sun May 05, 2019 4:47 pm I want to give that sensation of comfort of saving and loading files from anywhere to anywhere.
Frankly speaking, I don't see anything "comfortable" in dealing with file dialogs, etc.
In fact, most modern programs never ask you to browse around the device's filesystem.
A good example would be apps on Android and iOS.
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Is there a way of saving and loading files from anywhere?

Post by zorg »

ivan wrote: Sun May 05, 2019 5:12 pm
Darlex wrote: Sun May 05, 2019 4:47 pm I want to give that sensation of comfort of saving and loading files from anywhere to anywhere.
Frankly speaking, I don't see anything "comfortable" in dealing with file dialogs, etc.
In fact, most modern programs never ask you to browse around the device's filesystem.
A good example would be apps on Android and iOS.
Beauty in the eye of the beholder, i guess; frankly, i'd rather know how to navigate the cesspool of a filesystem that modern OS-es have than just blindly rely on apps telling me where they put my files. :o:
Darlex wrote: Sun May 05, 2019 4:54 pm Thanks! but is a little complex to me.
As the "Usage" part says on github, you really only need to do require('fml')() if you put the files next to your main.lua; after that, you can use syntax like "drv/c/Program Files/..." for windows or "drv/usr/..." for Linux and similar for OSX to refer to any file on your filesystem... and you can still use "src/..." or "usr/..." for the source or save directories, respectively.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 60 guests