JPLRepo / DeepFreeze

http://forum.kerbalspaceprogram.com/threads/124720
Other
12 stars 15 forks source link

API FrozenKerbals lists not working #71

Closed GarwelGarwel closed 7 years ago

GarwelGarwel commented 7 years ago

It looks like you can't access DF's FrozenKerbals list through the DFWrapper class.

When using DFWrapper.DeepFreezeAPI.FrozenKerbals (the dictionary), it always has 0 members. Referring DFWrapper.DeepFreezeAPI.FrozenKerbalsList causes an exception like this: InvalidCastException: Cannot cast from source type to destination type. at DeepFreezeWrapper.DFWrapper+DFAPI.get_FrozenKerbalsList () [0x00000] in <filename unknown>:0

GarwelGarwel commented 7 years ago

I can only assume that the reason is that FrozenKerbalsListMethod.Invoke(actualDFAPI, null) in FrozenKerbalsList property doesn't return List<KeyValuePair<string, KerbalInfo>>. But I have no idea why.

JPLRepo commented 7 years ago

I know of several mods that do. Including two of my own. Can you supply a link to your source so I can take a look?

GarwelGarwel commented 7 years ago

This is what I use (the code is here in IsKerbalFrozen function):

if (!DFWrapper.APIReady) return false;
foreach (KeyValuePair<string, DFWrapper.KerbalInfo> el in DFWrapper.DeepFreezeAPI.FrozenKerbalsList)
if (el.Key == name) return true;

Whether I use FrozenKerbals or FrozenKerbalsList, it doesn't work. The former returns an empty Vocabulary, the latter returns null.

JPLRepo commented 7 years ago

Where do you initialize the Reflection wrapper class? It's most likely a timing issue. Have you check that it initializes correctly?

GarwelGarwel commented 7 years ago

I do it in a method called by Start(), FixedUpdate() and OnSave(). The initializer works ok and DFWrapper.APIReady() then returns true, but the frozen kerbals collections are either empty or null.

I will try it all again when 1.3 comes out (and DF is updated).

JPLRepo commented 7 years ago

I don't think that will change anything to be honest. There are several mods using it. Wondering if you are having a timing issue or similar. Might be worth looking at one of those to compare. I doubt anything in 1.3 will change it. You could use my GameEvent I created as well. https://github.com/JPLRepo/DeepFreeze/blob/master/Source/APIs/DFGameEvents.cs

and refer to here on how it works: http://forum.kerbalspaceprogram.com/index.php?/topic/153112-ksp-122-gameevents-extension/

GarwelGarwel commented 7 years ago

Thanks, will try.

JPLRepo commented 7 years ago

I know of two other mods that integrate with DF, and they are working fine. Closing.