function write_recipe(fn,recipe)

game.write_file(fn,'{',true)

game.write_file(fn,{"",'"name":"',recipe.name,'",'},true)

game.write_file(fn,{"",'"localised_name":"',recipe.localised_name,'",'},true)

game.write_file(fn,{"",'"category":"',recipe.category,'",'},true)

game.write_file(fn,{"",'"order":"',recipe.order,'",'},true)

game.write_file(fn,{"",'"group":"',recipe.group.name,'",'},true)

game.write_file(fn,{"",'"subgroup":"',recipe.subgroup.name,'",'},true)

game.write_file(fn,{"",'"main_product":',(recipe.main_product~=nil) and ('"'..recipe.main_product.name..'"') or "null",','},true)

game.write_file(fn,{"",'"energy":',recipe.energy,','},true)

game.write_file(fn,{"",'"ingredients":',game.table_to_json(recipe.ingredients),','},true)

game.write_file(fn,{"",'"products":',game.table_to_json(recipe.products)},true)

game.write_file(fn,{"",'}'},true)

end

local fn = "recipes.json"

local num = #game.recipe_prototypes

game.write_file(fn,'[')

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

write_recipe(fn,recipe)

num=num-1

if num~=0 then game.write_file(fn,',',true) end

end



게임 들어가서 콘솔 창에 저 커맨드를 쓰면 모든 레시피가 factorio폴더/script_output/recipes.json 에 저장됨

json 형태로 저장하니 저걸 적당히..가공해서 쓰면됨


밥스모드 레시피를 추출한 모습



적절한 가공방법 예시


크롬에서 F12치면 아래와 같은 창이 뜰꺼임

Console 탭으로 이동하자


raw = `recipes.json파일 복붙`   // `는 키보드 1 왼쪽에 있는 기호

recipes = JSON.parse(raw)

recipes.map(recipe=>`${recipe.name}(${recipe.localised_name})=${(recipe.ingredients.map && recipe.ingredients.map(v=>`${v.amount} ${v.name}`))}`).join("\n")


위의 코드를 입력하면 아래와 같이 뜰꺼임




레시피는 영어이름이 뜨는데 이거까지 번역명으로 하려면 item prototpye 정보랑 fluid prototype 정보도 추출해야해서 조금 귀찮아짐


사실 이렇게 일 두번 안하고 lua로 한번에 처리할 수도 있기는 할텐데 나는 lua로 하는게 좀 헷갈려서 이렇게 했었음