How?
I heard someone made it possible, but nobody really gave any code & working example how to do it. (i dont know lua at all).
I would like to add lua based mods into Modit but its impossible without this kind of script that can write all the needed files in the format i prefer.
Extracting mod data into files in the format i prefer
Moderator: Moderators
Re: Extracting mod data into files in the format i prefer
Example attached.
It's a widget which dumps a lot (not all, in particular damages and categories are still missing) of unitDef and weaponDef data into files, which can be imported in PostgreSQL.
Should be easy to change to other SQL dialects, or even to make it dump in CSV or whatever.
It's a widget which dumps a lot (not all, in particular damages and categories are still missing) of unitDef and weaponDef data into files, which can be imported in PostgreSQL.
Should be easy to change to other SQL dialects, or even to make it dump in CSV or whatever.
- Attachments
-
- unit_sql_stats.lua
- (10.18 KiB) Downloaded 15 times
Re: Extracting mod data into files in the format i prefer
thanks!
but doesnt that translate the unit fbi variables into Spring internal variables? like, i cant find anywhere footprintx etc, or "foot" anywhere, only sizex etc.
also the "unitname" seems to be just "name"
etc...
do you have the translated table somewhere so people would actually know which variable is which?
or do i need to dig the spring source code again... >_>
Edit: does it also escape the \ and ' marks in the strings? like 'zo'mg\' should be 'zo\'mg\\'
Edit: seems like it doesnt support "yardmap", "footprintx", "footprintz" and "category" variables at all o.O, idk about "category", is it even used by spring anymore? but footprintx and z is used... and yardmap
but doesnt that translate the unit fbi variables into Spring internal variables? like, i cant find anywhere footprintx etc, or "foot" anywhere, only sizex etc.
also the "unitname" seems to be just "name"
etc...
do you have the translated table somewhere so people would actually know which variable is which?
or do i need to dig the spring source code again... >_>
Edit: does it also escape the \ and ' marks in the strings? like 'zo'mg\' should be 'zo\'mg\\'
Edit: seems like it doesnt support "yardmap", "footprintx", "footprintz" and "category" variables at all o.O, idk about "category", is it even used by spring anymore? but footprintx and z is used... and yardmap
Re: Extracting mod data into files in the format i prefer
Yes, it uses the names as they are defined by LuaUnitDefs and LuaWeaponDefs.TradeMark wrote:thanks!
but doesnt that translate the unit fbi variables into Spring internal variables? like, i cant find anywhere footprintx etc, or "foot" anywhere, only sizex etc.
also the "unitname" seems to be just "name"
No and yes.do you have the translated table somewhere so people would actually know which variable is which?
or do i need to dig the spring source code again... >_>
Look in Spring's UnitDefHandler, in the functions where the values are read from the Lua tables.
It escapes every one single quote to two single quotes. 'zo'mg\' becomes 'zo''mg\'. IIRC this is the correct escaping for PostgreSQL, for other SQL dialects this may be different and may require change. The escaping happens in function FilterFieldValue, line 48.Edit: does it also escape the \ and ' marks in the strings? like 'zo'mg\' should be 'zo\'mg\\'
Footprintx, footprintz are those sizex, sizez variables you mentioned earlier. (There is a multiplication factor though, I forgot what exactly it is.)Edit: seems like it doesnt support "yardmap", "footprintx", "footprintz" and "category" variables at all o.O, idk about "category", is it even used by spring anymore? but footprintx and z is used... and yardmap
Yardmap is just not exported yet (harder then simple bools and floats after all).
Categories are definitely still used. For stuff like which weapons can target which units. Also harder to export then simple bools and floats so didn't implement it yet

Re: Extracting mod data into files in the format i prefer
Is there any easy way to make it escape them like in PHP?Tobi wrote:It escapes every one single quote to two single quotes. 'zo'mg\' becomes 'zo''mg\'. IIRC this is the correct escaping for PostgreSQL, for other SQL dialects this may be different and may require change. The escaping happens in function FilterFieldValue, line 48.TradeMark wrote: Edit: does it also escape the \ and ' marks in the strings? like 'zo'mg\' should be 'zo\'mg\\'
Oh yeah, and the multiplication is 2, i checked. (actually xsize and zsize)Tobi wrote: Footprintx, footprintz are those sizex, sizez variables you mentioned earlier. (There is a multiplication factor though, I forgot what exactly it is.)
Do you know where to read that yardmap? i could do the conversion myself...Tobi wrote: Yardmap is just not exported yet (harder then simple bools and floats after all).
Also, do you know how to read those...?Tobi wrote: Categories are definitely still used. For stuff like which weapons can target which units. Also harder to export then simple bools and floats so didn't implement it yet
Re: Extracting mod data into files in the format i prefer
I would need corpses (mod features) list too, and the sidedata sides list, like ARM, CORE, etc... how many sides and their sides names, and those sides commander unitnames, so i know which is the starting unit for each side...
Also moveinfo.tdf, armors.txt, and sounds list
Also moveinfo.tdf, armors.txt, and sounds list
Re: Extracting mod data into files in the format i prefer
Yes, just look how it's done in PHP and code the appropriate string.gsub callsTradeMark wrote:Is there any easy way to make it escape them like in PHP?

Hmm good point, seems it isn't even present in LuaUnitDefs.Do you know where to read that yardmap? i could do the conversion myself...
No clue if you can read it from Lua, and if so, where.
Yes, when you request the member from the UnitDef (category, IIRC) or WeaponDef (onlyTargetCategory, badTargetCategory) you get a table with category names as strings.Also, do you know how to read those...?Tobi wrote: Categories are definitely still used. For stuff like which weapons can target which units. Also harder to export then simple bools and floats so didn't implement it yet
The issue isn't how to read those, but what the easiest way is to store them. (it's a many [units, weapons] to many [categories] binding after all, so the database structure requires some thought.)
For many of that there are Lua callouts or other mechanisms to fetch them.<em>TradeMark</em> wrote:I would need corpses (mod features) list too, and the sidedata sides list, like ARM, CORE, etc... how many sides and their sides names, and those sides commander unitnames, so i know which is the starting unit for each side...
Also moveinfo.tdf
and armors.txt
So feel free to extend the widget

I just posted it here as example or stepping stone for someone to work on it; I don't have it in active development currently. (and don't have plans to start on it either...)
Re: Extracting mod data into files in the format i prefer
im not using database so i dont really care whats the format is, i just want it in the same format as its in the units fbi files atm.Tobi wrote:The issue isn't how to read those, but what the easiest way is to store them. (it's a many [units, weapons] to many [categories] binding after all, so the database structure requires some thought.)
Like this:
Code: Select all
category=CORE VTOL CTRL_V CTRL_P LEVEL2 WEAPON NOTSUB ALL;
Re: Extracting mod data into files in the format i prefer
I also made it much faster now, by removing spring.echo() stuff :P
Re: Extracting mod data into files in the format i prefer
Now, is it possible to run this lua script without loading the map, and by using command line parameters like: spring.exe -mod "I:/spring/mods/ba695.sd7"
would be nice..
would be nice..