-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search Engine: Add support for fluid containers
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local search_utils = require "search_utils" | ||
local table = require "__flib__.table" | ||
local gui = require "__flib__.gui" | ||
|
||
local plugin = { | ||
options_type = "fluids", | ||
options_search = function(force, text) | ||
local filtered = table.filter(game.fluid_prototypes, function(_, key) | ||
return search_utils.name_contains(key, text) | ||
end) | ||
return table.map(filtered, function(_, key) return key end) | ||
end, | ||
options_render = function(context, results) | ||
for name in pairs(results) do | ||
local sprite_button = context.parent.add { | ||
type = "sprite-button", | ||
name = "fluids_result__" .. name, | ||
style = "slot_button", | ||
sprite = "fluid/" .. name | ||
} | ||
sprite_button.tooltip = game.fluid_prototypes[name].localised_name | ||
end | ||
gui.update_filters("small_search_window.choose_things.result_button", context.player.index, {"fluids_result"}, "add") | ||
end | ||
} | ||
|
||
return plugin |
36 changes: 36 additions & 0 deletions
36
factorio-search-engine_0.0.1/plugins/fluids/fluids_container.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
local CONTAINERS = "Containers" | ||
|
||
return { | ||
search_options = { | ||
fluids = { CONTAINERS } | ||
}, | ||
search_loops = { | ||
fluids = { | ||
[CONTAINERS] = function(_, _, task_data) | ||
local player = game.get_player(task_data.player_index) | ||
return player.surface.find_entities_filtered { | ||
type = "storage-tank", | ||
force = player.force | ||
} | ||
end | ||
} | ||
}, | ||
search_filters = { | ||
fluids = { | ||
[CONTAINERS] = { | ||
function(player, search_params, item, results) | ||
if not item.valid then return end | ||
local amount = item.get_fluid_count(search_params.name) | ||
if amount <= 0 then return nil end | ||
table.insert(results, { | ||
entity = item, | ||
location = item.position, | ||
owner = item.last_user, | ||
count = amount | ||
}) | ||
end | ||
} | ||
} | ||
} | ||
-- game.print(tostring(#game.player.surface.find_entities_filtered { type="transport-belt", force=game.player.force })) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters