folknor / factorio-justgo

Instantly pops you into a filtered vehicle when you place it within reach of the player character, and picks it up again when you exit.
1 stars 1 forks source link

Doesn't Interact with Helicopters #1

Open jarquafelmu opened 6 years ago

jarquafelmu commented 6 years ago

Helicopters#9

folknor commented 6 years ago

Hehe, when I read the bug title initially, I thought they'd added helicopters to vanilla factorio :-P

Anyway, the real question is whether the helicopters are actually vehicles ("car") in the sense that they trigger the necessary events and such, and it seems to me like they are, based on https://github.com/kumpuu/factorio-helicopters/blob/master/prototypes/entities/heli_entity.lua#L6

Since it passes that question, I'll have to install the mod and do some debugging.

kumpuu commented 6 years ago

Hi, it's a bit tricky. What you actually place is a preview "placement" entity, which gets destroyed immediately and replaced by several other entities. The entity that gives control is called "heli-entity-_-". Please let me know if you have any issues.

folknor commented 6 years ago

Hm, okay, that is tricky. The main question is if any events trigger when you replace the heli-placement-entity-_- with heli-entity-_-? Like on_built_entity or on_player_driving_changed_state.

At a minimum, I need to redesign my mod to support this, but I might need to give you a patch or two as well.

The way this mod works now is that it jumps you into the vehicle if the item name that you filter in your quickbar is the same as the entity name that is placed - and that won't be true either for the fake or the real helicopter.

So I think I'll need to add some remote facility to the mod that allows you to register a 3rd party mapping of item-to-entity, or at least register that an item/entity should be ignored by the mod.

One way is to use https://github.com/folknor/factorio-fill/blob/master/lib-events.lua, another way is to use the LuaRemote API directly, but then the mods will have to explicitly talk to eachother, instead of fire-and-forget, and a 3rd way is that I add a data table that you can hook into during the data stage (all mods share the same Lua state during the data stage).

kumpuu commented 6 years ago

No trigger will fire as far as I know, your remote manager looks like the way to go. So you would provide an item-entity mapper and a "custom-entity-created" event? Do you know then if there is any way I can load lib-events directly from your mod if it is present? If not I can include it myself of course, but that way I have to maintain and update it. Or I could just do remote.call(MAJOR, "lib-events", ...), hmm.

folknor commented 6 years ago

Alright, so if there's no events we need three things:

  1. Your mod triggers a on_built_custom_entity/on_placed_helicopter or similar event, where you provide the player and the entity (what is normally event.created_entity and event.player_index), using lib-events.
  2. Some sort of way for my mods (both justgo and fill mods) to know that they need to ignore your fake entity
  3. Some way for this mod (justgo) to map item-entity.

For #1, lib-events was made a few years ago and has never changed. Here is pseudo-code that you could trigger when you are done replacing the entities and such:

local ev = require("lib-events")
function doneWithReplace(player, entity)
    ev.trigger("on-placed-helicopter", player.index, entity)
end

And no, you can not load lib-events from my mod.

For #2, I think there are two ways; either I simply (1) make a local table IGNORE={} and put your fake entities in them, or (2) you add "ignore"/"fake" to the entity prototype .order property, for example. The .order property can be a string of any length, and can contain whatever you want. I don't mind either solution, so it's up to you.

For #3, either I add a local mapping table like #2, or I add a custom LuaRemote interface that you can use, and then you'd need to register in on_configuration_changed or something, like

script.on_configuration_changed(function(data)
    if remote.interfaces["folk-justgo"] and remote.interfaces["folk-justgo"]["item-entity-map"] then
        remote.call("folk-justgo", "item-entity-map", "item-id", "entity-id")
    end
end)

I'm not sure if remote is available in on_configuration_changed, but I presume it is.

kumpuu commented 6 years ago

Excellent roundup, I will implement the changes as soon as you're done with the interface. For #2, I don't think anything needs to be done, as the item and the fake preview entity have different names and shouldn't trigger your mod. For #3, I would prefer the interface method.

kumpuu commented 6 years ago

Hey there! When do you think you're done?