v0.4.0: mod support and more toggles. Fixed toggle buttons visual bug.

Support for YARM, orbital ion cannon and outpost planner. Toggle for
personal laser defense and shortcut for discharge defenswe
This commit is contained in:
Peter 2019-03-16 18:05:51 +08:00
parent 2c634396bf
commit f80ca357d7
31 changed files with 344 additions and 50 deletions

5
.gitignore vendored
View File

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

View File

@ -14,7 +14,7 @@ local function update_armor(event)
end
end
local function update_state(event, equipment_type)
local function update_state(event, equipment_type) -- toggles the armor
update_armor(event)
local grid = global.shortcuts_armor[game.players[event.player_index].index]
if grid then
@ -24,12 +24,14 @@ local function update_state(event, equipment_type)
local position = equipment.position
local energy = equipment.energy
if not (string.sub(equipment.name,1,9) == "disabled-") then
grid.take(equipment)
local new_equipment = grid.put{name="disabled-" .. name, position=position}
if new_equipment and new_equipment.valid then
new_equipment.energy = energy
if equipment_type ~= "active-defense-equipment" or (equipment_type == "active-defense-equipment" and game.equipment_prototypes["disabled-" .. equipment.name]) then
grid.take(equipment)
local new_equipment = grid.put{name="disabled-" .. name, position=position}
if new_equipment and new_equipment.valid then
new_equipment.energy = energy
end
game.players[event.player_index].set_shortcut_toggled(equipment_type, false)
end
game.players[event.player_index].set_shortcut_toggled(equipment_type, false)
elseif (string.sub(equipment.name,1,9) == "disabled-") then
grid.take(equipment)
local new_equipment = grid.put{name=(string.sub(name,10,#name)), position=position}
@ -68,6 +70,8 @@ local function shortcut_type(event)
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
toggle_light(game.players[event.player_index])
elseif prototype_name == "big-zoom" then
@ -87,44 +91,96 @@ local function shortcut_type(event)
end
end
local function update_inventory(event)
local function update_inventory(event) -- removes spare remotes
local item_prototypes = game.item_prototypes
local inventory = game.players[event.player_index].get_inventory(defines.inventory.player_main)
if inventory and inventory.valid then
inventory.remove("artillery-targeting-remote")
inventory.remove("discharge-defense-remote")
if item_prototypes["resource-monitor"] then
inventory.remove("resource-monitor")
end
if item_prototypes["outpost-builder"] then
inventory.remove("outpost-builder")
end
if item_prototypes["ion-cannon-targeter"] then
inventory.remove("ion-cannon-targeter")
end
end
end
local function reset_state(event)
local function false_shortcuts(player) -- disables things
player.set_shortcut_available("night-vision-equipment", false)
player.set_shortcut_toggled("night-vision-equipment", false)
player.set_shortcut_available("belt-immunity-equipment", false)
player.set_shortcut_toggled("belt-immunity-equipment", false)
player.set_shortcut_available("active-defense-equipment", false)
player.set_shortcut_toggled("active-defense-equipment", false)
end
local function enable_it(player, equipment, grid, type) -- enables things
if grid.valid and equipment.valid then
local name = equipment.name
local position = equipment.position
local energy = equipment.energy
player.set_shortcut_available(type, true)
player.set_shortcut_toggled(type, true)
if (string.sub(equipment.name,1,9) == "disabled-") then
grid.take(equipment)
local new_equipment = grid.put{name=(string.sub(name,10,#name)), position=position}
if new_equipment and new_equipment.valid then
new_equipment.energy = energy
end
end
end
end
local function reset_state(event, toggle) -- verifies placement of equipment and armor switching
update_armor(event)
local player = game.players[event.player_index]
local grid = global.shortcuts_armor[game.players[event.player_index].index]
if grid then
for _, equipment in pairs(grid.equipment) do
if equipment.type == "night-vision-equipment" then
player.set_shortcut_available("night-vision-equipment", true)
player.set_shortcut_toggled("night-vision-equipment", true)
elseif equipment.type == "belt-immunity-equipment" then
player.set_shortcut_available("belt-immunity-equipment", true)
player.set_shortcut_toggled("belt-immunity-equipment", true)
local equipment = event.equipment
if equipment and toggle == 1 then --place
local type = equipment.type
if type == "night-vision-equipment" or type == "belt-immunity-equipment" or (type == "active-defense-equipment" and game.equipment_prototypes["disabledinactive-" .. equipment.name] == nil) then
for _, equipment in pairs(grid.equipment) do
if equipment.valid and equipment.type == type then
enable_it(player, equipment, grid, type)
end
end
end
if equipment.valid and equipment.type == "night-vision-equipment" or equipment.type == "belt-immunity-equipment" then
local name = equipment.name
local position = equipment.position
local energy = equipment.energy
if (string.sub(equipment.name,1,9) == "disabled-") then
grid.take(equipment)
local new_equipment = grid.put{name=(string.sub(name,10,#name)), position=position}
if new_equipment and new_equipment.valid then
new_equipment.energy = energy
end
elseif equipment and toggle == 2 then --take
local type = game.equipment_prototypes[equipment].type
local name = game.equipment_prototypes[equipment].name
if type == "night-vision-equipment" or type == "belt-immunity-equipment" or type == "active-defense-equipment" then
local value = false
for _, equipment in pairs(grid.equipment) do
if equipment.type == type and equipment.valid then
if type ~= "active-defense-equipment" then
value = true
break
elseif type == "active-defense-equipment" and game.equipment_prototypes["disabledinactive-" .. equipment.name] == nil then
value = true
break
end
end
end
if value == false then
player.set_shortcut_available(type, false)
player.set_shortcut_toggled(type, false)
end
end
elseif toggle == 0 then --armor place
false_shortcuts(player)
for _, equipment in pairs(grid.equipment) do
local type = equipment.type
if equipment.valid and type == "night-vision-equipment" or type == "belt-immunity-equipment" or (type == "active-defense-equipment" and game.equipment_prototypes["disabledinactive-" .. equipment.name] == nil) then
enable_it(player, equipment, grid, equipment.type)
end
end
end
else
player.set_shortcut_available("night-vision-equipment", false)
player.set_shortcut_available("belt-immunity-equipment", false)
player.set_shortcut_toggled("night-vision-equipment", false)
player.set_shortcut_toggled("belt-immunity-equipment", false)
false_shortcuts(player)
end
end
@ -137,9 +193,9 @@ local function initialize()
end
end
script.on_event(defines.events.on_player_armor_inventory_changed, reset_state)
script.on_event(defines.events.on_player_placed_equipment, reset_state)
script.on_event(defines.events.on_player_removed_equipment, reset_state)
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_lua_shortcut, shortcut_type)
@ -150,6 +206,7 @@ script.on_event(defines.events.on_player_created, function(event)
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)
end)
script.on_init(initialize)

View File

@ -1,31 +1,54 @@
require("shortcuts")
data.raw["recipe"]["artillery-targeting-remote"].hidden = true
local effect = data.raw["technology"]["artillery"].effects
for i=1,(#effect) do
if effect[i].type == "unlock-recipe" then
if effect[i].recipe == "artillery-targeting-remote" then
table.remove(effect, i)
local function hide_the_remote(recipe, technology)
data.raw["recipe"][recipe].hidden = true
data.raw["recipe"][recipe].ingredients ={{"iron-plate", 1}}
if technology ~= nil then
local effect = data.raw["technology"][technology].effects
for i=1,(#effect) do
if effect[i].type == "unlock-recipe" then
if effect[i].recipe == recipe then
table.remove(effect, i)
end
end
end
end
end
hide_the_remote("artillery-targeting-remote", "artillery")
hide_the_remote("discharge-defense-remote", "discharge-defense-equipment")
if mods["YARM"] and data.raw["item"]["resource-monitor"] and data.raw["technology"]["resource-monitoring"] then
hide_the_remote("resource-monitor", "resource-monitoring")
end
if mods["OutpostPlanner"] and mods["PlannerCore"] and data.raw["selection-tool"]["outpost-builder"] then
hide_the_remote("outpost-builder", nil)
end
if mods["Orbital Ion Cannon"] and data.raw["item"]["ion-cannon-targeter"] and data.raw["technology"]["orbital-ion-cannon"] then
hide_the_remote("ion-cannon-targeter", "orbital-ion-cannon")
end
local disabled_equipment = {}
local disabled_equipment_item = {}
local equipment_list = {
"night-vision-equipment",
"belt-immunity-equipment",
"active-defense-equipment",
}
for i=1,(#equipment_list) do
for _, equipment in pairs(data.raw[equipment_list[i]]) do
local i = #disabled_equipment+1
disabled_equipment[i] = util.table.deepcopy(equipment)
local name = disabled_equipment[i].name
disabled_equipment[i].name = "disabled-" .. name
disabled_equipment[i].localised_name = {"", {"equipment-name." .. name}, " (", {"gui-constant.off"}, ")"}
if (equipment.type == "active-defense-equipment" and equipment.automatic == true) or equipment.type ~= "active-defense-equipment" then
disabled_equipment[i].name = "disabled-" .. name
disabled_equipment[i].localised_name = {"", {"equipment-name." .. name}, " (", {"gui-constant.off"}, ")"}
elseif (equipment.type == "active-defense-equipment" and equipment.automatic == false) then
disabled_equipment[i].name = "disabledinactive-" .. name
disabled_equipment[i].localised_name = {"equipment-name." .. name}
end
disabled_equipment[i].energy_input = "0kW"
disabled_equipment[i].take_result = name
if equipment_list[i] == "belt-immunity-equipment" then
if equipment_list[i] == "belt-immunity-equipment" or (equipment.type == "active-defense-equipment" and equipment.automatic == true) then
disabled_equipment[i].energy_source.input_flow_limit = "0kW"
disabled_equipment[i].energy_source.buffer_capacity = "0kJ"
disabled_equipment[i].energy_source.drain = "1kW"
@ -48,7 +71,6 @@ for i=1,(#equipment_list) do
-- disabled_equipment_item[i].localised_name = {"", {"equipment-name." .. name}, " (", {"gui-constant.off"}, ")"}
disabled_equipment_item[i].localised_description = {"item-description." .. name}
disabled_equipment_item[i].placed_as_equipment_result = name
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 869 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 769 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 646 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 611 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 827 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 930 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 786 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 623 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 547 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 688 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 445 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -1,10 +1,10 @@
{
"name": "Shortcuts",
"version": "0.3.0",
"version": "0.4.0",
"factorio_version": "0.17",
"title": "Shortcuts",
"author": "npc_strider(morley376)",
"contact": "",
"homepage": "http://steamcommunity.com/id/morley376",
"description": "Adds in a shortcut button for the artillery remote, and toggles for night-vision-equipment, belt-immunity-equipment and the player lamp. Suggest any new shortcut ideas to the discussion page."
"description": "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

@ -67,6 +67,106 @@ data:extend(
flags = {"icon"}
},
},
{
type = "shortcut",
name = "discharge-defense-remote",
order = "a[discharge-defense-remote]",
action = "create-blueprint-item",
localised_name = {"item-name.discharge-defense-remote"},
technology_to_unlock = "discharge-defense-equipment",
item_to_create = "discharge-defense-remote",
style = "red",
icon =
{
filename = "__Shortcuts__/graphics/discharge-defense-remote-x32-white.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/discharge-defense-remote-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/discharge-defense-remote-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",
@ -99,7 +199,7 @@ data:extend(
scale = 1,
flags = {"icon"}
},
},
},
{
type = "shortcut",
name = "flashlight-toggle",
@ -210,3 +310,123 @@ data:extend(
-- order, localised_name, technology_to_unlock, icon, small_icon, disabled_icon, disabled_small_icon as above
-- }
})
if mods["YARM"] and data.raw["item"]["resource-monitor"] and data.raw["technology"]["resource-monitoring"] then
data:extend(
{
{
type = "shortcut",
name = "resource-monitor",
order = "a[resource-monitor]",
action = "create-blueprint-item",
localised_name = {"item-name.resource-monitor"},
technology_to_unlock = "resource-monitoring",
item_to_create = "resource-monitor",
style = "green",
icon =
{
filename = "__Shortcuts__/graphics/resource-monitor-x32-white.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/resource-monitor-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/resource-monitor-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
}
})
end
if mods["OutpostPlanner"] and mods["PlannerCore"] and data.raw["selection-tool"]["outpost-builder"] then
data:extend(
{
{
type = "shortcut",
name = "outpost-builder",
order = "a[outpost-builder]",
action = "create-blueprint-item",
localised_name = {"item-name.outpost-builder"},
-- technology_to_unlock = "resource-monitor",
item_to_create = "outpost-builder",
style = "green",
icon =
{
filename = "__Shortcuts__/graphics/outpost-builder-x32-white.png",
priority = "extra-high-no-scale",
size = 32,
scale = 1,
flags = {"icon"}
},
small_icon =
{
filename = "__Shortcuts__/graphics/outpost-builder-x24.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
disabled_small_icon =
{
filename = "__Shortcuts__/graphics/outpost-builder-x24-white.png",
priority = "extra-high-no-scale",
size = 24,
scale = 1,
flags = {"icon"}
},
}
})
end
if mods["Orbital Ion Cannon"] and data.raw["item"]["ion-cannon-targeter"] and data.raw["technology"]["orbital-ion-cannon"] then
data:extend(
{
{
type = "shortcut",
name = "ion-cannon-targeter",
order = "a[ion-cannon-targeter]",
action = "create-blueprint-item",
localised_name = {"item-name.ion-cannon-targeter"},
technology_to_unlock = "orbital-ion-cannon",
item_to_create = "ion-cannon-targeter",
style = "red",
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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 16 KiB

BIN
crosshairs64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
image4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

BIN
laser-turret.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
resource-monitor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB