1
0
mirror of https://github.com/Wyrrrd/Autofilter.git synced 2026-06-01 22:02:27 +02:00

Initial release

This commit is contained in:
Wyrrrd
2020-02-22 03:25:25 +01:00
parent 7d02ab1025
commit 531243a765
8 changed files with 96 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
# Autofilter
![mod thumbnail](https://raw.githubusercontent.com/Wyrrrd/Autofilter/master/thumbnail.png)
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.
+6
View File
@@ -0,0 +1,6 @@
---------------------------------------------------------------------------------------------------
Version: 0.18.0
Date: 22. 2. 2020
Changes:
- Initial release
---------------------------------------------------------------------------------------------------
+44
View File
@@ -0,0 +1,44 @@
--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
end
return items
end
local function get_items_by_filter(inserter,inventory)
local items = {}
for slot = 1,#inventory,1 do
if #items < inserter.filter_slot_count and inventory.get_filter(slot) then
items[#items+1] = inventory.get_filter(slot)
end
end
return items
end
local function on_built_entity(event)
local inserter = event.created_entity
if inserter.filter_slot_count then
local inventory = inserter.surface.find_entities_filtered({position = inserter.pickup_position, limit = 1})[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)
end
end
end
end
end
--event handling
script.on_event(defines.events.on_built_entity, on_built_entity,{{filter="type", type = "inserter"}})
+9
View File
@@ -0,0 +1,9 @@
{
"name": "Autofilter",
"version": "0.18.0",
"title": "Autofilter",
"author": "Wyrrrd",
"dependencies": ["base >= 0.18.0"],
"description": "Automatically set inserter filters based on adjacent inventory.",
"factorio_version": "0.18"
}
+10
View File
@@ -0,0 +1,10 @@
[mod-setting-name]
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
+10
View File
@@ -0,0 +1,10 @@
[mod-setting-name]
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
+10
View File
@@ -0,0 +1,10 @@
data:extend({
{
type = "string-setting",
name = "Autofilter_Mode",
default_value = "content",
allowed_values = {"content","filter","none"},
setting_type = "runtime-per-user",
order = "a",
},
})
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB