Skip to content

Commit

Permalink
Add General Logging (#322)
Browse files Browse the repository at this point in the history
* Update logging.lua

* Update logging.lua

* Update logging.lua

* Update logging.lua

* Update logging.lua

* Update addons.cfg

* Update addons.cfg

* Update addons.cfg

* Update logging.lua

* Update logging.lua
  • Loading branch information
PHIDIAS0303 authored Sep 5, 2024
1 parent 1de395b commit d230649
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
4 changes: 4 additions & 0 deletions locale/en/addons.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,9 @@ jail=__1__ was jailed because they removed too many protected entities. Please w
[nukeprotect]
found=You cannot have __1__ in your inventory, so it was placed into the chests at spawn.
[logging]
add-l=[RES] __1__ at level __2__ has been researched
add-n=[RES] __1__ has been researched
[deconlog]
decon=__1__ tried to deconstruct on __2__ from __3__ to __4__ which has __5__ items.
4 changes: 4 additions & 0 deletions locale/zh-CN/addons.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,9 @@ jail=__1__ 因被多次拆除受保護物體而被禁止行動。請等候管理
[nukeprotect]
found=你的用戶組不允許你有 __1__ ,所以該物品已放在出生點的箱子。

[logging]
add-l=[RES] __1__ at level __2__ has been researched
add-n=[RES] __1__ has been researched

[deconlog]
decon=__1__ 試圖拆除在 __2__ 上從 __3__ 到 __4__ ,有 __5__ 個物品。
4 changes: 4 additions & 0 deletions locale/zh-TW/addons.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,9 @@ jail=__1__ 因被多次拆除受保護物體而被禁止行動。請等候管理
[nukeprotect]
found=你的用戶組不允許你有 __1__ ,所以該物品已放在出生點的箱子。

[logging]
add-l=[RES] __1__ at level __2__ has been researched
add-n=[RES] __1__ has been researched

[deconlog]
decon=__1__ 試圖拆除在 __2__ 上從 __3__ 到 __4__ ,有 __5__ 個物品。
17 changes: 7 additions & 10 deletions modules/addons/logging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ local config = require 'config.logging' --- @dep config.logging
local config_res = require 'config.research' --- @dep config.research

local function add_log(data)
game.write_file(config.file_name, data .. '\n', true, 0)
game.write_file(config.file_name, data, true, 0)
game.write_file(config.file_name, '\n', true, 0)
end

Event.add(defines.events.on_rocket_launched, function(event)
Expand All @@ -22,10 +23,10 @@ Event.add(defines.events.on_pre_player_died, function(event)
if event and event.player_index then
if event.cause then
if event.cause.type and event.cause.type == 'character' and event.cause.player and event.cause.player.index then
add_log('[DEATH] ' .. game.players[event.player_index].name .. ' died because of ' .. (game.players[event.cause.player.index].name or ' unknown reason'))
add_log('[DEATH] ' .. game.players[event.player_index].name .. ' died because of ' .. (game.players[event.cause.player.index].name or 'unknown reason'))

else
add_log('[DEATH] ' .. game.players[event.player_index].name .. ' died because of ' .. (event.cause.name or ' unknown reason'))
add_log('[DEATH] ' .. game.players[event.player_index].name .. ' died because of ' .. (event.cause.name or 'unknown reason'))
end

else
Expand All @@ -40,15 +41,11 @@ Event.add(defines.events.on_research_finished, function(event)
return
end

if event.research.level and event.research.level > 1 then
if config_res.inf_res[event.research.name] and (event.research.level >= config_res.inf_res[event.research.name]) then
add_log('[RES] ' .. string.match(event.research.name, '^(.-)%-%d+$'):gsub('-', ' ') .. ' at level ' .. (event.research.level - 1) .. ' has been researched')
else
add_log('[RES] ' .. string.match(event.research.name, '^(.-)%-%d+$'):gsub('-', ' ') .. ' at level ' .. event.research.level .. ' has been researched')
end
if (event.research.level and config_res.inf_res[event.research.name]) and (event.research.level >= config_res.inf_res[event.research.name]) then
add_log({'logging.add-l', event.research.prototype.localised_name, event.research.level - 1})

else
add_log('[RES] ' .. string.match(event.research.name, '^(.-)%-%d+$'):gsub('-', ' ') .. ' has been researched')
add_log({'logging.add-n', event.research.prototype.localised_name})
end
end
end)
Expand Down

0 comments on commit d230649

Please sign in to comment.