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

Add map poll for crashsite maps. (#1380)

This commit is contained in:
grilledham 2023-10-17 17:42:17 +01:00 committed by GitHub
parent 9870e7a14a
commit ac3b95284a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 115 additions and 1 deletions

View File

@ -13,6 +13,8 @@ local Discord = require 'resources.discord'
local ScoreTracker = require 'utils.score_tracker'
local PlayerStats = require 'features.player_stats'
local Restart = require 'features.restart_command'
local Poll = require 'features.gui.poll'
local MapPoll = require 'map_gen.maps.crash_site.map_poll'
local set_timeout_in_ticks = Task.set_timeout_in_ticks
local format_number = require 'util'.format_number
@ -226,7 +228,23 @@ function Public.control(config)
Server.set_data('crash_site_data', tostring(end_epoch), statistics) -- Store the table, with end_epoch as the key
end
Restart.register(can_restart, restart_callback)
local function restart_requested()
if not Restart.get_use_map_poll_result_option() then
return
end
local map_data = MapPoll.get_next_map()
if map_data == nil then
return
end
Restart.set_start_game_data({type = Restart.game_types.scenario, name = map_data.name, mod_pack = nil})
local poll_id = MapPoll.get_map_poll_id()
Poll.send_poll_result_to_discord(poll_id)
end
Restart.register(can_restart, restart_callback, restart_requested)
local chart_area_callback = Token.register(function(data)
local xpos = data.xpos

View File

@ -0,0 +1,96 @@
local Poll = require 'features.gui.poll'
local Global = require 'utils.global'
local Event = require 'utils.event'
local PollUtils = require 'utils.poll_utils'
local Restart = require 'features.restart_command'
local Server = require 'features.server'
local Ranks = require 'resources.ranks'
local data = {
created = false,
id = nil
}
Global.register(data, function(tbl)
data = tbl
end)
local maps = {
{
name = 'crashsite',
display_name = 'Normal'
},
{
name = 'crashsite-UK',
display_name = 'UK'
},
{
name = 'crashsite-arrakis',
display_name = 'Arrakis'
},
{
name = 'crashsite-desert',
display_name = 'Desert'
},
{
name = 'crashsite-manhattan',
display_name = 'Manhattan'
},
{
name = 'crashsite-venice',
display_name = 'Venice'
},
{
name = 'crashsite-world',
display_name = 'World'
},
}
Event.add(Server.events.on_server_started, function()
if data.created then
return
end
data.created = true
local answers = {}
for i, map_data in pairs(maps) do
answers[i] = map_data.display_name
end
local success, id = Poll.poll({
question = 'Next map? (Advisory only)',
duration = 0,
edit_rank = Ranks.admin,
answers = answers
})
if success then
data.id = id
end
Restart.set_use_map_poll_result_option(true)
end)
local Public = {}
function Public.get_map_poll_id()
return data.id
end
function Public.get_next_map()
local poll_data = Poll.get_poll_data(data.id)
if poll_data == nil then
return nil
end
local answers = poll_data.answers
local chosen_index = PollUtils.get_poll_winner(answers)
if chosen_index == nil then
return nil
end
return maps[chosen_index]
end
return Public