Another simple mod for the game "Factorio". Automatically strings circuit wire on long distance poles.
Revisión | ec428dbe06957e5a06cf0479f0ad9d26f8b0e99c (tree) |
---|---|
Tiempo | 2019-03-05 17:35:00 |
Autor | Eric Hopper <hopper@omni...> |
Commiter | Eric Hopper |
Update to use new 0.17 shortcut feature.
@@ -1,3 +1,9 @@ | ||
1 | +--------------------------------------------------------------------------------------------------- | |
2 | +Version: 0.2.2 | |
3 | +Date: 26. 02. 2019 | |
4 | + Major Features: | |
5 | + - Remove mod config setting and add shortcut toggle (like the | |
6 | + roboport toggle) to turn behavior on and off. | |
1 | 7 | --------------------------------------------------------------------------------------------------- |
2 | 8 | Version: 0.2.1 |
3 | 9 | Date: 26. 02. 2019 |
@@ -1,20 +1,14 @@ | ||
1 | -local conf_enable = setmetatable({}, { | |
2 | - __index = function(self, id) | |
3 | - local v = settings.get_player_settings(game.players[id])["ld_autocircuit-enabled"].value | |
4 | - rawset(self, id, v) | |
5 | - return v | |
6 | - end | |
7 | -}) | |
1 | +function OnShortCut(event) | |
2 | + if event.prototype_name == "ld-autocircuit-shortcut" then | |
3 | + local player = game.players[event.player_index] | |
4 | + if player.is_shortcut_available("ld-autocircuit-shortcut") then | |
5 | + local toggled = player.is_shortcut_toggled("ld-autocircuit-shortcut") | |
6 | + player.set_shortcut_toggled("ld-autocircuit-shortcut", not toggled) | |
7 | + end | |
8 | + end | |
9 | +end | |
8 | 10 | |
9 | -script.on_event(defines.events.on_runtime_mod_setting_changed, | |
10 | - function(event) | |
11 | - if not event or not event.setting then | |
12 | - return | |
13 | - end | |
14 | - if event.setting == "ld_autocircuit-enabled" then | |
15 | - conf_enable[event.player_index] = nil | |
16 | - end | |
17 | -end) | |
11 | +script.on_event(defines.events.on_lua_shortcut, OnShortCut) | |
18 | 12 | |
19 | 13 | local function is_long_distance_pole(entity) |
20 | 14 | if entity.type ~= "electric-pole" then |
@@ -41,8 +35,8 @@ | ||
41 | 35 | return (greenwires ~= nil) and (#greenwires > 0) |
42 | 36 | end |
43 | 37 | |
44 | -script.on_event(defines.events.on_built_entity, function(event) | |
45 | - if not conf_enable[event.player_index] then | |
38 | +function BuiltSomething(event) | |
39 | + if not game.players[event.player_index].is_shortcut_toggled("ld-autocircuit-shortcut") then | |
46 | 40 | return |
47 | 41 | end |
48 | 42 | local entity = event.created_entity |
@@ -71,4 +65,6 @@ | ||
71 | 65 | for _, newconnect in pairs(newconnects) do |
72 | 66 | entity.connect_neighbour(newconnect) |
73 | 67 | end |
74 | -end) | |
68 | +end | |
69 | + | |
70 | +script.on_event(defines.events.on_built_entity, BuiltSomething) |
@@ -0,0 +1,1 @@ | ||
1 | +require("shortcuts") |
@@ -1,11 +1,11 @@ | ||
1 | 1 | { |
2 | 2 | "name": "LD_AutoCircuit", |
3 | - "version": "0.2.1", | |
3 | + "version": "0.2.2", | |
4 | 4 | "title": "LD Auto Circuit", |
5 | 5 | "author": "Omnifarious", |
6 | 6 | "contact": "eric-factorio@omnifarious.org", |
7 | 7 | "homepage": "", |
8 | 8 | "factorio_version": "0.17", |
9 | 9 | "dependencies": ["base >= 0.17"], |
10 | - "description": "This mod will automatically string red and green wire over long distance poles." | |
10 | + "description": "This mod adds a shortcut toggle (like the roboport toggle) that will automatically string red and green wire from long distance poles that already have red and green wire to newly placed poles." | |
11 | 11 | } |
@@ -1,5 +1,2 @@ | ||
1 | -[mod-setting-name] | |
2 | -ld_autocircuit-enabled=LD Auto Circuit Enabled | |
3 | - | |
4 | -[mod-setting-description] | |
5 | -ld_autocircuit-enabled=Toggles whether or not to automatically string circuit wire from a long distance pole to another that also has circuit wire. | |
1 | +[shortcut-name] | |
2 | +ld-autocircuit-shortcut=Toggle LD AutoCircuit |
@@ -0,0 +1,11 @@ | ||
1 | +## LD AutoCircuit | |
2 | + | |
3 | +-------------------------------------- | |
4 | + | |
5 | +This mod adds a shortcut toggle (like the roboport toggle) that toggles | |
6 | +whether or not circuit wires are automatically strung to a newly placed | |
7 | +long-distance pole when you place the pole such that it connects to | |
8 | +another pole that already has circuit wires attached. | |
9 | + | |
10 | +This is useful for running circuit wires all along your rail network or | |
11 | +over other long distances. |
@@ -1,8 +0,0 @@ | ||
1 | -_G.data:extend({ | |
2 | - { | |
3 | - type = "bool-setting", | |
4 | - name = "ld_autocircuit-enabled", | |
5 | - setting_type = "runtime-per-user", | |
6 | - default_value = true, | |
7 | - }, | |
8 | -}) |
@@ -0,0 +1,19 @@ | ||
1 | +data:extend( | |
2 | +{ | |
3 | + { | |
4 | + type = "shortcut", | |
5 | + name = "ld-autocircuit-shortcut", | |
6 | + order = "zzz", | |
7 | + action = "lua", | |
8 | + technology_to_unlock = "circuit-network", | |
9 | + toggleable = true, | |
10 | + icon = | |
11 | + { | |
12 | + filename = "__LD_AutoCircuit__/icons/ld-autocircuit-button.png", | |
13 | + priority = "extra-high-no-scale", | |
14 | + size = 32, | |
15 | + scale = 1, | |
16 | + flags = { "icon" } | |
17 | + } | |
18 | + } | |
19 | +}) |