Loading files from an choosable user folder

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.
User avatar
Calandriel
Prole
Posts: 39
Joined: Wed Apr 22, 2015 9:00 am

Loading files from an choosable user folder

Post by Calandriel »

Alright, then. I just finished an essay in my university, wich was a simple tower defense game with choosable pictures from an user texture pack... In Java. Java it's strong and cool and I didn't need any framework, but, I want to remake this game as a LÖVE game :nyu: so... I have the folder "Texture Packs", which have the folder "Default" and wathever other folder that the user wish to put in. I list the files inside the default, list the files inside the new texture package, and compare each other. If they're equals(Same number of pics, .txts and midis) then if I want to, I can play using this texture pack. Well, it doesn't seem to be as simple in lua. But I love LÖVE, and I want to do this. Then I need some help.
Last edited by Calandriel on Tue Jul 14, 2015 6:39 pm, edited 1 time in total.
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
User avatar
Calandriel
Prole
Posts: 39
Joined: Wed Apr 22, 2015 9:00 am

Re: Loading files from an choosable user folder

Post by Calandriel »

The point of that game is that it's portable, andd everyone can make their own Texture/sound/txt pack, whic will change the story of the game. So, I was looking for a way to load pictures and txt files from folders inside the folder of the main.lua, but it seems that i cant control where the data of my game will be storaged, I'm stuck and frustrated. I can't list the folder contents, I can't create files outside roaming folder, I can't make a portable game with my favourite framework. (I guess I'm being too dramatic). I guess I'm missing something pretty simple, but I can't figure out what. So I had to ask. It's the only way to avoid my ignorance. Well, thanks, and if I wrote something wrong, please tell me, I'm brazilian, so english is not my mother language. :)
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
User avatar
Linkpy
Party member
Posts: 102
Joined: Fri Aug 29, 2014 6:05 pm
Location: France
Contact:

Re: Loading files from an choosable user folder

Post by Linkpy »

Helloooo ! ~

The first thing I can say : Wait Love2D 0.10 for drag and drop. So, installation of texture pack will be easy.

The second thing : Use .zip files for texture pack. So, you can use them with love.filesystem.mount.
And, so, when the texture pack will "be in" the "love.filesystem", you can use love.filesystem.getDirectoryItems for enumerate the two folders, and you just need to compare two Lua table (easy~).

If you don't want to wait Love2D 0.10, you can now use the love.system.openURL to open the file explorer to the texture pack folder, and ask to the user to manually install these texture packs. ^^
Founder of NeoShadow Studio. Currently working on the project "Sirami".
github / linkpy
User avatar
Calandriel
Prole
Posts: 39
Joined: Wed Apr 22, 2015 9:00 am

Re: Loading files from an choosable user folder

Post by Calandriel »

Well, thanks, that part about mount a zip escaped me. I was so blind! (Why the fahk I'm being so dramatic these days?)
And I was thinking about something like get an image as an icon for every texture, and use this icons like buttons to select the texture. But still, I really want to se LÖVE 0.10.0 and its android functions. It will help me to dont use Corona to make my ports. By the way, thanks! ^^
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
User avatar
Calandriel
Prole
Posts: 39
Joined: Wed Apr 22, 2015 9:00 am

Re: Loading files from an choosable user folder

Post by Calandriel »

Oh, One more thing. Mount and unmount .zip files would be maked in the save directorie, which I can't change, exceps for making subfolders. So, there is really nothing I could do to make my game portable in love, right?
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Muzz
Citizen
Posts: 54
Joined: Sun Jun 28, 2015 1:24 pm

Re: Loading files from an choosable user folder

Post by Muzz »

Check the code here. Even though you aren't supposed to you can manually set the user folder via FFI. (thanks to slime for actually writing this)

Code: Select all

    function changeDirectory()
      local ffi = require("ffi")
     
      ffi.cdef[[ int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath); ]]; 
      ffi.cdef[[ int PHYSFS_setWriteDir(const char *newDir); ]]

      local liblove = ffi.os == "Windows" and ffi.load("love") or ffi.C

      -- This grabs your source folder, but you can point it anywhere, 
      --Look at love.filesystem to see what you can call so that you can keep it multiplatform. 
      local docsdir = love.filesystem.getSourceBaseDirectory()

      liblove.PHYSFS_setWriteDir(docsdir)
      liblove.PHYSFS_mount(docsdir, nil, 0)

    end
Last edited by Muzz on Wed Jul 15, 2015 8:04 am, edited 2 times in total.
User avatar
Calandriel
Prole
Posts: 39
Joined: Wed Apr 22, 2015 9:00 am

Re: Loading files from an choosable user folder

Post by Calandriel »

So I must download FFI library and put it inside my .love? Or it's lua native then I can just write it inside my function Menu:saveTexture()?
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
User avatar
Linkpy
Party member
Posts: 102
Joined: Fri Aug 29, 2014 6:05 pm
Location: France
Contact:

Re: Loading files from an choosable user folder

Post by Linkpy »

FFI is a part of LuaJIT. If you use Love2D, you already have it ! ^^
Founder of NeoShadow Studio. Currently working on the project "Sirami".
github / linkpy
User avatar
Calandriel
Prole
Posts: 39
Joined: Wed Apr 22, 2015 9:00 am

Re: Loading files from an choosable user folder

Post by Calandriel »

Nice! Many thanks! I start it asap!
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
Muzz
Citizen
Posts: 54
Joined: Sun Jun 28, 2015 1:24 pm

Re: Loading files from an choosable user folder

Post by Muzz »

So I must download FFI library and put it inside my .love? Or it's lua native then I can just write it inside my function Menu:saveTexture()?
Just call it anywhere. it just sets the base write and real folder from %APPDATA% to being the directory above your code folder.
Post Reply

Who is online

Users browsing this forum: No registered users and 207 guests