Skip to content

Commit a22a0b3

Browse files
committed
Fix recipe normalization. Fix whitespace.
1 parent e9a7746 commit a22a0b3

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

processdata/processdata.lua

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ local function normalize_recipe(r)
3838
r.result = nil
3939
r.result_count = nil
4040
end
41+
for i, result in ipairs(r.results) do
42+
if result.amount == nil then
43+
r.results[i] = {name = result[1], amount = result[2]}
44+
end
45+
end
4146
if r.energy_required == nil then
4247
r.energy_required = 0.5
4348
end
@@ -95,7 +100,7 @@ end
95100

96101
-- XXX: We don't actually need this yet.
97102
local function localize_name(locale, name)
98-
return "<dummy name>"
103+
return "<dummy name>"
99104
end
100105

101106
function Process.process_data(data, locales, verbose)
@@ -104,35 +109,35 @@ function Process.process_data(data, locales, verbose)
104109
print(...)
105110
end
106111
end
107-
local function assign_localized_name(locale, raw_object, new_object, fallback)
108-
local locale_sections = {"recipe-name", "item-name", "fluid-name", "equipment-name", "entity-name"}
109-
if raw_object.localised_name then
110-
new_object.localized_name = {en = localize_name(locale, raw_object.localised_name)}
111-
else
112-
local localized_name = nil
113-
for _, obj in ipairs({raw_object, fallback}) do
114-
for _, section in ipairs(locale_sections) do
115-
localized_name = locale[section][obj.name]
116-
if localized_name ~= nil then
117-
goto found
118-
end
119-
end
120-
end
121-
::found::
122-
if localized_name == nil then
123-
msg("no localized name for", raw_object.type, "named", raw_object.name)
124-
else
125-
localized_name = localized_name:gsub("__(%S*)__(%S*)__", function(section, name)
126-
section = section:lower() .. "-name"
127-
return locale[section][name]
128-
end)
129-
new_object.localized_name = {en = localized_name}
130-
end
131-
end
132-
end
112+
local function assign_localized_name(locale, raw_object, new_object, fallback)
113+
local locale_sections = {"recipe-name", "item-name", "fluid-name", "equipment-name", "entity-name"}
114+
if raw_object.localised_name then
115+
new_object.localized_name = {en = localize_name(locale, raw_object.localised_name)}
116+
else
117+
local localized_name = nil
118+
for _, obj in ipairs({raw_object, fallback}) do
119+
for _, section in ipairs(locale_sections) do
120+
localized_name = locale[section][obj.name]
121+
if localized_name ~= nil then
122+
goto found
123+
end
124+
end
125+
end
126+
::found::
127+
if localized_name == nil then
128+
msg("no localized name for", raw_object.type, "named", raw_object.name)
129+
else
130+
localized_name = localized_name:gsub("__(%S*)__(%S*)__", function(section, name)
131+
section = section:lower() .. "-name"
132+
return locale[section][name]
133+
end)
134+
new_object.localized_name = {en = localized_name}
135+
end
136+
end
137+
end
133138

134-
-- Limit it to English for now.
135-
local locale = locales["en"]
139+
-- Limit it to English for now.
140+
local locale = locales["en"]
136141
local item_types = {"ammo", "armor", "blueprint", "blueprint-book", "capsule", "deconstruction-item", "fluid", "gun", "item", "item-with-entity-data", "mining-tool", "module", "rail-planner", "repair-tool", "tool"}
137142
local no_module_icon = data["utility-sprites"]["default"]["slot_icon_module"]["filename"]
138143
local clock_icon = data["utility-sprites"]["default"]["clock"]["filename"]
@@ -157,7 +162,7 @@ function Process.process_data(data, locales, verbose)
157162
new_item[attr] = item[attr]
158163
end
159164
end
160-
assign_localized_name(locale, item, new_item)
165+
assign_localized_name(locale, item, new_item)
161166
item = new_item
162167
local subgroup
163168
if item.subgroup ~= nil then
@@ -290,7 +295,7 @@ function Process.process_data(data, locales, verbose)
290295
end
291296
icon_paths[recipe.icon] = true
292297
normalize_recipe(recipe)
293-
assign_localized_name(locale, raw_recipe, recipe, recipe.results[1])
298+
assign_localized_name(locale, raw_recipe, recipe, recipe.results[1])
294299
r.recipes[name] = recipe
295300
::continue::
296301
end
@@ -323,7 +328,7 @@ function Process.process_data(data, locales, verbose)
323328
["resource"] = {"category", "minable"},
324329
["rocket-silo"] = {"active_energy_usage", "allowed_effects", "crafting_categories", "crafting_speed", "energy_usage", "idle_energy_usage", "lamp_energy_usage", "module_specification", "rocket_parts_required"},
325330
["solar-panel"] = {"production"},
326-
["transport-belt"] = {"speed"},
331+
["transport-belt"] = {"speed"},
327332
}
328333
for entity_type, attrs in pairs(entity_attrs) do
329334
local entities = {}
@@ -335,7 +340,7 @@ function Process.process_data(data, locales, verbose)
335340
end
336341
icon_paths[entity["icon"]] = true
337342
local new_entity = {name = entity.name, icon = entity.icon}
338-
assign_localized_name(locale, entity, new_entity)
343+
assign_localized_name(locale, entity, new_entity)
339344
local has_modules = false
340345
for i, attr in ipairs(attrs) do
341346
if attr == "module_specification" then
@@ -412,7 +417,7 @@ function Process.process_data(data, locales, verbose)
412417
end
413418
end
414419
end
415-
local version = data["module_info"]["core"]["version"]
420+
local version = data["module_info"]["core"]["version"]
416421
return {
417422
data = new_data,
418423
normal = normal_recipes,

0 commit comments

Comments
 (0)