mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Fixed maps played not being counted
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
|
||||
local Event = require 'utils.event' ---@dep utils.event
|
||||
local Global = require 'utils.global' ---@dep utils.global
|
||||
local config = require 'config.statistics' ---@dep config.statistics
|
||||
local format_time = _C.format_time
|
||||
local floor = math.floor
|
||||
local afk_required = 5*3600 -- 5 minutes
|
||||
|
||||
--- Stores players who have been created, required to avoid loss of data
|
||||
local new_players, MapsPlayed = {}, nil
|
||||
Global.register(new_players, function(tbl)
|
||||
new_players = tbl
|
||||
end)
|
||||
|
||||
--- Stores the statistics on a player
|
||||
local PlayerData = require 'expcore.player_data' --- @dep expcore.player_data
|
||||
local AllPlayerData = PlayerData.All
|
||||
@@ -18,6 +25,7 @@ Statistics:on_load(function(player_name, player_statistics)
|
||||
local existing_data = AllPlayerData:get(player_name)
|
||||
if existing_data and existing_data.valid then return end
|
||||
local counters = config.counters
|
||||
-- Merge all data from before you data loaded
|
||||
for key, value in pairs(Statistics:get(player_name, {})) do
|
||||
if config[key] or counters[key] then
|
||||
if not player_statistics[key] then
|
||||
@@ -27,6 +35,11 @@ Statistics:on_load(function(player_name, player_statistics)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Increment your maps played if this is your first time on this map
|
||||
if new_players[player_name] then
|
||||
new_players[player_name] = nil
|
||||
MapsPlayed:increment(player_name)
|
||||
end
|
||||
return player_statistics
|
||||
end)
|
||||
|
||||
@@ -39,6 +52,16 @@ local function format_minutes(value)
|
||||
})
|
||||
end
|
||||
|
||||
--- Add MapsPlayed if it is enabled
|
||||
if config.MapsPlayed then
|
||||
MapsPlayed = Statistics:combine('MapsPlayed')
|
||||
MapsPlayed:set_metadata{unit=' maps'}
|
||||
Event.add(defines.events.on_player_joined_game, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
new_players[player.name] = true
|
||||
end)
|
||||
end
|
||||
|
||||
--- Add Playtime and AfkTime if it is enabled
|
||||
if config.Playtime or config.AfkTime then
|
||||
local playtime, afk_time
|
||||
|
||||
Reference in New Issue
Block a user