KSP-ModularManagement / KSPe

Extensions and utilities for Kerbal Space Program
http://ksp.lisias.net/add-ons/KSPAPIExtensions
Other
11 stars 5 forks source link

Bug on `ConfigNodeWithSteroids.from` #23

Closed Lisias closed 1 year ago

Lisias commented 2 years ago

That's weird.

Let's say we have the following ConfigNode on the prefab:

[LOG 22:49:56.768] [KSP_Recall] INSTALLED
{
        Attached = false
        ChillingOut = false
        Driftless = true
        Refunding = false
        Resourceful = false
        AttachedOnEditor = false
        LetsStayTogether
        {
                PartModule = true
        }
}

The following code works fine:

                UrlDir.UrlConfig urlc = GameDatabase.Instance.GetConfigs("KSP-Recall")[0];
                ConfigNodeWithSteroids cn = ConfigNodeWithSteroids.from(urlc.config.GetNode("INSTALLED"));
                Log.force("{0}", cn.ToString());

and prints what's expected correctly. However, the following code:

                Log.force("{0}", cn.GetNode("LetsStayTogether").ToString());
                Log.force("{0}", ConfigNodeWithSteroids.from(cn.GetNode("LetsStayTogether").ToString()));

ends up printing what follows on the log:

[LOG 22:49:56.768] [KSP_Recall] LetsStayTogether
{
        PartModule = true
}

[LOG 22:49:56.769] [KSP_Recall] LetsStayTogether
{
}

what's clearly a bug, because both entries should be printing the same content!

By some reason, ConfigNodeWithSteroids.from is borking when being fed with a subnode!

Search and Destroy the bug!

Lisias commented 1 year ago

This issue is INVALID. There's an error on the reference code!!

This is wrong, the .ToString() is being applied on the wrong place:

    Log.force("{0}", ConfigNodeWithSteroids.from(cn.GetNode("LetsStayTogether").ToString()));

Is should be:

    Log.force("{0}", ConfigNodeWithSteroids.from(cn.GetNode("LetsStayTogether")).ToString());

And, now, this works fine, as I had proved while checking https://github.com/net-lisias-ksp/DistantObject/issues/28:

[LOG 00:23:34.929] DOE *****
 source root
{
        debugMode = False
        useToolbar = True
        useAppLauncher = True
        onlyInSpaceCenter = False
        DistantFlare
        {
                flaresEnabled = False
                flareSaturation = 1
                flareSize = 1
                flareBrightness = 1
                ignoreDebrisFlare = False
                debrisBrightness = 0.150000006
                situations = ORBITING,SUB_ORBITAL,ESCAPING,DOCKED,FLYING
                showNames = True
        }
        DistantVessel
        {
                renderVessels = False
                maxDistance = 750000
                renderMode = 0
                ignoreDebris = False
        }
        SkyboxBrightness
        {
                changeSkybox = True
                maxBrightness = 0.25
                referenceBodySize = 1
                minimumSignificantBodySize = 1
                minimumTargetRelativeAngle = 100
        }
}

 target root
{
        debugMode = False
        useToolbar = True
        useAppLauncher = True
        onlyInSpaceCenter = False
        DistantFlare
        {
                flaresEnabled = False
                flareSaturation = 1
                flareSize = 1
                flareBrightness = 1
                ignoreDebrisFlare = False
                debrisBrightness = 0.150000006
                situations = ORBITING,SUB_ORBITAL,ESCAPING,DOCKED,FLYING
                showNames = True
        }
        DistantVessel
        {
                renderVessels = False
                maxDistance = 750000
                renderMode = 0
                ignoreDebris = False
        }
        SkyboxBrightness
        {
                changeSkybox = True
                maxBrightness = 0.25
                referenceBodySize = 1
                minimumSignificantBodySize = 1
                minimumTargetRelativeAngle = 100
        }
}

using this code:

            ConfigNodeWithSteroids settings = ConfigNodeWithSteroids.from(configNode);
            UnityEngine.Debug.LogFormat("DOE *****\n source {0}\n target {1}", configNode, settings);