Page 1 of 2

[RFC] pickFile function

Posted: Wed Jun 26, 2013 12:45 pm
by kaedroho
Hi Everyone,

I have been using LOVE for the past week and so far I've been loving it!!


The problem

I am currently developing a game and I hope to create an in game editor at some point. It would be great if this editor can import images from the users documents and it would also be great if there could be a way to import/export maps

As we all know, for reasons I totally agree with, we can't access anything outside of the save directory.


A potential solution

One solution to this, without breaking LOVEs security model, is to implement a pickFile function

Fot those who don't know what a pickFile function is:
A pickFile function allows an application to open files from anywhere without exposing any users personal data to it. Its basically a function that you tell it what type of file you want and how you want to open it and it will call a callback with the File object when the file has been selected and opened. The application will never know what the filename was or where the file came from. Another potential advantage of this is it will allow other methods of getting a file such as taking a picture with a webcam to be seamlessly added in without the applications knowledge

This is how android opens files from other apps, it is part of their Intents system. A similar system is being implemented for the web called "Web Intents" which allows services such a facebook to import data from other services such as dropbox without them acctually seeing each other


Example

Asynchronous version:

Code: Select all

love.filesystem.pickFile(mimeTypes..., mode, callback)

Code: Select all

love.filesystem.pickFile("image/jpeg", "image/png", "r", function (file)  image = love.graphics.newImage(file) file:close() end)
Synchronous version:

Code: Select all

file = love.filesystem.pickFile(mimeTypes..., mode)

Code: Select all

file = love.filesystem.pickFile("image/jpeg", "image/png", "r")
image = love.graphics.newImage(file)
file:close()
Let me know what you think!

Re: [RFC] pickFile function

Posted: Wed Jun 26, 2013 2:03 pm
by raidho36
I think a simple Mappy would do, and you didn't had to come up with your own editor.

Also, it isn't entirely true that you can't access files outside of root and user folder with löve2d. You can use Lua's io.* and os.* functions to access any file. I'm not entirely sure if you can actually load images and sounds to löve2d that way though. Maybe playing around with raw data would work.

Re: [RFC] pickFile function

Posted: Wed Jun 26, 2013 2:12 pm
by Automatik
I'm not entirely sure if you can actually load images and sounds to löve2d that way though. Maybe playing around with raw data would work.
love.filesystem.newFileData

Code: Select all

img = love.graphics.newImage(love.image.newImageData(love.filesystem.newFileData(content,"image.png")))

Re: [RFC] pickFile function

Posted: Wed Jun 26, 2013 2:16 pm
by raidho36
Which means you can, via using raw data processing functions. Therefore, you can read and write any file and directory, it's just more advanced thing.

I was pretty sure it was possible, because I seen somewhere a code snipped with openfile dialog that lets you choose any file on filesystem.

Re: [RFC] pickFile function

Posted: Wed Jun 26, 2013 2:19 pm
by kaedroho
Also, it isn't entirely true that you can't access files outside of root and user folder with löve2d. You can use Lua's io.* and os.* functions to access any file.
I am aware of that, but I see at least three other advantages to the pickFile approach

1) pickFile doesnt care where the data came from, this would allow the user to use their webcam to provide an image for example
2) pickFile creates a dialog that fits with the OSes theme (no need to make your own!)
3) pickFile should work seamlessly with Android Intents so you can pick a file from another app such as the gallery app or your google drive (this isnt possible with the lua io library)

Re: [RFC] pickFile function

Posted: Wed Jun 26, 2013 2:22 pm
by raidho36
You just set löve2d big time challenge then, especially when you pointed that user would provide sources such as webcam. I'm no help on this, sorry. And you quite certainly would have to do it yourself anyway.

Re: [RFC] pickFile function

Posted: Wed Jun 26, 2013 2:24 pm
by Plu
And probably another one; a love api ensures that it works across different platforms. And will handle various kinds of errors for you (lack of permissions, file locked, file deleted mid-read, someone is writing while you read, whatever kind of weird crap happens with files all the time)

Re: [RFC] pickFile function

Posted: Wed Jun 26, 2013 2:26 pm
by kaedroho
especially when you pointed that user would provide sources such as webcam
I meant *could*, I was saying that it adds the possibility for that to happen, I didn't mean that feature will be supported though! :)


I would be happy to create something as I am an experienced C++ programmer. I just don't want to commit to alot of work without discussing my idea with the community first!

Re: [RFC] pickFile function

Posted: Wed Jun 26, 2013 2:31 pm
by raidho36
Speaking of which, make sure that pop-up system dialog is not mandatory. The feature is indeed handy, but as long as it doesn't break game's flow. Think of it: you were playing a game, then decided to load a save, and when you press "load" menu item some foreign window with system skin on it that looks completely alien pops up prompting you to browse your filesystem for save files, how would you feel? Anyway, I think you should only concentrate on webcam-like data sources implementation rather than open file dialog, since this kind of user interface functionality would normally be created in-game, and löve2d has all it takes to do it.

Re: [RFC] pickFile function

Posted: Wed Jun 26, 2013 2:50 pm
by bartbes
I'm actually pretty interested in this, but there's a few questions that arise, mostly about implementation. I can definitely see the use case (which is not, as raidho seems to think, saving and loading savegames), and we've discussed something similar with file drag-and-drop in SDL2 before, but I wonder how much it will actually be used, and how "nice" it will actually be. I do look forward to seeing the results of this, though.