diff --git a/changelog.txt b/changelog.txt index a79ae60..da94daa 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,9 +1,16 @@ --------------------------------------------------------------------------------------------------- +Version: 0.18.7 +Date: 5. 3. 2020 + Features: + - Added integration with Informatron (for german and english locales) + Changes: + - Minor code readability improvements + - Added earlier check for setting "none" to prevent more code from running +--------------------------------------------------------------------------------------------------- Version: 0.18.6 Date: 27. 2. 2020 Changes: - Updated retroactive downgrade to be on par with this version - Bugfixes: - Fixed empty filter check, so it checks all slots instead of just the first one --------------------------------------------------------------------------------------------------- @@ -13,7 +20,6 @@ Date: 24. 2. 2020 - Added hidden dependency to Bob's Adjustable Inserters (fixes setting filter from wrong inventory when pickup location is rotated) - Added check for empty filter and whitelist mode to avoid overwriting filter on replacing preexisting inserters/ghosts - Updated retroactive downgrade to be on par with this version - Locale: - Added translated mod description --------------------------------------------------------------------------------------------------- @@ -21,7 +27,6 @@ Version: 0.18.4 Date: 23. 2. 2020 Changes: - Removed incompatibility with Upgrade Builder and Planner (see Bugfixes) - Bugfixes: - Added additional check for entity type, since event filters are not applied to mod-raised events --------------------------------------------------------------------------------------------------- @@ -30,7 +35,6 @@ Date: 23. 2. 2020 Changes: - Minor improvements (typos, code style) - Added incompatibility with Upgrade Builder and Planner (until crash is fixed, see https://mods.factorio.com/mod/Autofilter/discussion/5e5177cbf26569000bdd51eb) - Graphics: - Changed thumbnail to the better --------------------------------------------------------------------------------------------------- @@ -38,7 +42,6 @@ Version: 0.18.2 Date: 22. 2. 2020 Changes: - Matched changelog file format to what Factorio expects - Info: - Also downgraded to Factorio 0.17, see below --------------------------------------------------------------------------------------------------- diff --git a/control.lua b/control.lua index 3ad45b7..34fe07a 100644 --- a/control.lua +++ b/control.lua @@ -1,4 +1,5 @@ --control.lua +require("integrations.informatron.control") --functions definitions local function is_filter_empty(inserter) @@ -10,7 +11,7 @@ local function is_filter_empty(inserter) return true end -local function get_items_by_content(inserter,inventory) +local function get_items_by_contents(inserter,inventory) local items = {} for item,_ in pairs(inventory.get_contents()) do if #items < inserter.filter_slot_count then @@ -31,22 +32,24 @@ local function get_items_by_filter(inserter,inventory) end local function on_built_entity(event) - local inserter = event.created_entity - if inserter.type == "inserter" then - if inserter.filter_slot_count then - if is_filter_empty(inserter) and inserter.inserter_filter_mode == "whitelist" then - local pickup = inserter.surface.find_entities_filtered({position = inserter.pickup_position, limit = 1}) - if #pickup > 0 then - local inventory = pickup[1].get_output_inventory() - if inventory then - local mode = game.players[event.player_index].mod_settings["Autofilter_Mode"].value - if mode == "content" and not inventory.is_empty() then - for slot,item in pairs(get_items_by_content(inserter,inventory)) do - inserter.set_filter(slot,item) - end - elseif mode == "filter" and inventory.is_filtered() then - for slot,item in pairs(get_items_by_filter(inserter,inventory)) do - inserter.set_filter(slot,item) + local mode = game.players[event.player_index].mod_settings["autofilter_mode"].value + if mode ~= "none" then + local inserter = event.created_entity + if inserter.type == "inserter" then + if inserter.filter_slot_count then + if is_filter_empty(inserter) and inserter.inserter_filter_mode == "whitelist" then + local pickup = inserter.surface.find_entities_filtered({position = inserter.pickup_position, limit = 1}) + if #pickup > 0 then + local inventory = pickup[1].get_output_inventory() + if inventory then + if mode == "contents" and not inventory.is_empty() then + for slot,item in pairs(get_items_by_contents(inserter,inventory)) do + inserter.set_filter(slot,item) + end + elseif mode == "filter" and inventory.is_filtered() then + for slot,item in pairs(get_items_by_filter(inserter,inventory)) do + inserter.set_filter(slot,item) + end end end end diff --git a/data.lua b/data.lua new file mode 100644 index 0000000..13980e6 --- /dev/null +++ b/data.lua @@ -0,0 +1,2 @@ +--data.lua +require("integrations.informatron.data") \ No newline at end of file diff --git a/info.json b/info.json index fd0fadd..cb30629 100644 --- a/info.json +++ b/info.json @@ -1,11 +1,12 @@ { "name": "Autofilter", - "version": "0.18.6", + "version": "0.18.7", "title": "Autofilter", "author": "Wyrrrd", "dependencies": [ "base >= 0.18.0", - "(?)bobinserters" + "(?) bobinserters >= 0.18.0", + "? informatron >= 0.1.5" ], "description": "Automatically set inserter filters based on adjacent inventory.", "factorio_version": "0.18" diff --git a/integrations/informatron/control.lua b/integrations/informatron/control.lua new file mode 100644 index 0000000..b586b2e --- /dev/null +++ b/integrations/informatron/control.lua @@ -0,0 +1,35 @@ +if script.active_mods["informatron"] then + remote.add_interface("autofilter", { + informatron_menu = function(data) + return autofilter_menu(data.player_index) + end, + informatron_page_content = function(data) + return autofilter_page_content(data.page_name, data.player_index, data.element) + end + }) +end + +function autofilter_menu(player_index) + return { + mode=1, + } +end + +function autofilter_page_content(page_name, player_index, element) + if page_name == "autofilter" then + element.add{type="label", name="text_autofilter", caption={"autofilter.page_autofilter_text"}} + local image_container = element.add{type="button", name="image_autofilter", style="autofilter_thumbnail"} + image_container.style.horizontal_align = "center" + end + if page_name == "mode" then + element.add{type="label", name="heading_contents", caption={"autofilter.page_contents_heading"}, style="heading_1_label"} + element.add{type="button", name="image_contents", style="autofilter_settings_contents"} + element.add{type="label", name="text_contents", caption={"autofilter.page_contents_text"}} + element.add{type="label", name="heading_filter", caption={"autofilter.page_filter_heading"}, style="heading_1_label"} + element.add{type="button", name="image_filter", style="autofilter_settings_filter"} + element.add{type="label", name="text_filter", caption={"autofilter.page_filter_text"}} + element.add{type="label", name="heading_none", caption={"autofilter.page_none_heading"}, style="heading_1_label"} + element.add{type="button", name="image_none", style="autofilter_settings_none"} + element.add{type="label", name="text_none", caption={"autofilter.page_none_text"}} + end +end \ No newline at end of file diff --git a/integrations/informatron/data.lua b/integrations/informatron/data.lua new file mode 100644 index 0000000..4a8101b --- /dev/null +++ b/integrations/informatron/data.lua @@ -0,0 +1,6 @@ +if mods["informatron"] then + informatron_make_image("autofilter_thumbnail", "__Autofilter__/integrations/informatron/thumbnail.png", 360, 156) + informatron_make_image("autofilter_settings_contents", "__Autofilter__/integrations/informatron/settings_contents.png", 400, 128) + informatron_make_image("autofilter_settings_filter", "__Autofilter__/integrations/informatron/settings_filter.png", 400, 128) + informatron_make_image("autofilter_settings_none", "__Autofilter__/integrations/informatron/settings_none.png", 400, 128) +end \ No newline at end of file diff --git a/integrations/informatron/settings_contents.png b/integrations/informatron/settings_contents.png new file mode 100644 index 0000000..fa91f4a Binary files /dev/null and b/integrations/informatron/settings_contents.png differ diff --git a/integrations/informatron/settings_filter.png b/integrations/informatron/settings_filter.png new file mode 100644 index 0000000..af26a4e Binary files /dev/null and b/integrations/informatron/settings_filter.png differ diff --git a/integrations/informatron/settings_none.png b/integrations/informatron/settings_none.png new file mode 100644 index 0000000..6ab657a Binary files /dev/null and b/integrations/informatron/settings_none.png differ diff --git a/integrations/informatron/thumbnail.png b/integrations/informatron/thumbnail.png new file mode 100644 index 0000000..76206a3 Binary files /dev/null and b/integrations/informatron/thumbnail.png differ diff --git a/locale/de/strings.cfg b/locale/de/strings.cfg index be7ee11..5f4a0e8 100644 --- a/locale/de/strings.cfg +++ b/locale/de/strings.cfg @@ -2,12 +2,25 @@ Autofilter=Setzt Greifarmfilter automatisch, basierend auf dem angrenzenden Inventar. [mod-setting-name] -Autofilter_Mode=Autofilter-Modus +autofilter_mode=Autofilter-Modus [mod-setting-description] -Autofilter_Mode=Ändere, ob Greifarmfilter durch Inventarinhalt, Inventarfilter oder gar nicht gesetzt werden sollen. +autofilter_mode=Ändere, ob Greifarmfilter durch Inventarinhalt, Inventarfilter oder gar nicht gesetzt werden sollen. [string-mod-setting] -Autofilter_Mode-content=Inhalt -Autofilter_Mode-filter=Filter -Autofilter_Mode-none=Keiner \ No newline at end of file +autofilter_mode-contents=Inhalt +autofilter_mode-filter=Filter +autofilter_mode-none=Keiner + +[autofilter] +menu_autofilter=Autofilter +title_autofilter=Autofilter +page_autofilter_text=Setzt Greifarmfilter automatisch, basierend auf dem angrenzenden Inventar. Diese Funktion kann in den Mod-Einstellungen während des Spiels angepasst werden. +menu_mode=Modus +title_mode=Autofilter-Modus +page_contents_heading=Inhalt +page_contents_text=Bei Verwendung des Inhaltsmodus wird der Filter manuell platzierter Filtergreifarme auf die Gegenstände gesetzt, die sich am Aufnahmepunkt in einem Inventar (Kiste, Wagon, etc.) befinden. Es können natürlich maximal so viele verschiedene Gegenstände als Filter gesetzt werden, wie Platz im Greifarmfilter ist. +page_filter_heading=Filter +page_filter_text=Bei Verwendung des Filtermodus wird der Filter manuell platzierter Filtergreifarme auf die Gegenstände gesetzt, auf die das am Aufnahmepunkt befindliche Inventar (Kiste, Wagon, etc.) gefiltert ist. Hierbei ist irrelevant, ob das Inventar komplett oder nur teilweise gefiltert ist. +page_none_heading=Keiner +page_none_text=Bei Deaktivierung des Modus funktioniert die Platzierung von Filtergreifarmen normal. Der Greifarmfilter wird nicht automatisch gesetzt. \ No newline at end of file diff --git a/locale/en/strings.cfg b/locale/en/strings.cfg index b4b9c83..b84a493 100644 --- a/locale/en/strings.cfg +++ b/locale/en/strings.cfg @@ -2,12 +2,25 @@ Autofilter=Automatically set inserter filters based on adjacent inventory. [mod-setting-name] -Autofilter_Mode=Autofilter Mode +autofilter_mode=Autofilter Mode [mod-setting-description] -Autofilter_Mode=Change if inserter filters should be set from inventory items, inventory filter or not at all. +autofilter_mode=Change if inserter filters should be set from inventory items, inventory filter or not at all. [string-mod-setting] -Autofilter_Mode-content=Content -Autofilter_Mode-filter=Filter -Autofilter_Mode-none=None \ No newline at end of file +autofilter_mode-contents=Contents +autofilter_mode-filter=Filter +autofilter_mode-none=None + +[Autofilter] +menu_autofilter=Autofilter +title_autofilter=Autofilter +page_autofilter_text=Automatically set inserter filters based on adjacent inventory. This can be changed on the fly in mod settings. +menu_mode=Modus +title_mode=Autofilter Modus +page_contents_heading=Contents +page_contents_text=When using contents mode, the filter of manually placed filter inserters is set to the items in an inventory (chest, waggon, etc.) at the pickup point. Naturally, the filter can only be set to as many items as there are filter slots in the inserter. +page_filter_heading=Filter +page_filter_text=When using filter mode, the filter of manually placed filter inserters is set to the filtered slots of an inventory (chest, waggon, etc.) at the pickup point. It is irrelevant, if the inventory is partially or completely filtered. +page_none_heading=None +page_none_text=When disabling the mode, manual placement of filter inserters works as usual. The inserter filter is not set automatically. \ No newline at end of file diff --git a/settings.lua b/settings.lua index 689da93..da1343e 100644 --- a/settings.lua +++ b/settings.lua @@ -1,9 +1,9 @@ data:extend({ { type = "string-setting", - name = "Autofilter_Mode", - default_value = "content", - allowed_values = {"content","filter","none"}, + name = "autofilter_mode", + default_value = "contents", + allowed_values = {"contents","filter","none"}, setting_type = "runtime-per-user", order = "a", },