Jump to content

[0.90] CrewFiles: persistence files for individual kerbals (16 dec 2014)


Ippo

Recommended Posts

CrewFiles

Now updated to KSP 0.90!

An API to provide persistent storage for individual kerbonauts.

DOWNLOAD

From kerbalstuff, the kommunity repository

Alternative download

Source code

Changelog:

- Fixed for 0.90

What is it?

CrewFiles is a tool intended for modders that allows your mod to store data separately for each kerbal. The system maintains a database of the known crew and allows you to associate ConfigNodes to each member that you can read and write at runtime.

Additionally, it provides a mechanism to generate or update data automatically.

This project is a spin-off of my main work on DangIt!, that will use this system to handle perks.

How to use

You will need to include the CrewFilesInterface assembly as a dependency of your mod.

In this class you will find a manager class that you can use to retrieve the current instance of the server, which you can use to access the file for each known crew member.

If redistributing this, make sure NOT to nest the CrewFiles folder within your mod.

Please distribute it alongside your folders, not inside it: there needs to be one only CrewFiles assembly! You can however safely distribute the CrewFilesInterface assembly.

Data generators

You can also have the data filled in and handled automatically for you by using classes defined with the appropriate interface.

You can create a Data Generator by defining a class that implements the ICrewDataGenerator: each time that the database is loaded / saved, the server will find your class and give it a chance to run and produce a ConfigNode to store.

See the included example generator that gives each kerbal his own tastes.

Edited by Ippo
0.90 update
Link to comment
Share on other sites

If this is what I think it is then it is exactlyvwhat I need to kick start my kerbal social / teamwork / achievements / rank ideas. I thank you. (such a shame I was going to give up kidding - oh well, the new job and house move will just have to wait)

Link to comment
Share on other sites

I might be missing something here... but where's the download for actual thing? I can only seem to download the source code.

Thanks, there had been an error during the upload and I hadn't noticed. It should be up now.

Again, sorry or the poor doc, I'll catch up over time but I'm kind of busy right now. If anyone wants to me to explain anything at all just ask.

Link to comment
Share on other sites

If this is what I think it is then it is exactlyvwhat I need to kick start my kerbal social / teamwork / achievements / rank ideas. I thank you. (such a shame I was going to give up kidding - oh well, the new job and house move will just have to wait)

I think it might be what you need, since you can basically associate whatever information you need to a kerbal :)

Also, checkout my example generators to see how you can have the system generate some data for you. I'm going to use it in my DangIt mod to give perks to kerbals: if a kerbal is found that has no perks yet, I generate some random perks for him, and then I can read them in flight to affect his ability to repair stuff :)

(That's the rationale for the generators system: I actually only needed a simpler system to store my perks, then realized that it might have been useful for other people and that's why I expanded the concept to be more general)

Link to comment
Share on other sites

Now I am back on my computer (rather than phone) I just wanted to say thanks for writing your crew files mod - it looks exactly like what I need, and will kick start a social/sanity mod that I have been wanting to start for a while. Together with Connected Living Space, I should have all the thinks I need (with the exception of working out what the in game consequences of having a good / bad team or having good/bad mental health.)

I am yet to get stuck into what you have produced, but I have a few thoughts:

1) how is your API defined? Is it likely to change in the future? Do you intend other mods that use it to access it using reflection (like toolbar), or a separate interfaces dll (like CLS) or just import your dll.

2) How do you intend to version your mod? This links to the issues of 1) above, but if we import your dll, and you up your version number, then we can get into dependency issues, but then on the other hand if your dll has changed perhaps a rebuild is necessary. Reflection can be used to interogate the version of the dll before using it, or having well defined versioned interfaces can also allow the implementation to be updated while keeping the api consistent.

3) How do you intend mods that use your api should distribute your mod? By including the dependent version of your mod, or by telling users to download it from somewhere?

4) Do you have a suggested snippet of code that we can use that checks your mod is installed an available and then accesses it?

5) Do you intend to create a config definition that other mods can make use of. So for example if it was well know and defined that every kerbal has a strength value, and a snappy-dressing value, then multiple mods could be written that both make use of those attributes. There is of course potential for different mods to interact badly in this way so it is no more a good idea that a bad one. What do you think?

6) Do you intend to create a common screen for displaying a kerbal's attributes? This could be useful, especially if more than one mod is trying to display the same data, and so essentially do the same thing.

Link to comment
Share on other sites

will kick start a social/sanity mod that I have been wanting to start for a while. Together with Connected Living Space, I should have all the thinks I need (with the exception of working out what the in game consequences of having a good / bad team or having good/bad mental health.)

Hell yeah, please do, I've been waiting for a such a thing for so long. If you need some help with research for this project, I volunteer to help; I can hardly code and can't model for my life, but I possess the seemingly rare trait of considering it an enjoyable leisure time activity to search for and read lengthy scientific papers on space-related stuff.

Link to comment
Share on other sites

Hell yeah, please do, I've been waiting for a such a thing for so long. If you need some help with research for this project, I volunteer to help; I can hardly code and can't model for my life, but I possess the seemingly rare trait of considering it an enjoyable leisure time activity to search for and read lengthy scientific papers on space-related stuff.

You are on! I am moving house and starting a new job soon, so ought to have little time for a new modding etc but this has tempted me to consider coding again! I have been gathering ideas etc on this thread. However I am also interested to find out what roverdude is up to as it sounds like he also has a project in the same area underway.

Link to comment
Share on other sites

I am yet to get stuck into what you have produced, but I have a few thoughts:

1) how is your API defined? Is it likely to change in the future? Do you intend other mods that use it to access it using reflection (like toolbar), or a separate interfaces dll (like CLS) or just import your dll.

I'm thinking you should link to the dll, putting a project reference in your IDE like you do for UnityEngine. That's the method I have been using with my project: also, CrewFiles uses reflection to find classes that implement ICrewDataGenerator, so I guess you should include it as a dependency anyway.

Basically, you have 2 access points to use the API:

1) Writing data generators: as poorly explained, they are run at the beginning and exit of each scene. Also, note the public RefreshDatabase method: it will also trigger a MidScene run of the generators. You can of course choose in which phases to run using the MustRun method.

2) During a scene, you can access the record of a kerbal with the GetKerbalFile or whatever it's called method: these two will most likely remain unchanged in the future, at most I could add stuff.

3) How do you intend mods that use your api should distribute your mod? By including the dependent version of your mod, or by telling users to download it from somewhere?

At the moment it's better if you don't include the dll in your download and point the users here mainly because, as I said, it doesn't check for multiple instances. I tried to do it but I got weird exceptions, I'm working on it.

4) Do you have a suggested snippet of code that we can use that checks your mod is installed an available and then accesses it?

I'm afraid not yet: I'll cook something up, but basically you just need to use reflection to check if the CrewFiles class is defined.

5) Do you intend to create a config definition that other mods can make use of. So for example if it was well know and defined that every kerbal has a strength value, and a snappy-dressing value, then multiple mods could be written that both make use of those attributes. There is of course potential for different mods to interact badly in this way so it is no more a good idea that a bad one. What do you think?

I hadn't thought of that yet: I'm sorry to be so vague but really it's just a generalized version of a system I needed inside another mod, also I never made a library before, so I'm not really quite sure how I should approach this: what do you think?

6) Do you intend to create a common screen for displaying a kerbal's attributes? This could be useful, especially if more than one mod is trying to display the same data, and so essentially do the same thing.

I had thought about it, but decided to keep it without gui for the moment. Maybe in a second release?

Link to comment
Share on other sites

Another question - any example on how to consume this? Meaning, I see the demo data in there and the config file - is there any abstraction/syntactic sugar over reading the config nodes?

Afraid not, not yet at least: in DangIt I just read in the ConfigNode for the kerbal I'm considering and checking if it has my perk node.

Link to comment
Share on other sites

I never really designed a library before: I'm not quite sure how to approach versioning, what API to expose, or anything else. So suggestions are not only welcome - I'm begging for them.

I openly encourage anyone with more skills than me (so basically anyone) to suggest changes or even contribute to the GIT repo themselves: if anyone even felt like taking charge of the whole project I seriously wouldn't mind.

Link to comment
Share on other sites

Uhm... it's not like anybody cares, but you're distributing Assembly-CSharp.dll and UnityEngine.dll in bin/Debug, and some lawyers might use that to extort money.

I suggest adding the entire bin and obj dirs to the .gitignore file.

Edited by mic_e
Link to comment
Share on other sites

I am not sure exactly what you mean by "separate config file", however I am tempted to disagree with you. I think it is better to have all the information about the state of a saved game in the single save file. I know for example that I get frustrated when I use quickload and find that all my kerbals alarm clock alarms are the once from before the quick load, so presumably KAC save that info separately to the save file. I think it would be better if it was in the save file.

Link to comment
Share on other sites

Uhm... it's not like anybody cares, but you're distributing Assembly-CSharp.dll and UnityEngine.dll in bin/Debug, and some lawyers might use that to extort money.

I suggest adding the entire bin and obj dirs to the .gitignore file.

Thanks, I missed it. I never use git, I use SVN locally, so I never really take a loot at what git is doing when it uploads :)

One suggestion/consideration - plug this into a Scenario node vs. a separate config file (ala Kethane, TAC, etc.)
I am not sure exactly what you mean by "separate config file", however I am tempted to disagree with you. I think it is better to have all the information about the state of a saved game in the single save file. I know for example that I get frustrated when I use quickload and find that all my kerbals alarm clock alarms are the once from before the quick load, so presumably KAC save that info separately to the save file. I think it would be better if it was in the save file.

Well, roverdude is actually right: right now it's a separate file in the save folder, it's not in the persistent file.

That's because right now I don't feel comfortable touching the main persistent file: just consider that this morning I re-downloaded the version I put on github (the same one I had tested before posting it) and now it doesn't work for some reason.

Link to comment
Share on other sites

I am not sure exactly what you mean by "separate config file", however I am tempted to disagree with you. I think it is better to have all the information about the state of a saved game in the single save file. I know for example that I get frustrated when I use quickload and find that all my kerbals alarm clock alarms are the once from before the quick load, so presumably KAC save that info separately to the save file. I think it would be better if it was in the save file.

We're in violent agreement ;) Right now, CrewStats is in it's own config file in the save folder, not built into the persistence file. My suggestion is (much as other mods do) to embed this in the persistence file vs. having it broken out in it's own file as it is currently.

Link to comment
Share on other sites

Can't you just implement OnSave and OnLoad in your scenario class and receive / pass some ConfigNodes and leave all the serialization to KSP. It does not sound too risky. The worse case scenario is you get an exception in your own code and bomb out.

Link to comment
Share on other sites

You are absolutely right, but at the moment it's very handy for me to have a separate file that I can mess with, especially in the wake of the strange bug I'm having today (no version of the code, no matter which one, saves the database to file. even the one that worked when I uploaded it).

Basically at the moment it's very very handy for me to be able to delete, modify or recreate the file without opening the persistent. I will move it in there as soon as this #!@@=! thing finally starts doing what I want it to.

Edited by Ippo
typo
Link to comment
Share on other sites

...looking at the code in hopes of stealthily sending a pull request with an RPM variable handler built in, I noticed something.

Suppose one had a Jebediah Kerman and a Jebediah Kerballer, latter being created with the use of Crew Manifest, which allows one to do it. It would be impossible for Jebediah Kerballer to ever have his own crew file.

Link to comment
Share on other sites

...looking at the code in hopes of stealthily sending a pull request with an RPM variable handler built in, I noticed something.

Suppose one had a Jebediah Kerman and a Jebediah Kerballer, latter being created with the use of Crew Manifest, which allows one to do it. It would be impossible for Jebediah Kerballer to ever have his own crew file.

... I didn't even know that it was possible to have a different last name. Thank you :)

Link to comment
Share on other sites

Hey, can I have a quick advice?

I thought that it might be useful to store a node with information about the mod itself. Aside from the version number of the DLL, what might be useful in that node?

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...