Jump to content
DavidW

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!)

Share this post


Link to post
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...