0.3.0pre: fix nanobots conflict, add artillery disable, max rate support

TODO: graphics for the new shortcuts and add wire cutters for the mod
portal release
This commit is contained in:
Peter 2019-03-21 19:36:20 +08:00
parent f80ca357d7
commit 58197dca55
7 changed files with 372 additions and 150 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
mod
*.svg
mod-list.json
*.dat
*.pdn
*.zip

View File

@ -1,2 +1,3 @@
# factorio-shortcuts
https://mods.factorio.com/mod/Shortcuts
Adds in a shortcut button for the artillery remote discharge defense remote, and toggles for night-vision-equipment, belt-immunity-equipment, personal-laser-defense and the player lamp. Shortcuts also for YARM, orbital ion cannon and outpost planner. Suggest any new shortcut ideas to the discussion page.

View File

@ -1,8 +1,18 @@
---------------------------------------------------------------------------------------------------
Version: 0.5.0
Date: 22. 03. 2019
Features:
- Add selection tool to disable rail artillery
- Add mod support for max rate calculator
Bugfixes:
- Fixed conflict with Nanobots mod
---------------------------------------------------------------------------------------------------
Version: 0.4.0
Date: 10. 03. 2019
Features:
-
- Add toggle shortcut for personal-laser-defense
- Add a shortcut for the discharge-defense-remote
- Add mod support for oupost planner, YARM and orbital ion cannon
Bugfixes:
- Toggle buttons visually work properly
- Using the lamp toggle on a god controller no longer crashes the game

View File

@ -1,3 +1,5 @@
require("util")
local function update_armor(event)
local player = game.players[event.player_index]
local power_armor = player.get_inventory(defines.inventory.player_armor)
@ -66,13 +68,19 @@ end
local function shortcut_type(event)
local prototype_name = event.prototype_name
if prototype_name == "night-vision-equipment" then
update_state(event, "night-vision-equipment")
elseif prototype_name == "belt-immunity-equipment" then
update_state(event, "belt-immunity-equipment")
elseif prototype_name == "active-defense-equipment" then
update_state(event, "active-defense-equipment")
elseif prototype_name == "flashlight-toggle" then
if not game.active_mods["Nanobots"] then
if prototype_name == "night-vision-equipment" then
update_state(event, "night-vision-equipment")
return
elseif prototype_name == "belt-immunity-equipment" then
update_state(event, "belt-immunity-equipment")
return
elseif prototype_name == "active-defense-equipment" then
update_state(event, "active-defense-equipment")
return
end
end
if prototype_name == "flashlight-toggle" then
toggle_light(game.players[event.player_index])
elseif prototype_name == "big-zoom" then
local player = game.players[event.player_index]
@ -106,6 +114,9 @@ local function update_inventory(event) -- removes spare remotes
if item_prototypes["ion-cannon-targeter"] then
inventory.remove("ion-cannon-targeter")
end
if item_prototypes["max-rate-calculator"] then
inventory.remove("max-rate-calculator")
end
end
end
@ -184,6 +195,54 @@ local function reset_state(event, toggle) -- verifies placement of equipment and
end
end
local function artillery_swap(wagon,new_name)
local shellname = {}
local shellcount = {}
local inventory = table.deepcopy(wagon.get_inventory(defines.inventory.artillery_wagon_ammo))
for i=1,(#inventory) do
if inventory[i].valid_for_read then
shellname[#shellname+1] = inventory[i].name
shellcount[#shellcount+1] = inventory[i].count
end
end
local name = wagon.name
local surface = wagon.surface.name
local position = wagon.position
local direction = wagon.direction
local force = wagon.force
local kills = wagon.kills
local damage = wagon.damage_dealt
local health = wagon.health
wagon.destroy()
local new_wagon = game.surfaces[surface].create_entity{name=new_name, position=position, direction=direction, force=force, kills=kills, damage=damage, create_build_effect_smoke=false}
if new_wagon then
new_wagon.health = health
for i=1,(#shellcount) do
if new_wagon.can_insert({name=shellname[i],count=shellcount[i]}) == true then
new_wagon.insert({name=shellname[i],count=shellcount[i]})
end
end
end
return new_wagon
end
local function jam_artillery(event)
if event.item == "artillery-jammer-tool" and event.entities ~= nil then
for _, wagon in pairs(event.entities) do
local name = wagon.name
if wagon.valid and wagon.type == "artillery-wagon" and not (string.sub(name,1,9) == "disabled-") then
local new_name = ("disabled-" .. name)
local new_wagon = artillery_swap(wagon,new_name)
rendering.draw_sprite{sprite="virtual-signal.signal-disabled", x_scale=1.5, y_scale=1.5, target_offset={0.0,-0.5}, render_layer="entity-info-icon", target=new_wagon, surface=new_wagon.surface, forces={new_wagon.force}}
elseif wagon.valid and wagon.type == "artillery-wagon" and (string.sub(name,1,9) == "disabled-") then
local new_name = (string.sub(name,10,#name))
artillery_swap(wagon,new_name)
end
end
end
end
local function initialize()
if global.shortcuts_light == nil then
global.shortcuts_light = {}
@ -193,9 +252,21 @@ local function initialize()
end
end
script.on_event(defines.events.on_player_armor_inventory_changed, function(event) reset_state(event,0) end)
script.on_event(defines.events.on_player_placed_equipment, function(event) reset_state(event,1) end)
script.on_event(defines.events.on_player_removed_equipment, function(event) reset_state(event,2) end)
script.on_event(defines.events.on_player_armor_inventory_changed, function(event)
if not game.active_mods["Nanobots"] then
reset_state(event,0)
end
end)
script.on_event(defines.events.on_player_placed_equipment, function(event)
if not game.active_mods["Nanobots"] then
reset_state(event,1)
end
end)
script.on_event(defines.events.on_player_removed_equipment, function(event)
if not game.active_mods["Nanobots"] then
reset_state(event,2)
end
end)
script.on_event(defines.events.on_lua_shortcut, shortcut_type)
@ -203,11 +274,18 @@ script.on_event(defines.events.on_player_main_inventory_changed, update_inventor
script.on_event(defines.events.on_player_created, function(event)
local player = game.players[event.player_index]
player.set_shortcut_toggled("flashlight-toggle", true)
player.set_shortcut_available("night-vision-equipment", false)
player.set_shortcut_available("belt-immunity-equipment", false)
player.set_shortcut_available("active-defense-equipment", false)
if not game.active_mods["Nanobots"] then
player.set_shortcut_toggled("flashlight-toggle", true)
player.set_shortcut_available("night-vision-equipment", false)
player.set_shortcut_available("belt-immunity-equipment", false)
player.set_shortcut_available("active-defense-equipment", false)
else
player.print("WARNING: Shortcuts for modular equipment disabled as Nanobots is installed")
player.print("> Use the Nanobots hotkeys instead: \"Ctrl F1 - F7 Will toggle specific modular armor equipment on or off\"")
end
end)
script.on_event(defines.events.on_player_selected_area, jam_artillery)
script.on_init(initialize)
script.on_configuration_changed(initialize)

View File

@ -34,6 +34,10 @@ local equipment_list = {
"belt-immunity-equipment",
"active-defense-equipment",
}
if mods["Nanobots"] then
equipment_list = {}
end
for i=1,(#equipment_list) do
for _, equipment in pairs(data.raw[equipment_list[i]]) do
local i = #disabled_equipment+1
@ -81,7 +85,8 @@ for i=1,(#disabled_equipment),1 do
end
end
local warning = {
data:extend({
{
type = "virtual-signal", -- TODO: placeholder, when removing, remember to remove localised name too!
name = "signal-danger",
localised_name = {"gui-alert-tooltip.title"},
@ -90,6 +95,55 @@ local warning = {
subgroup = "virtual-signal-color",
order = "d[colors]-[9danger]",
hidden = true,
},
{
type = "virtual-signal",
name = "signal-disabled",
localised_name = {"gui-alert-tooltip.title"},
icon = "__core__/graphics/destroyed-icon.png",
icon_size = 64,
subgroup = "virtual-signal-color",
order = "d[colors]-[9disabled]",
hidden = true,
}
})
local disabled_turret = {}
local disabled_turret_item = {}
local disabled_gun = {}
local disable_turret_list = {
"artillery-wagon",
}
data:extend{(warning)}
for i=1,(#disable_turret_list) do
for _, entity in pairs(data.raw[disable_turret_list[i]]) do
local i = #disabled_turret+1
disabled_turret[i] = util.table.deepcopy(entity)
local name = disabled_turret[i].name
local gun = disabled_turret[i].gun
disabled_turret_item[i] = util.table.deepcopy(data.raw["item-with-entity-data"][name])
if disabled_turret_item[i] == nil then
disabled_turret_item[i] = util.table.deepcopy(data.raw["item-with-entity-data"]["artillery-wagon"])
end
disabled_turret_item[i].name = "disabled-" .. name
disabled_turret_item[i].place_result = "disabled-" .. name
disabled_turret[i].name = "disabled-" .. name
disabled_turret[i].localised_name = {"", {"entity-name." .. entity.name}, " (", {"gui-constant.off"}, ")"}
disabled_gun[i] = util.table.deepcopy(data.raw["gun"][gun])
disabled_gun[i].name = "disabled-" .. gun
disabled_gun[i].tint = { r = 1.0, g = 0.0, b = 0.0, a = 1.0 }
disabled_gun[i].attack_parameters.range = 0
disabled_gun[i].attack_parameters.min_range = 0
disabled_turret[i].gun = disabled_gun[i].name
end
end
for i=1,(#disabled_turret),1 do
data:extend({disabled_turret[i]})
if disabled_gun[i] then
data:extend({disabled_gun[i]})
end
if disabled_turret_item[i] then
data:extend({disabled_turret_item[i]})
end
end

View File

@ -1,6 +1,6 @@
{
"name": "Shortcuts",
"version": "0.4.0",
"version": "0.5.0",
"factorio_version": "0.17",
"title": "Shortcuts",
"author": "npc_strider(morley376)",

View File

@ -1,5 +1,33 @@
data:extend(
{
-- for the artillery toggle
{
type = "selection-tool",
name = "artillery-jammer-tool",
icon = "__base__/graphics/icons/deconstruction-planner.png",
icon_size = 32,
flags = {"hidden"},
subgroup = "other",
order = "c[automated-construction]-a[deconstruction-planner]",
stack_size = 1,
stackable = false,
selection_color = { r = 1, g = 0, b = 0 },
alt_selection_color = { r = 1, g = 0, b = 0 },
selection_mode = {"blueprint"},
alt_selection_mode = {"blueprint"},
selection_cursor_box_type = "copy",
alt_selection_cursor_box_type = "copy",
entity_type_filters = {"artillery-wagon"},
tile_filters = {},
entity_filter_mode = "whitelist",
tile_filter_mode = "whitelist",
alt_entity_type_filters = {"artillery-wagon"},
alt_tile_filters = {},
alt_entity_filter_mode = "whitelist",
alt_tile_filter_mode = "whitelist",
show_in_library = false
},
-- all shortcuts
{
type = "shortcut",
name = "artillery-targeting-remote",
@ -34,39 +62,6 @@ data:extend(
flags = {"icon"}
},
},
{
type = "shortcut",
name = "night-vision-equipment",
order = "a[night-vision-equipment]",
action = "lua",
localised_name = {"equipment-name.night-vision-equipment"},
technology_to_unlock = "night-vision-equipment",
toggleable = true,
icon =
{
filename = "__Shortcuts__/graphics/night-vision-toggle-x32.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/night-vision-toggle-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/night-vision-toggle-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
},
{
type = "shortcut",
name = "discharge-defense-remote",
@ -101,105 +96,6 @@ data:extend(
flags = {"icon"}
},
},
{
type = "shortcut",
name = "night-vision-equipment",
order = "a[night-vision-equipment]",
action = "lua",
localised_name = {"equipment-name.night-vision-equipment"},
technology_to_unlock = "night-vision-equipment",
toggleable = true,
icon =
{
filename = "__Shortcuts__/graphics/night-vision-toggle-x32.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/night-vision-toggle-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/night-vision-toggle-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
},
{
type = "shortcut",
name = "active-defense-equipment",
order = "a[active-defense-equipment]",
action = "lua",
localised_name = {"equipment-name.personal-laser-defense-equipment"},
technology_to_unlock = "personal-laser-defense-equipment",
toggleable = true,
icon =
{
filename = "__Shortcuts__/graphics/active-defense-equipment-x32.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/active-defense-equipment-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/active-defense-equipment-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
},
{
type = "shortcut",
name = "belt-immunity-equipment",
order = "a[belt-immunity-equipment]",
action = "lua",
localised_name = {"item-name.belt-immunity-equipment"},
technology_to_unlock = "belt-immunity-equipment",
toggleable = true,
icon =
{
filename = "__Shortcuts__/graphics/belt-immunity-toggle-x32.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/belt-immunity-toggle-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/belt-immunity-toggle-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
},
{
type = "shortcut",
name = "flashlight-toggle",
@ -429,4 +325,181 @@ data:extend(
},
}
})
end
if mods["MaxRateCalculator"] and data.raw["selection-tool"]["max-rate-calculator"] then
data:extend(
{
{
type = "shortcut",
name = "max-rate-calculator",
order = "a[max-rate-calculator]",
action = "create-blueprint-item",
localised_name = {"item-name.max-rate-calculator"},
item_to_create = "max-rate-calculator",
style = "blue",
icon =
{
filename = "__Shortcuts__/graphics/ion-cannon-targeter-x32-white.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/ion-cannon-targeter-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/ion-cannon-targeter-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
}
})
end
if not mods["Nanobots"] then
data:extend(
{
{
type = "shortcut",
name = "night-vision-equipment",
order = "a[night-vision-equipment]",
action = "lua",
localised_name = {"equipment-name.night-vision-equipment"},
technology_to_unlock = "night-vision-equipment",
toggleable = true,
icon =
{
filename = "__Shortcuts__/graphics/night-vision-toggle-x32.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/night-vision-toggle-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/night-vision-toggle-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
},
{
type = "shortcut",
name = "night-vision-equipment",
order = "a[night-vision-equipment]",
action = "lua",
localised_name = {"equipment-name.night-vision-equipment"},
technology_to_unlock = "night-vision-equipment",
toggleable = true,
icon =
{
filename = "__Shortcuts__/graphics/night-vision-toggle-x32.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/night-vision-toggle-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/night-vision-toggle-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
},
{
type = "shortcut",
name = "active-defense-equipment",
order = "a[active-defense-equipment]",
action = "lua",
localised_name = {"equipment-name.personal-laser-defense-equipment"},
technology_to_unlock = "personal-laser-defense-equipment",
toggleable = true,
icon =
{
filename = "__Shortcuts__/graphics/active-defense-equipment-x32.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/active-defense-equipment-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/active-defense-equipment-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
},
{
type = "shortcut",
name = "belt-immunity-equipment",
order = "a[belt-immunity-equipment]",
action = "lua",
localised_name = {"item-name.belt-immunity-equipment"},
technology_to_unlock = "belt-immunity-equipment",
toggleable = true,
icon =
{
filename = "__Shortcuts__/graphics/belt-immunity-toggle-x32.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/belt-immunity-toggle-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/belt-immunity-toggle-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
}
})
end