diff --git a/Shortcuts/control.lua b/Shortcuts/control.lua new file mode 100644 index 0000000..91f251a --- /dev/null +++ b/Shortcuts/control.lua @@ -0,0 +1,78 @@ +local function update_armor(event) + player = game.players[event.player_index] + power_armor = player.get_inventory(defines.inventory.player_armor) + if power_armor and power_armor.valid then + if power_armor[1].valid_for_read then + if power_armor[1].grid.valid then + global.shortcuts_armor[player.index] = power_armor[1].grid + end + end + end +end + +local function update_state(event, equipment_type) + update_armor(event) + player = game.players[event.player_index].index + local grid = global.shortcuts_armor[player] + for _, equipment in pairs(grid.equipment) do + if equipment.valid and equipment.type == equipment_type then + local name = equipment.name + 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 + end + 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} + if new_equipment and new_equipment.valid then + new_equipment.energy = energy + end + end + end + end +end + +local function toggle_light(player) + if global.shortcuts_light[player.index] == nil then + global.shortcuts_light[player.index] = true + end + if global.shortcuts_light[player.index] == true then + player.character.disable_flashlight() + global.shortcuts_light[player.index] = false + elseif global.shortcuts_light[player.index] == false then + player.character.enable_flashlight() + global.shortcuts_light[player.index] = true + end +end + +local function toggle_type(event) + if event.prototype_name == "night-vision-toggle" then + update_state(event, "night-vision-equipment") + elseif event.prototype_name == "belt-immunity-toggle" then + update_state(event, "belt-immunity-equipment") + elseif event.prototype_name == "flashlight-toggle" then + toggle_light(game.players[event.player_index]) + end +end + +local function initialize() + if global.shortcuts_light == nil then + global.shortcuts_light = {} + end + if global.shortcuts_armor == nil then + global.shortcuts_armor = {} + end +end + +script.on_event(defines.events.on_player_armor_inventory_changed, update_armor) +script.on_event(defines.events.on_player_placed_equipment, update_armor) +script.on_event(defines.events.on_player_removed_equipment, update_armor) + +script.on_event(defines.events.on_lua_shortcut, toggle_type) + +script.on_init(initialize) +script.on_configuration_changed(initialize) \ No newline at end of file diff --git a/Shortcuts/data.lua b/Shortcuts/data.lua new file mode 100644 index 0000000..089a9ed --- /dev/null +++ b/Shortcuts/data.lua @@ -0,0 +1,43 @@ +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) + end + end +end + +local disabled_equipment = {} +local disabled_equipment_item = {} +local equipment_list = { + "night-vision-equipment", + "belt-immunity-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) + disabled_equipment_item[i] = util.table.deepcopy(data.raw["item"][equipment_list[i]]) + local name = disabled_equipment[i].name + local newname = "disabled-" .. name + disabled_equipment[i].name = newname + disabled_equipment[i].energy_input = "0kW" + if equipment_list[i] == "belt-immunity-equipment" 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" + end + disabled_equipment_item[i].name = newname + disabled_equipment_item[i].localised_name = {"", {"equipment-name." .. name}, " (", {"gui-constant.off"}, ")"} + disabled_equipment_item[i].localised_description = {"item-description." .. name} + disabled_equipment[i].localised_name = {"", {"equipment-name." .. name}, " (", {"gui-constant.off"}, ")"} + disabled_equipment_item[i].placed_as_equipment_result = newname + end +end + +for i=1,(#disabled_equipment),1 do + data:extend({disabled_equipment_item[i]}) + data:extend({disabled_equipment[i]}) +end \ No newline at end of file diff --git a/Shortcuts/graphics/artillery-targeting-remote-x24-white.png b/Shortcuts/graphics/artillery-targeting-remote-x24-white.png new file mode 100644 index 0000000..8d35c18 Binary files /dev/null and b/Shortcuts/graphics/artillery-targeting-remote-x24-white.png differ diff --git a/Shortcuts/graphics/artillery-targeting-remote-x24.png b/Shortcuts/graphics/artillery-targeting-remote-x24.png new file mode 100644 index 0000000..27ed3cb Binary files /dev/null and b/Shortcuts/graphics/artillery-targeting-remote-x24.png differ diff --git a/Shortcuts/graphics/artillery-targeting-remote-x32-white.png b/Shortcuts/graphics/artillery-targeting-remote-x32-white.png new file mode 100644 index 0000000..f098e0f Binary files /dev/null and b/Shortcuts/graphics/artillery-targeting-remote-x32-white.png differ diff --git a/Shortcuts/graphics/artillery-targeting-remote-x32.png b/Shortcuts/graphics/artillery-targeting-remote-x32.png new file mode 100644 index 0000000..0b6d7a3 Binary files /dev/null and b/Shortcuts/graphics/artillery-targeting-remote-x32.png differ diff --git a/Shortcuts/graphics/belt-immunity-toggle-x24-white.png b/Shortcuts/graphics/belt-immunity-toggle-x24-white.png new file mode 100644 index 0000000..8179e80 Binary files /dev/null and b/Shortcuts/graphics/belt-immunity-toggle-x24-white.png differ diff --git a/Shortcuts/graphics/belt-immunity-toggle-x24.png b/Shortcuts/graphics/belt-immunity-toggle-x24.png new file mode 100644 index 0000000..83d98ab Binary files /dev/null and b/Shortcuts/graphics/belt-immunity-toggle-x24.png differ diff --git a/Shortcuts/graphics/belt-immunity-toggle-x32-white.png b/Shortcuts/graphics/belt-immunity-toggle-x32-white.png new file mode 100644 index 0000000..76852ee Binary files /dev/null and b/Shortcuts/graphics/belt-immunity-toggle-x32-white.png differ diff --git a/Shortcuts/graphics/belt-immunity-toggle-x32.png b/Shortcuts/graphics/belt-immunity-toggle-x32.png new file mode 100644 index 0000000..cb5935c Binary files /dev/null and b/Shortcuts/graphics/belt-immunity-toggle-x32.png differ diff --git a/Shortcuts/graphics/flashlight-toggle-x24-white.png b/Shortcuts/graphics/flashlight-toggle-x24-white.png new file mode 100644 index 0000000..d320e04 Binary files /dev/null and b/Shortcuts/graphics/flashlight-toggle-x24-white.png differ diff --git a/Shortcuts/graphics/flashlight-toggle-x24.png b/Shortcuts/graphics/flashlight-toggle-x24.png new file mode 100644 index 0000000..f76a1bf Binary files /dev/null and b/Shortcuts/graphics/flashlight-toggle-x24.png differ diff --git a/Shortcuts/graphics/flashlight-toggle-x32-white.png b/Shortcuts/graphics/flashlight-toggle-x32-white.png new file mode 100644 index 0000000..39cec26 Binary files /dev/null and b/Shortcuts/graphics/flashlight-toggle-x32-white.png differ diff --git a/Shortcuts/graphics/flashlight-toggle-x32.png b/Shortcuts/graphics/flashlight-toggle-x32.png new file mode 100644 index 0000000..3b946e7 Binary files /dev/null and b/Shortcuts/graphics/flashlight-toggle-x32.png differ diff --git a/Shortcuts/graphics/night-vision-toggle-x24-white.png b/Shortcuts/graphics/night-vision-toggle-x24-white.png new file mode 100644 index 0000000..ba812c3 Binary files /dev/null and b/Shortcuts/graphics/night-vision-toggle-x24-white.png differ diff --git a/Shortcuts/graphics/night-vision-toggle-x24.png b/Shortcuts/graphics/night-vision-toggle-x24.png new file mode 100644 index 0000000..02364c3 Binary files /dev/null and b/Shortcuts/graphics/night-vision-toggle-x24.png differ diff --git a/Shortcuts/graphics/night-vision-toggle-x32-white.png b/Shortcuts/graphics/night-vision-toggle-x32-white.png new file mode 100644 index 0000000..2dba3b5 Binary files /dev/null and b/Shortcuts/graphics/night-vision-toggle-x32-white.png differ diff --git a/Shortcuts/graphics/night-vision-toggle-x32.png b/Shortcuts/graphics/night-vision-toggle-x32.png new file mode 100644 index 0000000..abae097 Binary files /dev/null and b/Shortcuts/graphics/night-vision-toggle-x32.png differ diff --git a/Shortcuts/info.json b/Shortcuts/info.json new file mode 100644 index 0000000..45ad1ce --- /dev/null +++ b/Shortcuts/info.json @@ -0,0 +1,10 @@ +{ + "name": "Shortcuts", + "version": "0.2.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." +} \ No newline at end of file diff --git a/Shortcuts/shortcuts.lua b/Shortcuts/shortcuts.lua new file mode 100644 index 0000000..e3feb77 --- /dev/null +++ b/Shortcuts/shortcuts.lua @@ -0,0 +1,143 @@ +data:extend( +{ + { + type = "shortcut", + name = "artillery-targeting-remote", + order = "a[artillery-targeting-remote]", + action = "create-blueprint-item", + localised_name = {"item-name.artillery-targeting-remote"}, + technology_to_unlock = "artillery", + item_to_create = "artillery-targeting-remote", + style = "red", + icon = + { + filename = "__Shortcuts__/graphics/artillery-targeting-remote-x32-white.png", + priority = "extra-high-no-scale", + size = 32, + scale = 1, + flags = {"icon"} + }, + small_icon = + { + filename = "__Shortcuts__/graphics/artillery-targeting-remote-x24.png", + priority = "extra-high-no-scale", + size = 24, + scale = 1, + flags = {"icon"} + }, + disabled_small_icon = + { + filename = "__Shortcuts__/graphics/artillery-targeting-remote-x24-white.png", + priority = "extra-high-no-scale", + size = 24, + scale = 1, + flags = {"icon"} + }, + }, + { + type = "shortcut", + name = "night-vision-toggle", + order = "a[night-vision-toggle]", + 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 = "belt-immunity-toggle", + order = "a[belt-immunity-toggle]", + 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", + order = "a[flashlight-toggle]", + action = "lua", + localised_name = {"entity-name.small-lamp"}, + toggleable = true, + icon = + { + filename = "__Shortcuts__/graphics/flashlight-toggle-x32.png", + priority = "extra-high-no-scale", + size = 32, + scale = 1, + flags = {"icon"} + }, + small_icon = + { + filename = "__Shortcuts__/graphics/flashlight-toggle-x24.png", + priority = "extra-high-no-scale", + size = 24, + scale = 1, + flags = {"icon"} + }, + disabled_small_icon = + { + filename = "__Shortcuts__/graphics/flashlight-toggle-x24-white.png", + priority = "extra-high-no-scale", + size = 24, + scale = 1, + flags = {"icon"} + }, + }, + -- Custom shortcut can be defined as follows: + -- { + -- type = "shortcut", + -- name = "shortcut-name", + -- action = "lua", + -- toggleable = true, -- whether or not the shortcut button is a toggle button or not + -- order, localised_name, technology_to_unlock, icon, small_icon, disabled_icon, disabled_small_icon as above + -- } +}) diff --git a/Shortcuts/thumbnail.png b/Shortcuts/thumbnail.png new file mode 100644 index 0000000..177d15c Binary files /dev/null and b/Shortcuts/thumbnail.png differ diff --git a/image1.png b/image1.png new file mode 100644 index 0000000..9f8f13f Binary files /dev/null and b/image1.png differ diff --git a/image2.png b/image2.png new file mode 100644 index 0000000..7a5839b Binary files /dev/null and b/image2.png differ