From 788b8aef3ae6531685b8f4b8cd08203a33c682c4 Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 1 Nov 2020 01:25:07 +0100 Subject: Initial Commit - Miguel's SuperTimer --- SuperTimer/SuperTimer.dds | Bin 0 -> 13584 bytes SuperTimer/SuperTimer.lua | 154 ++++++++++++++++++++++++++++++++++++++++++ SuperTimer/SuperTimer.modinfo | 33 +++++++++ SuperTimer/SuperTimer.png | Bin 0 -> 385303 bytes SuperTimer/SuperTimer.xml | 4 ++ 5 files changed, 191 insertions(+) create mode 100755 SuperTimer/SuperTimer.dds create mode 100755 SuperTimer/SuperTimer.lua create mode 100755 SuperTimer/SuperTimer.modinfo create mode 100755 SuperTimer/SuperTimer.png create mode 100755 SuperTimer/SuperTimer.xml diff --git a/SuperTimer/SuperTimer.dds b/SuperTimer/SuperTimer.dds new file mode 100755 index 0000000..5c0d64d Binary files /dev/null and b/SuperTimer/SuperTimer.dds differ diff --git a/SuperTimer/SuperTimer.lua b/SuperTimer/SuperTimer.lua new file mode 100755 index 0000000..d93dbbd --- /dev/null +++ b/SuperTimer/SuperTimer.lua @@ -0,0 +1,154 @@ +-- check yor installed steam mods for reference here: \steamapps\workshop\content\289070 +-- events: -- https://forums.civfanatics.com/threads/list-of-game-events.604914/#post-14561939 +-- put your mod in: C:\Users\Miguel\Documents\My Games\Sid Meier's Civilization VI\Mods\SuperTimer +-- lua log is here: /Documents and Settings/Miguel/My Documents/My Games/Sid Meier's Civilization VI/Logs +-- Icon codes: https://forums.civfanatics.com/threads/list-of-all-icon-codes.613516/ +-- lua objects: https://forums.civfanatics.com/threads/lua-objects.601146/ +-- persistance: +-- they're not saved, but see +-- https://forums.civfanatics.com/threads/lua-objects.601146/page-4#post-14634018 +-- https://forums.civfanatics.com/threads/saving-loading-simple-tables-with-a-game.609397/ +-- https://forums.civfanatics.com/threads/persisting-custom-data-with-saves.611878/ +-- this lua file, will be auto-reloaded on change by civ6 + +verbose = false + +function log( txt ) + if verbose then print ( '[' .. os.time() .. ']' .. " [SuperTimer] " .. txt ); end +end + +function getState() + state = GameConfiguration.GetValue ("SuperTimerState") + if state == nil + then + GameConfiguration.SetValue ("SuperTimerState","") + return "" + else + return state + end +end + +function split(s, delimiter) + result = {}; + for match in (s..delimiter):gmatch("(.-)"..delimiter) do + table.insert(result, match); + end + return result; +end + +function toEvent(event, turn) + if event == "B" then return "Turn " .. turn .. " begins" end + if event == "E" then return "Turn ends" end + if event == "S" then return "Game Saved" end + if event == "L" then return "Game Loaded" end + return "Unknown Event" +end + +function addState( state, turn ) + + newstate = getState() .. os.time() .. " " .. turn .. " " .. state .. "|"; + GameConfiguration.SetValue ("SuperTimerState",newstate); + tooltip = "[ICON_Capital]Miguel's SuperTimer[ICON_Capital][NEWLINE]" + + lastturn=0 + lastevent=0; + sumtime=0; + + for m in (newstate):gmatch("(.-)".."|") do + spl = split(m," ") + unixtime = tonumber(spl[1]); + turn = tonumber(spl[2]); + event = spl[3]; + if event == "B" then lastturn = turn - 1 end + if event == "L" + then + lastevent = unixtime; + else + sumtime = sumtime + ( unixtime-lastevent ); + log (sumtime); + lastevent = unixtime; + end + + t = os.date("*t", unixtime) + txt = toEvent(event,spl[2]); + log (t.hour .. ":" .. t.min .. ":" .. t.sec .. " " .. txt) + end + log("Total: " .. sumtime .. " seconds"); + log("Total: " .. os.date('!%T', sumtime)); + if lastturn == 0 + then + tooltip = "[ICON_Capital]Miguel's SuperTimer[ICON_Capital]" .. + "[NEWLINE]Complete first turn to collect data" + else + tooltip = "[ICON_Capital]Miguel's SuperTimer[ICON_Capital]" .. + "[NEWLINE]Turns Completed:" .. lastturn .. + "[NEWLINE]Total Time: " .. os.date('!%T', sumtime) .. + "[NEWLINE]Average Turn: " .. os.date('!%T', sumtime/lastturn); + end + + if Controls.SuperTimerButton ~= nil + then + Controls.SuperTimerButton:SetToolTipString (tooltip); + end +end + + +function mouseOverTimer() + log ( "mouseOverTimer" ); +end + + +function Initialise() + log ( "Game started/loaded" ); + addState( "L" , 0 ); + local topPanel = ContextPtr:LookUpControl("/InGame/TopPanel/RightContents"); + Controls.SuperTimerButton:ChangeParent(topPanel); + topPanel:AddChildAtIndex(Controls.SuperTimerButton, 0); + topPanel:CalculateSize(); + topPanel:ReprocessAnchoring(); + Controls.SuperTimerButton:RegisterCallback( Mouse.eMouseEnter, mouseOverTimer); +end + +function OnTurnBegin( turn ) + addState( "B" , turn ) +end + +function OnTurnEnd() + addState( "E" , 0 ); +end + +function OnPlayerTurnEnd( player ) +end + +function SaveList() + log( "Show Savegame List" ); + addState( "S" , 0 ); +end + +function SaveButton ( actionID ) + log( "InputAction" ); + if actionID == Input.GetActionId("QuickSave") then + addState( "S" , 0 ); + end +end + +function SaveKey ( pInputStruct:table ) + log( "InputHandler" ); + local uiMsg = pInputStruct:GetMessageType(); + if uiMsg == KeyEvents.KeyDown then + if pInputStruct:GetKey() == Keys.VK_F5 then -- but the binding can be changed... + addState( "S" , 0 ); + end + end +end + +log ( "Mod Loaded" ); + +--- EVENTS +LuaEvents.FileListQueryComplete.Add( SaveList ); +Events.InputActionTriggered.Add( SaveButton ); +ContextPtr:SetInputHandler( SaveKey, true ); -- does not work ? +Events.LoadScreenClose.Add( Initialise ); +Events.TurnBegin.Add( OnTurnBegin ); +Events.LocalPlayerTurnEnd.Add( OnTurnEnd ); +Events.RemotePlayerTurnEnd.Add( OnPlayerTurnEnd ); diff --git a/SuperTimer/SuperTimer.modinfo b/SuperTimer/SuperTimer.modinfo new file mode 100755 index 0000000..02c3ca3 --- /dev/null +++ b/SuperTimer/SuperTimer.modinfo @@ -0,0 +1,33 @@ + + + + SuperTimer + Count playtime! + Monitor playing time + Michal Idziorek + https://idziorek.net + 0 + 1.2,2.0 + + + + + InGame + 14000 + + SuperTimer.xml + + + + InGame + 400 + + SuperTimer.dds + + + + SuperTimer.lua + SuperTimer.xml + SuperTimer.dds + + diff --git a/SuperTimer/SuperTimer.png b/SuperTimer/SuperTimer.png new file mode 100755 index 0000000..3065225 Binary files /dev/null and b/SuperTimer/SuperTimer.png differ diff --git a/SuperTimer/SuperTimer.xml b/SuperTimer/SuperTimer.xml new file mode 100755 index 0000000..1315b52 --- /dev/null +++ b/SuperTimer/SuperTimer.xml @@ -0,0 +1,4 @@ + + +