mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-04 09:42:30 +02:00
Add player_onboarding
This commit is contained in:
parent
e43513fcc1
commit
dc0b597f5e
@ -331,6 +331,10 @@ global.config = {
|
||||
-- enables a command which allows for an end-game event
|
||||
apocalypse = {
|
||||
enabled = true
|
||||
},
|
||||
-- gradually informs players of features such as chat, toasts, etc.
|
||||
player_onboarding = {
|
||||
enabled = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,6 +86,9 @@ end
|
||||
if config.apocalypse.enabled then
|
||||
require 'features.apocalypse'
|
||||
end
|
||||
if config.player_onboarding.enabled then
|
||||
require 'features.player_onboarding'
|
||||
end
|
||||
|
||||
-- GUIs
|
||||
-- The order determines the order they appear from left to right.
|
||||
|
109
features/player_onboarding.lua
Normal file
109
features/player_onboarding.lua
Normal file
@ -0,0 +1,109 @@
|
||||
--[[
|
||||
This module aims to gradually teach players about redmew-specific features.
|
||||
]]
|
||||
-- Dependencies
|
||||
local Event = require 'utils.event'
|
||||
local Game = require 'utils.game'
|
||||
local Global = require 'utils.global'
|
||||
local Rank = require 'features.rank_system'
|
||||
local Task = require 'utils.task'
|
||||
local Toast = require 'features.gui.toast'
|
||||
local Token = require 'utils.token'
|
||||
local Ranks = require 'resources.ranks'
|
||||
|
||||
-- Constants
|
||||
local time_to_toast = 600 -- 60s * 10 mins
|
||||
local time_to_chat = 1200 -- 60s * 20 mins
|
||||
|
||||
-- Local vars
|
||||
local Public = {}
|
||||
|
||||
-- Global-registered locals
|
||||
local player_chatted = {}
|
||||
Global.register(
|
||||
{
|
||||
player_chatted = player_chatted
|
||||
},
|
||||
function(tbl)
|
||||
player_chatted = tbl.player_chatted
|
||||
end
|
||||
)
|
||||
|
||||
-- Local functions
|
||||
local toast_token =
|
||||
Token.register(
|
||||
function(data)
|
||||
local player_index = data.player_index
|
||||
|
||||
if data.chat_teaching and player_chatted[player_index] then
|
||||
return
|
||||
end
|
||||
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
if not player or not player.valid or not player.connected then
|
||||
return
|
||||
end
|
||||
|
||||
Toast.toast_player(player, 60, data.msg)
|
||||
end
|
||||
)
|
||||
|
||||
local function on_player_created(event)
|
||||
local player_index = event.player_index
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
local player_name = player.name
|
||||
if Rank.equal(player_name, Ranks.guest) then
|
||||
Task.set_timeout(
|
||||
time_to_toast,
|
||||
toast_token,
|
||||
{
|
||||
player_index = player_index,
|
||||
msg = {'player_onboarding.teach_toast'}
|
||||
}
|
||||
)
|
||||
Task.set_timeout(
|
||||
time_to_chat,
|
||||
toast_token,
|
||||
{
|
||||
player_index = player_index,
|
||||
chat_teaching = true,
|
||||
msg = {
|
||||
'player_onboarding.teach_chat',
|
||||
{'gui-menu.settings'},
|
||||
{'gui-menu.controls'},
|
||||
{'controls.toggle-console'}
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
--- Log all players who have chatted or used commands this map.
|
||||
-- This will also gives us a measure of how many players engage in chat in a map.
|
||||
local function on_player_chat(event)
|
||||
local player_index = event.player_index
|
||||
local player = Game.get_player_by_index(player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
player_chatted[player_index] = true
|
||||
end
|
||||
|
||||
-- Public functions
|
||||
|
||||
--- Returns the number of players who have chatted or used a command this map.
|
||||
function Public.get_num_players_chatted()
|
||||
return table_size(player_chatted)
|
||||
end
|
||||
|
||||
-- Event registers
|
||||
Event.add(defines.events.on_player_created, on_player_created)
|
||||
Event.add(defines.events.on_console_chat, on_player_chat)
|
||||
Event.add(defines.events.on_console_command, on_player_chat)
|
||||
|
||||
return Public
|
@ -100,3 +100,7 @@ mention_success=__1__ __2__ mentioned __3__!
|
||||
mention_fail_mention_self=__1__ Can't mention yourself!
|
||||
mention_not_found_plural=__1__ Players not found: __2__
|
||||
mention_not_found_singular=__1__ Player not found: __2__
|
||||
|
||||
[player_onboarding]
|
||||
teach_toast=This is a feature in RedMew called a toast!\nThey're little pieces of information that pop up.\nYou can dismiss is by waiting or by clicking on it.
|
||||
teach_chat=To chat with other players, press the __CONTROL__toggle-console__ key on your keyboard.\nThe default key on English keyboards is the grave (`) and is below the ESC key.\nThis key can be changed in __1__ -> __2__ -> __3__.
|
||||
|
Loading…
Reference in New Issue
Block a user