Page 1 of 1

baking unitdefs_post

Posted: 02 May 2015, 11:35
by Silentwings
I wrote basic functionality to bake unitdefs post into the individual unitdef files. Probably it has been done before, but I couldn't find it. You can find it attached to this post.

It works by saving the entire unitdef table into ud.customParams as a string, and then unpacking it and writing to file from LuaUI, because there is no io access from unitdefs_post. It doesn't handle OO unitdefs (in the style of e.g. S44), but it wouldn't be hard to modify it to do so.

update: BA 8.19+ contains a more complicated version of this system, which also has the ability to bake weapondefs, allowing for unitdef files which contain weapondefs.

Instructions:

(1) Put unitdefs_post_save_to_customparams.lua in gamedata
(2) Put unitdefs_write.lua in widgets
(3) Add VFS.Include("gamedata/unitdefs_post_save_to_customparams.lua") to unitdefs_post, at the point where you want to bake
(4) Load Spring, then load the widget
(5) Look in the spring folder, unitdefs should all be written to file, cut/paste these over the original files.
(6) Clean out the stuff you just baked into unitdefs from your unitdefs_post.lua.

Notes:
! Make sure your unitdefs don't contain lua keywords as table keys (remove them with unitdefs_post if so)
! Make sure you don't bake in any modoptions that alter unitdefs
! It will round all numbers to 5dp and then remove trailing 0s after the decimal point, to avoid e.g. 0==0.000000234876
! It will convert all string keys to lower case
! It won't bake weapondefs_post (make the changes in unitdefs_post and bake that instead)