sarbian/ModuleManager

:NEEDS breaks patch order

Sigma88 opened this issue · 2 comments

having :NEEDS on a patch seems to change the order in which it is applied, this was causing all kinds of issues in one of my mods and it took ages to realize what was actually going on

steps to reproduce (both 3.0.1 AND 2.8.1 seem to have this peculiar behaviour):

given the following cfg:

NODEA
{
}

NODEB
{
	testA = 0
	testB = 0
}

@NODEB:BEFORE[TEST]
{
	@testA = 1
}

@NODEB:BEFORE[TEST]:NEEDS[!TESTC]
{
	@testB = 1
}

@NODEA:BEFORE[TEST]
{
	testA1 = #$@NODEB/testA$
	testB1 = #$@NODEB/testB$
}

@NODEA:FOR[TEST]
{
	testA2 = #$@NODEB/testA$
	testB2 = #$@NODEB/testB$
}

the MM cache file generated is this:

UrlConfig
{
	name = NODEA
	type = NODEA
	parentUrl = /test
	NODEA
	{
		testA1 = 1
		testB1 = 0
		testA2 = 1
		testB2 = 1
	}
}
UrlConfig
{
	name = NODEB
	type = NODEB
	parentUrl = /test
	NODEB
	{
		testA = 1
		testB = 1
	}
}

NOTE: TestB1 should be 1 but it is 0 instead

I see why this is happening. When processing :NEEDS, MM removes the old config and adds a new one if applicable:

mod.parent.configs.Remove(currentMod);

I guess if if :NEEDS are satisfied it should insert at the same index rather than at the end.

thanks!