Recommended Posts

Can anybody explain to me, how to copy a config node from one module to another. I'm creating an engine switching plugin, where I need to copy an effect node from my module into the engine module.

 

MODULE
{
	name = mymodule
	EFFECTS					//  <---- SOURCE -->
	{
		SOMEEFFECT
		{
			.... = ....
			.... = ....
		}

	}
}

Now copy that into the engine module, replacing the entire effect node in there

PART
{
	name = SOMEENGINE
	MODULE
	{
		name = moduleengineFX
		... = ... (referencing some effects)
	}

	EFFECTS				<-- TARGET -->
	{
		SOMEEFFECT
		{
			.... = ....
			.... = ....
		}

	}
}

 

Edited by Warezcrawler

Share this post


Link to post
Share on other sites
  1. Why exactly don't you just put the effects directly in the part node?
     
  2. Is what you are trying to achieve *really* is to copy the node, or just transport the information?
     
  3. And depending on the answer to #2, are you sure this isn't something you can work around with MM?

Share this post


Link to post
Share on other sites

4. Why don't you use the stock engine switching module (MultiModeEngine) ?

Share this post


Link to post
Share on other sites
12 hours ago, stupid_chris said:
  1. Why exactly don't you just put the effects directly in the part node?
     
  2. Is what you are trying to achieve *really* is to copy the node, or just transport the information?
     
  3. And depending on the answer to #2, are you sure this isn't something you can work around with MM?

1. That's where I started, but when I put effect that are unneeded to begin with, the I have observed that the animations can run wild. I though originally that this was the product of an error in my plugin, but it was ksp doing it...
2. Well, basically I need to pick up the node, remove node I'm not to use, and put it into the part 3 at run-time.
3. I started with MM, I'd really prefer to put the entire EFFECTS node in the part to begin with, and only change the references for the effect... But the effect are simply running wild on certain parts when doing that ;.;

7 hours ago, sarbian said:

4. Why don't you use the stock engine switching module (MultiModeEngine) ?

I have for a long time wanted to be able to switch to mode that 2 modes, and I would like to have the mod evolve into integration to the tech tree. Currently I activated certain modes when tech tree node are unlocked. Eventually I will also like to deprecate obsolete configuration, and maybe put a price an certain configurations.... Far in the future that is..... But that is basically why.
Does that answer your question?

Basically more functionality and flexibility to the switching of engines.

Share this post


Link to post
Share on other sites
4 hours ago, Warezcrawler said:

2. Well, basically I need to pick up the node, remove node I'm not to use, and put it into the part 3 at run-time.

So what you want to do is transport the information of the node, not the node? Have you tried part.Effects.LoadEffects(ConfigNode node) ?? (I think I have the signature right)

Share this post


Link to post
Share on other sites
12 minutes ago, stupid_chris said:

So what you want to do is transport the information of the node, not the node? Have you tried part.Effects.LoadEffects(ConfigNode node) ?? (I think I have the signature right)

Well yes and no. I've tried it (and failed). I think my problem is that I need a valid node to put in it. So I'm thinking if I can somehow get the node from my module, I should be able to load it back in using .LoadEffects(ConfigNode node) syntax.

......... I just don't know how exactly to do that :(

[on a side note.... I think I will as Nifty255 to do a video at some point on config nodes...... :D Maybe he would take the suggestion]

EDIT: And yes, it is the information that is important, not the node itself, as long as KSP recognises it as an EFFECTS node :confused:

Edited by Warezcrawler

Share this post


Link to post
Share on other sites

@Warezcrawler Okay, I'm not 100% sure, but I believe this would work

Part p1;	//Part you want to take the effects from
Part p2;	//Part you want to transport the effects to

//Temporary node
ConfigNode node = new ConfigNode("EFFECTS");

p1.SaveEffects(node);	//Saves effects to node
p2.LoadEffects(node);	//Loads effects from node

But I recommend reconsidering your problem, because I'm highly suspicious that this is the best way to achieve what you're looking for, which isn't quite clear tbh.

Edited by stupid_chris

Share this post


Link to post
Share on other sites
1 minute ago, stupid_chris said:

 

@Warezcrawler Okay, I'm not 100% sure, but I believe this would work


Part p1;	//Part you want to take the effects from
Part p2;	//Part you want to transport the effects to

//Temporary node
ConfigNode node = new ConfigNode("EFFECTS);

p1.SaveEffects(node);	//Saves effects to node
p2.LoadEffects(node);	//Loads effects from node

Well, I think I might have been unclear regarding the fact that the module with the "Source" effect node is in a module in the same part as the target EFFECTS are supposed to be "copied" to. I can see the confusion based on the example given. Sorry about that. Maybe this is clearer...


PART
{
	name = SOMEENGINE
	MODULE
	{
		name = moduleengineFX
		... = ... (referencing some effects)
	}

	EFFECTS				<-- TARGET -->
	{
		SOMEEFFECT
		{
			.... = ....
			.... = ....
		}

	}

    MODULE
    {
        name = mymodule
        EFFECTS					//  <---- SOURCE -->
        {
            SOMEOTHEREFFECTS
            {
                .... = ....
                .... = ....
            }

        }
    }
}

That said, I don't get why if p1 one is the source, then why do I save effects to that node? Is it supposed to be the other ways around?

 

Share this post


Link to post
Share on other sites

Because you really don't want to put the EFFECTS nodes in the PartModule, and because SaveEffects just saves the parts effects to the passed ConfigNode parameter, if I'm correct.

Share this post


Link to post
Share on other sites
On 25/4/2016 at 9:51 PM, stupid_chris said:

Because you really don't want to put the EFFECTS nodes in the PartModule, and because SaveEffects just saves the parts effects to the passed ConfigNode parameter, if I'm correct.

You are right, I don't really want an effect node in the partmodule, however, I need a place to store the effects node contents until I need to load it into the EFFECTS node of the part. 

So I'm very sorry if I seem retarded, but I really appreciate your patience.

So I think I get how to load a confignode into the effects node, but I am still not where I understand how to pick up the intended Effects from another node. How can I collect it from the partsmodule? I think I need to get the entire node from somewhere (e.g. my partsmodule), delete unneeded nodes in it, and save it back to the effects node of the part. The last part I believe is covered nicely by now.

I hope you, or someone else, can and will help me with this part :)

Share this post


Link to post
Share on other sites

If you're planning to do it your way (which I highly reccomend not doing and instead finding the right way to do what you're trying to achieve), you're gonna have to save your config nodes somewhere, because they're not serializable anymore. Probably something like this. Just override your PartModule's OnLoad and do something like this:

public override void OnLoad(ConfigNode node)
{
	if (HighLogic.LoadedScene == GameScenes.LOADING)
	{
		PersistantManager.Instance.AddNode<MyPartModule>(this.part.name, node);
	}
}

Then, when needed, load the effects something like this:

ConfigNode node = null, effects = null;
if (PersistantManager.Instance.TryGetNode<MyPartModule>(this.part.name, ref node) && node.TryGetNode("EFFECTS", ref effects))
{
	Part p;		//Target part
  	p.LoadEffects(effects);
}

Something of the likes should do. Note that I typed everything by hand here, so there might be a few errors.

Share this post


Link to post
Share on other sites
2 minutes ago, stupid_chris said:

If you're planning to do it your way (which I highly reccomend not doing and instead finding the right way to do what you're trying to achieve), you're gonna have to save your config nodes somewhere, because they're not serializable anymore. Probably something like this. Just override your PartModule's OnLoad and do something like this:


public override void OnLoad(ConfigNode node)
{
	if (HighLogic.LoadedScene == GameScenes.LOADING)
	{
		PersistantManager.Instance.AddNode<MyPartModule>(this.part.name, node);
	}
}

Then, when needed, load the effects something like this:


ConfigNode node = null, effects = null;
if (PersistantManager.Instance.TryGetNode<MyPartModule>(this.part.name, ref node) && node.TryGetNode("EFFECTS", ref effects))
{
	Part p;		//Target part
  	p.LoadEffects(effects);
}

Something of the likes should do. Note that I typed everything by hand here, so there might be a few errors.

Thank you, I will try this.

However, I do get that you do not recommend it, the thing just is, that I haven't seen or come up with a viable alternative yet. I did try putting the effects in with MM from the beginning, which resulted in wierd animation behavior of the part. That's why I'm considering this way of handling it. I'm guessing that it will not animate something not referenced.... Hopefully....

If you have a good alternative, I am open for suggestions.

Goal is simply:

  • Have a working engine switch (DONE basically)
  • Have effects switch with the engine properties, like switching from jet to rocket mode....
    • This is the part giving me my headacke....

Share this post


Link to post
Share on other sites

Again just do it like the rapier. If you need more than one mode then write your own MultiModeEngine, but no need to play with the EFFECT nodes. Just .Activate() one engine and .Shutdown() the others...

Share this post


Link to post
Share on other sites
7 minutes ago, sarbian said:

Again just do it like the rapier. If you need more than one mode then write your own MultiModeEngine, but no need to play with the EFFECT nodes. Just .Activate() one engine and .Shutdown() the others...

Are you thinking deriving a new module from the MultiNodeEngine by inheritance?

Share this post


Link to post
Share on other sites

I don't think there is anything in it that would be usefull to inherit. Just create a new PartModule that store references to n engine and switch them on/off depending on the active one.

Share this post


Link to post
Share on other sites
6 hours ago, sarbian said:

I don't think there is anything in it that would be usefull to inherit. Just create a new PartModule that store references to n engine and switch them on/off depending on the active one.

Ok... seems like a simple approach, I like that... however, I've not found a way to hide the activate engine right click button except when using the multinode engine, so that only the active one is available? I really only want the selected engine to be the one that stages and the only one the player interacts with.

Is there a way to hide these functions for an enginemodule?

Share this post


Link to post
Share on other sites
31 minutes ago, Warezcrawler said:

Ok... seems like a simple approach, I like that... however, I've not found a way to hide the activate engine right click button except when using the multinode engine, so that only the active one is available? I really only want the selected engine to be the one that stages and the only one the player interacts with.

Is there a way to hide these functions for an enginemodule?

sure, just set PartModule.Events["eventName"].guiActive to false

Share this post


Link to post
Share on other sites
9 minutes ago, stupid_chris said:

sure, just set PartModule.Events["eventName"].guiActive to false

I know this functionality, however how do i find the stock event to do this to? I've never come across how to change them. Only my own event..... 

Share this post


Link to post
Share on other sites

a engine.isEnabled = false should hopefully hide the button of the disabled engine. I can't test from work.

Share this post


Link to post
Share on other sites
1 hour ago, sarbian said:

a engine.isEnabled = false should hopefully hide the button of the disabled engine. I can't test from work.

ohh. that's what it's for.... I never knew that..... Thanks. Will try.

Share this post


Link to post
Share on other sites
1 hour ago, sarbian said:

a engine.isEnabled = false should hopefully hide the button of the disabled engine. I can't test from work.

Just did a quick test on flipping engine.isEnabled on and off.... I did not notice a difference when doing so. Debug Log showed the value going from false to true just fine, but no difference. I was looking specifically for the activate/shutdown button to disappeare and reappeare.... :blush:

Share this post


Link to post
Share on other sites
1 hour ago, sarbian said:

a engine.isEnabled = false should hopefully hide the button of the disabled engine. I can't test from work.

I got frustrated by this, so I did some searching around, and came up with this

                foreach (var engineEvent in moduleEngine.Events)
                {
                    Debug.Log("moduleEngine.Events" +
                        "\nGUIName: " + engineEvent.GUIName +
                        "\nid: " + engineEvent.id +
                        "\nname: " + engineEvent.name +
                        "\nactive: " + engineEvent.active +
                        "\nassigned: " + engineEvent.assigned +
                        "\ncategory: " + engineEvent.category +
                        "\nexternalToEVAOnly: " + engineEvent.externalToEVAOnly +
                        "\nguiActive: " + engineEvent.guiActive +
                        "\nguiActiveEditor: " + engineEvent.guiActiveEditor +
                        "\nguiActiveUncommand: " + engineEvent.guiActiveUncommand +
                        "\nguiActiveUnfocused: " + engineEvent.guiActiveUnfocused +
                        "\nguiIcon: " + engineEvent.guiIcon +
                        "\nunfocusedRange: " + engineEvent.unfocusedRange);
                }

this gave me this

GUIName: Activate Engine
id: -1591330541
name: Activate
active: False
assigned: False
category: Activate Engine
externalToEVAOnly: True
guiActive: True
guiActiveEditor: False
guiActiveUncommand: False
guiActiveUnfocused: False
guiIcon: Activate Engine
unfocusedRange: 2

GUIName: Shutdown Engine
id: -104699274
name: Shutdown
active: True
assigned: False
category: Shutdown Engine
externalToEVAOnly: True
guiActive: True
guiActiveEditor: False
guiActiveUncommand: False
guiActiveUnfocused: False
guiIcon: Shutdown Engine
unfocusedRange: 2

GUIName: Disable Staging
id: 1164541479
name: ToggleStaging
active: True
assigned: False
category: Disable Staging
externalToEVAOnly: True
guiActive: False
guiActiveEditor: False
guiActiveUncommand: False
guiActiveUnfocused: False
guiIcon: Disable Staging
unfocusedRange: 2

I think it should be able to change the events through

moduleEngine.Events["Activate"].guiActive

moduleEngine.Events["Shutdown"].guiActive

I will test this and post what I find.... Fingers crossed. 

Share this post


Link to post
Share on other sites
5 hours ago, Warezcrawler said:

I think it should be able to change the events through


moduleEngine.Events["Activate"].guiActive

moduleEngine.Events["Shutdown"].guiActive

I will test this and post what I find.... Fingers crossed. 

That's literally what I proposed to do, and yes, this will hide the right click menu buttons :P

Share this post


Link to post
Share on other sites
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.