일단 이지랄이 나는데 어떻게하지
문제가
1. 아이콘 처리
2. 레시피 만들면 버튼 ㅈㄴ 늘어나서 보기 싫음 안나오게 하면서 실제로 사용은 가능했으면 좋겠음
3. recipe.ingredients 이거나 recipe.results 에 접근하는방법을 모르겠음
1번이야 3번에 접근해서 동명의 .png파일 가져오거나 2번으로 버튼 가리면 해결 될수도 있고
2번은 어디 새로운 제작항목 만드는법 알아내면 그쪽에 다 치워버릴수만 있다면 반은 해결될수도 있는데
3번은 임시방편도 없는데다 제일 중요한 레시피의 결과물을 for문으로 자동수정에 필요한건데 하는법을 모르겠다
https://lua-api.factorio.com/latest/prototypes/RecipePrototype.html
1.
icon이나 icons를 건드리면 됨
2. hidden을 true로 주면 보이진 않지만 사용가능한 레시피 상태가 됨
3. ingredients가 재료의 배열, results가 생산품임. 배열의 내용물은 각각 IngredientPrototype, ProductPrototype인데 어떤 구조인지는 링크타고 가서 봐보고 모르겠으면 질문 ㄱ
2번으로 가려지니까 1번 아이콘은 그대로 내비둬도 될거같고 { name = recipe.name, probability = 0.1, amount = 1 } 이렇게 레시피 이름과 동명의 아이템 넣고 그런건 하겠는데 ingredients는 어떻게 넣음?
https://lua-api.factorio.com/latest/types/ItemIngredientPrototype.html
https://lua-api.factorio.com/latest/types/FluidIngredientPrototype.html
이놈들의
배열로 이루어져있는데 고체만 보자면 고체쪽은 name, amount, catalyst_amount로 정의되어있음
전자회로의 재료를 저 표현에 맞게 나타내면
{{name="iron-plate",amount=1}, {name="copper-cable",amount=3} }
이런식으로 나타냄
아니면 어짜피 name, amount의 반복이니까 더 축약해서도 쓸수는 있는데
{{"iron-plate",1}, {"copper-cable",3} }
이렇게만 써도 인식하긴함
https://lua-api.factorio.com/latest/types/IngredientPrototype.html
여기서도
설명하고 있음
그래서 그거 보고 ingredients = { {"speed-module", 4}, {"advanced-circuit", 5}, {"processing-unit", 5} } 이런식으로 직접 하나하나 써주면 가능한데 for문 돌릴떄는 하나하나 해줄수가 없어서 ingredients 의 내용물에 접근하려는데 그게 잘 안됨recipe.ItemIngredientPrototype 이거 쓰면 에러는 안나는데 정작 인게임 들어가면 아무것도 안들어가있ㅇㅁ
ingredients를 바꾸는게 목적이 아니라 ingredients를 가져다가 results에 넣는게 목적임
그러면 예외인 레시피가 있을수도 있긴한데 newRecipe.results= oldRecipe.ingredients 정도로 해결이 될수도 있음, 어짜피 재료나 생산품이나 둘다 name이랑 amount는 있거든
일단 레시피를 보니까 { type = "recipe", name = "iron-gear-wheel", normal = { ingredients = {{"iron-plate", 2}}, result = "iron-gear-wheel" }, expensive = { ingredients = {{"iron-plate", 4}}, result = "iron-gear-wheel" } }처럼 무슨 nomal이니 expensive니 하면서 재료와 결과가 저 안에 들어가있는경우도 있고result인놈 따로 results인놈 따로 있어서 하나하나 다 구분해줘야 하는듯
oldRecipe.ingredients의 내용을 newRecipe.results으로 for써서 옮기는 법은 newRecipe.results={} for _,ingredient in pairs(oldRecipe.ingredients) do local product = {name=ingredient.name, amount=ingredient.amount} table.insert(newRecipe.results, product) end 이런식으로 할 수 있음
맞네 normal 또는 expensive가 있으면 그걸 써야하네
oldRecipeData = oldRecipe.normal or oldRecipe.expensive or oldRecipeold RecipeData.results = oldRecipeData.results or {{name=result, count=result_count}} 이런식으로 전처리를 하고 newRecipe.results={} for _,ingredient in pairs(oldRecipeData.ingredients) do local product = {name=ingredient.name, amount=ingredient.amount} table.insert(newRecipe.results, product) end 해줘야할것같은데
일단 재료 대입은 if recipe.normal then results =recipe.normal.ingredients로 nomal같은건 해결 함 그런데 수율을 줄이려면 { name = recipe.ingredients[1][1], probability = 0.1, amount = 1 } 이런식으로 확률을 대입한 식을 써야하는데 그러면 자꾸 에러가남 empty-barrel같은데서 에러나서 고치는중
empty-barrel 이친구 정의가 { amount = 1, name = "empty-barrel", type = "item" } 이렇게 되어있어서 [1][1]로 접근을 못하는게 아닌가 싶은데 [1].name 해야하나 싶기도하고
table.insert(new_recipe.results, { name = recipe.ingredients[1][1] or recipe.ingredients[1].name, probability = 0.2, amount = 1 }) 이걸로 하니까 된거같음 왜 되는진 아직도 헷갈리네
A or B가 A가 있을 때는 A를 쓰라는 거고 A가 없으면 B를 쓰라는거임 A ? A : B와 유사
이제 for문 한번 더써서 table.insert(new_recipe.results, { name = recipe.normal.ingredients[i][1] or recipe.normal.ingredients[1].name, probability = 0.2, amount = 1 }) 이렇게 만든담에 i를 1씩 더해서 재료 갯수만큼 반복하면 될듯
저거 하나만 쓰면 첫번째 재료만 반환하니까