Page 1 of 1
Is it possible to export and import information in the same format as the plans?
Posted: Sun Feb 06, 2022 4:28 am
by yaim904
I just want to know if there is a way to access the functions that are used to import and export the information, such as the plans or the map.
I want to use those functions to get information from my mod.
If not possible, no problem, I'll build my own function, but I hope they can be used.
Re: Is it possible to export and import information in the same format as the plans?
Posted: Fri Mar 04, 2022 12:02 pm
by yaim904
I suppose not
Re: Is it possible to export and import information in the same format as the plans?
Posted: Fri Mar 04, 2022 9:22 pm
by robot256
Generic JSON import/export are available:
https://lua-api.factorio.com/latest/Lua ... n_to_table
And mods can import/export blueprints into items (not the Library):
https://lua-api.factorio.com/latest/Lua ... port_stack
Re: Is it possible to export and import information in the same format as the plans?
Posted: Sat Mar 05, 2022 3:58 pm
by yaim904
I appreciate the help, but I don't understand how to use these functions
export_stack( ) and
import_stack( data ); and if I can use it for this data:
Code: Select all
[ "JSON " ] = '{"zzYAIM":{"maximum-stack-size":{"Players":{"yaim904":{}}}}}'
[ "LUA" ] = {
[ 'zzYAIM' ] = {
[ 'maximum-stack-size' ] = {
[ 'Players' ] = {
[ 'yaim904' ] = { },
},
},
},
}
If you can, please show me some simple code to give me an idea of what I should do.
I just want to use the encryption they use.
Re: Is it possible to export and import information in the same format as the plans?
Posted: Sat Mar 05, 2022 4:52 pm
by robot256
Export_stack function gives an encoded JSON string. Json_to_table turns that JSON strings into a lua table you can print (with serpent.block formatting) and edit. Then re-encode the new table with table_to_json and put it back into an item with import_stack. The table/string data includes whether it is a blueprint, upgrade or deconatruction planner. At least I think this is how it works.
Re: Is it possible to export and import information in the same format as the plans?
Posted: Wed Mar 09, 2022 2:36 pm
by yaim904
I still don't understand, but thank you for responding.
Re: Is it possible to export and import information in the same format as the plans?
Posted: Wed Mar 09, 2022 3:19 pm
by robot256
Maybe you could explain in more detail what you want to accomplish? I just saw the word "map" and that is unrelated to the blueprint API, so I'm not sure what you want after all.
Re: Is it possible to export and import information in the same format as the plans?
Posted: Thu Mar 10, 2022 11:42 pm
by yaim904
I have this data, I want to use the export function that Factorio has.
Code: Select all
[ "JSON " ] = '{"zzYAIM":{"maximum-stack-size":{"Players":{"yaim904":{}}}}}'
[ "LUA" ] = {
[ 'zzYAIM' ] = {
[ 'maximum-stack-size' ] = {
[ 'Players' ] = {
[ 'yaim904' ] = { },
},
},
},
}
An example of the function is: How to export the blueprints or the map configuration.
Code: Select all
0eNrcvWtyW0mSrTsX/mxL1N3xjii7tyfSViaDKEiCFR8ykso+aW05gDOQM7EzkgtQKWCL2L5jfYF6WOpPVydFrojt4e7xWrH8f27e333dfXnaP7zc/PV/bva3jw/PN3/9r/+5ed5/etjeHX/28tuX3c1fb/Yvu/ubX24etvfH/3p+eXzYbT5+fXrY3u5ufv/lZv/wYfe/bv7qfv+l+7fb5+fd/fu7/cOnzf329vP+AORnEF6AuNu+n/
Re: Is it possible to export and import information in the same format as the plans?
Posted: Fri Mar 11, 2022 2:17 pm
by robot256
Do you mean that you want to export your custom data table *as though it were a blueprint*? Not to export an actual blueprint? Or do you want to do something with blueprints that you cannot already with the import/export shortcut buttons?
To export the custom data table, you would use
https://lua-api.factorio.com/latest/Lua ... le_to_json
To export:
Code: Select all
/c game.write_file( "export_string.txt", game.table_to_json( my_table_variable ) )
Map exchange string can be exported from a game:
https://lua-api.factorio.com/latest/Lua ... nge_string
To export:
Code: Select all
/c game.print( game.get_map_exchange_string() )
or
Code: Select all
/c game.write_file( "map_string.txt", game.get_map_exchange_string() )
Map exchange string can be parsed by mod code to show its meaning:
https://lua-api.factorio.com/latest/Lua ... nge_string
To parse:
Code: Select all
/c game.print( serpent.block( game.parse_map_exchange_string( game.get_map_exchange_string() ) ) )
or
Code: Select all
/c game.write_file( "map_data.txt", serpent.block( game.parse_map_exchange_string( game.get_map_exchange_string() ) ) )
Blueprint data can be accessed if you have a LuaItemStack object handle. For example, hold it in your cursor and run
Code: Select all
/c game.print( game.player.cursor_stack.export_stack() )
Re: Is it possible to export and import information in the same format as the plans?
Posted: Fri Mar 11, 2022 4:34 pm
by yaim904
robot256 wrote: Fri Mar 11, 2022 2:17 pm
Do you mean that you want to export your custom data table *as though it were a blueprint*?
Yes!!
But from what I understand, it only works for some parts and structures of the game, am I correct?
Re: Is it possible to export and import information in the same format as the plans?
Posted: Fri Mar 11, 2022 4:54 pm
by robot256
My first example is what you need. The rest of my examples use the built in functions to export map share strings and blueprint/planner strings. For data that is not a map config or blueprint, you can make your own Lua table in your mod's code, copying in the parameters you want out of the LuaObjects, and export the table with game.table_to_json(). Doing this, you can export any information available through the mod API. You cannot pass a LuaObject (like a LuaPlayer or LuaEntity) directly to game.table_to_json().
Re: Is it possible to export and import information in the same format as the plans?
Posted: Fri Mar 11, 2022 7:13 pm
by yaim904
robot256 wrote: Fri Mar 11, 2022 4:54 pm
Yes, you're right, that function would convert any table from Lua to JSon; but, the result would be in JSon, not in the peculiar format of get_map_exchange_string( ).
I think I'll have to create my encryptor.
Re: Is it possible to export and import information in the same format as the plans?
Posted: Fri Mar 11, 2022 11:01 pm
by robot256
Oh, sorry, I should have tested the function myself. Yes, the blueprints uses a binary-to-base-64 translator. Which is also in the API! Try
Code: Select all
game.encode_string(game.table_to_json(my_table))
Re: Is it possible to export and import information in the same format as the plans?
Posted: Sat Mar 12, 2022 2:59 am
by yaim904
robot256 wrote: Fri Mar 11, 2022 11:01 pm
Oh, sorry, I should have tested the function myself. Yes, the blueprints uses a binary-to-base-64 translator. Which is also in the API! Try
Code: Select all
game.encode_string(game.table_to_json(my_table))
I tried it, it's what I'm looking for, thank you very much.
To learn what I did wrong, why did you take so long to understand what I was asking?
Re: Is it possible to export and import information in the same format as the plans?
Posted: Sat Mar 12, 2022 4:31 am
by robot256
Well, half the trouble was that I forgot the encode_string() function existed until today! And also that I forgot JSON is plaintext and not encoded data.
Your wording of "access the functions that..." confused me, because there are purpose-made API functions for plans and maps which are unrelated to the ones for generic data. I might have understood better if you had started by describing the result you wanted rather than a method of getting it.
For example, "I know the game can put blueprints and map data into a compressed string of characters for easy copy and paste. How can I put my own arbitrary data into a similar string of characters?"