战斗log日志优化

gaoxin 2020-09-28 16:26:20 +08:00
parent e3e1bd33d6
commit 04cc2529fa
3 changed files with 35 additions and 15 deletions

View File

@ -1,6 +1,7 @@
BattleLogManager = {}
local this = BattleLogManager
local isEditor = AppConst and AppConst.Platform == "EDITOR"
local isEditor = AppConst and AppConst.Platform == "EDITOR"
local isMobile = AppConst and (AppConst.Platform == "ANDROID" or AppConst.Platform == "IOS")
local isDebug = false
function LogBattle(str)
@ -13,7 +14,7 @@ function LogBattle(str)
end
end
local isLog = true or isEditor
local isLog = (true and not isMobile) or isEditor
local function pairsByKeys(t)
local a = {}
@ -93,6 +94,7 @@ function this.Init(fightdata, userdata)
end
this.logList = {}
this.WriteFightDataToFile()
end
function this.Log(...)
@ -106,12 +108,14 @@ function this.Log(...)
log = log .. string.format("%s = %s, ", key, value)
end
table.insert(this.logList, log)
-- 打印一下
LogBattle(log)
-- 如果log大于100条写一便日志到文件
if #this.logList > 100 then
this.WriteLogToFile()
end
end
function this.WriteFile()
if not isLog then return end
function this.GetFile(wType)
local time = string.format("%d-%d-%d-%d-%d-%d",
os.date("%Y"),
os.date("%m"),
@ -123,29 +127,44 @@ function this.WriteFile()
local platform
-- linux
if not file then
file = io.open("../luafight/BattleRecord/log-"..(this.userId or time)..".txt", "w")
file = io.open("../luafight/BattleRecord/log-"..(this.userId or time)..".txt", wType)
platform = "Linux"
end
-- local window server
if not file then
file = io.open("luafight/BattleRecord/log-"..(this.userId or time)..".txt", "w")
file = io.open("luafight/BattleRecord/log-"..(this.userId or time)..".txt", wType)
platform = "Local Windows Server"
end
-- local
if not file then
file = io.open("BattleRecord/log-"..(this.userId or time)..".txt", "w")
file = io.open("BattleRecord/log-"..(this.userId or time)..".txt", wType)
platform = "Local"
end
return file, platform
end
-- 将战斗数据写入log
function this.WriteFightDataToFile()
if not isLog then return end
local file, platform = this.GetFile("w")
file:write(platform..":\n\n\n")
for i = 1, #this.logList do
file:write(this.logList[i].."\n")
end
file:write("\n\n\n\n\n")
file:write("fightData:\n")
file:write(this.PrintBattleTable(this.fightdata))
file:write("\n\n")
file:write("timeStamp: " .. this.timestamp)
file:write("\n\n\n\n\n")
io.close(file)
end
-- 将日志写入log
function this.WriteLogToFile()
if not isLog then return end
local file, platform = this.GetFile("a")
for i = 1, #this.logList do
file:write(this.logList[i].."\n")
end
this.logList = {}
io.close(file)
end

View File

@ -371,7 +371,7 @@ function BattleLogic.BattleEnd(result)
BattleLogic.Event:DispatchEvent(BattleEventName.BattleEnd, result)
-- 战斗日志写入
if not BattleLogic.GetIsDebug() then
BattleLogManager.WriteFile()
BattleLogManager.WriteLogToFile("a")
end
end
--

View File

@ -24,6 +24,7 @@ function RoleLogic.New()
end
function RoleLogic:Init(uid, data, position)
data.star = data.star or 1
self.uid = uid
self.position = position
self.roleData = data