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로 하는게 좀 헷갈려서 이렇게 했었음
어떻게 가공하냐ㅠㅠ
ㄱㄷ 방법 정리해봄
줄바꿈이라도 깔끔하게 됐으면 좋겠는데 너가 알려준 커맨드에 뭐 줄바꿈 명령어 삽입할수는 없음?
일단 가공법 하나 적어둠
json 줄바꿈하고 탭 안나오는거 급한대로
https://jsonformatter.org/json-pretty-print
이런데 넣고 돌려봐
이거 나만 안되나? 첫줄부터 무슨 포맷에 오류있다고 안먹히는뎅
맨앞에 [ 때문인가? [를 치워보던가 맨뒤에 ]를 넣어보던가 해봐봐 지금 저 짤린 스샷만 가지곤 잘모르겠네
저게 안된다면 아마 localised name에 문제가 있을수도 있음, 번역이 안 된 케이스가 있으면 좀 꼬임
그럼 localized name 빼고 json파일 하나 더 뽑아볼까
lua에서 localised 있는 줄이랑, 크롬에서 치는 코드에서 (${recipe.localised_name}) 부분 지우고 해봐
이거 안되네 일단 F12로 해봄
VM572:1 Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse () at :3:16 이건 뭔뜻임? 안되는데
문자열을 봐야 알것같은디, 316번째 글자에 문제가 있다는데 안보면 모르겠음
아 저거 그냥 테이블 한개 만들고 table.insert 해서 그냥 쭉쭉 집어넣고 파일에 기록하기 전에 game.table_to_json 함수 하나 돌려주면 되는데...
안그래도 묻고 싶은거 있었는데 그런식으로 localised name도 원하는대로 뽑아낼 수 있음? 얘는 번역 이름을 직접 변수에는 저장을 못하고 print나 파일로쓰거나 할때만 번역명으로 바뀌는 것 같던데
오 시 그러네. 이걸 해결해본다.