Changeset 343

User picture

Author: Pilus

(2011/08/09 14:02) 10 months ago

- API class and progress on ItemInfo (re #53 re #62 re #68)

Affected files

Updated GH.PILUS-LAPTOP.Christian.pui Download diff

342343
1
[Open Files]
1
[Open Files]
2
Active File Display Mode=3
2
Active File Display Mode=3
3
Active File Index=3
3
Active File Index=1
4
Open File Line0=528
4
Open File Line0=528
5
Open File Line1=21785
5
Open File Line1=23217
6
Open File Line2=6501
6
Open File Line2=6501
7
Open File Line3=437
7
Open File Line3=913
8
Open File Line4=1289
8
Open File Line4=1289
9
Open File Line5=13086
9
Open File Line5=13086
10
Open File Pos0=1170
10
Open File Pos0=808
11
Open File Pos1=23041
11
Open File Pos1=23956
12
Open File Pos2=7034
12
Open File Pos2=7034
13
Open File Pos3=1125
13
Open File Pos3=1583
14
Open File Pos4=1714
14
Open File Pos4=1714
15
Open File Pos5=13860
15
Open File Pos5=13889
16
Open File Window Pos0=0,1,-1,-1,-8,-30,100,100,913,471
16
Open File Window Pos0=0,1,-1,-1,-8,-30,100,100,913,471
17
Open File Window Pos1=0,1,-1,-1,-8,-30,125,125,938,520
17
Open File Window Pos1=2,3,-1,-1,-8,-30,125,125,938,520
18
Open File Window Pos2=0,1,-1,-1,-8,-30,150,150,963,545
18
Open File Window Pos2=0,1,-1,-1,-8,-30,150,150,963,545
19
Open File Window Pos3=2,3,-1,-1,-8,-30,175,175,988,570
19
Open File Window Pos3=0,1,-1,-1,-8,-30,175,175,988,570
20
Open File Window Pos4=0,1,-1,-1,-8,-30,0,0,813,395
20
Open File Window Pos4=0,1,-1,-1,-8,-30,0,0,813,395
21
Open File Window Pos5=0,1,-1,-1,-8,-30,125,125,938,520
21
Open File Window Pos5=0,1,-1,-1,-8,-30,125,125,938,520
22
Open File0=.\GHI\ghi_buff.lua
22
Open File0=.\GHI\ghi_buff.lua
...
...
30
30
31
[Project Information]
31
[Project Information]
32
Project Start=DB0706000300010012001D00300000004B
32
Project Start=DB0706000300010012001D00300000004B
33
Working Time=799731
33
Working Time=825402
34
34
35
[Folders]
35
[Folders]
36
GHI=1
36
GHI=1

Updated GHI/ghi.lua Download diff

342343
44
	--GHI_ItemLinkHookings(self);
44
	--GHI_ItemLinkHookings(self);
45
--	GHI_CommunicationHookings(self);
45
--	GHI_CommunicationHookings(self);
46
	--GHI_TradeHookings(self);
46
	--GHI_TradeHookings(self);
47
	GHI_BuffHookings(self);
47
	--GHI_BuffHookings(self);
48
	GHI_ActionbarHookings(self);
48
	GHI_ActionbarHookings(self);
49
	GHI_ChatLogHookings(self); --]]
49
	GHI_ChatLogHookings(self); --]]
50
	
50
	
...
...
284
	GHI_DeleteDurationWatchlistItems()
284
	GHI_DeleteDurationWatchlistItems()
285
	--GHI_CheckUpdateWatcher();
285
	--GHI_CheckUpdateWatcher();
286
	
286
	
287
	GHI_CheckTarget()
287
	--GHI_CheckTarget()
288
end
288
end
289
289
290
function GHI_EachTenSec()
290
function GHI_EachTenSec()

Updated GHI/ghi_actionAPI.lua Download diff

342343
20
	class = GHClass("GHI_ActionAPI");
20
	class = GHClass("GHI_ActionAPI");
21
	
21
	
22
	local api = {};
22
	local api = {};
23
	local itemGuid,itemSlot,itemBag,itemCreatorGuid;
23
	local itemGuid,itemSlot,itemBag,itemCreatorGuid,playerIsCreator,playerGuid,playerName;
24
	
24
	
25
	local expressionHandler = GHI_ExpressionHandler();
25
	local expressionHandler = GHI_ExpressionHandler();
26
	local buffHandler = GHI_BuffHandler();
26
	--local buffHandler = GHI_BuffHandler();
27
	local areaSound = GHI_AreaSound();
27
	local areaSound = GHI_AreaSound();
28
	
28
	
29
	api.emote = function(text,delay) expressionHandler.DoEmote(text,delay,itemGuid,true); end
29
	api.emote = function(text,delay,evtManualItemGuid) expressionHandler.DoEmote(text,delay,evtManualItemGuid or itemGuid,true); end
30
	api.say = function(text,delay) expressionHandler.DoSay(text,delay,itemGuid,true); end
30
	api.say = function(text,delay,evtManualItemGuid) expressionHandler.DoSay(text,delay,evtManualItemGuid or itemGuid,true); end
31
	api.ApplyBuff = function(...) buffHandler.CastBuff(...); end
31
	api.ApplyBuff = function(...) buffHandler.CastBuff(...); end
32
	api.CountBuffs = function(name,unit) return buffHandler.CountBuffs(name,unit) end
32
	api.CountBuffs = function(name,unit) return buffHandler.CountBuffs(name,unit) end
33
	api.RemoveBuff = function(name,count) return buffHandler.RemoveBuff(name,unit) end
33
	api.RemoveBuff = function(name,count) return buffHandler.RemoveBuff(name,unit) end
34
	api.RemoveAllBuffs = function() buffHandler.RemoveAllBuffs() end
34
	api.RemoveAllBuffs = function() buffHandler.RemoveAllBuffs() end
35
	api.PlaySound = function(path,delay) areaSound.PlaySound(path,0,delay); end
35
	api.PlaySound = function(path,delay) areaSound.PlaySound(path,0,delay); end
36
	api.PlayAreaSound = function(path,range,delay) areaSound.PlaySound(path,range,delay); end
36
	api.PlayAreaSound = function(path,range,delay) areaSound.PlaySound(path,range,delay); end
37
	
38
	-- book 
39
	api.ShowBook = function(click)
40
		local edit = 0;
41
		local _,_,_,_,_,_,_,creater = GHI_GetItemInfo(ID);
42
		if itemCreatorGuid == UnitGUID("player") then
43
			edit = 1;
44
		end
45
		
46
		
47
		GHI_ShowBook(click.title,click[1],edit,click.material,click.font,click.n,click.h1,click.h2)
48
		GHI_ItemTextFrameCurrentPage:SetText("1/"..click.pages);
49
		
50
		if click.pages == 1 then 
51
			GHI_ItemTextFramePrevPageButton:Hide();
52
			GHI_ItemTextFrameNextPageButton:Hide();
53
		else
54
			GHI_ItemTextFramePrevPageButton:Show();
55
			GHI_ItemTextFrameNextPageButton:Show();
56
		end
57
		
58
		GHI_ItemTextFrameScrollFrame:SetVerticalScroll(0);
59
		GHI_CurrentBookPage = 1;
60
		GHI_CurrentBookID = ID;
61
		GHI_CurrentBook = click;
62
		GHI_CurrentBookEdit = edit;
63
		GHI_CurrentMaterial = click.material;
64
	end;
65
	
66
	-- equip item = use EquipItemByName
67
	
68
	-- produce / consume item = requires the new structure
69
	
37
70
38
39
	-- alias functions
71
	-- alias functions
40
	api.Emote = api.emote;
72
	api.Emote = api.emote;
41
	api.Say = api.say;
73
	api.Say = api.say;
...
...
44
	api.RemoveAllGHIBuffs = api.RemoveAllBuffs;
76
	api.RemoveAllGHIBuffs = api.RemoveAllBuffs;
45
	api.CountGHIBuff = api.CountBuff;
77
	api.CountGHIBuff = api.CountBuff;
46
	
78
	
47
	class.ApplyAPI = function(environment)
79
	class.GetAPI = function()
48
		assert(type(environment)=="table" and environment.IsClass("GHI_ScriptEnviroment"),"Useage: GHI_ActionAPI.ApplyAPI(GHI_ScriptEnviroment)");
80
		return api;
49
		for index,func in pairs(api) do
50
			environment.SetValue(index,func);
51
		end
52
	end
81
	end
53
	
82
	
54
	class.SetMetaInfoForCurrentExecutedItem = function(guid,slot,bag,creatorGuid)
83
	class.SetMetaInfoForCurrentExecutedItem = function(_creatorGuid,_itemGuid)
55
		itemGuid = guid;
84
		itemGuid = _itemGuid;
56
		itemSlot = slot;
85
		itemCreatorGuid = _creatorGuid;
57
		itemBag = bag;
86
		playerIsCreator = (itemCreatorGuid == playerGuid) or (itemCreatorGuid == playerName);
58
		itemCreatorGuid = creatorGuid;
59
	end
87
	end
60
	
88
	
89
	playerGuid = UnitGUID("player");
90
	playerName = UnitName("player");
61
	
91
	
62
92
	return class;
63
end
93
end

Updated GHI/ghi_buffUI.lua Download diff

342343
888
GHI_BuffUI.hooked ={};
888
GHI_BuffUI.hooked ={};
889
889
890
-- 	standard
890
-- 	standard
891
_["GHI_BuffUI"] = function(...)
891
_G["GHI_BuffUI"] = function(...)
892
	
892
	
893
	local obj = {}          
893
	local obj = {}          
894
	setmetatable(obj,GHI_BuffUI)  
894
	setmetatable(obj,GHI_BuffUI)  

Updated GHI/ghi_buttonUI.lua Download diff

342343
91
		GameTooltip:AddLine(GHI_BAG_DRAG);
91
		GameTooltip:AddLine(GHI_BAG_DRAG);
92
		
92
		
93
		GameTooltip:Show();
93
		GameTooltip:Show();
94
		self.UpdateTooltip = nil;
94
		--self.UpdateTooltip = nil;
95
	end
95
	end
96
	
96
	
97
	OnClick = function(b)
97
	OnClick = function(b)

Updated GHI/ghi_createitem.lua Download diff

342343
1980
	
1980
	
1981
end
1981
end
1982
1982
1983
local importExportEnvironment = GHI_ScriptEnviroment();
1983
local importExportEnvironment;
1984
1984
1985
function GHI_ImportItem(code)
1985
function GHI_ImportItem(code)
1986
	if not(importExportEnvironment) then
1987
		importExportEnvironment = GHI_ScriptEnviroment();
1988
		importExportEnvironment.SetValue("GHI_MiscData",{Import = GHI_MiscData.Import});
1989
	end
1986
	
1990
	
1991
	
1987
	local s = Decrypt(code,true);
1992
	local s = Decrypt(code,true);
1988
	local t = StringToTable(s);
1993
	local t = StringToTable(s);
1989
	if not(type(t)=="table") then
1994
	if not(type(t)=="table") then
...
...
2043
	GHI_MiscData.Import = misc.Import;
2048
	GHI_MiscData.Import = misc.Import;
2044
end
2049
end
2045
2050
2046
local f = CreateFrame("frame");
2047
f:SetScript("OnEvent",function(self,...)
2048
	importExportEnvironment.SetValue("GHI_MiscData",{Import = GHI_MiscData.Import});
2049
end);
2050
f:RegisterEvent("VARIABLES_LOADED");
2051
2052

Updated GHI/ghi_expressionHandler.lua Download diff

342343
131
	InsertLinksInText = function(text,link)
131
	InsertLinksInText = function(text,link)
132
	
132
	
133
	end	
133
	end	
134
134
	
135
	return class;
135
end
136
end

Updated GHI/ghi_itemInfo.lua Download diff

342343
1
function GHI_ItemInfo()
1
function GHI_ItemInfo(itemTable)
2
	local class = GHClass("GHI_ItemInfo");
2
	local class = GHClass("GHI_ItemInfo");
3
	
3
	
4
	local guid, name, itemType, quality, white1, white2, comment, icon, useText, stackSize, version, creatorName, creatorGuid, rawData;
4
	local guid, name, itemType, quality, white1, white2, comment, icon, useText, stackSize, version, creatorName, creatorGuid, rawData, cooldown, lastCastTime;
5
	local GetTimeString;
5
	
6
	
6
	InitializeItemData = function()
7
	InitializeItemData = function()
7
		guid			= 0;
8
		guid			= 0;
8
		name			= '';
9
		name			= '';
9
		itemType 		= '';
10
		itemType 		= 1;
10
		quality 		= 1;
11
		quality 		= 1;
11
		white1 			= '';
12
		white1 			= '';
12
		white2 			= '';
13
		white2 			= '';
...
...
17
		version 		= 0;
18
		version 		= 0;
18
		creatorName		= '';
19
		creatorName		= '';
19
		creatorGuid		= '';
20
		creatorGuid		= '';
20
		rawData 		= nil;
21
		cooldown		= 0;
22
		lastCastTime	= 0;
23
		
24
		if type(itemTable)=="table" then
25
			local t = itemTable;
26
			guid = t.guid or t.ID or guid;
27
			name = t.name or name;
28
			itemType = t.itemType or itemType;
29
			quality = t.quality or quality;
30
			white1 = t.white1 or white1;
31
			white2 = t.white2 or white2;
32
			comment = t.comment or comment;
33
			icon = t.icon or icon;
34
			useText = t.rightClicktext or useText;
35
			stackSize = t.StackSize or stackSize;
36
			version = t.version or version;
37
			creatorName = t.creater or t.creator or creatorName;
38
			creatorGuid = t.creatorGuid or t.creator or creatorGuid;
39
			cooldown = t.cooldown or (t.rightClick or {}).CD or cooldown;
40
		end
21
	end;
41
	end;
22
	
42
	
23
	class.ReturnItemData = function()
43
	class.ReturnItemData = function()
24
		return {
44
		local t = itemTable;
25
			guid 		= guid,
45
		t.guid 		= guid;
26
			name 		= name,
46
		t.name 		= name;
27
			itemType 	= itemType,
47
		t.itemType 	= itemType;
28
			quality 	= quality,
48
		t.quality 	= quality;
29
			white1 	    = white1,
49
		t.white1 	    = white1;
30
			white2 	    = white2,
50
		t.white2 	    = white2;
31
			comment 	= comment,
51
		t.comment 	= comment;
32
			icon 		= icon,
52
		t.icon 		= icon;
33
			useTex 	    = useText,
53
		t.useTex 	    = useText;
34
			stackSize 	= stackSize,
54
		t.stackSize 	= stackSize;
35
			version 	= version,
55
		t.version 	= version;
36
			creatorName = creatorName,
56
		t.creatorName = creatorName;
37
			creatorGuid = creatorGuid,
57
		t.creatorGuid = creatorGuid;
38
			rawData 	= rawData
58
		return t;		
39
		}
40
	end;
59
	end;
41
	
60
	
61
	class.GetTooltipLines = function()
62
		local lines = {};
63
		
64
		table.insert(lines,{
65
			order = 10,
66
			text = name,
67
			r = ITEM_QUALITY_COLORS[quality].r,
68
			g = ITEM_QUALITY_COLORS[quality].g,
69
			b = ITEM_QUALITY_COLORS[quality].b,
70
		});
71
		
72
		table.insert(lines,{
73
			order = 20,
74
			text = white1,
75
			r = 1,
76
			g = 1,
77
			b = 1,
78
		});
79
		
80
		table.insert(lines,{
81
			order = 30,
82
			text = white2,
83
			r = 1,
84
			g = 1,
85
			b = 1,
86
		});
87
		
88
		table.insert(lines,{
89
			order = 50,
90
			text = comment,
91
			r = 1,
92
			g = 0.8196079,
93
			b = 0,
94
		});
95
		
96
		table.insert(lines,{
97
			order = 50,
98
			text = GHI_USE.." "..rightClicktext,
99
			r = ITEM_QUALITY_COLORS[2].r,
100
			g = ITEM_QUALITY_COLORS[2].g,
101
			b = ITEM_QUALITY_COLORS[2].b,
102
		});
103
		
104
		table.insert(lines,{
105
			order = 50,
106
			text = comment,
107
			r = 1,
108
			g = 0.8196079,
109
			b = 0,
110
		});
111
		
112
		local timeSinceLastCast = GetTime() - lastCastTime;
113
		if (timeSinceLastCast > cooldown) then
114
			table.insert(lines,{
115
				order = 60,
116
				text = string.format("%s %s",GHI_CD_LEFT,GetTimeString(cooldown - timeSinceLastCast));
117
				r = 1,
118
				g = 1,
119
				b = 1,
120
			});
121
		end 
122
		
123
		table.insert(lines,{
124
			order = 70,
125
			text = string.format("<%s %s>",GHI_MADE_BY,creatorName);
126
			r = ITEM_QUALITY_COLORS[2].r,
127
			g = ITEM_QUALITY_COLORS[2].g,
128
			b = ITEM_QUALITY_COLORS[2].b,
129
		});
130
		tooltip:AddLine("<"..GHI_MADE_BY.." "..creater..">",color2.r,color2.g,color2.b);
131
		
132
		return lines;
133
	end;
134
	
135
	GetTimeString = function(secs)
136
		if secs == 1 then
137
			return secs.." "..GHI_SEC_S;
138
		end
139
		if secs < 60 then
140
			 return secs.." "..GHI_SECS_S;
141
		end
142
		local mins = floor(secs/60);
143
		if mins == 1 then
144
			return mins.." "..GHI_MIN_S;
145
		end
146
		if mins < 60 then
147
			return mins.." "..GHI_MINS_S;
148
		end
149
		local hours = floor(mins/60);
150
		if  hours == 1 then
151
			return hours.." "..GHI_HOUR_S;
152
		end
153
		if hours < 24 then
154
			return hours.." "..GHI_HOURS_S;
155
		end
156
		local days = floor(hours/24);
157
		if days == 1 then
158
			return days.." "..GHI_DAY_S;
159
		end
160
		return days.." "..GHI_DAYS_S;
161
	end
162
	
42
	InitializeItemData();
163
	InitializeItemData();
43
	
164
	
44
	return class;
165
	return class;

Updated GHI/ghi_scriptEnv.lua Download diff

342343
11
--								All rights reservated
11
--								All rights reservated
12
--===================================================	
12
--===================================================	
13
13
14
function GHI_ScriptEnviroment()
14
function GHI_ScriptEnviroment(ownerGuid)
15
	local class = GHClass("GHI_ScriptEnviroment"); -- a class object
15
	local class = GHClass("GHI_ScriptEnviroment"); -- a class object
16
	local delayedScripts = {};
17
	local api = GHI_ActionAPI();
18
	local currentItemGuid;
16
	
19
	
17
	-- create special objects
20
	-- create special objects
18
	local GHUIParent = CreateFrame("Frame",UIParent);
21
	local GHUIParent = CreateFrame("Frame",UIParent);
...
...
845
		end,
848
		end,
846
        
849
        
847
	}
850
	}
848
	environment._G = environment;
851
	
852
	
849
    
853
    
850
    if type(GHI_MiscData["WhiteList"]) == "table" then
854
    if type(GHI_MiscData["WhiteList"]) == "table" then
851
       for _,var in pairs(GHI_MiscData["WhiteList"]) do
855
       for _,var in pairs(GHI_MiscData["WhiteList"]) do
...
...
853
       end
857
       end
854
    end
858
    end
855
    
859
    
856
	class.ExecuteScript = function(code) 
860
	
861
	
862
	GHI_Timer(function() 
863
		for i,v in pairs(delayedScripts) do
864
			if type(v) == "table" and (v.time or 0) <= time() then
865
				class.ExecuteScript(v.code,0);
866
				delayedScripts[i] = nil;
867
			end
868
		end
869
	end,1);
870
	
871
	class.SetCurrentItemGuid = function(_currentItemGuid)
872
		currentItemGuid = _currentItemGuid;
873
	end
874
	
875
	class.GetCurrentItemGuid = function()
876
		return currentItemGuid;
877
	end
878
	
879
	class.ExecuteScript = function(code,delay) 
880
		if type(delay) == "number" and delay > 0 then
881
			table.insert(delayedScripts,{code = code,time= time()+delay});
882
			return
883
		end
884
		
857
		-- execute the code in the enviroment
885
		-- execute the code in the enviroment
858
		local codeFunc,err = loadstring(code);
886
		local codeFunc,err = loadstring(code);
859
        if not(codeFunc) then
887
        if not(codeFunc) then
860
           print("Error in GHI item");
888
           print("Error in GHI item");
861
           error(err);
889
           error(err);
862
        end
890
        end
891
				
863
		setfenv(codeFunc, environment);
892
		setfenv(codeFunc, environment);
864
		return codeFunc();
893
		return codeFunc();
865
	end
894
	end
866
		
895
	environment.DoScript = class.ExecuteScript;
896
	
867
	class.SetValue = function(name,val) 
897
	class.SetValue = function(name,val) 
868
		GHCheck("GHI_ScriptEnviroment.SetValue",{"string","any"},{name,val});
898
		GHCheck("GHI_ScriptEnviroment.SetValue",{"string","any"},{name,val});
869
		local codeFunc = function() _G[name] = val end;
899
		local codeFunc = function() _G[name] = val end;
...
...
878
		return codeFunc();
908
		return codeFunc();
879
	end
909
	end
880
	
910
	
911
	
912
	
913
	environment._G = environment;
914
	local t = api.GetAPI();
915
	for i,v in pairs(t) do
916
		class.SetValue(i,function(...)
917
			api.SetMetaInfoForCurrentExecutedItem(ownerGuid,class.GetCurrentItemGuid());
918
			local result = {v(...)};
919
			api.SetMetaInfoForCurrentExecutedItem(nil,nil);
920
			return unpack(result);
921
		end);
922
	end
923
	
881
	return class;
924
	return class;
882
end
925
end
883
926

Updated GHI/ghi_useitem.lua Download diff

342343
104
	--		return;
104
	--		return;
105
	--	end
105
	--	end
106
		
106
		
107
		local code = GHI_RemoveShortcuts(code);
107
		--local code = GHI_RemoveShortcuts(code);
108
		
108
		
109
		--isert link
109
		--isert link
110
		local link = GHI_GenerateLink(ID);
110
		local link = GHI_GenerateLink(ID);
...
...
443
			--GHI_Message(a..": "..d.." = "..string.sub(code,a-1,a-1));
443
			--GHI_Message(a..": "..d.." = "..string.sub(code,a-1,a-1));
444
			--GHR_Message("c: "..c);
444
			--GHR_Message("c: "..c);
445
			if c == 40 and (d == 10 or d == 32) then
445
			if c == 40 and (d == 10 or d == 32) then
446
				code = strsub(code,0,a-1).."GHI_DoEmote"..strsub(code,b+1);
446
				--code = strsub(code,0,a-1).."GHI_DoEmote"..strsub(code,b+1);
447
				b = b+5;
447
				b = b+5;
448
			end
448
			end
449
		end		
449
		end		
...
...
465
			--GHI_Message(a..": "..d.." = "..string.sub(code,a-1,a-1));
465
			--GHI_Message(a..": "..d.." = "..string.sub(code,a-1,a-1));
466
			--GHR_Message("c: "..c);
466
			--GHR_Message("c: "..c);
467
			if c == 40 and (d == 10 or d == 32) then
467
			if c == 40 and (d == 10 or d == 32) then
468
				code = strsub(code,0,a-1).."GHI_DoSay"..strsub(code,b+1);
468
				--code = strsub(code,0,a-1).."GHI_DoSay"..strsub(code,b+1);
469
				b = b+5;
469
				--b = b+5;
470
			end
470
			end
471
		end		
471
		end		
472
	end	
472
	end