mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-18 03:21:47 +02:00
Added easy on_init feature hook
This commit is contained in:
parent
b799da20e3
commit
36168771dd
@ -16,6 +16,8 @@ global.MarketExchange = {
|
||||
stone_sent_to_surface = 0,
|
||||
}
|
||||
|
||||
local on_init;
|
||||
|
||||
--[[--
|
||||
Registers all event handlers.
|
||||
]]
|
||||
@ -35,15 +37,18 @@ function MarketExchange.register(config)
|
||||
end
|
||||
|
||||
local on_market_timeout_finished = Token.register(function(params)
|
||||
Template.market(game.surfaces.nauvis, {x = 0, y = -5}, game.forces.player, params.currency_item, params.market_items)
|
||||
Template.market(params.surface, params.position, params.player_force, params.currency_item, params.market_items)
|
||||
end)
|
||||
|
||||
Event.on_init(function()
|
||||
on_init = function()
|
||||
Task.set_timeout_in_ticks(60, on_market_timeout_finished, {
|
||||
surface = game.surfaces.nauvis,
|
||||
position = {x = 0, y = -5},
|
||||
player_force = game.forces.player,
|
||||
currency_item = config.currency_item,
|
||||
market_items = market_items,
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
Event.add(defines.events.on_market_item_purchased, function (event)
|
||||
@ -59,4 +64,12 @@ function MarketExchange.get_extra_map_info(config)
|
||||
return 'Market Exchange, trade your stone or send it to the surface'
|
||||
end
|
||||
|
||||
function MarketExchange.on_init()
|
||||
if ('function' ~= type(on_init)) then
|
||||
error('Expected local on_init in MarketExchange to have a function assigned.')
|
||||
end
|
||||
|
||||
on_init()
|
||||
end
|
||||
|
||||
return MarketExchange
|
||||
|
@ -56,10 +56,8 @@ function MiningEfficiency.get_extra_map_info(config)
|
||||
Efficiency increase per level: ]] .. config.mining_speed_productivity_multiplier .. '%'
|
||||
end
|
||||
|
||||
Event.on_init(
|
||||
function()
|
||||
update_mining_speed(game.forces.player)
|
||||
end
|
||||
)
|
||||
function MiningEfficiency.on_init()
|
||||
update_mining_speed(game.forces.player)
|
||||
end
|
||||
|
||||
return MiningEfficiency
|
||||
|
@ -71,13 +71,12 @@ function StartingZone.register(config)
|
||||
daytime = config.daytime
|
||||
end
|
||||
|
||||
Event.on_init(
|
||||
function()
|
||||
local surface = game.surfaces.nauvis
|
||||
function StartingZone.on_init()
|
||||
local surface = game.surfaces.nauvis
|
||||
|
||||
surface.daytime = daytime
|
||||
surface.freeze_daytime = 1
|
||||
end
|
||||
|
||||
surface.daytime = daytime
|
||||
surface.freeze_daytime = 1
|
||||
end
|
||||
)
|
||||
|
||||
return StartingZone
|
||||
|
@ -2,6 +2,7 @@
|
||||
local Config = require 'map_gen.Diggy.Config'
|
||||
local Debug = require 'map_gen.Diggy.Debug'
|
||||
local ScenarioInfo = require 'info'
|
||||
local Event = require 'utils.event'
|
||||
|
||||
require 'utils.list_utils'
|
||||
require 'utils.utils'
|
||||
@ -60,16 +61,20 @@ function Scenario.register(debug)
|
||||
local extra_map_info = ''
|
||||
|
||||
each_enabled_feature(
|
||||
function(feature_name, feature_data)
|
||||
function(feature_name, feature_config)
|
||||
local feature = require ('map_gen.Diggy.Feature.' .. feature_name)
|
||||
if ('function' ~= type(feature.register)) then
|
||||
error('Feature ' .. feature_name .. ' did not define a register function.')
|
||||
end
|
||||
|
||||
feature.register(feature_data)
|
||||
feature.register(feature_config)
|
||||
|
||||
if ('function' == type(feature.get_extra_map_info)) then
|
||||
extra_map_info = extra_map_info .. feature.get_extra_map_info(feature_data) .. '\n\n'
|
||||
extra_map_info = extra_map_info .. feature.get_extra_map_info(feature_config) .. '\n\n'
|
||||
end
|
||||
|
||||
if ('function' == type(feature.on_init)) then
|
||||
Event.on_init(feature.on_init)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user