이전글 : https://gall.dcinside.com/mgallery/board/view/?id=factorio&no=12251


거의 1년 반만에 쓰는 2편글임..


이번에 연말기간에 휴가 몰아쓰게되서 연휴가 생긴김에 이전부터 각만 잡고 있던 모바일 레시피 뷰어를 다시 만들어 보려고 하고 있음


그동안 lua도 좀 더 다뤄보면서 더 익숙해지기도 해서 어느정도 진행이 수월하게 된 것같다


예를들면 이전엔 레시피 추출 코드가 이랬더라면


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

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


지금은 이렇게 바뀜


function recipeWrap(recipe)

  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",

  }

  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


function recipesWrap()

  local res = {}

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

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

  end

  return res

end


game.write_file("prototype.json", game.table_to_json(recipesWrap()))



쓰고나니 코드 길이는 거기서 거기같은데 읽는 입장에서는 가독성이 훨씬 좋아짐

아직 모드화는 시키지 않아서 저 커맨드를 직접 콘솔에 쳐야함

그래도 최근에 한번 연습용으로 모드 만들어보니까 저 코드를 모드안에 때려박는건 그리 어렵지 않을 것 같음


아 그리고 localised_string 쪽은 다른 코드로 처리를 하도록 했음


예전에 갤러가 on_string_translated 이벤트 있다는거 알려줘서 유용하게 잘 써먹음

좀 변태같은 코드긴한데 아무튼 돌아가니 됐다


요로코롬 localised_stirng과 번역명을 매칭시켜준다.




인게임쪽은 어느정도 와꾸가 됐으니 본격적으로 앱쪽을 건드려봄

옛날에 자바로 안드로이드 어플만들어본 경험은 있는데 이번엔 자바스크립트가 익숙하기도 하고해서 expo란 것을 이용해보기로함

자바스크립트로 안드앱, iOS앱(배포하려면 맥북은 있어야한다는듯), Web앱을 동시에 만들 수 있는 프레임워크라고함


expo 튜토리얼좀 보고 공부한다음 한번 레시피들만 어찌어찌 띄우도록 만들어봤음


위에 버튼을 누르면 다음/이전 레시피로 넘어가는것까진 구현을 한 상태

해당 레시피를 만들 수 있는 건물 목록도 띄워주고있음

아직 연구정보들은 추출을 안해서 레시피를 해금시켜주는 연구 목록은 못 띄운다


이제 I나 P 버튼을 누르면 FNEI 모드처럼 그 아이템을 재료로 사용하는 레시피와 그 아이템을 만드는 레시피 목록으로 넘어가는 기능을 추가하려고 함

엔티티<->아이템/유체<->레시피<->연구들 상호유기적으로 연결되게 다 만들려면 좀 머리좀 많이 굴려야할듯