Add Tool Gui (#20)

* Update _file_loader.lua

* Create tool.lua

* Update trains.lua

* Update research.lua

* Fix use of created_entity in events

* Update trains.lua

* Update tool.lua

* Update research.lua

* Update research.lua

* Update tool.lua

* Update research.lua

* Update trains.lua

* Fix waterfill locale

* Fix bug with selection tools and remote view

* Fix tool GUI

* Update tool.lua

---------

Co-authored-by: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com>
This commit is contained in:
2024-12-29 02:29:51 +09:00
committed by GitHub
parent d489615542
commit 8c19d67450
7 changed files with 328 additions and 30 deletions

View File

@@ -36,24 +36,34 @@ function module.res_queue(force, silent)
end
end
--- @param state boolean? use nil to toggle current state
--- @return boolean # New auto research state
function module.set_auto_research(state)
local new_state
if state == nil then
new_state = not research.res_queue_enable
else
new_state = state ~= false
end
research.res_queue_enable = new_state
return new_state
end
--- Sets the auto research state
Commands.new("set-auto-research", { "exp-commands_research.description" })
:optional("state", { "exp-commands_research.arg-state" }, Commands.types.boolean)
:add_aliases{ "auto-research" }
:register(function(player, state)
--- @cast state boolean?
if state == nil then
research.res_queue_enable = not research.res_queue_enable
else
research.res_queue_enable = state
end
local enabled = module.set_auto_research(state)
if research.res_queue_enable then
if enabled then
module.res_queue(player.force --[[@as LuaForce]], true)
end
local player_name = format_player_name(player)
game.print{ "exp-commands_research.auto-research", player_name, research.res_queue_enable }
game.print{ "exp-commands_research.auto-research", player_name, enabled }
end)
--- @param event EventData.on_research_finished

View File

@@ -4,9 +4,26 @@ Adds a command that set all train back to automatic
local Commands = require("modules/exp_commands")
local format_player_name = Commands.format_player_name_locale
local format_number = require("util").format_number
--- @class Command.Trains
local module = {}
function module.manual(player, surface, force)
local trains = game.train_manager.get_trains{
has_passenger = false,
is_manual = true,
surface = surface,
force = force,
}
for _, train in ipairs(trains) do
train.manual_mode = false
end
game.print{ "exp-commands_trains.response", format_player_name(player), format_number(#trains, false) }
end
--- Set all trains to automatic
Commands.new("set-trains-to-automatic", { "exp-commands_trains.description" })
:optional("surface", { "exp-commands_trains.arg-surface" }, Commands.types.surface)
@@ -14,16 +31,7 @@ Commands.new("set-trains-to-automatic", { "exp-commands_trains.description" })
:register(function(player, surface, force)
--- @cast surface LuaSurface?
--- @cast force LuaForce?
local trains = game.train_manager.get_trains{
has_passenger = false,
is_manual = true,
surface = surface,
force = force,
}
for _, train in ipairs(trains) do
train.manual_mode = false
end
game.print{ "exp-commands_trains.response", format_player_name(player), format_number(#trains, false) }
module.manual(player, surface, force)
end)
return module

View File

@@ -29,19 +29,19 @@ Selection.on_selection(SelectionName, function(event)
local surface = event.surface
if surface.planet and surface.planet ~= game.planets.nauvis then
player.print({ "exp-cods_waterfill.nauvis-only" }, Commands.print_settings.error)
player.print({ "exp-commands_waterfill.nauvis-only" }, Commands.print_settings.error)
return
end
local area_size = (area.right_bottom.x - area.left_top.x) * (area.right_bottom.y - area.left_top.y)
if area_size > 1000 then
player.print({ "exp-cods_waterfill.area-too-large", 1000, area_size }, Commands.print_settings.error)
player.print({ "exp-commands_waterfill.area-too-large", 1000, area_size }, Commands.print_settings.error)
return
end
local item_count = player.get_item_count("cliff-explosives")
if item_count < area_size then
player.print({ "exp-cods_waterfill.too-few-explosives", area_size, item_count }, Commands.print_settings.error)
player.print({ "exp-commands_waterfill.too-few-explosives", area_size, item_count }, Commands.print_settings.error)
return
end
@@ -62,8 +62,8 @@ Selection.on_selection(SelectionName, function(event)
player.remove_item{ name = "cliff-explosives", count = tile_count - remaining_tiles }
if remaining_tiles > 0 then
player.print({ "exp-cods_waterfill.part-complete", tile_count, remaining_tiles }, Commands.print_settings.default)
player.print({ "exp-commands_waterfill.part-complete", tile_count, remaining_tiles }, Commands.print_settings.default)
else
player.print({ "exp-cods_waterfill.complete", tile_count }, Commands.print_settings.default)
player.print({ "exp-commands_waterfill.complete", tile_count }, Commands.print_settings.default)
end
end)