Skip to content

Commit

Permalink
STDLIB Update
Browse files Browse the repository at this point in the history
Former-commit-id: 1cce67d [formerly 1d81c1b]
Former-commit-id: 1cce67d
Former-commit-id: e047a8c
  • Loading branch information
Nexela committed Apr 1, 2018
1 parent 8c18615 commit 1a3cb42
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions stdlib/config/migrate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
local Migrate = {}
setmetatable(Migrate, {__index = require('stdlib/core')})

local Is = require('stdlib/utils/is')
local Is = Migrate.Is

--- Migrate a dictionary of recipe -> tech names
-- @tparam dictionary dictionary
Expand All @@ -25,7 +25,7 @@ function Migrate.all_recipes()
for _, force in pairs(game.forces) do
for _, tech in pairs(force.technologies) do
if tech.researched then
for _, unlock in pairs(force.effects or {}) do
for _, unlock in pairs(tech.effects or {}) do
if unlock.type == "unlock-recipe" then
force.recipes[unlock.recipe].enabled = true
end
Expand Down
16 changes: 8 additions & 8 deletions stdlib/event/force.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ local function new(force_name)
index = force_name,
name = force_name
}
if Event._new_force_data then
if type(Event._new_force_data) == 'table' then
table.merge(fdata, table.deepcopy(Event._new_force_data))
elseif type(Event._new_force_data) == 'function' then
local new_data = Event._new_force_data(force_name)
if Force._new_force_data then
if type(Force._new_force_data) == 'table' then
table.merge(fdata, table.deepcopy(Force._new_force_data))
elseif type(Force._new_force_data) == 'function' then
local new_data = Force._new_force_data(force_name)
if type(new_data) == 'table' then
table.merge(fdata, new_data)
else
Expand All @@ -42,7 +42,7 @@ local function new(force_name)
end

function Force.additional_data(func_or_table)
Event._new_force_data = func_or_table
Force._new_force_data = func_or_table
return Force
end

Expand Down Expand Up @@ -108,10 +108,10 @@ function Force.register_init()
return Force
end

function Force.register_events(skip_init)
function Force.register_events(do_on_init)
Event.register(defines.events.on_force_created, Force.init)
Event.register(defines.events.on_forces_merging, Force.merge)
if not skip_init then
if do_on_init then
Force.register_init()
end
return Force
Expand Down
18 changes: 9 additions & 9 deletions stdlib/event/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ local function new(player_index)
name = game.players[player_index].name,
force = game.players[player_index].force.name
}
if Event._new_player_data then
if type(Event._new_player_data) == 'table' then
table.merge(pdata, table.deepcopy(Event._new_player_data))
elseif type(Event._new_player_data) == 'function' then
local new_data = Event._new_player_data(player_index)
if Player._new_player_data then
if type(Player._new_player_data) == 'table' then
table.merge(pdata, table.deepcopy(Player._new_player_data))
elseif type(Player._new_player_data) == 'function' then
local new_data = Player._new_player_data(player_index)
if type(new_data) == 'table' then
table.merge(pdata, new_data)
else
Expand All @@ -40,7 +40,7 @@ local function new(player_index)
end

function Player.additional_data(func_or_table)
Event._new_player_data = func_or_table
Player._new_player_data = func_or_table
return Player
end

Expand All @@ -59,7 +59,7 @@ end

--- Merge a copy of the passed data to all players in `global.players`.
-- @tparam table data a table containing variables to merge
-- @usage local data = {a = 'abc', b= 'def'}
-- @usage local data = {a = 'abc', b = 'def'}
-- Player.add_data_all(data)
function Player.add_data_all(data)
local pdata = global.players
Expand Down Expand Up @@ -126,11 +126,11 @@ function Player.register_init()
return Player
end

function Player.register_events(skip_init)
function Player.register_events(do_on_init)
Event.register(defines.events.on_player_created, Player.init)
Event.register(defines.events.on_player_changed_force, Player.update_force)
Event.register(defines.events.on_player_removed, Player.remove)
if not skip_init then
if do_on_init then
Player.register_init()
end
return Player
Expand Down

0 comments on commit 1a3cb42

Please sign in to comment.