Extracting mod data into files in the format i prefer

Extracting mod data into files in the format i prefer

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Extracting mod data into files in the format i prefer

Post by TradeMark »

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.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Extracting mod data into files in the format i prefer

Post by Tobi »

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.
Attachments
unit_sql_stats.lua
(10.18 KiB) Downloaded 15 times
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Re: Extracting mod data into files in the format i prefer

Post by TradeMark »

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
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Extracting mod data into files in the format i prefer

Post by Tobi »

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"
Yes, it uses the names as they are defined by LuaUnitDefs and LuaWeaponDefs.
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... >_>
No and yes.

Look in Spring's UnitDefHandler, in the functions where the values are read from the Lua tables.
Edit: does it also escape the \ and ' marks in the strings? like 'zo'mg\' should be 'zo\'mg\\'
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: 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
Footprintx, footprintz are those sizex, sizez variables you mentioned earlier. (There is a multiplication factor though, I forgot what exactly it is.)

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 ;-)
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Re: Extracting mod data into files in the format i prefer

Post by TradeMark »

Tobi wrote:
TradeMark wrote: Edit: does it also escape the \ and ' marks in the strings? like 'zo'mg\' should be 'zo\'mg\\'
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.
Is there any easy way to make it escape them like in PHP?
Tobi wrote: Footprintx, footprintz are those sizex, sizez variables you mentioned earlier. (There is a multiplication factor though, I forgot what exactly it is.)
Oh yeah, and the multiplication is 2, i checked. (actually xsize and zsize)
Tobi wrote: Yardmap is just not exported yet (harder then simple bools and floats after all).
Do you know where to read that yardmap? i could do the conversion myself...
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 ;-)
Also, do you know how to read those...?
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Re: Extracting mod data into files in the format i prefer

Post by TradeMark »

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
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Extracting mod data into files in the format i prefer

Post by Tobi »

TradeMark wrote:Is there any easy way to make it escape them like in PHP?
Yes, just look how it's done in PHP and code the appropriate string.gsub calls :-P
Do you know where to read that yardmap? i could do the conversion myself...
Hmm good point, seems it isn't even present in LuaUnitDefs.

No clue if you can read it from Lua, and if so, where.
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 ;-)
Also, do you know how to read those...?
Yes, when you request the member from the UnitDef (category, IIRC) or WeaponDef (onlyTargetCategory, badTargetCategory) you get a table with category names as strings.

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.)
<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
For many of that there are Lua callouts or other mechanisms to fetch them.

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...)
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Re: Extracting mod data into files in the format i prefer

Post by TradeMark »

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

Like this:

Code: Select all

category=CORE VTOL CTRL_V CTRL_P LEVEL2 WEAPON NOTSUB ALL;
though, im not sure do i even need that shit...
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Re: Extracting mod data into files in the format i prefer

Post by TradeMark »

I also made it much faster now, by removing spring.echo() stuff :P
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Re: Extracting mod data into files in the format i prefer

Post by TradeMark »

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

Return to “Lua Scripts”