이거 문자 같은거 누락없이 디씨가 받아들여줄라나
----------------
/c
local copy = nil
copy = function(obj)
local t = type(obj)
local ret
if t == "table" then
ret = {}
for k, v in next, obj, nil do
ret[copy(k)] = copy(v)
end
else
ret = obj
end
return ret
end
local localising_table = {}
local localisation = function(obj)
if type(obj.localised_name) == "table" then
local id = #localising_table + 1
localising_table[id] = obj.localised_name
return "@a@s@d@f@"..id.."@@@@@"
else
return obj.name
end
end
local function write_recipe(recipe)
return {
name = recipe.name,
localised_name = localisation(recipe),
category = recipe.category,
order = recipe.order,
group = recipe.group.name,
subgroup = recipe.subgroup.name,
main_product = assert(function()
if recipe.main_product then
local tbl = copy(recipe.main_product)
if game[tbl.type.."_prototypes"][tbl.name] then
tbl.name = localisation( game[tbl.type.."_prototypes"][tbl.name] )
end
return tbl
else
return "null"
end
end)(),
energy = recipe.energy,
ingredients = assert(function()
local tbl = copy(recipe.ingredients)
for i, v in ipairs(tbl) do
if game[v.type.."_prototypes"][v.name] then
tbl[i].name = localisation( game[v.type.."_prototypes"][v.name] )
end
end
return tbl
end)(),
products = assert(function()
local tbl = copy(recipe.products)
for i, v in ipairs(tbl) do
if game[v.type.."_prototypes"][v.name] then
tbl[i].name = localisation( game[v.type.."_prototypes"][v.name] )
end
end
return tbl
end)(),
}
end
local tbl = {}
for _, recipe in pairs(game.recipe_prototypes) do
table.insert( tbl, write_recipe(recipe) )
end
local str = game.table_to_json(tbl) .. "@a@s@d@f@ABCD@@@@@"
local fn = "recipes.json"
game.write_file( fn, '' )
for match1, match2 in str:gmatch("(.-)@a@s@d@f@(.-)@@@@@") do
game.write_file( fn, match1, true )
if match2 ~= "ABCD" then
game.write_file( fn, localising_table[match2 + 0], true )
end
end
---------------
콘솔창에 넣고 실행하면 레에에ㅔㅔㅔ엑 걸린 다음에 파일 만들어짐.
그냥 pastebin 쓰면 되잖아
어 생각해보니 그렇긴한데 저거 긁어서 테스트해보니 문제없어서 놔둘래 ㅋㅋㅋ
json 파싱 문제없이 되고 한글두 나와
돌려보긴 했는데 저번꺼랑 별 차이 없는것같음..
오 이거는 json 정리 먹힌다!!!
localised는 그냥 별도의 테이블로 따로 관리하다가 처리하는건가
제대로 된 번역명칭 없어도 문제없이 동작하나?
번역명이 있으면 obj.localised_name의 타입이 테이블이고, 없으면 길이 0짜리 스트링인거 같더라.
지금 해봤는데 Unknown key: "recipe-name.slag-processing-1" 이런식으로 key가 없는애들 나오면 문자열에 큰따옴표 들어가서 json이 깨진다
그건 모드 만든놈이 잘못했네...파일에 쓰는 순간에 번역명이 들어가는거 같던데 그런건 뭔수로 캐치하냐?...
난 이것땜에 예전에 이상황 나왔을 때 .replace(/"Unknown key:(.*?"){3}/g,"null") 이런식으로 정규식으로 잡아다가 null로 치환해서 쓰긴했음
번역명자체를 직접 다룰 수 있으면 편할텐데 좀 귀찮아