mirror of
https://github.com/peter-tanner/spidertron-squad-control.git
synced 2024-11-30 11:00:17 +08:00
Added mod options: gui tickrate, max templates, default remotes
This commit is contained in:
parent
6677ac9b29
commit
f9436c315b
|
@ -56,7 +56,7 @@ Date: 2020-11-28
|
|||
- Completely refactor code to be cleaner
|
||||
- Spidertron Waypoints mod compatibility
|
||||
- Added menu/gui to save and load squad configurations
|
||||
- Spidertron link tool (Link squads to an entity)
|
||||
- 2NOTICE: THIS VERSION IS A WORK IN PROGRESS - CHANGELOG IS NOT FINAL
|
||||
- Added Spidertron link tool (Link squads to an entity)
|
||||
- Added mod option to override the default tool/remote given by shortcut
|
||||
- 3NOTICE: THIS VERSION IS A WORK IN PROGRESS - CHANGELOG IS NOT FINAL
|
||||
- 4NOTICE: THIS VERSION IS A WORK IN PROGRESS - CHANGELOG IS NOT FINAL
|
||||
|
|
17
constants.lua
Normal file
17
constants.lua
Normal file
|
@ -0,0 +1,17 @@
|
|||
--[[ Copyright (c) 2020 npc_strider
|
||||
* For direct use of code or graphics, credit is appreciated. See LICENSE.txt for more information.
|
||||
* This mod may contain modified code sourced from base/core Factorio
|
||||
*
|
||||
* constants.lua
|
||||
* Constants.
|
||||
--]]
|
||||
|
||||
-- Settings constants
|
||||
SETTING_REMOTE_SEL = "Spidertron squad selection"
|
||||
SETTING_REMOTE = "Spidertron squad remote"
|
||||
|
||||
SETTING_LINK = "Spidertron link tool"
|
||||
SETTING_UNLINK = "Spidertron unlink tool"
|
||||
|
||||
SETTING_AUTOMATIC = "Automatic"
|
||||
--
|
27
control.lua
27
control.lua
|
@ -8,6 +8,7 @@
|
|||
|
||||
require("util")
|
||||
|
||||
require("constants")
|
||||
require("control.debug")
|
||||
-- REMEMBER TO COMMENT DEBUG OUT IN RELEASE!!
|
||||
-- REMEMBER TO COMMENT DEBUG OUT IN RELEASE!!
|
||||
|
@ -25,7 +26,6 @@ require("control.entity_follow")
|
|||
require("control.functions")
|
||||
-- require("control.select")
|
||||
|
||||
|
||||
------------------------------------------------------------------------
|
||||
-- EVENTS
|
||||
------------------------------------------------------------------------
|
||||
|
@ -38,25 +38,34 @@ end)
|
|||
|
||||
-- link tool
|
||||
script.on_event("squad-spidertron-link-tool", function(event)
|
||||
GiveLinkTool(event.player_index)
|
||||
local index = event.player_index
|
||||
local settings = settings.get_player_settings(game.players[index])
|
||||
GiveLinkTool(index, settings)
|
||||
end)
|
||||
|
||||
script.on_event("squad-spidertron-remote", function(event)
|
||||
local index = event.player_index
|
||||
local settings = settings.get_player_settings(game.players[index])
|
||||
GiveSquadTool(index, settings)
|
||||
end)
|
||||
|
||||
script.on_event("squad-spidertron-list", function(event)
|
||||
ToggleGuiList(event.player_index)
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_lua_shortcut, function (event)
|
||||
script.on_event(defines.events.on_lua_shortcut, function(event)
|
||||
local index = event.player_index
|
||||
local settings = settings.get_player_settings(game.players[index])
|
||||
local name = event.prototype_name
|
||||
if name == "squad-spidertron-remote" then
|
||||
GiveStack(game.players[event.player_index], {name = "squad-spidertron-remote-sel", count = 1})
|
||||
GiveLinkTool(index, settings)
|
||||
elseif name == "squad-spidertron-link-tool" then
|
||||
GiveSquadTool(index, settings)
|
||||
elseif name == "squad-spidertron-follow" then
|
||||
local index = event.player_index
|
||||
-- squad_leader_state(index)
|
||||
SpiderbotFollow(game.players[index])
|
||||
elseif name == "squad-spidertron-link-tool" then
|
||||
GiveLinkTool(event.player_index)
|
||||
elseif name == "squad-spidertron-list" then
|
||||
ToggleGuiList(event.player_index)
|
||||
ToggleGuiList(index)
|
||||
end
|
||||
end)
|
||||
|
||||
|
@ -64,7 +73,7 @@ script.on_nth_tick(settings.global["spidertron-follow-update-interval"].value, f
|
|||
UpdateFollow()
|
||||
UpdateFollowEntity()
|
||||
end)
|
||||
script.on_nth_tick(60, function(event)
|
||||
script.on_nth_tick(settings.global["spidertron-gui-update-interval"].value, function(event)
|
||||
for _, player in pairs(game.players) do
|
||||
UpdateGuiList(player)
|
||||
end
|
||||
|
|
|
@ -8,21 +8,49 @@
|
|||
|
||||
require("control.functions")
|
||||
|
||||
function GiveLinkTool(index)
|
||||
local function giveTwoTool(index, stack0, stack1)
|
||||
local d = global.spidercontrol_player_s[index].active
|
||||
if (#d > 0 and d[1].spider.valid) then
|
||||
local player = game.players[index]
|
||||
if GiveStack(player, {name="squad-spidertron-link-tool",count=1}) then
|
||||
if GiveStack(player, stack0) then
|
||||
player.cursor_stack.connected_entity = d[1].spider
|
||||
end
|
||||
else
|
||||
GiveStack(game.players[index], {name="squad-spidertron-unlink-tool",count=1})
|
||||
GiveStack(game.players[index], stack1)
|
||||
end
|
||||
end
|
||||
|
||||
function GiveLinkTool(index, settings)
|
||||
local player = game.players[index]
|
||||
local value = settings["spidertron-default-link-remote"].value
|
||||
if value == SETTING_LINK then
|
||||
GiveStack(player, {name = "squad-spidertron-link-tool", count = 1})
|
||||
elseif value == SETTING_UNLINK then
|
||||
GiveStack(player, {name = "squad-spidertron-unlink-tool", count = 1})
|
||||
else -- value == AUTOMATIC
|
||||
giveTwoTool(index,
|
||||
{name="squad-spidertron-link-tool",count=1},
|
||||
{name="squad-spidertron-unlink-tool",count=1}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
function GiveSquadTool(index, settings)
|
||||
local player = game.players[index]
|
||||
local value = settings["spidertron-default-squad-remote"].value
|
||||
if value == SETTING_REMOTE_SEL then
|
||||
GiveStack(player, {name = "squad-spidertron-remote-sel", count = 1})
|
||||
elseif value == SETTING_LINK then
|
||||
GiveStack(player, {name = "squad-spidertron-remote", count = 1})
|
||||
else -- value == AUTOMATIC
|
||||
giveTwoTool(
|
||||
index,
|
||||
{name="squad-spidertron-remote",count=1},
|
||||
{name="squad-spidertron-remote-sel",count=1}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
script.on_event("squad-spidertron-remote", function(event)
|
||||
GiveStack(game.players[event.player_index], {name="squad-spidertron-remote-sel",count=1})
|
||||
end)
|
||||
|
||||
script.on_event("squad-spidertron-switch-modes", function(event)
|
||||
local player = game.players[event.player_index]
|
||||
|
@ -40,7 +68,7 @@ script.on_event("squad-spidertron-switch-modes", function(event)
|
|||
elseif name == "squad-spidertron-link-tool" then
|
||||
GiveStack(player, {name="squad-spidertron-unlink-tool",count=1})
|
||||
elseif name == "squad-spidertron-unlink-tool" then
|
||||
GiveLinkTool(event.player_index)
|
||||
GiveStack(player, {name = "squad-spidertron-link-tool", count = 1})
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -53,7 +81,7 @@ end)
|
|||
-- squad_leader_state(index)
|
||||
-- spiderbot_follow(game.players[index])
|
||||
-- elseif name == "squad-spidertron-link-tool" then
|
||||
-- GiveLinkTool(event.player_index)
|
||||
-- GiveStack(player, {name = "squad-spidertron-link-tool", count = 1})
|
||||
-- end
|
||||
-- end)
|
||||
|
||||
|
|
|
@ -138,15 +138,15 @@ function ToggleGuiList(index)
|
|||
end
|
||||
|
||||
|
||||
commands.add_command("ssc_gui", "Create gui", function(cmd)
|
||||
gui(game.players[cmd.player_index])
|
||||
commands.add_command("ssc_gui", "Spidertron squad control configured squads gui toggle", function(cmd)
|
||||
ToggleGuiList(cmd.player_index)
|
||||
end)
|
||||
|
||||
script.on_event(defines.events.on_gui_click, function(event)
|
||||
local gui = event.element
|
||||
local index = event.player_index
|
||||
local player = game.players[index]
|
||||
local limit = 20
|
||||
local limit = settings.global["spidertron-max-squads"].value
|
||||
if not (player and player.valid and gui and gui.valid) then
|
||||
return
|
||||
end
|
||||
|
|
46
settings.lua
46
settings.lua
|
@ -6,6 +6,7 @@
|
|||
* Mod settings
|
||||
--]]
|
||||
|
||||
require("constants")
|
||||
|
||||
data:extend({
|
||||
-- server
|
||||
|
@ -27,5 +28,50 @@ data:extend({
|
|||
setting_type = "runtime-global",
|
||||
default_value = 20,
|
||||
minimum_value = 5
|
||||
},
|
||||
{
|
||||
type = "int-setting",
|
||||
name = "spidertron-gui-update-interval",
|
||||
localised_name = "GUI update interval",
|
||||
localised_description = "Rate at which the spidertron save/load GUI is updated. This value is in ticks. Larger values are less laggy but result in less responsive information. Minimum value: 5, Default value: 60",
|
||||
setting_type = "runtime-global",
|
||||
default_value = 60,
|
||||
minimum_value = 5
|
||||
},
|
||||
{
|
||||
type = "int-setting",
|
||||
name = "spidertron-max-squads",
|
||||
localised_name = "Maximum templates per player",
|
||||
localised_description = "Maximum number of squad templates a player can save. Minimum value: 1, Default value: 20",
|
||||
setting_type = "runtime-global",
|
||||
default_value = 20,
|
||||
minimum_value = 1
|
||||
},
|
||||
-- player
|
||||
{
|
||||
type = "string-setting",
|
||||
name = "spidertron-default-squad-remote",
|
||||
localised_name = "Default squad tool",
|
||||
localised_description = "Type of remote to give when the squad remote shortcut is used. Default value: "..SETTING_REMOTE_SEL,
|
||||
setting_type = "runtime-per-user",
|
||||
default_value = SETTING_REMOTE_SEL,
|
||||
allowed_values = {
|
||||
SETTING_AUTOMATIC,
|
||||
SETTING_REMOTE_SEL,
|
||||
SETTING_REMOTE
|
||||
}
|
||||
},
|
||||
{
|
||||
type = "string-setting",
|
||||
name = "spidertron-default-link-remote",
|
||||
localised_name = "Default link tool",
|
||||
localised_description = "Type of remote to give when the Link shortcut is used. Default value: "..SETTING_AUTOMATIC,
|
||||
setting_type = "runtime-per-user",
|
||||
default_value = SETTING_AUTOMATIC,
|
||||
allowed_values = {
|
||||
SETTING_AUTOMATIC,
|
||||
SETTING_LINK,
|
||||
SETTING_UNLINK
|
||||
}
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue
Block a user