local filename = "recipe.json"

local enabledOnly = false


local function recipeWrap(recipe)

local typeList = {

"name",

"enabled",

"category",

"ingredients",

"products",

"main_product" ,

"hidden",

"energy",

"order",

"request_paste_multiplier",

"overload_multiplier",

"allow_as_intermediate",

"allow_intermediates",

"emissions_multiplier",

"valid",

}

local luaTypeList = {

"group",

"subgroup",

}

local res={}

for _,type in pairs(typeList) do

res[type] = recipe[type]

end

for _,type in pairs(luaTypeList) do

res[type] = recipe[type].name

end

return res

end



local function recipesWrap()

local res = {}

for _,recipe in pairs(game.recipe_prototypes) do

if (not enabledOnly) or game.player.force.recipes[recipe.name].enabled then

res[#res+1] = recipeWrap(recipe)

end

end

return res

end


local function table_to_json(table)

if type(table)=="table" then return game.table_to_json(table) else return table end

end


local recipes = recipesWrap()

local localised = {}

local endCommand = "Translation end"


script.on_event(defines.events.on_string_translated,

function(event)

if event.localised_string==endCommand then

for _,recipe in pairs(recipes) do

recipe.localised_name = localised[table_to_json(recipe.localised_name )]

recipe.localised_description = localised[table_to_json(recipe.localised_description)]

end


game.write_file(filename, table_to_json(recipes))

script.on_event(defines.events.on_string_translated,nil)

else

localised[table_to_json(event.localised_string)] = event.result

end

end

)


for _,recipe in pairs(recipes) do

game.player.request_translation(recipe.localised_name)

game.player.request_translation(recipe.localised_description)

end


game.player.request_translation(endCommand)




예전에 쓴 글 조오금 더 개량한 버전


이 코드를 커맨드창에 /c 붙이고 실행하면 script-output 폴더에 recipe.json이라는 파일이 생기게 된다


script-output 폴더는 저기가면 있음



코드 첫 줄에 있는

local filename = "recipe.json"

이 부분을 바꿔준다면 저장되는 파일이름을 바꿀 수 있다.


저 파일을 열어본다면



뭐 이딴것들이 써있다


https://jsoneditoronline.org/

알아보기 힘드니 이런 사이트에 복붙해보면



이런식으로 보기좋게 바꾸어준다

뭐 프로그래밍 끄적거리는 사람이라면 JSON 다루는 법은 대부분 알겠지



지금 코드는 게임내에 존재하는 모든 레시피를 모조리 출력해버리는데 만약 현재 연구가 완료된 레시피만 추출하고 싶다면 두번째 줄에 있는

local enabledOnly = false

이 코드를

local enabledOnly = ture

이렇게 바꾸어 주면 된다




지금 뭔가 정보를 이것저것 많이 띄워주고 있는데 필요 없는 정보다 싶으면


local typeList = {

"name",

"localised_name",

"localised_description",

"enabled",

"category",

"ingredients",

"products",

"main_product" ,

"hidden",

"energy",

"order",

"request_paste_multiplier",

"overload_multiplier",

"allow_as_intermediate",

"allow_intermediates",

"emissions_multiplier",

"valid",

}

local luaTypeList = {

"group",

"subgroup",

}


이 부분에서 필요 없는 라인을 제거해주면 된다


위 코드 수정 없이 그대로 우탐모에서 실행하면 대충 900KB로 출력되는 듯