sarbian / ModuleManager

177 stars 96 forks source link

:NEEDS breaks patch order #90

Closed Sigma88 closed 6 years ago

Sigma88 commented 6 years ago

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

blowfishpro commented 6 years ago

I see why this is happening. When processing :NEEDS, MM removes the old config and adds a new one if applicable: https://github.com/sarbian/ModuleManager/blob/58e1ca29a64494d72a06e6b4dffa300f9a79f349/ModuleManager/NeedsChecker.cs#L28

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

Sigma88 commented 6 years ago

thanks!