Skip to content

Commit

Permalink
Inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bombo committed Aug 2, 2015
0 parents commit 57bdf2f
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea/ export-ignore
PlayedAll.iml export-ignore
.gitattributes export-ignore
.gitignore export-ignore
README.md export-ignore
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/workspace.xml
.idea/tasks.xml
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Boris Rosenow

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
11 changes: 11 additions & 0 deletions PlayedAll.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="LUA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
91 changes: 91 additions & 0 deletions PlayedAll.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
PlayedAll = {}
PlayedAll.name = "PlayedAll"
PlayedAll.version = "0.1"

local savedVariables
local charName = GetUnitName("player")

local function formatCharNames(charNames)
local allNames = ''
local index, name = next(charNames, nil)
while index do
local nextIndex, nextName = next(charNames, index)
local isFirst = string.len(allNames) == 0
if not isFirst then
allNames = allNames .. (nextIndex and ', ' or GetString(SI_PLAYEDALL_AND))
end
allNames = allNames .. name
index, name = nextIndex, nextName
end
return allNames
end

local function displayTotalPlayedTime(charNames, time)
local playedTime = ZO_FormatTime(time, TIME_FORMAT_STYLE_DESCRIPTIVE, TIME_FORMAT_PRECISION_SECONDS)
CHAT_SYSTEM:AddMessage(zo_strformat(SI_CHAT_MESSAGE_PLAYED_TIME, formatCharNames(charNames), playedTime))
end

local function getSavedVariables()
local username = GetDisplayName()
local playedAllVars = _G['PlayedAllVars']
if not playedAllVars then
playedAllVars = {}
_G['PlayedAllVars'] = playedAllVars
end
local savedVariables = PlayedAllVars[username]
if not savedVariables then
savedVariables = {}
PlayedAllVars[username] = savedVariables
end
return savedVariables
end

local function updatePlayedTime()
savedVariables[charName] = GetSecondsPlayed()
end

local function setupHooks()
ZO_PreHook("ReloadUI", updatePlayedTime)

ZO_PreHook("Logout", updatePlayedTime)

ZO_PreHook("SetCVar", updatePlayedTime)

ZO_PreHook("Quit", updatePlayedTime)
end

local function initialize()
local playedCommand = GetString(SI_SLASH_PLAYED_TIME)
local normalPlayed = SLASH_COMMANDS[playedCommand]

savedVariables = getSavedVariables()
updatePlayedTime()

SLASH_COMMANDS[playedCommand] = function (args)
updatePlayedTime()
if args ~= 'all' then
normalPlayed(args)
return
end

local charNames = {}
local totalPlayed = 0

for name, time in pairs(savedVariables) do
table.insert(charNames, name)
totalPlayed = totalPlayed + time
end

displayTotalPlayedTime(charNames, totalPlayed)
end

setupHooks()
end

local function onAddOnLoaded(_, addonName)
if addonName ~= PlayedAll.name then return end
initialize()
end

-- register addon load
EVENT_MANAGER:RegisterForEvent(PlayedAll.name, EVENT_ADD_ON_LOADED, onAddOnLoaded)
9 changes: 9 additions & 0 deletions PlayedAll.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Title: PlayedAll
## Description: Adds a parameter to the /played command to display the played time of all your characters.
## APIVersion: 100011
## SavedVariables: PlayedAllVars

lang/en.lua
lang/$(language).lua

PlayedAll.lua
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# PlayedAll

PlayedAll is a simple addon for the MMORPG Elder Scrolls Online.
1 change: 1 addition & 0 deletions lang/de.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ZO_CreateStringId('SI_PLAYEDALL_AND', ' und ')
1 change: 1 addition & 0 deletions lang/en.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ZO_CreateStringId('SI_PLAYEDALL_AND', ' and ')
1 change: 1 addition & 0 deletions lang/fr.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ZO_CreateStringId('SI_PLAYEDALL_AND', ' et ')

0 comments on commit 57bdf2f

Please sign in to comment.