Trying to create a file structure with modding in mind

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.
Post Reply
User avatar
SirDust
Prole
Posts: 15
Joined: Sat Feb 11, 2017 12:53 am

Trying to create a file structure with modding in mind

Post by SirDust »

I have been trying to create a file structure for my game that stores the game's assets (such as sprites and audio) and output data (such as the player's save files and options) outside of the working directory so that they can be easily modified even after the .love file has been fused.

Here are the potential file structures I have considered, in order of preference:
  1. Store both game assets and output data in the game's source directory
  2. Store assets in the source directory and output in the save directory
  3. Store assets and output in the save directory
These are my issues with them; why I need help:
  • Option 1 may not be possible as I have not found a way to write to the game's source directory.
  • Option 2 seems possible, however I cannot figure out how to read from the source directory while the game is either fused or unfused.
  • Option 3 I know is possible, if this is the only option then I would just like to know how I can get the game to use the same save directory while either fused or unfused (or at least make it so I don't have to store the game's assets in two separate directories).
I am sorry, I have been struggling to understand the wiki and its explanation of the love.filesystem module, so I may have missed where it answers these problems.
BorhilIan
Prole
Posts: 38
Joined: Wed Mar 15, 2017 6:46 am

Re: Trying to create a file structure with modding in mind

Post by BorhilIan »

Option 2 is your best bet, you can have an in-game option to open the save folder/ (which is sadly restrained to appdata) However I've heard you can use the 'io' library (Built into lua) to write to any location, given that love.exe has access.

ERIT: As for your assets just pack them into your '.love' file or put them in the save directory (AppData).
User avatar
SirDust
Prole
Posts: 15
Joined: Sat Feb 11, 2017 12:53 am

Re: Trying to create a file structure with modding in mind

Post by SirDust »

BorhilIan wrote: Fri Aug 11, 2017 2:09 am Option 2 is your best bet, you can have an in-game option to open the save folder/ (which is sadly restrained to appdata) However I've heard you can use the 'io' library (Built into lua) to write to any location, given that love.exe has access.

ERIT: As for your assets just pack them into your '.love' file or put them in the save directory (AppData).
Well, option 3 is the one where I put the assets in the save directory, not option 2, and I'm trying to avoid packing the assets in the .love file.
I want to store the assets in the source directory (the directory containing the .love or .exe file) if at all possible.

I might try testing the io library, but I feel dirty using it.
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

Re: Trying to create a file structure with modding in mind

Post by Beelz »

I scribbled up notes on paper a while back for how to allow modding but never actually tried to implement it. Basically what I figured the best plan was to put all base entities/assets/etc into the love file, then when the game is loaded you enumerate the folders inside a mods folder in the save directory. Sandbox them with pcall(require, "filepath") so the game can continue to load if a mod fails. Each mod can be structured however the modder wants, but the folder must contain a "desc.lua" file to declare it, etc. That's about the gist of what I wrote, but I hope it helps develop your ideas on the matter.

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
User avatar
SirDust
Prole
Posts: 15
Joined: Sat Feb 11, 2017 12:53 am

Re: Trying to create a file structure with modding in mind

Post by SirDust »

Thanks, I was able to narrowed down my problem to a lack of knowledge about accessing the source directory, and I found a forum post which answered most of my questions: https://love2d.org/forums/viewtopic.php ... 9&p=200356.
With that in mind, I now know option 2 is possible with some limitations (the game must be fused for it to work), and I know that option 1 is not possible since the source directory cannot be written to.

So I will definitely store the game's output data in the save directory, and I think I will support storing the game's assets in both the save directory and source directory.
User avatar
zorg
Party member
Posts: 3446
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Trying to create a file structure with modding in mind

Post by zorg »

love.filesystem.getSourceBaseDirectory might be an option, since the docs state that you can read from that directory where the .love file (or .exe) is.

As for the other issue... i had a gist on github that allowed writing to the source directory, though i haven't checked whether the code works post-0.9.1 or on any other OS apart from windows.

Code: Select all

-- NOT RECOMMENDED AT ALL FOR ANYONE TO USE THIS...
-- that said, feel free to.
local ffi = require "ffi"
local liblove = ffi.os == "Windows" and ffi.load "love" or ffi.C

ffi.cdef[[
	int PHYSFS_setWriteDir(const char* newDir);
]] -- This call will fail (and fail to change the write dir) if the current write dir still has files open in it.

local usrPath = love.filesystem.getSaveDirectory()
local srcPath = love.filesystem.getSourceBaseDirectory()
local dir = 'usr'

local t = {}

t.getCurrentWriteDirectory = function()
	return dir	
end

t.setCurrentWriteDirectory = function(d)
	assert(string.lower(d) == 'usr' or string.lower(d) == 'src',"The given parameter is not accepted!")
	if dir == d then return true end
	dir = d
	local success
	if dir == 'usr' then
		success = liblove.PHYSFS_setWriteDir(usrPath)
	elseif dir == 'src' then
		if not love.filesystem.isFused() then error "Can't set the write directory to the source; The game is not fused!" end
		success = liblove.PHYSFS_setWriteDir(srcPath)
	end
	return success ~= 0 and true or false,success
end

return t
Also no idea whether you could use this with the project un-fused...
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 3 guests