Skip to content

Commit

Permalink
Merge pull request #3 from robot256/mod_support
Browse files Browse the repository at this point in the history
Mod support
  • Loading branch information
ndelta0 authored Apr 5, 2019
2 parents 970f590 + 0eb8ebd commit ccfc0a5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ script.on_load(on_load)
script.on_configuration_changed(on_configuration_changed)

script.on_event(defines.events.on_built_entity, on_built_entity)
script.on_event(defines.events.script_raised_built, script_raised_built)
script.on_event(defines.events.on_entity_died, on_entity_died)
script.on_event(defines.events.script_raised_destroy, script_raised_destroy)
script.on_event(defines.events.on_player_placed_equipment, on_player_placed_equipment)
script.on_event(defines.events.on_player_removed_equipment, on_player_removed_equipment)
script.on_event(defines.events.on_pre_player_mined_item, on_pre_player_mined_item)
Expand Down
25 changes: 20 additions & 5 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ local fuel_tick
local handle_train_state_change
local on_entity_removed
local on_train_removed
local on_entity_added
local read_equipment
local recover_energy
local update_equipment
Expand Down Expand Up @@ -333,21 +334,35 @@ on_entity_removed = function(entity)
end
end

on_entity_added = function(entity)
if(entity and entity.valid) then
if(vehicle_types[entity.type] and entity.grid) then
global.vehicles[entity.unit_number] = entity
update_equipment(entity.unit_number, entity.grid)
end
end
end

-- Event entry points
-------------------------------------------------------------------------------

function on_built_entity(event)
local entity = event.created_entity
if(vehicle_types[entity.type] and entity.grid) then
global.vehicles[entity.unit_number] = entity
update_equipment(entity.unit_number, entity.grid)
end
on_entity_added(event.created_entity)
end

function script_raised_built(event)
on_entity_added(event.entity) -- script_raised has different structure than on_built_entity
end

function on_entity_died(event)
on_entity_removed(event.entity)
end

function script_raised_destroy(event)
on_entity_removed(event.entity)
end


function on_player_placed_equipment(event)
for unit, entity in pairs(global.vehicles) do
if(entity.valid) then
Expand Down

0 comments on commit ccfc0a5

Please sign in to comment.