Comments (5)
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.
@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.
I would be lying if I said I knew much about that. I'll have to do some investigation.
from factorio-stdlib.
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.
Well that's good news! I'll make a PR in the next couple of days.
from factorio-stdlib.
Related Issues (20)
- Upgrade Readme and Wiki HOT 2
- To Do List
- Data.Util.Duplicate on normal/expensive recipes HOT 6
- Wiki with list of functions and their functionalities HOT 2
- Recipe:clear_ingredients error HOT 5
- Small errors found with trains/events HOT 6
- add_ingredient issue HOT 8
- 0.18 support? HOT 1
- remove_prereq nullifies prerequisites value of technology table.
- errors found with trains/events
- add_ingredient cant find items that are modules
- Event handler filter is ignored if more than one event ID is specified in `register`
- spidertron-remotes aren't checked as "items" so a recipe result (and more) may fail to find one HOT 1
- documentation broken HOT 2
- Event.register not passing pattern to function HOT 1
- Inconsistency of technology pack methods
- Gui events not working HOT 1
- String.contains doesn't work with strings that contain a hyphen.
- Question: Which tool can be used to interpret the code documentation in VSCode
- This does not look right: return (Area.size(Area)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from factorio-stdlib.