1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-04 09:42:30 +02:00

Add set_alt_on_create

This commit is contained in:
plague006 2019-03-02 02:12:12 -05:00
parent 6a8d07cc8a
commit 060ee3afb7
2 changed files with 52 additions and 2 deletions

View File

@ -278,7 +278,9 @@ global.config = {
-- gives players entity ghosts (from destruction like biter attacks) before the required research is complete
ghosts_before_research = true,
-- adds craftable loaders.
loaders = true
loaders = true,
-- turns on entity info aka alt-mode on first joining
set_alt_on_create = true
},
-- adds a useless button with the biter percentage
evolution_progress = {

View File

@ -7,6 +7,7 @@ local Utils = require 'utils.core'
local Global = require 'utils.global'
local table = require 'utils.table'
local Task = require 'utils.task'
local Game = require 'utils.game'
local Rank = require 'features.rank_system'
local config = global.config.redmew_qol
@ -18,7 +19,12 @@ local random = math.random
local Public = {}
-- Global registers
local enabled = {}
local enabled = {
random_train_color = nil,
restrict_chest = nil,
change_backer_name = nil,
set_alt_on_create = nil
}
Global.register(
{
@ -91,6 +97,18 @@ local change_backer_name =
end
)
--- Changes the backer name on an entity that supports having a backer name.
local set_alt_on_create =
Token.register(
function(event)
local player = Game.get_player_by_index(event.player_index)
if not player then
return
end
player.game_view_settings.show_entity_info = true
end
)
local loaders_technology_map = {
['logistics'] = 'loader',
['logistics-2'] = 'fast-loader',
@ -152,6 +170,15 @@ local function register_change_backer_name()
return true
end
local function register_set_alt_on_create()
if enabled.set_alt_on_create then
return false -- already registered
end
enabled.set_alt_on_create = true
Event.add_removable(defines.events.on_player_created, set_alt_on_create)
return true
end
local function on_init()
-- Set player force's ghost_time_to_live to an hour. Giving the players ghosts before the research of robots is a nice QOL improvement.
if config.ghosts_before_research then
@ -231,6 +258,24 @@ function Public.get_backer_name()
return enabled.change_backer_name or false
end
--- Sets set_alt_on_create on or off.
-- @param enable <boolean> true to toggle on, false for off
-- @return <boolean> Success/failure of command
function Public.set_set_alt_on_create(enable)
if enable then
return register_set_alt_on_create()
else
Event.remove_removable(defines.events.on_player_created, set_alt_on_create)
enabled.set_alt_on_create = false
return true
end
end
--- Return status of set_alt_on_create
function Public.set_alt_on_create()
return enabled.set_alt_on_create or false
end
-- Initial event setup
if config.random_train_color then
@ -242,6 +287,9 @@ end
if config.backer_name then
register_change_backer_name()
end
if config.set_alt_on_create then
register_set_alt_on_create()
end
if config.loaders then
Event.add(defines.events.on_research_finished, enable_loaders)