mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 04:21:41 +09:00
Update all code styles
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
|
||||
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 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 format_time = _C.format_time
|
||||
local floor = math.floor
|
||||
local afk_required = 5*3600 -- 5 minutes
|
||||
local afk_required = 5 * 3600 -- 5 minutes
|
||||
|
||||
--- Stores players who have been created, required to avoid loss of data
|
||||
local new_players = {}
|
||||
@@ -17,7 +16,7 @@ local PlayerData = require("modules.exp_legacy.expcore.player_data") --- @dep ex
|
||||
local AllPlayerData = PlayerData.All
|
||||
local Statistics = PlayerData.Statistics
|
||||
Statistics:set_metadata{
|
||||
display_order = config.display_order
|
||||
display_order = config.display_order,
|
||||
}
|
||||
|
||||
--- Update your statistics with any which happened before the data was valid
|
||||
@@ -49,27 +48,27 @@ end)
|
||||
|
||||
--- Used to format time in minute format
|
||||
local function format_minutes(value)
|
||||
return format_time(value*3600, {
|
||||
return format_time(value * 3600, {
|
||||
long = true,
|
||||
hours = true,
|
||||
minutes = true
|
||||
minutes = true,
|
||||
})
|
||||
end
|
||||
|
||||
--- Used to format time into a clock
|
||||
local function format_clock(value)
|
||||
return format_time(value*3600, {
|
||||
hours=true,
|
||||
minutes=true,
|
||||
seconds=false,
|
||||
time=false,
|
||||
string=true
|
||||
return format_time(value * 3600, {
|
||||
hours = true,
|
||||
minutes = true,
|
||||
seconds = false,
|
||||
time = false,
|
||||
string = true,
|
||||
})
|
||||
end
|
||||
|
||||
--- Add MapsPlayed if it is enabled
|
||||
if config.MapsPlayed then
|
||||
Statistics:combine('MapsPlayed')
|
||||
Statistics:combine("MapsPlayed")
|
||||
Event.add(defines.events.on_player_created, function(event)
|
||||
local player = game.players[event.player_index]
|
||||
new_players[player.name] = true
|
||||
@@ -79,8 +78,14 @@ 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=format_minutes, stringify_short=format_clock} end
|
||||
if config.AfkTime then afk_time = Statistics:combine('AfkTime') afk_time:set_metadata{stringify=format_minutes, stringify_short=format_clock} end
|
||||
if config.Playtime then
|
||||
playtime = Statistics:combine("Playtime")
|
||||
playtime:set_metadata{ stringify = format_minutes, stringify_short = format_clock }
|
||||
end
|
||||
if config.AfkTime then
|
||||
afk_time = Statistics:combine("AfkTime")
|
||||
afk_time:set_metadata{ stringify = format_minutes, stringify_short = format_clock }
|
||||
end
|
||||
Event.on_nth_tick(3600, function()
|
||||
if game.tick == 0 then return end
|
||||
for _, player in pairs(game.connected_players) do
|
||||
@@ -92,8 +97,8 @@ end
|
||||
|
||||
--- Add DistanceTravelled if it is enabled
|
||||
if config.DistanceTravelled then
|
||||
local stat = Statistics:combine('DistanceTravelled')
|
||||
stat:set_metadata{unit=' tiles'}
|
||||
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
|
||||
@@ -104,18 +109,22 @@ 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
|
||||
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
|
||||
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
|
||||
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)
|
||||
@@ -123,35 +132,35 @@ end
|
||||
|
||||
--- Add DamageDealt if it is enabled
|
||||
if config.DamageDealt then
|
||||
local stat = Statistics:combine('DamageDealt')
|
||||
local stat = Statistics:combine("DamageDealt")
|
||||
Event.add(defines.events.on_entity_damaged, function(event)
|
||||
local character = event.cause -- Check character is valid
|
||||
if not character or not character.valid or character.type ~= 'character' then return end
|
||||
if not character or not character.valid or character.type ~= "character" then return end
|
||||
local player = character.player -- Check player is valid
|
||||
if not player.valid or not player.connected then return end
|
||||
local entity = event.entity -- Check entity is valid
|
||||
if not entity.valid or entity.force == player.force or entity.force.name == 'neutral' then return end
|
||||
if not entity.valid or entity.force == player.force or entity.force.name == "neutral" 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')
|
||||
local stat = Statistics:combine("Kills")
|
||||
Event.add(defines.events.on_entity_died, function(event)
|
||||
local character = event.cause -- Check character is valid
|
||||
if not character or not character.valid or character.type ~= 'character' then return end
|
||||
if not character or not character.valid or character.type ~= "character" then return end
|
||||
local player = character.player -- Check player is valid
|
||||
if not player or not player.valid or not player.connected then return end
|
||||
local entity = event.entity -- Check entity is valid
|
||||
if not entity.valid or entity.force == player.force or entity.force.name == 'neutral' then return end
|
||||
if not entity.valid or entity.force == player.force or entity.force.name == "neutral" then return end
|
||||
stat:increment(player)
|
||||
end)
|
||||
end
|
||||
|
||||
--- Add RocketsLaunched if it is enabled
|
||||
if config.RocketsLaunched then
|
||||
local stat = Statistics:combine('RocketsLaunched')
|
||||
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
|
||||
@@ -165,9 +174,9 @@ end
|
||||
|
||||
--- Add RocketsLaunched if it is enabled
|
||||
if config.ResearchCompleted then
|
||||
local stat = Statistics:combine('ResearchCompleted')
|
||||
local stat = Statistics:combine("ResearchCompleted")
|
||||
Event.add(defines.events.on_research_finished, function(event)
|
||||
local research = event.research -- Check research is valid
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user