Skip to content

Commit

Permalink
Search Engine: Show search progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Oct 14, 2020
1 parent e0c2928 commit 4f90730
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 15 deletions.
13 changes: 8 additions & 5 deletions factorio-search-engine_0.0.1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ Use Async to perform the search in many cases. Use a somewhat good filter for th

## TODO Next steps

- Progress bar (especially important for Signals search)
- Producer/Consumer search (for items and fluids)
- Table-like results when searching for text, avoid huge window (such as when searching for "signal")
- Possibility to search for multiple items/signals/fluids at the same time (such as all "Induction Furnace") - selection is possible with flib styles
- Filter signals by "connected to entity" (LTN input for example)
- Fluid search
- Entity search
- Possibility to search for multiple items/signals/fluids at the same time (such as all "Induction Furnace") - selection is possible with flib styles
- Producer/Consumer search (for items and fluids)
- Improve view of results

## Features

- Recent searches
- Favorite searches - especially for "Find my car" and similar?
- Favorite searches
- Saved search results - especially for "Find my car" and similar?
- Some kind of share feature... Add icon to other players GUI's? "Simon is sharing XYZ with you"
- Aliases? Such as "LTN" -> logistics-train-stop (entity name in this case)
- Search selector: Select area, show options about what is in that area (transport belt, items on belt, inserters, machines, recipes in machines, inputs, outputs...)
Expand All @@ -43,7 +45,8 @@ Search as soon as you click the first search button, search for all possibilitie
Search for train stop name - Where the hell are all those "Unused" stations anyway?
GROUP BY functionality? Such as "Find all assembling machines, group by product/recipe" (show grouped-by-thing, count, sum of count property?)
ORDER BY functionality? Such as "closest" or "highest count"
WiM integration - click on something in WiM (left/right-click like FNEI) to launch search for producers/consumers with extra filter not-enough-ingredients-of-that-kind
WiM integration - click on something in WiM (left/right-click like FNEI) to launch search for producers/consumers
with extra filter not-enough-ingredients-of-that-kind
Handle special items, such as "item with inventory"

- Item filters: Logistics requests
Expand Down
33 changes: 31 additions & 2 deletions factorio-search-engine_0.0.1/async.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function Async:load_task(task_state)
local task_config = Async:config_lookup(task_state.task_data)
task:load_loop_functions()
task.perform_function = task_config.perform_function
task.progress_function = task_config.progress_function
task.on_finished = task_config.on_finished
add_async_task(task)
return task
Expand Down Expand Up @@ -105,6 +106,7 @@ local function loop_next(loop, current, all_iterators, all_state, task_data)
elseif loop.type == "loop_func" then
if current == nil then
loop.values = loop.func(all_state, all_iterators, task_data)
loop.size = table_size(loop.values)
end
return next(loop.values, current)
elseif loop.type == "dynamic" then
Expand Down Expand Up @@ -155,6 +157,26 @@ function AsyncTask:load_loop_functions()
end
end

function AsyncTask:get_status()
local result = {
tasks_completed = self.save_state.completions,
tasks_remaining = self.save_state.remaining,
loops = { }
}
for loop_index, loop in pairs(self.save_state.loops) do
if loop.type == "loop_func" then
table.insert(result.loops, {
identifier = loop.identifier,
step = self.save_state.iterators[loop_index],
total = loop.size,
})
else
error("No get_status() support for loop of type " .. loop.type)
end
end
return result
end

function AsyncTask:restart_loops()
local save_state = self.save_state
save_state.state = {}
Expand Down Expand Up @@ -204,13 +226,19 @@ function AsyncTask:finished()
self.save_state.remaining = self.save_state.remaining - 1
if self.on_finished then
-- game.print("Finished")
self.on_finished(self.save_state.task_data)
self.on_finished(self.save_state.task_data, self.save_state)
end
end

function AsyncTask:call_perform_function()
-- log("Call perform with " .. serpent.line(self.state))
self.perform_function(self.save_state.state, self.save_state.task_data)
self.perform_function(self.save_state.state, self.save_state.task_data, self)
end

function AsyncTask:call_progress_update_function()
if self.progress_function then
self:progress_function()
end
end

function AsyncTask:tick(tick)
Expand All @@ -225,6 +253,7 @@ function AsyncTask:tick(tick)
self:next_iteration()
end
end
self:call_progress_update_function()
end
end

Expand Down
13 changes: 9 additions & 4 deletions factorio-search-engine_0.0.1/async_config.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
local searcher = require "searcher/main_searcher"
local step3 = require "gui/step_3_progress_and_result"

local function async_search_step(values, task)
searcher:search_step(task, values)
local function async_search_step(values, task_data)
searcher:search_step(task_data, values)
end

local function async_search_completed(task)
step3.search_completed(task)
local function async_search_update(task)
step3.search_progress(task)
end

local function async_search_completed(task_data, task)
step3.search_completed(task_data, task)
end

Async:configure_loop_functions(function(loop)
Expand All @@ -17,6 +21,7 @@ Async:configure(function(task)
if task.type == "search" then
return {
perform_function = async_search_step,
progress_function = async_search_update,
on_finished = async_search_completed
}
end
Expand Down
4 changes: 2 additions & 2 deletions factorio-search-engine_0.0.1/gui/step_2_choose_things.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ local function perform_search(event, search)
name = search_for_name,
search_options = search_options
}
local search = searcher:create_search(player, search_params)
-- step3.progress_gui(search)
local search_task = searcher:create_search(player, search_params)
step3.progress_gui(search_task)
end

gui.add_handlers {
Expand Down
53 changes: 51 additions & 2 deletions factorio-search-engine_0.0.1/gui/step_3_progress_and_result.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ gui.add_handlers {
local function show_window(search)
global.search_windows = global.search_windows or {}
local search_id = search.id
if global.search_windows[search_id] then
return global.search_windows[search_id].elems
end
local player = game.get_player(search.player_index)
local elems = gui.build(player.gui.screen, {
{type="frame", direction="vertical", save_as="window", children={
Expand Down Expand Up @@ -79,8 +82,52 @@ local function add_to_table(search_id, element, result_columns)
end
end

local function show_results(search)
local function progress_gui(search_task)
if global.search_windows[search_id] then
return global.search_windows[search_id].elems
end
local elems = show_window(search_task.task_data)
elems.status.clear()
-- TODO: Show table over loops: identifier (label), step / total (label), progressbar

local table_children = {}
for _, loop in pairs(search_task.loops) do
table.insert(table_children, {type="label", caption=loop.identifier})
table.insert(table_children, {type="label", save_as="loops." .. loop.identifier .. ".status"})
table.insert(table_children, {type="progressbar", save_as="loops." .. loop.identifier .. ".progressbar"})
end
local elems = gui.build(elems.status, {
{type="table", column_count=3, children=table_children}
})
search_task.task_data.status_progress_gui = elems
end

local function update_progress_gui(search_task)
local task_data = search_task.save_state.task_data
local search_id = task_data.id
if not global.search_windows[search_id] then
return
end
local status = search_task:get_status()
local status_progress_gui = task_data.status_progress_gui
if not status_progress_gui then
return
end
for _, loop in pairs(status.loops) do
if loop.step then
status_progress_gui.loops[loop.identifier].status.caption = loop.step .. " / " .. loop.total
status_progress_gui.loops[loop.identifier].progressbar.value = loop.step / loop.total
else
status_progress_gui.loops[loop.identifier].status.caption = "??? / " .. loop.total
status_progress_gui.loops[loop.identifier].progressbar.value = 0
end
end
end

local function show_results(search, search_task)
local window_elems = show_window(search)
window_elems.status.clear()
search.status_progress_gui = nil

-- TODO: Use plugin approach. local result_renders = searcher:result_renders(search)

Expand Down Expand Up @@ -115,5 +162,7 @@ local function show_results(search)
end

return {
search_completed = show_results
search_completed = show_results,
search_progress = update_progress_gui,
progress_gui = progress_gui,
}

0 comments on commit 4f90730

Please sign in to comment.