DiEvAl Posted July 9, 2013 Share Posted July 9, 2013 How do I load and parse an XML file from my PluginData folder? I tried to use System.Xml.Linq.XDocument, but plugins are not allowed to use System.Xml namespace. Quote Link to comment Share on other sites More sharing options...
TriggerAu Posted July 9, 2013 Share Posted July 9, 2013 How do I load and parse an XML file from my PluginData folder? I tried to use System.Xml.Linq.XDocument, but plugins are not allowed to use System.Xml namespace.You have to do it with your own code i'm afraid. You can use KSP.IO.File.ReadAllText (I think thats it) to get the contents as a string, but you have to parse in in code - system.xml and system.io are blocked. Quote Link to comment Share on other sites More sharing options...
MrFailSauce Posted July 10, 2013 Share Posted July 10, 2013 http://forum.kerbalspaceprogram.com/showthread.php/7529-Plugin-Posting-Rules-And-Official-Documentation?p=156430&viewfull=1#post156430That was exactly the link that I was looking for. Problem solved. Now I just need to figure out how not to suck at 3d modeling.... Quote Link to comment Share on other sites More sharing options...
DiEvAl Posted July 10, 2013 Share Posted July 10, 2013 I found a workaround.Basically I wrote a program that parses the xml file and outputs 100+ C# lines like this:elements.Add(new Element(1, "H", "Hydrogen", 1, 1, 1.008, 1));Every time I edit my xml file, I run this program and copypaste the output into my source code.It's ugly (and doesn't allow players to edit their periodic table), but will work for now.Are there any plans for adding KSP.Xml? Quote Link to comment Share on other sites More sharing options...
BlackNecro Posted July 11, 2013 Share Posted July 11, 2013 Anyone got a clue how to disable the resolution rescaling on a per texture basis? I'm working with button textures in the size range of 37x28. I have to enable texture resolution halving due to horrible memory handling regarding textures in order to not kill the 32 bit memory mark and thus the result on the GUI looks horrible at best.Any suggestion is welcome Quote Link to comment Share on other sites More sharing options...
TriggerAu Posted July 11, 2013 Share Posted July 11, 2013 Anyone got a clue how to disable the resolution rescaling on a per texture basis? I'm working with button textures in the size range of 37x28. I have to enable texture resolution halving due to horrible memory handling regarding textures in order to not kill the 32 bit memory mark and thus the result on the GUI looks horrible at best.Any suggestion is welcome For the buttons in my project I couldn't find a way to do this with the new GameDatabase Loader (ie. GameDatabase.Instance.GetTexture routine). I reverted to using the older style process using Texture2D.LoadImage(KSP.IO.File.ReadAllBytes(<FileName>) and they stay fixed at full res disregarding the setting.I'm hoping as we get closer to a final game some more details on the APi will provide a way to do this. Quote Link to comment Share on other sites More sharing options...
BlackNecro Posted July 11, 2013 Share Posted July 11, 2013 Ah you got my hopes up. Tried it that way and it still got scaled down.So off the List now are:Texture2D.LoadImageWWW.LoadImageIntoTextureGameDatabase.GetTexture Quote Link to comment Share on other sites More sharing options...
TriggerAu Posted July 12, 2013 Share Posted July 12, 2013 Ah you got my hopes up. Tried it that way and it still got scaled down.So off the List now are:Texture2D.LoadImageWWW.LoadImageIntoTextureGameDatabase.GetTextureI'm using Texture2D.LoadImage in the KerbalAlarmClock and it is working at any texture setting all the way down to eight res, keeping the buttons at normal resolution. Just tested it again, latest version in 0.20.2If you want to look at the source its linked from my signature. The files are png's and they are stored in the plugindata folder and loaded via a binary array. Its definately working Quote Link to comment Share on other sites More sharing options...
MrFailSauce Posted July 12, 2013 Share Posted July 12, 2013 Is there a list I can access in the KSP API that contains all the CelestialBodies? Or a method I can use to iterate over all the existing CelestialBodies?Thanks! Quote Link to comment Share on other sites More sharing options...
BlackNecro Posted July 12, 2013 Share Posted July 12, 2013 If you want to look at the source its linked from my signature. The files are png's and they are stored in the plugindata folder and loaded via a binary array. Its definately workingNow that helped much more. I created the Texture2D with just height and width, adding the TextureFormat and probably more important setting mipmapping to false and that solved it.Apartly the engine just uses lower order mipmaps to provide the low resolution textures. Makes sense as you already got the proper downscaling functionality there. Quote Link to comment Share on other sites More sharing options...
EndlessWaves Posted July 12, 2013 Share Posted July 12, 2013 Is there a list I can access in the KSP API that contains all the CelestialBodies? Or a method I can use to iterate over all the existing CelestialBodies?Thanks!FlightGlobals.Bodies Quote Link to comment Share on other sites More sharing options...
nyrath Posted July 13, 2013 Share Posted July 13, 2013 Stupid newbie here with yet another stupid newbie questions.Say you have two vessels that are docked. According to the old docs, the two vessels merge into one.Is there any way to tell which component parts used to belong to vessel Alfa and which component parts used to belong to vessel Bravo?I sort of had an idea that one could somehow identify the original root nodes and work it out by walking the trees. But I am unsure how to identify the original roots.What I am trying to do is deal with the fact that Orion nuclear pulse units do not work well with KSP's resource flow system. I want to allow two Orion ships to be able to dock and let one re-fuel the other. To do this I need to identify which ship each nuclear magazine part belongs to. Quote Link to comment Share on other sites More sharing options...
ummwut Posted July 13, 2013 Share Posted July 13, 2013 I thought the pellets were treated as generic resources like liquid fuel? Transferring pellets should be as easy as a right-click & alt-right-click.What you wanna do is make a resources.cfg file in a folder titled Resources under the Nyrath folder. Put this in the file:RESOURCE_DEFINITION{ name = NukePellets density = however dense these things should be flowMode = ALL_VESSEL or STACK_PRIORITY_SEARCH transfer = PUMP}The more you treat your resources like Squad's resources, the nicer they'll behave. Quote Link to comment Share on other sites More sharing options...
nyrath Posted July 13, 2013 Share Posted July 13, 2013 (edited) I thought the pellets were treated as generic resources like liquid fuel? Transferring pellets should be as easy as a right-click & alt-right-click.Alas, generic resources are problematic.First off I'd need a different resource for every bomb type (seven at last count), and a way to create a new resource type for any new custom bomb type created by a user working with my plug in. Each bomb type has a unique specific impulse and thrust value.Secondly, bombs are discrete, not a fluid like liquid fuel. If each 5 kiloton bomb has a mass of 1.152 tonnes, you have to transfer in units of 1.152 tonnes, that is, as a whole number of bombs. You cannot transfer 0.74 bombs.Thirdly the bombs do not entirely fill the volume of the magazine (aka "fuel tank"). You cannot discover the maximum bomb capacity of a magazine by taking the magazine volume and dividing by bomb density.Resources were designed for fluids. Edited July 13, 2013 by nyrath Quote Link to comment Share on other sites More sharing options...
ummwut Posted July 13, 2013 Share Posted July 13, 2013 I was thinking you could handle the pellets purely as integers, but you're right, this won't work as a generic resource. The only other thing I can think of is including such a capability with a plugin, such that "transfer pellets" would come up as an option on a right-click menu. Otherwise, you'll have to treat it as a liquid fuel if you want the alt+right-click capabilities.I think, for realism and functionality, you may want the pellet containers to dock directly with another container of the same pellet type (find the other compatible tank by iterating through neighbor parts), and transferring pellets from the right-click menu.I don't think adding a certain type of docking node on the side of the container as a "bomb transfer plug" would be too difficult, right?I'm out of ideas. Quote Link to comment Share on other sites More sharing options...
nyrath Posted July 13, 2013 Share Posted July 13, 2013 I don't think adding a certain type of docking node on the side of the container as a "bomb transfer plug" would be too difficult, right?I'm out of ideas.Well, adding the docking node is not too hard. The problem is that a fully loaded Orion can have around 60 magazines, each of which have to be loaded.For unrelated reasons, I've already written a "magazine manager" that keeps track of all the magazines currently in the same vessel part tree as the Orion engine (I needed it to evenly expend the bombs while the engine is running. Since an individual magazine can be several tens of tons, drawing from a single magazine will quickly move the vessel's center of gravity off the thrust axis).I've added a right-click pop up dialog for the engine to use as a user interface to transfer bombs from one docked ship to another.The only remaining piece of the puzzle I need is a way to tell which "ship" each magazine "belongs" to. I'm currently looking into parsing the parts tree and assuming that branches that start with pairs of ModuleDockingNode are separate ships.Thank you for your help. Quote Link to comment Share on other sites More sharing options...
ummwut Posted July 13, 2013 Share Posted July 13, 2013 You're welcome, although I doubt I contributed much. One thing I should mention, take advantage of the UID every part has, so you can organize or even build custom part trees having to do with your engines and magazines.Good luck! I look forward to future installments of your mod! Quote Link to comment Share on other sites More sharing options...
nyrath Posted July 14, 2013 Share Posted July 14, 2013 You're welcome, although I doubt I contributed much. One thing I should mention, take advantage of the UID every part has, so you can organize or even build custom part trees having to do with your engines and magazines.thanks! I was already caching the UIDs for an unrelated reason, but it is good to know. I'm currently taking my existing magazine manager code and making all the dictionaries into lists of dictionaries, with each list entry representing a docked vessel. So I can try several strategies for sorting by vessel, but use the same data structures. Quote Link to comment Share on other sites More sharing options...
EndlessWaves Posted July 14, 2013 Share Posted July 14, 2013 Say you have two vessels that are docked. According to the old docs, the two vessels merge into one.Is there any way to tell which component parts used to belong to vessel Alfa and which component parts used to belong to vessel Bravo?I do seem to remember the devs mentioning a stub vessel type class that retained original vessel information (name etc.) when docked. Unfortunately I don't remember where it was stored. If you've looked through the vessel and part classes for references then you could try grabbing the components on the docking nodes or current root part and see if there is anything there that looks likely:foreach(Component aComponent in aPart.gameObject.GetComponents<Component>()){ if(aComponent.GetType().ToString() != "UnityEngine.Transform") print(aComponent.GetType());} Quote Link to comment Share on other sites More sharing options...
nyrath Posted July 15, 2013 Share Posted July 15, 2013 I do seem to remember the devs mentioning a stub vessel type class that retained original vessel information (name etc.) when docked. Unfortunately I don't remember where it was stored. If you've looked through the vessel and part classes for references then you could try grabbing the components on the docking nodes or current root part and see if there is anything there that looks likely:foreach(Component aComponent in aPart.gameObject.GetComponents<Component>()){ if(aComponent.GetType().ToString() != "UnityEngine.Transform") print(aComponent.GetType());}Thanks! I'll try that. Quote Link to comment Share on other sites More sharing options...
Guest Posted July 17, 2013 Share Posted July 17, 2013 (edited) Hello all, I'm interested in joining the crowd here, personal time permitting. I'm not new to development; I've got three years of open-source development experience and another four years of professional programming experience with a multitude of languages (that doesn't mean I remember them all!), but I know next to nothing about game/mod development aside from some Tetris I wrote a few years back (and I apparently forgot that I wrote a Minecraft mod. Time flies...). I'm about to ask some seriously n00b questions here, I suspect, so please bear with me.E: Found the Anatid API docs, it's helping a lot.E2: So I've actually answered a lot of my own questions the normal way, inspecting other people's code. One still remains, if you don't mind helping:Is there a way to tell when the mouse is hovering over an orbit and where that point is on the orbit? Specifically, I want the longitude of the point on the orbit. This is easy to get current from the active vessel, but I want future longitudes.It looks like I'll want the universal time of the point in the orbit I am hovering over. I can then get the position on the orbit and convert it to whatever measurement I need. The easiest way would be to get this from the most current maneuver node, but is there any way to get it from current input? The game puts a small "bulb" over the orbit where I'm hovering, is there any way to access that?Thanks in advance! Edited July 17, 2013 by regex Quote Link to comment Share on other sites More sharing options...
Gary_P Posted July 19, 2013 Share Posted July 19, 2013 Is there a debug screen that I can write to in KSP, like the one in Unity? I tried Alt-F2 and it brought up a screen but then my window with my button goes away.I want to test if my button click is working correctly. Quote Link to comment Share on other sites More sharing options...
Echo 8 ÉRÀ Posted July 19, 2013 Share Posted July 19, 2013 The stuff in the debug window gets printed out to %KSPFolder%\KSP.log as well, so in the event you can't work out how to keep the log window and your window open at the same time, there's always the option of checking the log file.The PDebug class has a bunch of static methods which print to the log. Quote Link to comment Share on other sites More sharing options...
Iannic-ann-od Posted July 19, 2013 Share Posted July 19, 2013 Is there a debug screen that I can write to in KSP, like the one in Unity? I tried Alt-F2 and it brought up a screen but then my window with my button goes away.I want to test if my button click is working correctly.Hit F2 again to unhide all the GUI stuff. Using Alt-F2 seems to count as both Alt-F2 and F2.Personally, I like the debug window in Alt-F12. Quote Link to comment Share on other sites More sharing options...
EndlessWaves Posted July 20, 2013 Share Posted July 20, 2013 The stuff in the debug window gets printed out to %KSPFolder%\KSP.log as well, KSP_Data/output_log.txt tends to be more comprehensive. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.