mirror of
https://github.com/Wyrrrd/Autofilter.git
synced 2026-03-26 00:19:48 +01:00
Fix and add stuff
- Add shortcut tile - Fix filter mode - Fix check mode - Add uk locale
This commit is contained in:
@@ -1,4 +1,14 @@
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 2.0.1
|
||||
Date: 2024-10-26
|
||||
Features:
|
||||
- Replace enable checkbox in settings with shortcut tile (CTRL+SHIFT+A)
|
||||
Bugfixes:
|
||||
- Fix filter mode
|
||||
- Fix check mode
|
||||
Locale:
|
||||
- Add ukrainian locale (thanks to Met_en_Bouldry)
|
||||
---------------------------------------------------------------------------------------------------
|
||||
Version: 2.0.0
|
||||
Date: 2024-10-25
|
||||
Features:
|
||||
|
||||
129
control.lua
129
control.lua
@@ -1,6 +1,20 @@
|
||||
--control.lua
|
||||
|
||||
--functions definitions
|
||||
local function get_item_name(item)
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
local itemname = item
|
||||
if type(itemname) ~= "string" then
|
||||
itemname = itemname.name
|
||||
if type(itemname) ~= "string" then
|
||||
itemname = itemname.name
|
||||
end
|
||||
end
|
||||
return itemname
|
||||
end
|
||||
|
||||
local function concatenate_tables(table1,table2)
|
||||
for i = 1,#table2 do
|
||||
table1[#table1+1]=table2[i]
|
||||
@@ -16,6 +30,16 @@ local function string_to_table(str)
|
||||
return words
|
||||
end
|
||||
|
||||
local function toggle_shortcut(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
local input = event.prototype_name or event.input_name
|
||||
|
||||
if player and input == "autofilter" then
|
||||
-- Toggle shortcut state
|
||||
player.set_shortcut_toggled(input, not player.is_shortcut_toggled(input))
|
||||
end
|
||||
end
|
||||
|
||||
local function is_filter_empty(inserter)
|
||||
for slot = 1,inserter.filter_slot_count do
|
||||
if inserter.get_filter(slot) then
|
||||
@@ -44,38 +68,49 @@ end
|
||||
|
||||
local function remove_noninsertable_items(items,entity)
|
||||
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.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
|
||||
chest = {defines.inventory.chest},
|
||||
furnace = {defines.inventory.furnace_source},
|
||||
roboport = {defines.inventory.roboport_robot, defines.inventory.roboport_material},
|
||||
assembling_machine = {defines.inventory.assembling_machine_input},
|
||||
lab = {defines.inventory.lab_input},
|
||||
rocket_silo = {defines.inventory.rocket_silo_rocket, defines.inventory.rocket_silo_input},
|
||||
cargo_wagon = {defines.inventory.cargo_wagon},
|
||||
turret = {defines.inventory.turret_ammo},
|
||||
artillery_turret = {defines.inventory.artillery_turret_ammo},
|
||||
artillery_wagon = {defines.inventory.artillery_wagon_ammo},
|
||||
spider = {defines.inventory.spider_ammo},
|
||||
hub = {defines.inventory.hub_main},
|
||||
cargo_landing_pad = {defines.inventory.cargo_landing_pad_main}
|
||||
}
|
||||
|
||||
local insert_items = {}
|
||||
local no_inventory_flag = true
|
||||
local item_insertable_flag = false
|
||||
|
||||
for i=1,#items do
|
||||
for _,search_inventory in pairs(search_inventories) do
|
||||
local inventory = entity.get_inventory(search_inventory)
|
||||
if inventory then
|
||||
no_inventory_flag = false
|
||||
if inventory.can_insert(items[i]) then
|
||||
item_insertable_flag = true
|
||||
|
||||
-- Check fuel inventory
|
||||
local inventory = entity.get_fuel_inventory()
|
||||
if inventory and inventory.valid then
|
||||
no_inventory_flag = false
|
||||
if inventory.can_insert({name=items[i]}) then
|
||||
item_insertable_flag = true
|
||||
end
|
||||
end
|
||||
|
||||
-- Check other inventories
|
||||
if search_inventories[entity.prototype] then
|
||||
for _,search_inventory in pairs(search_inventories[entity.prototype]) do
|
||||
inventory = entity.get_inventory(search_inventory)
|
||||
if inventory and inventory.valid then
|
||||
no_inventory_flag = false
|
||||
if inventory.can_insert({name=items[i]}) then
|
||||
item_insertable_flag = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if no_inventory_flag then
|
||||
insert_items = items
|
||||
break
|
||||
@@ -91,16 +126,30 @@ 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.name
|
||||
content_items[#content_items+1] = get_item_name(item)
|
||||
end
|
||||
return content_items
|
||||
end
|
||||
|
||||
local function get_items_by_filter(inventory)
|
||||
local function get_items_by_inventory_filter(inventory)
|
||||
local filter_items = {}
|
||||
for slot = 1,#inventory do
|
||||
if inventory.get_filter(slot) then
|
||||
filter_items[#filter_items+1] = inventory.get_filter(slot)
|
||||
filter_items[#filter_items+1] = get_item_name(inventory.get_filter(slot))
|
||||
end
|
||||
end
|
||||
return filter_items
|
||||
end
|
||||
|
||||
local function get_items_by_entity_filter(entity)
|
||||
local filter_items = {}
|
||||
for slot = 1,entity.filter_slot_count do
|
||||
if entity.get_filter(slot) then
|
||||
-- Debug message
|
||||
if __DebugAdapter then
|
||||
__DebugAdapter.print("[Autofilter] " .. get_item_name(entity.get_filter(slot)))
|
||||
end
|
||||
filter_items[#filter_items+1] = get_item_name(entity.get_filter(slot))
|
||||
end
|
||||
end
|
||||
return filter_items
|
||||
@@ -118,12 +167,9 @@ local function get_items_by_transport_line(belt)
|
||||
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)
|
||||
|
||||
if enabled then
|
||||
if game.players[event.player_index].is_shortcut_toggled("autofilter") then
|
||||
local inserter = event.entity
|
||||
local mode = string_to_table(game.players[event.player_index].mod_settings["autofilter_mode"].value)
|
||||
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
|
||||
@@ -165,7 +211,17 @@ local function on_built_entity(event)
|
||||
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))
|
||||
items = concatenate_tables(items,get_items_by_inventory_filter(inventory_pickup))
|
||||
if __DebugAdapter then
|
||||
__DebugAdapter.print("[Autofilter] Inventory: " .. table.concat(items,", "))
|
||||
end
|
||||
end
|
||||
-- Read entity filter at pickup, write to filter
|
||||
if pickup[1].filter_slot_count > 0 then
|
||||
items = concatenate_tables(items,get_items_by_entity_filter(pickup[1]))
|
||||
if __DebugAdapter then
|
||||
__DebugAdapter.print("[Autofilter] Entity: " .. table.concat(items,", "))
|
||||
end
|
||||
end
|
||||
elseif step == "belt" then
|
||||
-- Read belt transport lines at pickup, write to filter
|
||||
@@ -182,20 +238,20 @@ local function on_built_entity(event)
|
||||
|
||||
-- Filter candidate cleanup
|
||||
if #items > 0 then
|
||||
-- Deduplication
|
||||
items = deduplicate_items(items)
|
||||
|
||||
-- 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
|
||||
|
||||
-- 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])
|
||||
inserter.set_filter(slot,items[slot])
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -206,4 +262,5 @@ local function on_built_entity(event)
|
||||
end
|
||||
|
||||
--event handling
|
||||
script.on_event({defines.events.on_lua_shortcut, "autofilter"}, toggle_shortcut)
|
||||
script.on_event(defines.events.on_built_entity, on_built_entity,{{filter="type", type = "inserter"}})
|
||||
39
data.lua
39
data.lua
@@ -2,13 +2,34 @@
|
||||
|
||||
data:extend(
|
||||
{
|
||||
{
|
||||
type = "tips-and-tricks-item",
|
||||
name = "autofilter",
|
||||
tag = "[entity=inserter]",
|
||||
category = "inserters",
|
||||
indent = 1,
|
||||
order = "g",
|
||||
dependencies = {"inserters"},
|
||||
},
|
||||
{
|
||||
type = "tips-and-tricks-item",
|
||||
name = "autofilter",
|
||||
tag = "[entity=inserter]",
|
||||
category = "inserters",
|
||||
indent = 1,
|
||||
order = "g",
|
||||
dependencies = {"inserters"},
|
||||
},
|
||||
{
|
||||
type = "custom-input",
|
||||
name = "autofilter",
|
||||
key_sequence = "CONTROL + SHIFT + A",
|
||||
consuming = "game-only",
|
||||
action = "lua"
|
||||
},
|
||||
{
|
||||
type = "shortcut",
|
||||
name = "autofilter",
|
||||
action = "lua",
|
||||
order = "h[combatRobot]",
|
||||
technology_to_unlock = "electronics",
|
||||
associated_control_input = "autofilter",
|
||||
toggleable = true,
|
||||
icon = "__Autofilter__/graphics/autofilter.png",
|
||||
icon_size = 32,
|
||||
small_icon = "__Autofilter__/graphics/autofilter-small.png",
|
||||
small_icon_size = 24,
|
||||
unavailable_until_unlocked = true,
|
||||
},
|
||||
})
|
||||
BIN
graphics/autofilter-small-white.png
Normal file
BIN
graphics/autofilter-small-white.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 913 B |
BIN
graphics/autofilter-small.png
Normal file
BIN
graphics/autofilter-small.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 916 B |
BIN
graphics/autofilter-white.png
Normal file
BIN
graphics/autofilter-white.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 993 B |
BIN
graphics/autofilter.png
Normal file
BIN
graphics/autofilter.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1000 B |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Autofilter",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.1",
|
||||
"title": "Autofilter",
|
||||
"author": "Wyrrrd",
|
||||
"dependencies": [
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
Autofilter=Setzt Greifarmfilter automatisch, basierend auf angrenzenden Inventaren/Fließbändern.
|
||||
|
||||
[mod-setting-name]
|
||||
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]
|
||||
@@ -15,3 +13,5 @@ autofilter=Autofilter
|
||||
[tips-and-tricks-item-description]
|
||||
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.
|
||||
|
||||
[shortcut-name]
|
||||
autofilter=Autofilter
|
||||
@@ -2,15 +2,16 @@
|
||||
Autofilter=Automatically set inserter filters based on adjacent inventory/belt.
|
||||
|
||||
[mod-setting-name]
|
||||
autofilter_enabled=Enable automatic filters
|
||||
autofilter_mode=Automatic filter mode
|
||||
|
||||
[mod-setting-description]
|
||||
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=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=inserter].\n - filter : Checks for filter candidates in the inventory's filter settings at the pickup position of the [entity=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=inserter].\n - check : Checks for the current filter candidates, if they could be inserted in the inventory at the drop position of the [entity=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.
|
||||
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=inserter].\n - filter : Checks for filter candidates in the inventory's filter settings at the pickup position of the [entity=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=inserter].\n - check : Checks for the current filter candidates, if they could be inserted in the inventory at the drop position of the [entity=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.
|
||||
|
||||
[shortcut-name]
|
||||
autofilter=Autofilter
|
||||
@@ -2,11 +2,9 @@
|
||||
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]
|
||||
@@ -14,3 +12,4 @@ autofilter_mode=Sélectionner la priorité de la source (contents = contenu de l
|
||||
[tips-and-tricks-item-description]
|
||||
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=inserter].\n - filter : Recherche d'un objet filtrable dans le filtre d'inventaire situé côté ramassage du [entity=inserter].\n - belt : Recherche d'un objet filtrable dans le [entity=transport-belt] ou le [entity=splitter] situé côté ramassage du [entity=inserter].\n - check : S'assurer que le [entity=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=inserter]. (Auquel cas, jusqu'à complétion.)
|
||||
|
||||
[shortcut-name]
|
||||
@@ -2,11 +2,9 @@
|
||||
Autofilter=Автоматичне налаштування фільтрів маніпуляторів на основі сусідніх запасів/стрічок.
|
||||
|
||||
[mod-setting-name]
|
||||
autofilter_enabled=Увімкнути автоматичні фільтри
|
||||
autofilter_mode=Автоматичний режим фільтрації
|
||||
|
||||
[mod-setting-description]
|
||||
autofilter_enabled=Автоматично вмикати та налаштовувати фільтри під час створення маніпулятора.
|
||||
autofilter_mode=Налаштуйте пріоритет джерел зчитування (contents = вміст інвентарю, filter = фільтр інвентарю, belt = вміст стрічки, check = перевірка на можливість вставки в позиції падіння).
|
||||
|
||||
[tips-and-tricks-item-name]
|
||||
@@ -15,3 +13,5 @@ autofilter=Автофільтр
|
||||
[tips-and-tricks-item-description]
|
||||
autofilter=Коли ви вручну розміщуєте [entity=inserter] (і якщо у налаштуваннях увімкнено автоматичні фільтри), він зчитує вміст інвентарю, фільтри інвентарю або вміст конвеєра на стороні підбирання і встановлює свій фільтр на ці предмети.\n\nІснує лише одне текстове поле для введення конфігурації цієї поведінки. Це можна зробити на льоту, під час гри. Ви можете додати кожне з наведених нижче ключових слів до текстового поля у довільному порядку, розділяючи їх пробілами. Вони будуть оброблені зліва направо.\n\n - вміст : Перевіряє наявність кандидатів на фільтр у вмісті інвентарю на позиції збирання [entity=inserter].\n - filter : Перевіряє наявність кандидатів на фільтр у налаштуваннях фільтра інвентарю на позиції збирання [entity=inserter].\n - belt : Перевіряє наявність кандидатів на фільтр у предметах на [entity=transport-belt] або [entity=splitter] у позиції збору [entity=inserter].\n - check : Перевіряє поточні кандидати на фільтр, якщо їх можна вставити в інвентар у позиції скидання [entity=inserter] і видаляє їх зі списку кандидатів, якщо це не вдасться.\n - Все інше ігнорується. Якщо ви хочете вимкнути всю функціональність автофільтру, просто напишіть будь-що у текстовому полі.\n\nПісля обробки цих даних дедуплікація вилучає зі списку кандидатів фільтру всі, крім першої появи кожного елемента, а потім кандидати записуються до фільтру [entity=inserter], доки він не буде заповнений.
|
||||
|
||||
[shortcut-name]
|
||||
autofilter=Автофільтр
|
||||
@@ -1,11 +1,4 @@
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user