Jump to content

Immutability and encapsulation in mod design


Recommended Posts

In case this is any use to anyone, here's an immutable wrapper for HANDLE_AUDIO:

 

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////    immutable version of HANDLE_AUDIO
////////////
////////////    Assumes "ext_music_loc" and "ext_audio_loc" have been set appropriately
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

DEFINE_ACTION_FUNCTION handle_audio_immutably
	INT_VAR music=0
	STR_VAR	oggdec_path="%MOD_FOLDER%/audio"
			sox_path="%MOD_FOLDER%/audio"
			audio_path="%MOD_FOLDER%/audio"
BEGIN
	OUTER_SET new_files=0
	ACTION_IF music BEGIN
		ACTION_IF !VARIABLE_IS_SET ext_music_loc BEGIN
			OUTER_SPRINT ext_music_loc "weidu_external/music/%MOD_FOLDER%"
		END
		OUTER_SPRINT new_audio_path "%ext_music_loc%"
	END ELSE BEGIN
		ACTION_IF !VARIABLE_IS_SET ext_audio_loc BEGIN
			OUTER_SPRINT ext_audio_loc "weidu_external/audio/%MOD_FOLDER%"
		END
		OUTER_SPRINT new_audio_path "%ext_audio_loc%"	
	END
	MKDIR "%new_audio_path%"
	// copy everything over
	ACTION_BASH_FOR "%audio_path%" ".*\.ogg" BEGIN
		ACTION_IF !FILE_EXISTS "%new_audio_path%/%BASH_FOR_FILE%" BEGIN
			OUTER_SET new_files=1
			COPY_LARGE "%audio_path%/%BASH_FOR_FILE%" "%new_audio_path%"
		END
	END
	ACTION_IF new_files BEGIN
	PRINT "handling audio"
		LAF HANDLE_AUDIO INT_VAR music STR_VAR audio_path="%new_audio_path%" oggdec_path sox_path END
	
	
	END


END

To use: just call handle_audio_immutably, with the same arguments as HANDLE_AUDIO.

(Not extensively tested yet!)

Link to comment

One of the benefits of mod immutability is that "%MOD_FOLDER%" can be used multiple times for many installations, even at once. Instead of coping the mod folder which takes time, the "%MOD_FOLDER%" is "deployed" into the game folder via Junctions/Symlinks/HardLinks instantly. Enabling players to use such an improvement would require the modder to consciously place an additional entry in the .ini file.

@DavidW @CamDawg @argent77 (to name few) Would you be interested in such a feature?

Link to comment

Yes, it's for end users. The coping time depends: coping 20 mods is relatively quick, but 200 mods with BGGO, SoS, RoT, CtB etc might take minutes. I see this as a nice benefit without extra work since immutability is something that you set only once.  I should probably prepare some data and testing but I wanted to get some initial feedback before actually coding such feature.

Link to comment
2 minutes ago, AL|EN said:

The coping time depends: coping 20 mods is relatively quick, but 200 mods with BGGO, SoS, RoT, CtB etc might take minutes.

Wouldn't you rather extract an archive than copy ? Cause yes, extracting data from a smaller source file is FASTER than copying a files form one folder to another, at least in todays computers(multi core) .. I don't know the details, but I know it's true.

Link to comment
On 2/1/2024 at 12:55 PM, AL|EN said:

@mickabouille I've missed this, yep, it's one of the possible ways to check. But there is a chance that the mod author already uses .gitignore to exclude some folders/files so it might not get reliable results.

In that case, you can still check with `git clean`, using the `-x` flag. E.g. `git clean -xdn` won't delete anything, but will list the files that would have to be removed.

Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...