Jump to content

A different tank question: Is PartResource.flowMode broken?


Recommended Posts

I've also been playing with a failure mod and I am trying to 'lock' a resource (think pump failure).   PartResource.flowMode looks like it does this since you can set the resource to FlowMode.None and the resource is still there but can't be accessed. 

However this does not stop other parts from seeing the resource for transfers.  Other tanks can fill or drain infinitely via transfer without changing the failed resource.   I haven't found a good way to stop this from happening. 

Things I've tried:

  • Use PartResource.flowState (the start/stop button in the paw).  This works for using the resource (i.e. it can't be used) although it still allows resource transfers, just without the magic infinite resource.  I also haven't found a good way to lock the stop button so it can't just be turned on again.  I think I can hide button but haven't gone any further.
  • Use PartResource.isVisible.  This works but it of course removes the resource from the PAW.   I do put a failure message in the PAW, but this is not ideal.

Things I think might work:

  • Swap the resource for a dummy resource.  I'm not sure how to do this and I don't think it will play well with other mods.
  • Disable crossfeed.  I don't know if this can be done with a single resource though and I have no idea how to do this either.
  • Remove the resource while broken and add it back in after it's repaired.  I assume I can create a hidden 'Mass' resource via MM and add or remove the right amount of mass to balance the removed resource, but this seems clunky.

Right now I'm just locking and hiding the resource.  Something like:

resource.flowMode = PartResource.FlowMode.None;
resource.isVisible = false;

Does anyone know if there's something I'm missing about this 'broken' resource transfer behavior or have any better ideas?

Link to comment
Share on other sites

  • 2 weeks later...

There is a PartResource.hideFlow bool. If set to true, it will hide the button that allow the user from toggling PartResource.flowState.
So setting the following should completely lock the resource :

resource.flowMode = PartResource.FlowMode.None;
resource.flowState = false;
resource.hideFlow = true;

Edit : you will likely run into the issue that when setting hideFlow, if the PAW is already opened (or has been opened previously), the flow toggle button will still stay visible or hidden.
You will likely need to manually trigger a PAW rebuild when your "resource locking" event is triggered :

if (resource.part.PartActionWindow != null)
  resource.part.PartActionWindow.displayDirty = true;
Edited by Gotmachine
Link to comment
Share on other sites

6 hours ago, Gotmachine said:

There is a PartResource.hideFlow bool. If set to true, it will hide the button that allow the user from toggling PartResource.flowState.
So setting the following should completely lock the resource :

resource.flowMode = PartResource.FlowMode.None;
resource.flowState = false;
resource.hideFlow = true;

Edit : you will likely run into the issue that when setting hideFlow, if the PAW is already opened (or has been opened previously), the flow toggle button will still stay visible or hidden.
You will likely need to manually trigger a PAW rebuild when your "resource locking" event is triggered :

if (resource.part.PartActionWindow != null)
  resource.part.PartActionWindow.displayDirty = true;

I was never able to stop PartResource.FlowMode.None from allowing magical resource transfers.  Other parts seem to still see it as a source/destination for transfers regardless of flowState or flowMode.

I finally just went with just flowState = false and hideFlow = true.  This still allows manual resource transfers, but since the mod is really intended as an 'in flight' failure mod, it seems like a reasonable compromise.  Hey, if players can manage to transfer fuel while in flight (or have a craft that can survive a tank pressurization failure and transfer it later) good!

Yeah, I ran into the PAW update problem.  I went with MonoUtilities.RefreshPartContextWindow(part); but this looks like a better option. 

I'm still very much at the 'monkey pounding the keyboard until something good happens' stage here so I really appreciate your help.

Link to comment
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.

×
×
  • Create New...