1
0
mirror of https://github.com/Wyrrrd/Autofilter.git synced 2026-06-30 18:07:19 +02:00

21 Commits

Author SHA1 Message Date
Wyrrrd ef61bd94dd A lot
- Added option to read belt at pickup position
- Added option to leave out filter candidates if they cannot enter inventory at drop position
- Changed modus setting format to allow for more customization
- Added deduplication to filter candidates (needed for belt transport lines)
- Removed integrations for Informatron, Factorio Wiki Mod and Booktorio (feels like bloat)
2021-04-16 20:23:04 +02:00
Wyrrrd 461a88e6bd Version bump for base game 1.1 2020-12-02 18:51:08 +01:00
Wyrrrd bfc4e6aa3d Added integration with Booktorio 2020-04-03 13:42:39 +02:00
Wyrrrd c36e55c961 Added wiki integration
Also moved graphics to be used by both integrations
2020-03-29 14:03:06 +02:00
Wyrrrd e6164a2d96 Update changelog.txt
Fixed formatting (again)
2020-03-07 10:47:14 +01:00
Wyrrrd e2ece3e288 Update README.md
i did a link oopsie
2020-03-06 15:33:24 +01:00
Wyrrrd 31e723c8df Update README.md
Matched to mod portal description
2020-03-06 15:29:51 +01:00
Wyrrrd 27fa26ee13 Merged Informatron pages into one 2020-03-06 15:11:53 +01:00
Wyrrrd 8ce0cbbf8e Multiple things
- Fixed changelog (again)
- Added integration for Informatron
- Moved some capitalisation around
- Added mode=none check for performance
2020-03-05 18:34:55 +01:00
Wyrrrd aed3caddda Fixed empty filter check
Now checks all slots instead of just one
2020-02-27 06:34:36 +01:00
Wyrrrd d3ca77eede Update changelog.txt
Fixed formatting (again)
2020-02-24 19:18:50 +01:00
Wyrrrd 94e7309dd0 Update README.md
Matched with mod portal description
2020-02-24 19:09:55 +01:00
Wyrrrd a7a7816f89 Update changelog.txt
Updated retroactive downgrade
2020-02-24 18:58:40 +01:00
Wyrrrd 3a859a941d Added check for empty filter and whitelist mode
Avoids overwriting filter on replacing preexisting inserters/ghosts
2020-02-24 18:56:01 +01:00
Wyrrrd 50d63e8e3c Added hidden dependency
Fixes setting filter from wrong inventory when pickup location is rotated by Bob's Adjustable Inserters
2020-02-24 18:43:00 +01:00
Wyrrrd d87491c622 Added translated mod description 2020-02-24 18:27:24 +01:00
Wyrrrd 5ed50dcfb3 Added entity type check
Apparently event filters are not applied to mod-raised events
2020-02-23 15:17:15 +01:00
Wyrrrd 312cb20225 Added incompatibility (for now) 2020-02-23 10:38:53 +01:00
Wyrrrd 7ec64d2f62 Added incompatibility (for now) 2020-02-23 10:36:12 +01:00
Wyrrrd fc2afea961 Minor improvements
- Typos
- Code style
- Better thumbnail
2020-02-23 00:45:02 +01:00
Wyrrrd acb9688477 Update README.md
Matched with mod portal desciption
2020-02-22 17:11:04 +01:00
9 changed files with 292 additions and 59 deletions
+1
View File
@@ -0,0 +1 @@
*.zip
+23 -5
View File
@@ -1,7 +1,25 @@
# Autofilter
![mod thumbnail](https://raw.githubusercontent.com/Wyrrrd/Autofilter/master/thumbnail.png)
<img src="https://raw.githubusercontent.com/Wyrrrd/Autofilter/master/thumbnail.png" width="128" height="128">
Description
- When you place a filter inserter, it reads either the inventory contents or inventory filters on the input side and sets it's filter to those items.
- Works only until the inserter filter is full (of course).
- The mode can be changed or disabled in player mod settings on the fly as needed.
### 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.
### 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.
+ **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 contents of 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.
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.
### Compatibility
This mod should work with all modded filter inserters, but I specifically added compatibility for the following mods:
+ [Bob's Adjustable Inserters](https://mods.factorio.com/mod/bobinserters) - rotated pickup positions
### Locale
If you want to contribute by translating this mod, you can view the existing translations [here](https://github.com/Wyrrrd/Autofilter/tree/master/locale). I'd be happy to add your language and credits to the next release.
+74 -7
View File
@@ -1,25 +1,92 @@
---------------------------------------------------------------------------------------------------
Version: 1.1.1
Date: 2021-04-16
Features:
- Added option to read belt at pickup position
- Added option to leave out filter candidates if they cannot enter inventory at drop position
Changes:
- Changed modus setting format to allow for more customization
- Added deduplication to filter candidates (needed for belt transport lines)
- Removed integrations for Informatron, Factorio Wiki Mod and Booktorio (feels like bloat)
---------------------------------------------------------------------------------------------------
Version: 1.1.0
Date: 2020-12-02
Changes:
- Version bump for base game 1.1
---------------------------------------------------------------------------------------------------
Version: 0.18.10
Date: 2020-04-03
Features:
- Added integration with Booktorio (for german and english locales)
---------------------------------------------------------------------------------------------------
Version: 0.18.9
Date: 2020-03-29
Features:
- Added integration with Factorio Wiki Mod (for german and english locales)
---------------------------------------------------------------------------------------------------
Version: 0.18.8
Date: 2020-03-06
Changes:
- Merged Informatron pages into single one
---------------------------------------------------------------------------------------------------
Version: 0.18.7
Date: 2020-03-05
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: 2020-02-27
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
---------------------------------------------------------------------------------------------------
Version: 0.18.5
Date: 2020-02-24
Changes:
- 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
---------------------------------------------------------------------------------------------------
Version: 0.18.4
Date: 2020-02-23
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
---------------------------------------------------------------------------------------------------
Version: 0.18.3
Date: 2020-02-23
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
---------------------------------------------------------------------------------------------------
Version: 0.18.2
Date: 22. 2. 2020
Date: 2020-02-22
Changes:
- Matched changelog file format to what Factorio expects
Info:
- Also downgraded to Factorio 0.17, see below
---------------------------------------------------------------------------------------------------
Version: 0.18.1
Date: 22. 2. 2020
Date: 2020-02-22
Bugfixes:
- Added missing entity check (caused game crash on inserter placement without adjacent entity)
---------------------------------------------------------------------------------------------------
Version: 0.18.0
Date: 22. 2. 2020
Date: 2020-02-22
Features:
- Added automatic setting of filter on inserter placement
- Added player mod setting to control mod behaviour
---------------------------------------------------------------------------------------------------
Version: 0.17.0
Date: 22. 2. 2020
Date: 2020-02-27
Info:
- Retroactive downgrade
---------------------------------------------------------------------------------------------------
- Retroactive downgrade
+171 -25
View File
@@ -1,41 +1,187 @@
--control.lua
--functions definitions
local function get_items_by_content(inserter,inventory)
local items = {}
for item,count in pairs(inventory.get_contents()) do
if #items < inserter.filter_slot_count then
items[#items+1] = item
end
local function concatenate_tables(table1,table2)
for i = 1,#table2 do
table1[#table1+1]=table2[i]
end
return items
return table1
end
local function get_items_by_filter(inserter,inventory)
local items = {}
for slot = 1,#inventory do
if #items < inserter.filter_slot_count and inventory.get_filter(slot) then
items[#items+1] = inventory.get_filter(slot)
local function string_to_table(str)
local words = {}
for word in str:gmatch("([^%s]+)") do
words[#words+1] = word
end
return words
end
local function is_filter_empty(inserter)
for slot = 1,inserter.filter_slot_count do
if inserter.get_filter(slot) then
return false
end
end
return items
return true
end
local function deduplicate_items(items)
local dedup_items = {}
local marker = false
for i=1,#items do
for j=i+1,#items do
if items[i] == items[j] then
marker = true
end
end
if not marker then
dedup_items[#dedup_items+1]=items[i]
end
marker = false
end
return dedup_items
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.cargo_wagon,
defines.inventory.turret_ammo,
defines.inventory.artillery_turret_ammo,
defines.inventory.artillery_wagon_ammo,
}
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
end
end
end
if no_inventory_flag then
insert_items = items
break
end
if item_insertable_flag then
insert_items[#insert_items+1]=items[i]
item_insertable_flag = false
end
end
return insert_items
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
end
return content_items
end
local function get_items_by_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)
end
end
return filter_items
end
local function get_items_by_transport_line(belt)
local belt_items = {}
for i = 1,belt.get_max_transport_line_index() do
local line = belt.get_transport_line(i)
if line and line.valid then
belt_items = concatenate_tables(belt_items,get_items_by_content(line))
end
end
return belt_items
end
local function on_built_entity(event)
-- Read settings
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.filter_slot_count 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)
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
local pickup = inserter.surface.find_entities_filtered({position = inserter.pickup_position, force = inserter.force, surface = inserter.surface, limit = 1})
local drop = inserter.surface.find_entities_filtered({position = inserter.drop_position, force = inserter.force, surface = inserter.surface, limit = 1})
if pickup[1] and pickup[1].valid then
-- Prequisites
local inventory_pickup = pickup[1].get_output_inventory()
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
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 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
-- Filter candidate cleanup
if #items > 0 then
-- Deduplication
items = deduplicate_items(items)
-- Writing filter until full
for slot = 1, inserter.filter_slot_count do
inserter.set_filter(slot,items[slot])
end
end
end
end
+10 -4
View File
@@ -1,9 +1,15 @@
{
"name": "Autofilter",
"version": "0.18.2",
"version": "1.1.1",
"title": "Autofilter",
"author": "Wyrrrd",
"dependencies": ["base >= 0.18.0"],
"description": "Automatically set inserter filters based on adjacent inventory.",
"factorio_version": "0.18"
"dependencies": [
"base >= 1.1.0",
"(?) bobinserters >= 0.18.0",
"? Booktorio >= 1.1.0",
"? informatron >= 0.1.5",
"? wiki >= 0.18.01"
],
"description": "Automatically set inserter filters based on adjacent inventory/belt.",
"factorio_version": "1.1"
}
+5 -7
View File
@@ -1,10 +1,8 @@
[mod-description]
Autofilter=Setzt Greifarmfilter automatisch, basierend auf angrenzenden Inventaren/Fließbändern.
[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.
[string-mod-setting]
Autofilter_Mode-content=Inhalt
Autofilter_Mode-filter=Filter
Autofilter_Mode-none=Keiner
autofilter_mode=Bestimmt die Reihenfolge der Auslesevorgänge (contents = Inventarinhalt, filter = Inventarfilter, belt = Fließbandinhalt, check = Zielinventarprüfung).
+5 -7
View File
@@ -1,10 +1,8 @@
[mod-description]
Autofilter=Automatically set inserter filters based on adjacent inventory/belt.
[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.
[string-mod-setting]
Autofilter_Mode-content=Content
Autofilter_Mode-filter=Filter
Autofilter_Mode-none=None
autofilter_mode=Configure the priority of reading sources (contents = inventory contents, filter = inventory filter, belt = belt contents, check = check for insertability at drop position).
+3 -4
View File
@@ -1,10 +1,9 @@
data:extend({
{
type = "string-setting",
name = "Autofilter_Mode",
default_value = "content",
allowed_values = {"content","filter","none"},
name = "autofilter_mode",
default_value = "contents belt",
setting_type = "runtime-per-user",
order = "a",
order = "autofilter",
},
})
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 110 KiB

After

Width:  |  Height:  |  Size: 174 KiB