diff --git a/README.md b/README.md index fd01d9c..5b89475 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,17 @@ ### Features -When you manually place a filter inserter, it reads the inventory contents, inventory filters or belt contents on the pickup side and sets its filter to those items. There are extensive configuration options. +When you manually place an inserter, it reads the inventory contents, inventory filters or belt contents on the pickup side and enables and sets its filter to those items. There are extensive configuration options. ### Settings -There is only one text field to enter configuration into. This can be done on the fly, while ingame. You can add each of the following keywords into the text field, in any order, separated by spaces. They will be processed left to right. +There is only one text field to enter configuration into (apart from an enabling checkbox). This can be done on the fly, while ingame. You can add each of the following keywords into the text field, in any order, separated by spaces. They will be processed left to right. + **contents** - Checks for filter candidates in the inventory contents at the inserter's pickup position. + **filter** - Checks for filter candidates in the inventory's filter settings at the inserter's pickup position. + **belt** - Checks for filter candidates in the items on a belt at the inserter's pickup position. + **check** - Checks for the current filter candidates, if they could be inserted in the inventory at the inserter's drop position and removes them from the candidate list, if unsuccessful. -+ *anything else* - Gets ignored. If you want to disable all functionality, just write anything. ++ *anything else* - Gets ignored. After those are processed, a deduplication removes all but the first appearance of each item from the filter candidate list, and then the candidates are written to the inserter's filter until it is full. diff --git a/changelog.txt b/changelog.txt index 0cea6fc..59349dd 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,12 @@ --------------------------------------------------------------------------------------------------- +Version: 2.0.0 +Date: 2024-10-25 + Features: + - Added option to quickly enable/disable all functions (will be replaced with a shortcut tile in the future) + - If enabled, now sets filters for all inserters (since filter inserters don't exist anymore) + Changes: + - Version bump for base game 2.0 +--------------------------------------------------------------------------------------------------- Version: 1.1.3 Date: 2021-09-06 Locale: diff --git a/control.lua b/control.lua index 80e0bdc..69dadd6 100644 --- a/control.lua +++ b/control.lua @@ -53,10 +53,14 @@ local function remove_noninsertable_items(items,entity) defines.inventory.lab_input, defines.inventory.item_main, defines.inventory.rocket_silo_rocket, + defines.inventory.rocket_silo_input, defines.inventory.cargo_wagon, defines.inventory.turret_ammo, defines.inventory.artillery_turret_ammo, defines.inventory.artillery_wagon_ammo, + defines.inventory.spider_ammo, + defines.inventory.hub_main, + defines.inventory.cargo_landing_pad_main } local insert_items = {} local no_inventory_flag = true @@ -86,8 +90,8 @@ end local function get_items_by_content(inventory) local content_items = {} - for item,_ in pairs(inventory.get_contents()) do - content_items[#content_items+1] = item + for _,item in pairs(inventory.get_contents()) do + content_items[#content_items+1] = item.name end return content_items end @@ -115,88 +119,84 @@ end local function on_built_entity(event) -- Read settings + local enabled = game.players[event.player_index].mod_settings["autofilter_enabled"].value local mode = string_to_table(game.players[event.player_index].mod_settings["autofilter_mode"].value) - local search_inventories = { - defines.inventory.fuel, - defines.inventory.chest, - defines.inventory.furnace_source, - defines.inventory.roboport_robot, - defines.inventory.roboport_material, - defines.inventory.assembling_machine_input, - defines.inventory.lab_input, - defines.inventory.item_main, - defines.inventory.rocket_silo_rocket, - defines.inventory.cargo_wagon, - defines.inventory.turret_ammo, - defines.inventory.artillery_turret_ammo, - defines.inventory.artillery_wagon_ammo, - } - local inserter = event.created_entity - if inserter and inserter.valid and (inserter.type == "inserter") then - if inserter.filter_slot_count then - if is_filter_empty(inserter) and inserter.inserter_filter_mode == "whitelist" then - -- Read pickup and drop position entity - local pickup = inserter.surface.find_entities_filtered({ - position = inserter.pickup_position, - force = inserter.force, - surface = inserter.surface, - collision_mask_layer= "object-layer", - to_be_deconstructed = false, - limit = 1 - }) - local drop = inserter.surface.find_entities_filtered({ - position = inserter.drop_position, - force = inserter.force, - surface = inserter.surface, - collision_mask= "object-layer", - to_be_deconstructed = false, - limit = 1 - }) - - if pickup[1] and pickup[1].valid then - -- Prequisites - local inventory_pickup = pickup[1].get_output_inventory() + if enabled then + local inserter = event.entity + if inserter and inserter.valid and inserter.type == "inserter" then + if inserter.filter_slot_count then + if not inserter.use_filters and is_filter_empty(inserter) and inserter.inserter_filter_mode == "whitelist" then + -- Read pickup and drop position entity + local pickup = inserter.surface.find_entities_filtered({ + position = inserter.pickup_position, + force = inserter.force, + surface = inserter.surface, + collision_mask_layer= "is_object", + to_be_deconstructed = false, + limit = 1 + }) + local drop = inserter.surface.find_entities_filtered({ + position = inserter.drop_position, + force = inserter.force, + surface = inserter.surface, + collision_mask= "is_object", + to_be_deconstructed = false, + limit = 1 + }) - if (pickup[1].type == "transport-belt" or pickup[1].type == "underground-belt" or pickup[1].type == "splitter") then - local maxlines = pickup[1].get_max_transport_line_index() - end - local items = {} - local check = false + if pickup[1] and pickup[1].valid then + -- Prequisites + local inventory_pickup = pickup[1].get_output_inventory() - -- Read each mode element - for _,step in pairs(mode) do - if step == "contents" then - -- Read inventory contents at pickup, write to filter - if inventory_pickup and not inventory_pickup.is_empty() then - items = concatenate_tables(items,get_items_by_content(inventory_pickup)) - end - elseif step == "filter" then - -- Read inventory filter at pickup, write to filter - if inventory_pickup and inventory_pickup.is_filtered() then - items = concatenate_tables(items,get_items_by_filter(inventory_pickup)) - end - elseif step == "belt" then - -- Read belt transport lines at pickup, write to filter - if (pickup[1].type == "transport-belt" or pickup[1].type == "underground-belt" or pickup[1].type == "splitter") and pickup[1].get_max_transport_line_index() then - items = concatenate_tables(items,get_items_by_transport_line(pickup[1])) - end - elseif step == "check" then - -- Drop inventory insertion check - if drop[1] and drop[1].valid then - items = remove_noninsertable_items(items,drop[1]) + if (pickup[1].type == "transport-belt" or pickup[1].type == "underground-belt" or pickup[1].type == "splitter") then + local maxlines = pickup[1].get_max_transport_line_index() + end + local items = {} + local check = false + + -- Read each mode element + for _,step in pairs(mode) do + if step == "contents" then + -- Read inventory contents at pickup, write to filter + if inventory_pickup and not inventory_pickup.is_empty() then + items = concatenate_tables(items,get_items_by_content(inventory_pickup)) + end + elseif step == "filter" then + -- Read inventory filter at pickup, write to filter + if inventory_pickup and inventory_pickup.is_filtered() then + items = concatenate_tables(items,get_items_by_filter(inventory_pickup)) + end + elseif step == "belt" then + -- Read belt transport lines at pickup, write to filter + if (pickup[1].type == "transport-belt" or pickup[1].type == "underground-belt" or pickup[1].type == "splitter") and pickup[1].get_max_transport_line_index() then + items = concatenate_tables(items,get_items_by_transport_line(pickup[1])) + end + elseif step == "check" then + -- Drop inventory insertion check + if drop[1] and drop[1].valid then + items = remove_noninsertable_items(items,drop[1]) + end end end - end - -- Filter candidate cleanup - if #items > 0 then - -- Deduplication - items = deduplicate_items(items) + -- Filter candidate cleanup + if #items > 0 then + -- Debug message + if __DebugAdapter then + __DebugAdapter.print("[Autofilter] Inserter at (" .. inserter.position.x .. "," .. inserter.position.y .. ") had its filter set to: " .. table.concat(items,", ")) + end - -- Writing filter until full - for slot = 1, inserter.filter_slot_count do - inserter.set_filter(slot,items[slot]) + -- Deduplication + items = deduplicate_items(items) + + -- Enable filters + inserter.use_filters = true + + -- Writing filters until full + for slot = 1, inserter.filter_slot_count do + inserter.set_filter(slot,items[slot]) + end end end end diff --git a/data.lua b/data.lua index ab4299e..505772c 100644 --- a/data.lua +++ b/data.lua @@ -5,16 +5,10 @@ data:extend( { type = "tips-and-tricks-item", name = "autofilter", - tag = "[entity=filter-inserter]", + tag = "[entity=inserter]", category = "inserters", indent = 1, order = "g", - trigger = - { - type = "build-entity", - entity = "filter-inserter", - count = 1 - }, dependencies = {"inserters"}, }, }) \ No newline at end of file diff --git a/info.json b/info.json index 086cfeb..c842e23 100644 --- a/info.json +++ b/info.json @@ -1,12 +1,12 @@ { "name": "Autofilter", - "version": "1.1.3", + "version": "2.0.0", "title": "Autofilter", "author": "Wyrrrd", "dependencies": [ - "base >= 1.1.0", - "(?) bobinserters >= 0.18.0" + "base >= 2.0.0", + "(?) bobinserters >= 1.3.0" ], "description": "Automatically set inserter filters based on adjacent inventory/belt.", - "factorio_version": "1.1" + "factorio_version": "2.0" } \ No newline at end of file diff --git a/locale/de/strings.cfg b/locale/de/strings.cfg index 97b5a0c..b06d8fe 100644 --- a/locale/de/strings.cfg +++ b/locale/de/strings.cfg @@ -2,13 +2,15 @@ Autofilter=Setzt Greifarmfilter automatisch, basierend auf angrenzenden Inventaren/Fließbändern. [mod-setting-name] -autofilter_mode=Autofilter-Modus +autofilter_enabled=Automatische Filter aktivieren +autofilter_mode=Automatischer-Filter-Modus [mod-setting-description] +autofilter_enabled=Aktiviert und setzt Filter beim Bauen von Greifarmen automatisch. autofilter_mode=Bestimmt die Reihenfolge der Auslesevorgänge (contents = Inventarinhalt, filter = Inventarfilter, belt = Fließbandinhalt, check = Zielinventarprüfung). [tips-and-tricks-item-name] autofilter=Autofilter [tips-and-tricks-item-description] -autofilter=Wenn du einen [entity=filter-inserter] von Hand platzierst, liest er den Inventarinhalt, die Inventarfilter oder den Fließbandinhalt and der Aufnahmeposition aus und setzt seinen Filter auf diese Gegenstände.\n\nFür die Konfiguration dieses Verhaltens gibt es nur ein Textfeld. Dieses kann während des Spiels angepasst werden. Du kannst jedes der folgenden Schlüsselworte in beliebiger Reihenfolge getrennt durch Leerzeichen in das Textfeld eintragen. Sie werden von links nach rechts abgearbeitet.\n\n - contents : Überprüft den Inventarinhalt an der [entity=filter-inserter]-Aufnahmeposition nach Filterkandidaten.\n - filter : Überprüft den Inventarfilter an der [entity=filter-inserter]-Aufnahmeposition nach Filterkandidaten.\n - belt : Überprüft die Gegenstände auf einem [entity=transport-belt] oder [entity=splitter] an der [entity=filter-inserter]-Aufnahmeposition nach Filterkandidaten.\n - check : Überprüft, ob die aktuellen Filterkandidaten in ein Inventar an der [entity=filter-inserter]-Ablageposition gelegt werden können, und entfernt sie aus der Kandidatenliste, wenn nicht.\n - Alles andere wird ignoriert. Wenn du alle Funktionen von Autofilter abschalten willst, schreibe einfach irgendetwas in das Textfeld.\n\nNachdem diese Punkte verarbeitet wurden, entfernt eine Deduplikation alle mehrfachen Vorkommen von Gegenständen aus der Filterkandidatenliste, und dann werden die Kandidaten in den [entity=filter-inserter]-Filter geschrieben, bis er voll ist. \ No newline at end of file +autofilter=Wenn du einen [entity=inserter] von Hand platzierst (und automatische Filter in den Optionen aktiviert sind), liest er den Inventarinhalt, die Inventarfilter oder den Fließbandinhalt and der Aufnahmeposition aus und setzt seinen Filter auf diese Gegenstände.\n\nFür die Konfiguration dieses Verhaltens gibt es nur ein Textfeld. Dieses kann während des Spiels angepasst werden. Du kannst jedes der folgenden Schlüsselworte in beliebiger Reihenfolge getrennt durch Leerzeichen in das Textfeld eintragen. Sie werden von links nach rechts abgearbeitet.\n\n - contents : Überprüft den Inventarinhalt an der [entity=filter-inserter]-Aufnahmeposition nach Filterkandidaten.\n - filter : Überprüft den Inventarfilter an der [entity=filter-inserter]-Aufnahmeposition nach Filterkandidaten.\n - belt : Überprüft die Gegenstände auf einem [entity=transport-belt] oder [entity=splitter] an der [entity=filter-inserter]-Aufnahmeposition nach Filterkandidaten.\n - check : Überprüft, ob die aktuellen Filterkandidaten in ein Inventar an der [entity=filter-inserter]-Ablageposition gelegt werden können, und entfernt sie aus der Kandidatenliste, wenn nicht.\n - Alles andere wird ignoriert. Wenn du alle Funktionen von Autofilter abschalten willst, schreibe einfach irgendetwas in das Textfeld.\n\nNachdem diese Punkte verarbeitet wurden, entfernt eine Deduplikation alle mehrfachen Vorkommen von Gegenständen aus der Filterkandidatenliste, und dann werden die Kandidaten in den [entity=inserter]-Filter geschrieben, bis er voll ist. \ No newline at end of file diff --git a/locale/en/strings.cfg b/locale/en/strings.cfg index bb7cf32..b4f9548 100644 --- a/locale/en/strings.cfg +++ b/locale/en/strings.cfg @@ -2,13 +2,15 @@ Autofilter=Automatically set inserter filters based on adjacent inventory/belt. [mod-setting-name] -autofilter_mode=Autofilter mode +autofilter_enabled=Enable automatic filters +autofilter_mode=Automatic filter mode [mod-setting-description] -autofilter_mode=Configure the priority of reading sources (contents = inventory contents, filter = inventory filter, belt = belt contents, check = check for insertability at drop position). +autofilter_enabled=Automatically enable and set filters when building inserters. +autofilter_mode=Configure the priority of reading sources (contents = inventory contents, filter = inventory filter, belt = belt contents, check = check for insertability at drop position). [tips-and-tricks-item-name] autofilter=Autofilter [tips-and-tricks-item-description] -autofilter=When you manually place a [entity=filter-inserter], it reads the inventory contents, inventory filters or belt contents on the pickup side and sets its filter to those items.\n\nThere is only one text field to enter configuration of this behaviour into. This can be done on the fly, while ingame. You can add each of the following keywords into the text field, in any order, separated by spaces. They will be processed left to right.\n\n - contents : Checks for filter candidates in the inventory contents at the pickup position of the [entity=filter-inserter].\n - filter : Checks for filter candidates in the inventory's filter settings at the pickup position of the [entity=filter-inserter].\n - belt : Checks for filter candidates in the items on a [entity=transport-belt] or [entity=splitter] at the pickup position of the [entity=filter-inserter].\n - check : Checks for the current filter candidates, if they could be inserted in the inventory at the drop position of the [entity=filter-inserter] and removes them from the candidate list, if unsuccessful.\n - Anything else gets ignored. If you want to disable all functionality of Autofilter, just write anything into the text field.\n\nAfter those are processed, a deduplication removes all but the first appearance of each item from the filter candidate list, and then the candidates are written to the filter of the [entity=filter-inserter] until it is full. \ No newline at end of file +autofilter=When you manually place a [entity=inserter] (and if automatic filters are enabled in settings), it reads the inventory contents, inventory filters or belt contents on the pickup side and sets its filter to those items.\n\nThere is only one text field to enter configuration of this behaviour into. This can be done on the fly, while ingame. You can add each of the following keywords into the text field, in any order, separated by spaces. They will be processed left to right.\n\n - contents : Checks for filter candidates in the inventory contents at the pickup position of the [entity=filter-inserter].\n - filter : Checks for filter candidates in the inventory's filter settings at the pickup position of the [entity=filter-inserter].\n - belt : Checks for filter candidates in the items on a [entity=transport-belt] or [entity=splitter] at the pickup position of the [entity=filter-inserter].\n - check : Checks for the current filter candidates, if they could be inserted in the inventory at the drop position of the [entity=filter-inserter] and removes them from the candidate list, if unsuccessful.\n - Anything else gets ignored. If you want to disable all functionality of Autofilter, just write anything into the text field.\n\nAfter those are processed, a deduplication removes all but the first appearance of each item from the filter candidate list, and then the candidates are written to the filter of the [entity=inserter] until it is full. \ No newline at end of file diff --git a/locale/fr/strings.cfg b/locale/fr/strings.cfg index c296ac9..4211ea4 100644 --- a/locale/fr/strings.cfg +++ b/locale/fr/strings.cfg @@ -2,13 +2,15 @@ Autofilter=Configuration automatique du filtre des bras robotisés en fonction des inventaires et convoyeurs adjacents. [mod-setting-name] +autofilter_enabled=Activer les filtres automatiques autofilter_mode=Mode du filtre automatique [mod-setting-description] +autofilter_enabled=Activer et définir automatiquement des filtres lors de la construction des bras robotisés. autofilter_mode=Sélectionner la priorité de la source (contents = contenu de l'inventaire, filter = filtre de l'inventaire, belt = contenu du convoyeur, check = s'assurer qu'il y a de la place dans la zone de dépôt). [tips-and-tricks-item-name] autofilter=Autofilter [tips-and-tricks-item-description] -autofilter=Permet à un [entity=filter-inserter] placé manuellement de reconnaître le contenu des inventaires, des filtres d'inventaire et des convoyeurs côté ramassage, pour pouvoir configurer automatiquement son propre filtre avec le même objet.\n\nCette zone de texte sert de configuration, et peut être changée en temps réel pendant le jeu. Pour se faire, ajoutez-y ces mots clefs, séparés par un espace et dans l'ordre souhaité, en fonction de vos choix : (L'odre de priorité ira de gauche à droite.)\n\n - contents : Recherche d'un objet filtrable dans l'inventaire situé côté ramassage du [entity=filter-inserter].\n - filter : Recherche d'un objet filtrable dans le filtre d'inventaire situé côté ramassage du [entity=filter-inserter].\n - belt : Recherche d'un objet filtrable dans le [entity=transport-belt] ou le [entity=splitter] situé côté ramassage du [entity=filter-inserter].\n - check : S'assurer que le [entity=filter-inserter] pourra transmettre l'objet envisagé par le filtre dans l'inventaire visé, ou le retirer de la liste des candidats dans le cas contraire.\nToute autre chose ajoutée sera ignorée, et si aucune de ces options n'est désirée il suffira de ne pas les y ajouter.\n\nLe filtre automatique fonctionne en faisant une liste provisoire de tous les candidats possibles, suivant les options choisies, puis élimine les doublons avant de transférer cette liste provisoire à celle du [entity=filter-inserter]. (Auquel cas, jusqu'à complétion.) \ No newline at end of file +autofilter=Permet à un [entity=inserter] placé manuellement (si les filtres automatiques sont activés dans les paramètres) de reconnaître le contenu des inventaires, des filtres d'inventaire et des convoyeurs côté ramassage, pour pouvoir configurer automatiquement son propre filtre avec le même objet.\n\nCette zone de texte sert de configuration, et peut être changée en temps réel pendant le jeu. Pour se faire, ajoutez-y ces mots clefs, séparés par un espace et dans l'ordre souhaité, en fonction de vos choix : (L'odre de priorité ira de gauche à droite.)\n\n - contents : Recherche d'un objet filtrable dans l'inventaire situé côté ramassage du [entity=filter-inserter].\n - filter : Recherche d'un objet filtrable dans le filtre d'inventaire situé côté ramassage du [entity=filter-inserter].\n - belt : Recherche d'un objet filtrable dans le [entity=transport-belt] ou le [entity=splitter] situé côté ramassage du [entity=filter-inserter].\n - check : S'assurer que le [entity=filter-inserter] pourra transmettre l'objet envisagé par le filtre dans l'inventaire visé, ou le retirer de la liste des candidats dans le cas contraire.\nToute autre chose ajoutée sera ignorée, et si aucune de ces options n'est désirée il suffira de ne pas les y ajouter.\n\nLe filtre automatique fonctionne en faisant une liste provisoire de tous les candidats possibles, suivant les options choisies, puis élimine les doublons avant de transférer cette liste provisoire à celle du [entity=filter-inserter]. (Auquel cas, jusqu'à complétion.) \ No newline at end of file diff --git a/settings.lua b/settings.lua index 8743f0a..54ba0f4 100644 --- a/settings.lua +++ b/settings.lua @@ -1,9 +1,16 @@ data:extend({ + { + type = "bool-setting", + name = "autofilter_enabled", + default_value = true, + setting_type = "runtime-per-user", + order = "autofilter-a", + }, { type = "string-setting", name = "autofilter_mode", default_value = "contents belt", setting_type = "runtime-per-user", - order = "autofilter", + order = "autofilter-b", }, }) \ No newline at end of file