diff --git a/exp_legacy/module/config/_file_loader.lua b/exp_legacy/module/config/_file_loader.lua index 79e8688f..3d029c51 100644 --- a/exp_legacy/module/config/_file_loader.lua +++ b/exp_legacy/module/config/_file_loader.lua @@ -5,7 +5,4 @@ -- @config File-Loader return { "expcore.player_data", -- must be loaded first to register event handlers - - --- Data - "modules.data.statistics", } diff --git a/exp_legacy/module/config/statistics.lua b/exp_legacy/module/config/statistics.lua deleted file mode 100644 index c4a4d4a0..00000000 --- a/exp_legacy/module/config/statistics.lua +++ /dev/null @@ -1,46 +0,0 @@ ---- A list of all tracked statistics and the events which trigger them --- @config Statistics - -local e = defines.events -- order as per lua api as it was easier just to go down the list -return { - MapsPlayed = true, --- @setting MapsPlayed If the number of maps which a player has played should be tracked - Playtime = true, --- @setting Playtime If playtime is tracked for a player, play time measured in minutes - AfkTime = true, --- @setting AfkTime If afk time is tracked for a player, play time measured in minutes, afk is once a player does nothing for 5 minutes - DistanceTravelled = true, --- @setting DistanceTravelled If distance Travelled is checked, only counts if not afk - MachinesRemoved = true, --- @setting MachinesRemoved If removed machines are tracked, includes marked for decon and player mined entity - TreesDestroyed = true, --- @setting OreMined If ore mined is tracked for a player, includes marked for decon and player mined entity but only trees - OreMined = true, --- @setting OreMined If ore mined is tracked for a player, includes player mined entity but only ore - DamageDealt = true, --- @setting DamageDealt If damage dealt is tracked for a player, includes any damage to entities not on the same force or neutral - Kills = true, --- @setting Kills If kills are tracked for a player, includes all kills not on same force or neutral - RocketsLaunched = true, --- @setting RocketsLaunched If the number of rockets launched should be tracked, done for all players on the force - ResearchCompleted = true, --- @setting ResearchCompleted If the number of researches completed should be tracked, done for all players on the force - counters = { --- @setting counters Simple statistics that just go up by one each time an event happens - MachinesBuilt = e.on_built_entity, - MapTagsMade = e.on_chart_tag_added, - ChatMessages = e.on_console_chat, - CommandsUsed = e.on_console_command, - ItemsPickedUp = e.on_picked_up_item, - TilesBuilt = e.on_player_built_tile, - ItemsCrafted = e.on_player_crafted_item, - DeconstructionPlannerUsed = e.on_player_deconstructed_area, - Deaths = e.on_player_died, - JoinCount = e.on_player_joined_game, - TilesRemoved = e.on_player_mined_tile, - CapsulesUsed = e.on_player_used_capsule, - EntityRepaired = e.on_player_repaired_entity, - }, - display_order = { --- @setting display_order The order that the statistics should be shown in when in a gui or command - "Playtime", "AfkTime", - "MapsPlayed", "JoinCount", - "ChatMessages", "CommandsUsed", - "RocketsLaunched", "ResearchCompleted", - "MachinesBuilt", "MachinesRemoved", - "TilesBuilt", "TilesRemoved", - "TreesDestroyed", "OreMined", - "ItemsCrafted", "ItemsPickedUp", - "Kills", "Deaths", - "DamageDealt", "DistanceTravelled", - "CapsulesUsed", "EntityRepaired", - "DeconstructionPlannerUsed", "MapTagsMade", - }, -} diff --git a/exp_legacy/module/locale/en.cfg b/exp_legacy/module/locale/en.cfg index 9e85f680..1de56114 100644 --- a/exp_legacy/module/locale/en.cfg +++ b/exp_legacy/module/locale/en.cfg @@ -19,72 +19,6 @@ Bonus=Player Bonus Bonus-tooltip=The bonus given to your character Bonus-value-tooltip=Change by using /bonus -[exp-statistics] -MapsPlayed=Maps Played -MapsPlayed-tooltip=The number of unique maps you have played on -JoinCount=Join Count -JoinCount-tooltip=The number of times you have joined our servers -Playtime=Playtime -Playtime-tooltip=The amount of time you have spent on our servers -AfkTime=AFK Time -AfkTime-tooltip=The amount of time you have been AFK on our servers -ChatMessages=Messages -ChatMessages-tooltip=The number of messages you have sent in chat -CommandsUsed=Commands -CommandsUsed-tooltip=The number of commands you have used -RocketsLaunched=Rockets Launched -RocketsLaunched-tooltip=The number of rockets launched while you were online -ResearchCompleted=Research Completed -ResearchCompleted-tooltip=The number of research projects completed while you were online -MachinesBuilt=Machines Built -MachinesBuilt-tooltip=The number of machines you have built -MachinesRemoved=Machines Removed -MachinesRemoved-tooltip=The number of machines you have removed -TilesBuilt=Tiles Placed -TilesBuilt-tooltip=The number of tiles you have placed -TilesRemoved=Tiles Removed -TilesRemoved-tooltip=The number of tiles you have removed -TreesDestroyed=Trees Destroyed -TreesDestroyed-tooltip=The number of trees you have destroyed -OreMined=Ore Mined -OreMined-tooltip=The amount of ore you have mined -ItemsCrafted=Items Crafted -ItemsCrafted-tooltip=The number of items you have crafted -ItemsPickedUp=Items Picked Up -ItemsPickedUp-tooltip=The number of items you have picked up -Kills=Kills -Kills-tooltip=The number of biters and biter bases you have squished -Deaths=Deaths -Deaths-tooltip=The number of times you have died -DamageDealt=Damage Dealt -DamageDealt-tooltip=The amount of damage you have dealt to other forces -DistanceTravelled=Distance Travelled -DistanceTravelled-tooltip=The total distance in tiles that you have travelled -CapsulesUsed=Capsules Used -CapsulesUsed-tooltip=The number of capsules you have used -EntityRepaired=Machines Repaired -EntityRepaired-tooltip=The number of machines which you have repaired -DeconstructionPlannerUsed=Decon Planner Used -DeconstructionPlannerUsed-tooltip=The number of times you have used the deconstruction planner -MapTagsMade=Map Tags Created -MapTagsMade-tooltip=The number of map tags you have created -DamageDeathRatio=Damage Death Ratio -DamageDeathRatio-tooltip=Damage over Death -KillDeathRatio=Kill Death Ratio -KillDeathRatio-tooltip=Kill over Death -SessionTime=Session Time -SessionTime-tooltip=Session Time -BuildRatio=Build Ratio -BuildRatio-tooltip=Build over Remove -RocketPerHour=Rocket Per Hour -RocketPerHour-tooltip=Rocket Launched Over Play Time in Hour -TreeKillPerMinute=Tree Kill Per Minute -TreeKillPerMinute-tooltip=Tree Destroyed Per Minute -NetPlayTime=Net Play Time -NetPlayTime-tooltip=Net Play Time -AFKTimeRatio=AFK Time Ratio -AFKTimeRatio-tooltip=AFK Time over Play Time - # expcore [expcore-data] description-preference=Allows you to set/get your data saving preference. diff --git a/exp_legacy/module/locale/zh-CN.cfg b/exp_legacy/module/locale/zh-CN.cfg index 4d1ce2e2..82f411b8 100644 --- a/exp_legacy/module/locale/zh-CN.cfg +++ b/exp_legacy/module/locale/zh-CN.cfg @@ -19,72 +19,6 @@ Bonus=人物附加屬性 Bonus-tooltip=你的人物附加屬性 Bonus-value-tooltip=使用 /bonus 來更改 -[exp-statistics] -MapsPlayed=地圖遊玩次數 -MapsPlayed-tooltip=你在本服務器遊玩過的地圖數 -JoinCount=登入次數 -JoinCount-tooltip=你在本服務器遊玩的次數 -Playtime=遊玩時間 -Playtime-tooltip=你在本服務器遊玩的時間 -AfkTime=掛機時間 -AfkTime-tooltip=你在本服務器掛機的時間 -ChatMessages=傳送信息次數 -ChatMessages-tooltip=你在本服務器發送信息的次數 -CommandsUsed=使用指令次數 -CommandsUsed-tooltip=你在本服務器使用指令的次數 -RocketsLaunched=火箭發射次數 -RocketsLaunched-tooltip=你在本服務器在線時所發射過火箭的次數 -ResearchCompleted=研究次數 -ResearchCompleted-tooltip=你在本服務器在線時完成研究的次數 -MachinesBuilt=機器建造次數 -MachinesBuilt-tooltip=你在本服務器建造過機器的次數 -MachinesRemoved=機器拆除次數 -MachinesRemoved-tooltip=你在本服務器拆除過機器的次數 -TilesBuilt=地磚建造次數 -TilesBuilt-tooltip=你在本服務器建造過地磚的次數 -TilesRemoved=地磚拆除次數 -TilesRemoved-tooltip=你在本服務器拆除過地磚的次數 -TreesDestroyed=樹木拆除次數 -TreesDestroyed-tooltip=你在本服務器拆除過樹木的次數 -OreMined=挖礦次數 -OreMined-tooltip=你在本服務器挖掘礦的次數 -ItemsCrafted=物品合成數 -ItemsCrafted-tooltip=你在本服務器合成過物品的次數 -ItemsPickedUp=物品拾起數 -ItemsPickedUp-tooltip=你在本服務器起過物品的次數 -Kills=撃殺數 -Kills-tooltip=你在本服務器殺過的敵人數量 -Deaths=死亡次數 -Deaths-tooltip=你在本服務器死過的數量 -DamageDealt=傷害量 -DamageDealt-tooltip=你在本伺服器對敵人所造成的傷害量 -DistanceTravelled=移動距離 -DistanceTravelled-tooltip=你在本服務器的總移動距離 -CapsulesUsed=膠囊使用次數 -CapsulesUsed-tooltip=你在本服務器使用過膠囊的次數 -EntityRepaired=機器維修次數 -EntityRepaired-tooltip=你在本服務器維修過機器的次數 -DeconstructionPlannerUsed=拆除規劃器使用次數 -DeconstructionPlannerUsed-tooltip=你在本服務器使用過拆除規劃器的次數 -MapTagsMade=地圖標籤數量 -MapTagsMade-tooltip=你在本服務器放過的地圖標籤數量 -DamageDeathRatio=傷害死亡比 -DamageDeathRatio-tooltip=傷害除以死亡 -KillDeathRatio=撃殺死亡比 -KillDeathRatio-tooltip=撃殺除以死亡 -SessionTime=平均遊玩時間 -SessionTime-tooltip=平均遊玩時間 -BuildRatio=建築比 -BuildRatio-tooltip=建築次數除以拆除次數 -RocketPerHour=每小時火箭發射次數 -RocketPerHour-tooltip=火箭發射次數除以遊玩時間 -TreeKillPerMinute=每分鐘樹木拆除數 -TreeKillPerMinute-tooltip=樹木拆除數除以遊玩時間 -NetPlayTime=淨遊玩時間 -NetPlayTime-tooltip=遊玩時間減掛機時間 -AFKTimeRatio=掛機時間比 -AFKTimeRatio-tooltip=掛機時間除以遊玩時間 - # expcore [expcore-data] description-preference=允許寫入資料。 diff --git a/exp_legacy/module/locale/zh-TW.cfg b/exp_legacy/module/locale/zh-TW.cfg index 4d1ce2e2..82f411b8 100644 --- a/exp_legacy/module/locale/zh-TW.cfg +++ b/exp_legacy/module/locale/zh-TW.cfg @@ -19,72 +19,6 @@ Bonus=人物附加屬性 Bonus-tooltip=你的人物附加屬性 Bonus-value-tooltip=使用 /bonus 來更改 -[exp-statistics] -MapsPlayed=地圖遊玩次數 -MapsPlayed-tooltip=你在本服務器遊玩過的地圖數 -JoinCount=登入次數 -JoinCount-tooltip=你在本服務器遊玩的次數 -Playtime=遊玩時間 -Playtime-tooltip=你在本服務器遊玩的時間 -AfkTime=掛機時間 -AfkTime-tooltip=你在本服務器掛機的時間 -ChatMessages=傳送信息次數 -ChatMessages-tooltip=你在本服務器發送信息的次數 -CommandsUsed=使用指令次數 -CommandsUsed-tooltip=你在本服務器使用指令的次數 -RocketsLaunched=火箭發射次數 -RocketsLaunched-tooltip=你在本服務器在線時所發射過火箭的次數 -ResearchCompleted=研究次數 -ResearchCompleted-tooltip=你在本服務器在線時完成研究的次數 -MachinesBuilt=機器建造次數 -MachinesBuilt-tooltip=你在本服務器建造過機器的次數 -MachinesRemoved=機器拆除次數 -MachinesRemoved-tooltip=你在本服務器拆除過機器的次數 -TilesBuilt=地磚建造次數 -TilesBuilt-tooltip=你在本服務器建造過地磚的次數 -TilesRemoved=地磚拆除次數 -TilesRemoved-tooltip=你在本服務器拆除過地磚的次數 -TreesDestroyed=樹木拆除次數 -TreesDestroyed-tooltip=你在本服務器拆除過樹木的次數 -OreMined=挖礦次數 -OreMined-tooltip=你在本服務器挖掘礦的次數 -ItemsCrafted=物品合成數 -ItemsCrafted-tooltip=你在本服務器合成過物品的次數 -ItemsPickedUp=物品拾起數 -ItemsPickedUp-tooltip=你在本服務器起過物品的次數 -Kills=撃殺數 -Kills-tooltip=你在本服務器殺過的敵人數量 -Deaths=死亡次數 -Deaths-tooltip=你在本服務器死過的數量 -DamageDealt=傷害量 -DamageDealt-tooltip=你在本伺服器對敵人所造成的傷害量 -DistanceTravelled=移動距離 -DistanceTravelled-tooltip=你在本服務器的總移動距離 -CapsulesUsed=膠囊使用次數 -CapsulesUsed-tooltip=你在本服務器使用過膠囊的次數 -EntityRepaired=機器維修次數 -EntityRepaired-tooltip=你在本服務器維修過機器的次數 -DeconstructionPlannerUsed=拆除規劃器使用次數 -DeconstructionPlannerUsed-tooltip=你在本服務器使用過拆除規劃器的次數 -MapTagsMade=地圖標籤數量 -MapTagsMade-tooltip=你在本服務器放過的地圖標籤數量 -DamageDeathRatio=傷害死亡比 -DamageDeathRatio-tooltip=傷害除以死亡 -KillDeathRatio=撃殺死亡比 -KillDeathRatio-tooltip=撃殺除以死亡 -SessionTime=平均遊玩時間 -SessionTime-tooltip=平均遊玩時間 -BuildRatio=建築比 -BuildRatio-tooltip=建築次數除以拆除次數 -RocketPerHour=每小時火箭發射次數 -RocketPerHour-tooltip=火箭發射次數除以遊玩時間 -TreeKillPerMinute=每分鐘樹木拆除數 -TreeKillPerMinute-tooltip=樹木拆除數除以遊玩時間 -NetPlayTime=淨遊玩時間 -NetPlayTime-tooltip=遊玩時間減掛機時間 -AFKTimeRatio=掛機時間比 -AFKTimeRatio-tooltip=掛機時間除以遊玩時間 - # expcore [expcore-data] description-preference=允許寫入資料。 diff --git a/exp_legacy/module/modules/data/statistics.lua b/exp_legacy/module/modules/data/statistics.lua deleted file mode 100644 index ac844387..00000000 --- a/exp_legacy/module/modules/data/statistics.lua +++ /dev/null @@ -1,208 +0,0 @@ -local ExpUtil = require("modules/exp_util") -local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event -local Storage = require("modules/exp_util/storage") --- @dep utils.global -local config = require("modules.exp_legacy.config.statistics") --- @dep config.statistics -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 = {} -Storage.register(new_players, function(tbl) - new_players = tbl -end) - ---- Stores the statistics on a player -local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep expcore.player_data -local AllPlayerData = PlayerData.All -local Statistics = PlayerData.Statistics -Statistics:set_metadata{ - display_order = config.display_order, -} - ---- Update your statistics with any which happened before the data was valid -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 - player_statistics[key] = value - else - player_statistics[key] = player_statistics[key] + value - 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 - local ctn = player_statistics.MapsPlayed - player_statistics["MapsPlayed"] = ctn and ctn + 1 or 1 - end - - return player_statistics -end) - -local long_time_format = ExpUtil.format_time_factory_locale{ format = "long", coefficient = 3600, hours = true, minutes = true } -local short_time_format = ExpUtil.format_time_factory_locale{ format = "short", coefficient = 3600, hours = true, minutes = true } - ---- Add MapsPlayed if it is enabled -if config.MapsPlayed then - Statistics:combine("MapsPlayed") - Event.add(defines.events.on_player_created, 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 - if config.Playtime then - playtime = Statistics:combine("Playtime") - playtime:set_metadata{ stringify = long_time_format, stringify_short = short_time_format } - end - if config.AfkTime then - afk_time = Statistics:combine("AfkTime") - afk_time:set_metadata{ stringify = long_time_format, stringify_short = short_time_format } - end - Event.on_nth_tick(3600, function() - if game.tick == 0 then return end - for _, player in pairs(game.connected_players) do - if playtime then playtime:increment(player) end - if afk_time and player.afk_time > afk_required then afk_time:increment(player) end - end - end) -end - ---- Add DistanceTravelled if it is enabled -if config.DistanceTravelled then - local stat = Statistics:combine("DistanceTravelled") - stat:set_metadata{ unit = " tiles" } - Event.add(defines.events.on_player_changed_position, function(event) - local player = game.players[event.player_index] - if not player.valid or not player.connected or player.afk_time > afk_required then return end - stat:increment(player) - end) -end - ---- Add MachinesRemoved and TreesDestroyed and config.OreMined if it is enabled -if config.MachinesRemoved or config.TreesDestroyed or config.OreMined then - local machines, trees, ore - if config.MachinesRemoved then machines = Statistics:combine("MachinesRemoved") end - if config.TreesDestroyed then trees = Statistics:combine("TreesDestroyed") end - if config.OreMined then ore = Statistics:combine("OreMined") end - local function on_event(event) - if not event.player_index then return end -- Check player is valid - local player = game.players[event.player_index] - if not player.valid or not player.connected then return end - local entity = event.entity -- Check entity is valid - if not entity.valid then return end - if entity.type == "resource" then - ore:increment(player) - elseif entity.type == "tree" then - trees:increment(player) - elseif entity.force == player.force then - machines:increment(player) - end - end - Event.add(defines.events.on_marked_for_deconstruction, on_event) - Event.add(defines.events.on_player_mined_entity, on_event) -end - ---- Vehicles which credit their driver, or failing that their passenger, with what they hit -local crewed_vehicles = { car = true, ["spider-vehicle"] = true, locomotive = true } - ---- Get the connected player behind the cause of damage or a death, nil for turrets, trains without a crew and the like ---- @param cause LuaEntity? ---- @return LuaPlayer? -local function get_cause_player(cause) - if not cause or not cause.valid then return nil end - - local occupant = cause --- @type LuaEntity | LuaPlayer - if crewed_vehicles[cause.type] then - local crew = cause.get_driver() or cause.get_passenger() - if not crew then return nil end - occupant = crew - end - - local player --- @type LuaPlayer? - if occupant.object_name == "LuaPlayer" then - player = occupant --[[@as LuaPlayer]] - elseif occupant.type == "character" then - player = occupant.player - end - - if not player or not player.valid or not player.connected then return nil end - return player -end - ---- Check that damage or a death counts against an entity, it must be hostile to the player ---- @param entity LuaEntity ---- @param player LuaPlayer ---- @return boolean -local function is_hostile(entity, player) - return entity.valid and entity.force ~= player.force and entity.force.name ~= "neutral" -end - ---- Add DamageDealt if it is enabled -if config.DamageDealt then - local stat = Statistics:combine("DamageDealt") - Event.add(defines.events.on_entity_damaged, function(event) - local player = get_cause_player(event.cause) - if not player or not is_hostile(event.entity, player) then return end - stat:increment(player, floor(event.final_damage_amount)) - end) -end - ---- Add Kills if it is enabled -if config.Kills then - local stat = Statistics:combine("Kills") - Event.add(defines.events.on_entity_died, function(event) - local player = get_cause_player(event.cause) - if not player or not is_hostile(event.entity, player) then return end - stat:increment(player) - end) -end - ---- Add RocketsLaunched if it is enabled -if config.RocketsLaunched then - local stat = Statistics:combine("RocketsLaunched") - Event.add(defines.events.on_rocket_launched, function(event) - local silo = event.rocket_silo -- Check silo is valid - if not silo or not silo.valid then return end - local force = silo.force -- Check force is valid - if not force or not force.valid then return end - for _, player in pairs(force.connected_players) do - stat:increment(player) - end - end) -end - ---- Add RocketsLaunched if it is enabled -if config.ResearchCompleted then - local stat = Statistics:combine("ResearchCompleted") - Event.add(defines.events.on_research_finished, function(event) - local research = event.research -- Check research is valid - if event.by_script or not research or not research.valid then return end - local force = research.force -- Check force is valid - if not force or not force.valid then return end - for _, player in pairs(force.connected_players) do - stat:increment(player) - end - end) -end - ---- Add all the remaining statistics from the config -for statistic, event_name in pairs(config.counters) do - local stat = Statistics:combine(statistic) - Event.add(event_name, function(event) - if not event.player_index then return end - local player = game.players[event.player_index] - if not player.valid or not player.connected then return end - stat:increment(player) - end) -end diff --git a/exp_scenario/module/gui/player_stats.lua b/exp_scenario/module/gui/player_stats.lua index ca453243..2a08cbc0 100644 --- a/exp_scenario/module/gui/player_stats.lua +++ b/exp_scenario/module/gui/player_stats.lua @@ -6,10 +6,7 @@ local ExpUtil = require("modules/exp_util") local Gui = require("modules/exp_gui") local ElementsExtra = require("modules/exp_scenario/gui/elements") local Roles = require("modules/exp_roles") - -require("modules/exp_legacy/modules/data/statistics") -local PlayerData = require("modules/exp_legacy/expcore/player_data") -local PlayerStats = PlayerData.Statistics +local ExpStatistics = require("modules/exp_statistics") --- @class ExpGui_PlayerStats.elements local Elements = {} @@ -23,54 +20,64 @@ end local short_time_zero, format_number_zero = short_time_format(0), format_number_2dp(0) +--- Get a statistic of a player, or the default when it is zero +--- @param player LuaPlayer +--- @param statistic string +--- @param default number +--- @return number +local function get_stat(player, statistic, default) + local value = ExpStatistics.get(player, statistic) + return value == 0 and default or value +end + --- @type table local computed_stats = { DamageDeathRatio = { default = format_number_zero, calculate = function(player) - return format_number_2dp(PlayerStats["DamageDealt"]:get(player, 0) / PlayerStats["Deaths"]:get(player, 1)) + return format_number_2dp(get_stat(player, "DamageDealt", 0) / get_stat(player, "Deaths", 1)) end, }, KillDeathRatio = { default = format_number_zero, calculate = function(player) - return format_number_2dp(PlayerStats["Kills"]:get(player, 0) / PlayerStats["Deaths"]:get(player, 1)) + return format_number_2dp(get_stat(player, "Kills", 0) / get_stat(player, "Deaths", 1)) end, }, SessionTime = { default = short_time_zero, calculate = function(player) - return short_time_format((PlayerStats["Playtime"]:get(player, 0) - PlayerStats["AfkTime"]:get(player, 0)) / PlayerStats["JoinCount"]:get(player, 1)) + return short_time_format((get_stat(player, "Playtime", 0) - get_stat(player, "AfkTime", 0)) / get_stat(player, "JoinCount", 1)) end, }, BuildRatio = { default = format_number_zero, calculate = function(player) - return format_number_2dp(PlayerStats["MachinesBuilt"]:get(player, 0) / PlayerStats["MachinesRemoved"]:get(player, 1)) + return format_number_2dp(get_stat(player, "MachinesBuilt", 0) / get_stat(player, "MachinesRemoved", 1)) end, }, RocketPerHour = { default = format_number_zero, calculate = function(player) - return format_number_2dp(PlayerStats["RocketsLaunched"]:get(player, 0) * 60 / PlayerStats["Playtime"]:get(player, 1)) + return format_number_2dp(get_stat(player, "RocketsLaunched", 0) * 60 / get_stat(player, "Playtime", 1)) end, }, TreeKillPerMinute = { default = format_number_zero, calculate = function(player) - return format_number_2dp(PlayerStats["TreesDestroyed"]:get(player, 0) / PlayerStats["Playtime"]:get(player, 1)) + return format_number_2dp(get_stat(player, "TreesDestroyed", 0) / get_stat(player, "Playtime", 1)) end, }, NetPlayTime = { default = short_time_zero, calculate = function(player) - return short_time_format((PlayerStats["Playtime"]:get(player, 0) - PlayerStats["AfkTime"]:get(player, 0))) + return short_time_format((get_stat(player, "Playtime", 0) - get_stat(player, "AfkTime", 0))) end, }, AFKTimeRatio = { default = format_number_zero, calculate = function(player) - return format_number_2dp(PlayerStats["AfkTime"]:get(player, 0) * 100 / PlayerStats["Playtime"]:get(player, 1)) + return format_number_2dp(get_stat(player, "AfkTime", 0) * 100 / get_stat(player, "Playtime", 1)) end, }, Locale = { @@ -106,19 +113,15 @@ Elements.player_stats_table = Gui.define("player_stats/data_table") local labels = {} -- Add all standalone stats - for _, stat_name in pairs(PlayerData.Statistics.metadata.display_order) do - local metadata = PlayerData.Statistics[stat_name].metadata - local value = metadata.stringify_short and metadata.stringify_short(0) - or metadata.stringify and metadata.stringify(0) - or format_number(0, false) + for _, stat_name in ipairs(ExpStatistics.display_order) do Elements.table_label(data_table, { - caption = metadata.name or { "exp-statistics." .. stat_name }, - tooltip = metadata.tooltip or { "exp-statistics." .. stat_name .. "-tooltip" }, + caption = { "exp-statistics." .. stat_name }, + tooltip = { "exp-statistics." .. stat_name .. "-tooltip" }, width = 135, }) labels[stat_name] = Elements.table_label(data_table, { - caption = { "exp-gui_readme.data-format", value, metadata.unit or "" }, - tooltip = metadata.value_tooltip or { "exp-statistics." .. stat_name .. "-tooltip" }, + caption = { "exp-gui_readme.data-format", ExpStatistics.format(stat_name, 0, true), ExpStatistics.units[stat_name] or "" }, + tooltip = { "exp-statistics." .. stat_name .. "-tooltip" }, width = 105, }) end @@ -148,18 +151,9 @@ function Elements.player_stats_table.refresh(data_table, player) local labels = Elements.player_stats_table.data[data_table] -- Update all standalone stats - for _, stat_name in pairs(PlayerStats.metadata.display_order) do - local stat = PlayerStats[stat_name] - local metadata = stat.metadata - local value = stat:get(player, 0) - if metadata.stringify_short then - value = metadata.stringify_short(value) - elseif metadata.stringify then - value = metadata.stringify(value) - else - value = format_number(value, false) - end - labels[stat_name].caption = { "exp-gui_readme.data-format", value, metadata.unit or "" } + for _, stat_name in ipairs(ExpStatistics.display_order) do + local value = ExpStatistics.format(stat_name, ExpStatistics.get(player, stat_name), true) + labels[stat_name].caption = { "exp-gui_readme.data-format", value, ExpStatistics.units[stat_name] or "" } end -- Update all computed stats diff --git a/exp_scenario/module/gui/readme.lua b/exp_scenario/module/gui/readme.lua index 19c21eac..a53838f0 100644 --- a/exp_scenario/module/gui/readme.lua +++ b/exp_scenario/module/gui/readme.lua @@ -6,6 +6,7 @@ local ExpUtil = require("modules/exp_util") local Gui = require("modules/exp_gui") local Roles = require("modules/exp_roles") local Commands = require("modules/exp_commands") +local ExpStatistics = require("modules/exp_statistics") local PlayerData = require("modules.exp_legacy.expcore.player_data") local ExpServerList = require("modules/exp_server_list") local community = require("modules/exp_scenario/config/community_details").config @@ -582,6 +583,14 @@ define_tab( default_stringify = function(value) return format_number(value or 0, false) end, + extra_rows = function(statistics) + for _, name in ipairs(ExpStatistics.display_order) do + local value = ExpStatistics.format(name, ExpStatistics.get(player_name, name)) + local tooltip = { "exp-statistics." .. name .. "-tooltip" } + Gui.elements.centered_label(statistics, 150, { "exp-statistics." .. name }, tooltip) + Gui.elements.centered_label(statistics, 130, { "exp-gui_readme.data-format", value, ExpStatistics.units[name] or "" }, tooltip) + end + end, } end diff --git a/exp_scenario/module/module.json b/exp_scenario/module/module.json index 85b7a4e0..1c011673 100644 --- a/exp_scenario/module/module.json +++ b/exp_scenario/module/module.json @@ -12,6 +12,7 @@ "exp_roles": "*", "exp_reports": "*", "exp_server_list": "*", + "exp_statistics": "*", "exp_gui": "*", "exp_commands": "*" } diff --git a/exp_scenario/package.json b/exp_scenario/package.json index ab53eb6f..0997b985 100644 --- a/exp_scenario/package.json +++ b/exp_scenario/package.json @@ -52,6 +52,7 @@ "@expcluster/permission-groups": "workspace:^", "@expcluster/roles": "workspace:^", "@expcluster/server-list": "workspace:^", + "@expcluster/statistics": "workspace:^", "@sinclair/typebox": "catalog:" }, "publishConfig": {