Giter VIP home page Giter VIP logo

Comments (5)

AP-Hunt avatar AP-Hunt commented on July 26, 2024

This shouldn't be too difficult to do. Something like the below would be my proposed solution.

-- Use an array to support multiple types
Trains.settings.locomotive_types= {'diesel-locomotive', 'farl'}

local function filter_event(event_parameter, callback)
    return function(evt)
        for _, entity_type in pairs(Trains.settings.locomotive_types) do
            if(evt[event_parameter].name == entity_type) then
                callback(evt[event_parameter])
            end
        end
    end
end

Event.register(defines.events.on_entity_died, filter_event('entity', Trains._on_locomotive_changed))

Since Trains.find_filtered more or less passes its input directly to Surface.find_all_entities, you can already search for different types of locomotives in the same way you would when using that module.

from factorio-stdlib.

Afforess avatar Afforess commented on July 26, 2024

@AndyBursh admittedly I don't have the Factorio prototypes in front of me, but isn't there only one type of entity that can be a train, the diesel locomotive? I believe the FARL train, or electric trains I seem to recall in some other mod, do have different entity names, but the entity type should still be diesel locomotive (or whatever type they all share). Couldn't we filter based on type and make this even easier?

from factorio-stdlib.

AP-Hunt avatar AP-Hunt commented on July 26, 2024

I would be lying if I said I knew much about that. I'll have to do some investigation.

from factorio-stdlib.

Choumiko avatar Choumiko commented on July 26, 2024

Yes, they all have type locomotive. That would have been my first PR once i would have found the time to do anything xD

from factorio-stdlib.

AP-Hunt avatar AP-Hunt commented on July 26, 2024

Well that's good news! I'll make a PR in the next couple of days.

from factorio-stdlib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.