changeset 3:a55f4f2a4603 tip

intial (real) commit!
author Kyle@Kyle-PC
date Thu, 23 Feb 2012 00:34:43 -0500
parents 37321677b4d9
children
files Import.lua README Roster.lua SuicideKings.lua SuicideKings.toc Utility.lua
diffstat 5 files changed, 320 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Import.lua	Thu Feb 23 00:34:43 2012 -0500
@@ -0,0 +1,117 @@
+--[[ 
+Title: Suicide Kings
+Author: Brom
+Version: 0.1
+]]
+
+function SuicideKings:GetUIDFromName( name )
+
+    for uid,v in pairs( self.db.profile.roster ) do     
+        if ( v["main"] == name ) then
+            return uid
+        end
+    end
+    
+    SuicideKings:Print( "Warning: could not find UID for " .. name )
+    return 0
+    
+end
+
+function SuicideKings:ImportFromKSK()
+
+    SuicideKings:Print( "-- Importing KonferSK Data --" )
+    
+    --[[
+    import rosters 
+    ]]--
+        
+    SuicideKings:Print( "Importing KonferSK roster..." )
+    self.db.profile.roster = {}
+            
+    -- search for unique mains
+    for _,v in pairs( ksk.sortedusers ) do
+        if ( ksk:UserIsAlt(v.id) == false ) then
+        
+            -- generate unique key
+            local uid = SuicideKings:UID( self.db.profile.roster )
+            
+            -- associate with main character key
+            self.db.profile.roster[uid] = {};
+            self.db.profile.roster[uid]["main"] = ksk.users[v.id].name;
+                        
+            -- debug
+            -- SuicideKings:Print( "Imported main: " .. ksk.users[v.id].name .. " (key = " .. uid .. ")" )
+            
+        end
+    end
+    
+    -- search for alts
+    for _,v in pairs( ksk.sortedusers ) do
+        if ( ksk:UserIsAlt(v.id) == true ) then
+    
+            -- ksk data
+            local altName = ksk.users[v.id].name;
+            local mainIdx = ksk.users[v.id].main;
+            local mainName = ksk.users[mainIdx].name;
+            
+            -- find a main in our data with that name
+            local found = false
+            for uid,vv in pairs( self.db.profile.roster ) do        
+                 if ( vv["main"] == mainName ) then
+                    found = true
+                    
+                    -- check for alts table
+                    if ( not self.db.profile.roster[uid]["alts"] ) then
+                        self.db.profile.roster[uid]["alts"] = {}
+                    end
+                        
+                    -- associate alt name with character key
+                    table.insert( self.db.profile.roster[uid]["alts"], altName )
+                    
+                    -- debug
+                    -- SuicideKings:Print( "Imported alt: " .. altName .. " (main = " .. vv["main"] .. " | key = "  .. uid .. ")" )
+                end
+            end 
+           
+            -- debugging
+            if ( found == false ) then
+                SuicideKings:Print( "Warning: could not find main for " .. altName )
+            end
+            
+        end
+    end
+    
+    --[[
+    import lists 
+    ]]--
+        
+    SuicideKings:Print( "Importing KonferSK lists..." )
+    self.db.profile.lists = {}
+    
+    -- get lists
+    for _,v in pairs( ksk.sortedlists ) do
+    
+        -- generate unique key
+        local uid = SuicideKings:UID( self.db.profile.lists )
+    
+        -- ksk data
+        local listName = ksk.lists[v.id].name
+        local listUsers = ksk.lists[v.id].users
+        
+        -- associate with main character key
+        self.db.profile.lists[uid] = {};
+        self.db.profile.lists[uid]["name"] = listName;
+        
+        -- get user ids
+        self.db.profile.lists[uid]["users"] = {}
+        for _,vv in pairs( listUsers ) do
+            local userName = ksk.users[vv].name;
+            local userId = SuicideKings:GetUIDFromName( userName )
+            table.insert( self.db.profile.lists[uid]["users"], userId )
+        end
+        
+        SuicideKings:Print( "Imported list: " .. listName )
+    
+    end
+    
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Roster.lua	Thu Feb 23 00:34:43 2012 -0500
@@ -0,0 +1,6 @@
+--[[ 
+Title: Suicide Kings
+Author: Brom
+Version: 0.1
+]]
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SuicideKings.lua	Thu Feb 23 00:34:43 2012 -0500
@@ -0,0 +1,128 @@
+--[[ 
+Title: Suicide Kings
+Author: Brom
+Version: 0.1
+]]
+
+local ADDON_NAME = ...
+local ADDON_VERSION = "0.1"
+
+-- create addon
+SuicideKings = LibStub("AceAddon-3.0") : NewAddon("SuicideKings", "AceConsole-3.0")
+
+-- library objects
+local libS = LibStub:GetLibrary("AceSerializer-3.0")
+local libC = LibStub:GetLibrary("LibCompress")
+local libCE = libC:GetAddonEncodeTable()
+
+-- creating a database object
+local db; 
+
+--[[
+Ace3 Addon Object
+]]
+
+function SuicideKings:OnInitialize()
+
+	-- Greetings
+	local loadingMessage = "version " .. ADDON_VERSION .. " loaded"
+	local optionsMessage = "type /sk for options"
+	SuicideKings:Print( loadingMessage )
+	SuicideKings:Print( optionsMessage )
+	
+	-- Slash commands
+	SuicideKings:RegisterChatCommand( "sk", "SlashProcessor" )
+	
+	-- Database defaults
+	self.db = LibStub("AceDB-3.0"):New("SuicideKingsDB", { profile = {} }, 'Default')
+		
+	-- Options
+	LibStub("AceConfig-3.0"): RegisterOptionsTable("SuicideKingsOptions", {
+		name = "Brohm's Suicide Kings Configuration",
+		type = "group",
+		args = {
+			roster = {
+				name = "View Roster",
+				desc = "Prints the SK Roster",
+				type = "execute",
+				func = function() SuicideKings:PrintRoster() end,
+			},
+			list = {
+				name = "View Lists",
+				desc = "Prints the SK Lists",
+				type = "execute",
+				func = function() SuicideKings:PrintLists() end,
+			},
+			
+			utilities = {
+				name = "utilities",
+				desc = "Utility functions",
+				type = "group",
+				args =	{			
+					import = {
+						name = "Import from KSK",
+						desc = "Import data from Konfer Suicide Kings",
+						type = "execute",
+						func = function() SuicideKings:ImportFromKSK() end,				
+					},
+					reset = {
+						name = "Reset Everything",
+						desc = "Resets the database",
+						type = "execute",
+						func = function() self.db:ResetProfile() end,
+					},
+				}		
+			}
+		}
+	})
+
+end
+
+function SuicideKings:OnEnable()
+  -- Do more initialization here, that really enables the use of your addon.
+  -- Register Events, Hook functions, Create Frames, Get information from 
+  -- the game that wasn't available in OnInitialize
+end
+
+function SuicideKings:OnDisable()
+  -- Unhook, Unregister Events, Hide frames that you created.
+  -- You would probably only use an OnDisable if you want to 
+  -- build a "standby" mode, or be able to toggle modules on/off.
+end
+
+--[[
+Slash Handler
+]]
+
+function SuicideKings:SlashProcessor(input)
+	
+	if not input or input:trim() == "" then
+		LibStub("AceConfigDialog-3.0"):Open("SuicideKingsOptions")
+	else
+		LibStub("AceConfigCmd-3.0").HandleCommand(MyAddon, "sk", "SuicideKingsOptions", input)
+	end
+
+end
+
+--[[
+Roster Functions
+]]
+
+function SuicideKings:PrintHelp()
+
+	SuicideKings:Print("usage: /sk")
+	
+end
+
+function SuicideKings:PrintRoster()
+
+	local one = libS:Serialize( self.db.profile.roster )
+	local two = LibSyncC:CompressHuffman(one)
+	local final = LibSyncCE:Encode(two)
+
+end
+
+function SuicideKings:PrintLists()
+
+end
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SuicideKings.toc	Thu Feb 23 00:34:43 2012 -0500
@@ -0,0 +1,21 @@
+## Interface: 40300
+## Title: Suicide Kings
+## Notes: Yet another suicide kings addon
+## Author: Brom
+## Version: 0.1
+## SavedVariables: SuicideKingsDB
+
+#@no-lib-strip@
+Libs\LibStub\LibStub.lua
+Libs\AceAddon-3.0\AceAddon-3.0.xml
+Libs\AceGUI-3.0\AceGUI-3.0.xml
+Libs\AceConfig-3.0\AceConfig-3.0.xml
+Libs\AceConsole-3.0\AceConsole-3.0.xml
+Libs\AceDB-3.0\AceDB-3.0.xml
+Libs\AceSerializer-3.0\AceSerializer-3.0.xml
+Libs\LibCompress\lib.xml
+#@end-no-lib-strip@
+
+SuicideKings.lua
+Import.lua
+Utility.lua
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Utility.lua	Thu Feb 23 00:34:43 2012 -0500
@@ -0,0 +1,48 @@
+--[[ 
+Title: Suicide Kings
+Author: Brom
+Version: 0.1
+]]
+
+local function RandomCharacter()
+    
+    -- 0-9, A-Z, a-z = 10 + 26 + 16
+    local i = math.random(0,61)
+    
+    -- strip offset and ascii jump
+    if ( i >= 36 ) then
+        -- a:z
+        i = ( i - 36 ) + 97
+    elseif ( i >= 10 ) then
+        -- A:Z
+        i = ( i - 10 ) + 65
+    else
+        -- 0:9
+        i = ( i + 48 )
+    end
+    
+    return string.char( i )
+
+end
+
+function SuicideKings:UID( reserved )
+    
+    -- uid length
+    -- unique values = 62^4 = 14776336
+    local length = 4
+    
+    -- generate a random string
+    local s = RandomCharacter()
+    for i = 1, length-1 do
+        local c = RandomCharacter()
+        s = s .. c
+    end
+    
+    -- if taken, try again
+    while ( reserved[s] ~= nil ) do
+        s = SuicideKings:UID( reserved )
+    end
+    
+    return s
+    
+end
\ No newline at end of file