summaryrefslogtreecommitdiff
path: root/Data/BuiltIn/Libraries/lua-addons/addons/shoutHelper/shoutHelper.lua
blob: c4ccc3e89638c438deb082d65c967658da710da7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
--[[
Copyright (c) 2013, Chiara De Acetis
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
    * Neither the name of <addon name> nor the
    names of its contributors may be used to endorse or promote products
    derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <your name> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
]]


_addon.name = 'shoutHelper'
_addon.version = '0.2'
_addon.commands = {'shouthelper','sh'}
_addon.author = 'Jandel'

require 'tables'
require 'strings'
require 'logger'
--local file = require 'files'
local Blackboard = require 'blackboard'
local lavagna = nil
local config = require 'config'

-- Memo: //lua load shoutHelper

-- Constructor
windower.register_event('load',function ()
	settings = config.load({
		posx = 300,
		posy = 140,
		bgtransparency = 200,
		font = 'courier',
		fontsize = 10
	})
	lavagna = Blackboard:new(settings)
end)

-- Handle addon args
windower.register_event('addon command',function (...)
    local params = {...};
	
    if #params < 1 then
        return
    end
    if params[1] then
	if params[1]:lower() == "help" then
		--Idea of helper
	    local color = '204' -- !!there is a function in scoreboard for add_to_chat
            windower.add_to_chat(color, 'SH: ShoutHelper v' .. _addon.version .. '. Author: Jandel')
            windower.add_to_chat(color, 'SH: sh help : Shows help message')
            windower.add_to_chat(color, 'SH: sh pos <x> <y> : Positions the list')
            windower.add_to_chat(color, 'SH: sh clear [<party>]: Reset list (if no party is given, it will reset all alliance).')
            --the following two line are commented because there's no function implemented
            --windower.add_to_chat(color, 'SH: sh save <filename> : Save alliance settings. If the file already exists it will overwrite it.')
            --windower.add_to_chat(color, 'SH: sh load <filename>  : Load the <filename> alliance settings.')
            windower.add_to_chat(color, "SH: sh set <party> <job1> <job2> ... : Add a job to the party. pt1 is for first party, pt2 and pt3 for second and third party. ".."Won\'t add jobs if the party list is full")
            windower.add_to_chat(color, 'SH: sh add [<job>] <player> : assign the name of that player to the corrisponding job.')
            windower.add_to_chat(color, 'SH: sh del [<party>] <job> : deletes the job from the alliance list. Party from wich delet it is optional')
            windower.add_to_chat(color, 'SH: sh rm <player>: removes the player from the alliance list')
            windower.add_to_chat(color, 'SH: sh visible : shows/hide the current alliance list')
        elseif params[1]:lower() == "pos" then
            if params[3] then
                local posx, posy = tonumber(params[2]), tonumber(params[3])
                lavagna:set_position(posx, posy)
                --TODO check this if to save settings
                if posx ~= settings.posx or posy ~= settings.posy then
                    settings.posx = posx
                    settings.posy = posy
                    settings:save()
                end
            end
        elseif params[1]:lower() == "clear" then
            lavagna:reset(params[2])
	--elseif params[1]:lower() == "save" then
            --if --[[the filename isn't legit(emplty string too)]] --then
		--error('Invalid name')
		--return
            --end
	    -- TODO function that create&save xml
	    --log('This function needs to be implemented')
	--elseif params[1]:lower() == "load" then
            --if --[[the filename isn't legit(emplty string too)] --then
		--error('Invalid name')
		--return
            --end
	    -- TODO function that load xml
	    --log('This function needs to be implemented')
	elseif params[1]:lower() == "set" then --add jobs to party list
	    local party = params[2]
	    if not party then
		error('No input given')
		return
	    end
	    if not params[3] then
		error('no jobs given')
		return
	    end
	    local jobs = {}
	    local j = 1
	    for i=3, #params do
		jobs[j] = params[i]
		j = j + 1
	    end
	    lavagna:set(party, jobs)
	elseif params[1]:lower() == "add" then --add playername to party
	    local job = params[2]
	    if not job then
		error('No input given')
		return
	    end
	    local name = params[3]
	    if not name then
                name = job
		job = nil
	    end
	    lavagna:addPlayer(job, name)
	elseif params[1]:lower() == "del" then --delete job
	    local party = params[2]
	    if not party then
		error('No input given')
		return
	    end
	    local job = nil
	    if (party and params[3]) then
		job = params[3]
	    else
		job = party
	    end
	    lavagna:deleteJob(job, party)
	elseif params[1]:lower() == "rm" then --remove player
	    if not params[2] then
		error('Missing player name')
		return
	    end
	    lavagna:rmPlayer(params[2])
	elseif params[1]:lower() == "visible" then
	    if(lavagna.visible) then
		lavagna:hide()
	    else
		lavagna:show()
	    end
	else --I don't know if leave the error message or "do nothing" (deleting else) in case the command isn't legit
	    error('Invalid command')
	end
    end
end)



-- Destructor
windower.register_event('unload',function ()
    lavagna:destroy()
end)