Skip to content

Conversation

@Imbion
Copy link
Contributor

@Imbion Imbion commented Aug 24, 2025

Changes to each camp/stop to support multi mod patching to junctions. This might break dungeon accessibility for current dungeon mods.

Here is an example of how to patch, with the target in this case being base_camp:

require 'origin.common'

local base_camp_resource_pack = {}

local base_junc = CURMAPSCR.East_Exit_Touch

function base_camp_resource_pack.East_Exit_Touch(obj, activator, newDunEnts, newGroEnts)
	local patchDuns = {'berry_grove'}
	local patchGros = {}


	-- clone sillies! i think this should handle cases where other mods add stuff
	local copy = function (target)
		local clone = {}
		if target then
		    for i=1,#target do
		      clone[#clone+1] = target[i]
		    end
	    end
	    return clone
	end

	local merge = function (tableAddedTo, tableTakenFrom)
		  if tableAddedTo and tableTakenFrom then
		    for i=1,#tableTakenFrom do
		      tableAddedTo[#tableAddedTo+1] = tableTakenFrom[i]
		    end
		  end
		end

	local dunEnts = copy(newDunEnts)
	merge(dunEnts,patchDuns)

	local groEnts = copy(newGroEnts)
	merge(groEnts,patchGros)

	GAME:UnlockDungeon('berry_grove')

	base_junc(obj, activator, dunEnts, groEnts)
end

return base_camp_resource_pack

Notes about these commits for future work:

  • Patching is done by using CURMAPSCR in a particular way.
    • It's pretty specific, as recursion is part of how it works (to support other mods) - interface function should be created for modders to make the process easier.
  • There are repeated helper functions in each script file that should be moved to somewhere else to be accessed commonly.
    • Ideally the process for junctions would also be moved into its own function in a separate file to avoid repeated code.
  • I wanted to be able to sort the junction list by dungeon name colour, but this functionally hasn't been implemented yet. Would like to implement this while moving the common functions to their own file.
  • A lot of merges and deep copies are made with these changes. This is currently not of much concern, but the way this is done may have to be changed in the future for runtime concerns.
    • Could cache all of the patch changes and generate the destination list upon loading the save file?

Imbion added 10 commits August 24, 2025 02:47
General improvements that could be made:
* Dungeon colour isn't sorted for patches yet
* Helper functions belong in a common file rather than being repeated across camps
* Time complexity may be a future concern due to the amount of deep copying and merges
@Imbion
Copy link
Contributor Author

Imbion commented Sep 13, 2025

Updated example for mod scripts with the refactoring:

require 'origin.common'

local base_camp_resource_pack = {}

local base_junc = CURMAPSCR.North_Exit_Touch

function base_camp_resource_pack.North_Exit_Touch(obj, activator, other_new_dungeons, other_new_grounds)
	local patchDuns = {'berry_grove'}
	local patchGros = {}

	COMMON.DoJuncPatch(obj, activator, other_new_dungeons, other_new_grounds, patchDuns, patchGros, base_junc)
end

return base_camp_resource_pack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant