Page 1 of 1

Wiring Pencil

Posted: Sun Sep 09, 2018 11:10 am
by tehfreek
Since power wires are essentially free with power poles and blueprints make circuit network wires almost completely free, it makes sense to me to have a reusable, all-in-one tool that can apply wires of any type. Enter the wiring pencil. It is a tool with a one-time-cost that can apply or break power, red, or green wire in exactly the same way that those actions are currently performed. A hotkey switches between the wire used.

I can give a stab at writing this myself if I get some hints on how to implement it, but I can't help but feel that someone that already has modding experience would get it done much faster.

Re: Wiring Pencil

Posted: Mon Sep 10, 2018 9:08 am
by bobingabout
I am unsure if it is possible with 0.16, because I think it's pretty hard wired to cost an item to make a wire.

Re: Wiring Pencil

Posted: Mon Sep 10, 2018 9:48 am
by tehfreek
I don't know, after a quick flip through at the Lua API it looks like you could use LuaEntity::{,dis}connect_neighbour() to implement this.

Re: Wiring Pencil

Posted: Mon Sep 10, 2018 10:09 am
by eradicator
bobingabout wrote:I am unsure if it is possible with 0.16, because I think it's pretty hard wired to cost an item to make a wire.
Wire cost can be changed in 0.17 (thread).

But you can't make a wiring "pencil" because the half-connected wire-to-cursor preview is hardcoded to the actual wire types. But there's nothing preventing you from making a hotkey that changes the "color" of a wire-stack on your cursor and replenishing the stack when some of it is used up (on_cursor_stack_changed).

Hm..looking at the base lua files. Are the wire names hardcoded? I can't find any reference on the "green-wire" item that defines it as an item to make green wires (Bob, can you confirm?). In that case you'd have to live with the fact that players can convert copper-wire to green-wire for free with the hotkey if they want to build combinators with them.
tehfreek wrote:I can give a stab at writing this myself if I get some hints on how to implement it, but I can't help but feel that someone that already has modding experience would get it done much faster.
If you learn modding you contribute to the communities overall coding speed :p.

Re: Wiring Pencil

Posted: Mon Sep 10, 2018 10:50 am
by tehfreek
Looking deeper it does seem that there is in fact no way to perform the appropriate interactions in Lua, e.g. see which end of a combinator was clicked, or to tell if the wire is too far to connect.

Re: Wiring Pencil

Posted: Mon Sep 10, 2018 11:07 am
by eradicator
tehfreek wrote:[...] see which end of a combinator was clicked, or to tell if the wire is too far to connect.
If you use the wire as is you don't need that info. If you wanted to implement your own logic you have to intercept the click anyway and thus know what was clicked, and the distance is LuaEntityPrototype.max_circuit_wire_distance.

Re: Wiring Pencil

Posted: Tue Sep 11, 2018 11:14 pm
by tehfreek
Okay, the items (along with custom eye-bleeding sprites), recipe, technology, and wire rotation parts are done. But that was the easy part. Now I just need to figure out how to emulate or delegate the actual wiring operations.

I can try a bit of wire switcheroo and invoking the appropriate event(s), but 1) I'm worried about what will happen if I switch back to the pencil in the middle of a wiring operation (for visual purposes), and 2) I have absolutely no idea what events are invoked.

Re: Wiring Pencil

Posted: Thu Sep 13, 2018 10:48 am
by tehfreek
And of course wiring operations generate no events. Probably just as you were trying to get though my skull. Time for more thought, and possibly a dev request or two.

Re: Wiring Pencil

Posted: Thu Sep 13, 2018 5:39 pm
by eradicator
tehfreek wrote:
Thu Sep 13, 2018 10:48 am
And of course wiring operations generate no events. Probably just as you were trying to get though my skull. Time for more thought, and possibly a dev request or two.
on_wire_changed is implemented in 0.17 as far as i remember (and i don't even know why you would need that, as described above), but it's not going to solve your problem. You still have no way to get the entity-to-cursor wire effect.

Re: Wiring Pencil

Posted: Wed Apr 10, 2019 6:06 pm
by Qon
In case you haven't found it yet: https://mods.factorio.com/mod/WireShortcuts