From 883a9425ffd396664e07590e76116fbfcbdf20ce Mon Sep 17 00:00:00 2001 From: Wyrrrd Date: Wed, 6 Nov 2024 15:17:53 +0100 Subject: [PATCH] Fix and add stuff - Add shortcut tile - Fix filter mode - Fix check mode - Add uk locale --- changelog.txt | 10 +++ control.lua | 129 ++++++++++++++++++++-------- data.lua | 39 +++++++-- graphics/autofilter-small-white.png | Bin 0 -> 913 bytes graphics/autofilter-small.png | Bin 0 -> 916 bytes graphics/autofilter-white.png | Bin 0 -> 993 bytes graphics/autofilter.png | Bin 0 -> 1000 bytes info.json | 2 +- locale/de/strings.cfg | 4 +- locale/en/strings.cfg | 7 +- locale/fr/strings.cfg | 3 +- locale/uk/strings.cfg | 4 +- settings.lua | 7 -- 13 files changed, 143 insertions(+), 62 deletions(-) create mode 100644 graphics/autofilter-small-white.png create mode 100644 graphics/autofilter-small.png create mode 100644 graphics/autofilter-white.png create mode 100644 graphics/autofilter.png diff --git a/changelog.txt b/changelog.txt index 59349dd..7450000 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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: diff --git a/control.lua b/control.lua index 69dadd6..daae181 100644 --- a/control.lua +++ b/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"}}) \ No newline at end of file diff --git a/data.lua b/data.lua index 505772c..110a995 100644 --- a/data.lua +++ b/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, + }, }) \ No newline at end of file diff --git a/graphics/autofilter-small-white.png b/graphics/autofilter-small-white.png new file mode 100644 index 0000000000000000000000000000000000000000..23ae94352b4c0722c633f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-5|T7aPs(YMQ5 z_z+q);ryzs8M|aSZ`)dFI010qNS#tmY3ljhU3ljkVnw%H_00IR`L_t(o zNA1_kE(1{<$ML#^h}iG|V(SUKfy4{&3M`40HxOcDBWws3uEB<|VTHtHfej%paf`4Z zaaZ5pv?rNzI?l|Xk@zK_c6!=5|Nl&&IHB@U-4@?8?n8GoB@_NwRN0>mD1`@gm)2h&kGnl-k@8iTj$0<5c z39qjIB0Rt##&M~EZ;1bF>N?Zhs&R+{WSjxf$Fc^!xJKNVqrX8PG`GK2#u-r5@dk!4 zg9pS(9`2#JH0LHvQfJ54kzWaFF^wlg%`>K;xisgeTAv1dN>PVpJR)qg&k8h$=CaiY zY(R=pk2Qp8;sM&H0h+@$x5qkY(S!}Syd8SYIvQb{D}!~=LPybpZ3L|idQPutMiFdt zW%&3h$d*TppdULL$dYXgU<^+h_$saqC|aiHun5~irLiT&E#A^%C2RvKybAreT);l`MWyI$Xnk;9HN8YR z16uF9(S{z(;|9+NRa`NDPAjyn4aex;%?q?oHCj;)H8YA`IK?!Oqa+gVj4W*ZQh-P& P00000NkvXXu0mjfNy5k} literal 0 HcmV?d00001 diff --git a/graphics/autofilter.png b/graphics/autofilter.png new file mode 100644 index 0000000000000000000000000000000000000000..25aa2d4b8835eb6023f87e8e09182e890777d33d GIT binary patch literal 1000 zcmV>P)4Tx04UFukxeK>Q5?m829ZXJSx6RdF|14p$x=h4sA*=DuZ8#Cn4#u9(|aQu zOJ%Dpd~6IBHr8w{Y?V?zN_KWu#75Kezi-q`YLr{I`|I3$PWPS*fkM`_+`3+{?7R~n zk7_fsb6Ud-bu`k-5MkYPb5n`2Bvr@f9W`pbji@aCH=0vRt_d}o@UWS4^1_S4gX{U6 z;yvMzxvZyz&xCs%xuEca(v1?oD$e*EP?;eo86Oc232T`OHY(U$b}Zom;c&{bB|k7z z;*{bI#a4FB{JE!kVQ|TwPAFYwC*w>oMGOstHCD)yCnBpYic4JfqgDJJzCR`|LtHDE z;uvKW3*Gml{@{1FZo0p(loX6Y{j=x2cR|Ar6t_L^>&Wwp$58tOmv-5|T7aPs(YMQ5 z_z+q);ryzs8M|aSZ`)dFI010qNS#tmY3ljhU3ljkVnw%H_00In2L_t(o zN9~teOBGQVhPMYgcpxP0LXgTE|4VUqCOc=vh(|&33fZjqE^uaXGd5U_yL_PUwdYP~K41 zO!gVSU;>8Vn+?H$T7f@s1#Uq*s4@n^+vPLNvq>0%&tUBRtN~@GWia?{xC&)ua0mAU z4E_?1bliY)7XCsT48XzbQcwopfEgGCgYUqR@(h@z&crHQ2Xi8?UyKa)6o%m$Y(ljB z8ScPy*aCmg6ujpJ_>7QG$+`@8VGdGEI8yJq2R@^;9>8nZhP;4T?DGolL*3*k9>ROr zgS^1vHTw+0B{)^F$z@{xsGfV_2IR@$kHN*p*ZEYXWVdgHD`q#`gyV_z8)jh~zSt0> z*m9g*O5cIAp`7+0+q`BU6}5uK8psB!C4+{*QTL>7NJ41ea(Q&h30!!4bQ8b;O^*5^dX0@Lx|@e W!jvLV_OQeN0000