Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: exp analyzer & fix: cooldown bars #802

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 208 additions & 0 deletions modules/game_analyzer/game_analyzer.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
GameAnalyzer = {}

Analyzers = {
GameExpAnalyzer = {
name = "Experience",
toggle = GameExpAnalyzerToggle,
},
}

contentPanel = nil
analyzerButton = nil
analyzerWindow = nil
expAnalyzerWindow = nil
expStart = nil
expHourStart = 0
expTimeElapsed = 0

function GameAnalyzer.init()
print("Init Game Analyzer")
analyzerButton = modules.game_mainpanel.addToggleButton('analyzerButton',
tr('Open analytics selector window'),
'/images/options/analyzers',
GameAnalyzer.toggle)

analyzerButton:setOn(false)
analyzerWindow = g_ui.loadUI('game_analyzer')
analyzerWindow:disableResize()
analyzerWindow:setup()

expAnalyzerInit()

loadContentPanel()

connect(LocalPlayer, {
onExperienceChange = onExperienceChange,
})
connect(g_game, {
onGameStart = online,
onGameEnd = offline,
onPingBack = refresh
})
refresh()
end

function expAnalyzerInit()
expAnalyzerWindow = g_ui.loadUI('game_exp_analyzer')
expAnalyzerWindow:disableResize()
expAnalyzerWindow:setup()

expHourStart = g_clock.seconds()

local expGainValue = expAnalyzerWindow:getChildById('expGainValue')
if expGainValue then
expGainValue:setText(0)
end

local expHourValue = expAnalyzerWindow:getChildById('expHourValue')
if expHourValue then
expHourValue:setText(0)
end
end

function expAnalyzerTerminate()
expAnalyzerWindow:destroy()
expStart = nil
expHourStart = nil
expTimeElapsed = 0
end

function GameAnalyzer.terminate()
analyzerButton:destroy()
analyzerWindow:destroy()
expAnalyzerTerminate()
disconnect(LocalPlayer, {
onExperienceChange = onExperienceChange,
})
disconnect(g_game, {
onGameStart = online,
onGameEnd = offline,
onPingBack = refresh
})

GameAnalyzer = nil
end

function onMiniWindowOpen()
analyzerButton:setOn(true)
end

function onMiniWindowClose()
analyzerButton:setOn(false)
end

function loadContentPanel()
contentPanel = modules.game_interface.findContentPanelAvailable(analyzerWindow, analyzerWindow:getMinimumHeight())
if not contentPanel then
print("No content panel available")
return
end
end

function GameAnalyzer.toggle()
if analyzerButton:isOn() then
analyzerWindow:close()
analyzerWindow:setOn(false)
else
if not analyzerWindow:getParent() then
contentPanel:addChild(analyzerWindow)
end
analyzerWindow:open()
analyzerButton:setOn(true)
end
end

function online()
analyzerButton:show()
refresh()
expStart = nil
expHourStart = 0
expTimeElapsed = 0
end

function offline()
analyzerButton:hide()
analyzerWindow:setParent(nil, true)
expStart = nil
expHourStart = 0
expTimeElapsed = 0
end

function refresh()
local player = g_game.getLocalPlayer()
if not player then
return
end

if expStart == nil then
expStart = player:getExperience()
end

onExperienceChange(player, player:getExperience())
end

function toggleAnalyzer(analyzer)
analyzer:setChecked(not analyzer:isChecked())
toggleFromAnalyzer(analyzer)
end

function toggleFromAnalyzer(analyzer)
local analyzerType = getFirstWordBeforeCapital(analyzer:getId())
analyzerType = 'Game' .. analyzerType .. 'Analyzer'

local analyzerConfig = Analyzers[analyzerType]
if analyzerConfig and analyzerConfig.toggle then
analyzerConfig.toggle(analyzer)
else
print("Toggle function for " .. analyzerType .. " not found")
end
end

function GameExpAnalyzerToggle(analyzer)
if analyzer:isChecked() then
if not expAnalyzerWindow:getParent() then
contentPanel:addChild(expAnalyzerWindow)
end
expAnalyzerWindow:open()
else
expAnalyzerWindow:close()
end
end

function onExperienceChange(player, exp, oldExp)
if expAnalyzerWindow then
local expGainValue = expAnalyzerWindow:getChildById('expGainValue')
if expGainValue then
if expStart == nil then
expStart = exp
end
expGainValue:setText(exp - expStart)
end

local expHourValue = expAnalyzerWindow:getChildById('expHourValue')
if expHourValue then
if expHourStart == 0 then
expHourStart = g_clock.seconds()
end

timeElapsed = g_clock.seconds() - expHourStart
expHourValue:setText(calculateExpPerHour(exp, expStart, timeElapsed, expHourStart))
end
end
end

function calculateExpPerHour(exp, expStart, currentTime, expHourStart)
local expGained = exp - expStart
local timeElapsed = currentTime - expHourStart
local expPerHour = math.floor((expGained / timeElapsed) * 3600) + 0
print("Exp Per Hour: " .. expPerHour)
return comma_value(expPerHour)
end

function getFirstWordBeforeCapital(str)
local firstWord = str:match("^[^A-Z]*")
if firstWord then
firstWord = firstWord:sub(1, 1):upper() .. firstWord:sub(2)
end
return firstWord
end
14 changes: 14 additions & 0 deletions modules/game_analyzer/game_analyzer.otmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Module
name: game_analyzer
sandboxed: true
scripts: [ game_analyzer ]
reloadable: true
autoload: true
dependencies:
- game_interface
@onLoad: |
dofile 'game_analyzer'
GameAnalyzer.init()

@onUnload: |
GameAnalyzer.terminate()
28 changes: 28 additions & 0 deletions modules/game_analyzer/game_analyzer.otui
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

MiniWindow
id: analyzerWindow
!text: tr('Analytics')
height: 63
@onOpen: modules.game_analyzer.onMiniWindowOpen()
@onClose: modules.game_analyzer.onMiniWindowClose()
&save: true

MiniWindowContents
UIWidget
id: expAnalyzerButton
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
image-source: /images/ui/tabbutton_new_shadowed
height: 21
!text: tr('XP Analyzer')
margin-top: 6
margin-left: 4
margin-right: 4
@onClick: modules.game_analyzer.toggleAnalyzer(self)
$checked:
image-clip: 0 21 114 21
text-offset: 0 1
$!checked:
image-clip: 0 0 114 21
text-offset: 0 0
41 changes: 41 additions & 0 deletions modules/game_analyzer/game_exp_analyzer.otui
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
MiniWindow
id: expAnalyzerWindow
!text: tr('XP Analyzer')
height: 63
&save: true

MiniWindowContents
SkillNameLabel
id: expGainLabel
font: verdana-11px-monochrome
!text: tr('XP Gain:')
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
margin-top: 25
margin-left: 10

SkillValueLabel
id: expGainValue
!text: tr('0')
font: verdana-11px-monochrome
text-align: topright
anchors.left: expGainLabel.right
margin-top: 25
margin-right: 25

SkillNameLabel
id: expHourLabel
!text: tr('XP/h:')
font: verdana-11px-monochrome
margin-top: 40
margin-left: 10

SkillValueLabel
id: expHourValue
!text: tr('0')
font: verdana-11px-monochrome
text-align: topright
anchors.left: expHourLabel.right
margin-top: 40
margin-right: 25
2 changes: 2 additions & 0 deletions modules/game_cooldown/cooldown.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ function onSpellGroupCooldown(groupId, duration)
return
end

print('onSpellGroupCooldown: ' .. groupId)
local icon = contentsPanel:getChildById('groupIcon' .. SpellGroups[groupId])
print("Progress Rect: " .. 'progressRect' .. SpellGroups[groupId])
local progressRect = contentsPanel:getChildById('progressRect' .. SpellGroups[groupId])
if icon then
icon:setOn(true)
Expand Down
8 changes: 4 additions & 4 deletions modules/game_cooldown/cooldown.otui
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Panel
!tooltip: tr('Focus')

SpellGroupIcon
id: groupIconUltimateStrike
id: groupIconUltimateStrikes
image-clip: 120 0 20 20
anchors.top: parent.top
anchors.left: groupIconFocus.right
Expand All @@ -126,15 +126,15 @@ Panel
image-clip: 120 20 20 20

SpellProgressRect
id: progressRectUltimateStrike
anchors.fill: groupIconUltimateStrike
id: progressRectUltimateStrikes
anchors.fill: groupIconUltimateStrikes
!tooltip: tr('Ultimate Strike')

SpellGroupIcon
id: groupIconGreatBeams
image-clip: 140 0 20 20
anchors.top: parent.top
anchors.left: groupIconUltimateStrike.right
anchors.left: groupIconUltimateStrikes.right
margin-left: 3
$on:
image-clip: 140 20 20 20
Expand Down
6 changes: 3 additions & 3 deletions modules/gamelib/spells.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2893,9 +2893,9 @@ SpellGroups = {
[4] = 'Special',
[5] = 'Crippling',
[6] = 'Focus',
[7] = 'Ultimate Strikes',
[8] = 'Great Beams',
[9] = 'Bursts of Nature'
[7] = 'UltimateStrikes',
[8] = 'GreatBeams',
[9] = 'BurstsOfNature'
}

Spells = {}
Expand Down
Loading