[RFC] pickFile function

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.
kaedroho
Prole
Posts: 5
Joined: Wed Jun 26, 2013 11:46 am

[RFC] pickFile function

Post 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!
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: [RFC] pickFile function

Post 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.
Last edited by raidho36 on Wed Jun 26, 2013 2:14 pm, edited 2 times in total.
Automatik
Citizen
Posts: 57
Joined: Sun Feb 17, 2013 7:05 pm

Re: [RFC] pickFile function

Post 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")))
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: [RFC] pickFile function

Post 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.
kaedroho
Prole
Posts: 5
Joined: Wed Jun 26, 2013 11:46 am

Re: [RFC] pickFile function

Post 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)
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: [RFC] pickFile function

Post 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.
Last edited by raidho36 on Wed Jun 26, 2013 2:24 pm, edited 1 time in total.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: [RFC] pickFile function

Post 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)
kaedroho
Prole
Posts: 5
Joined: Wed Jun 26, 2013 11:46 am

Re: [RFC] pickFile function

Post 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!
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: [RFC] pickFile function

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: [RFC] pickFile function

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests