Author: Pilus
(2011/08/09 14:02) 10 months ago
- API class and progress on ItemInfo (re #53 re #62 re #68)
1
[Open Files]
2
Active File Display Mode=3
3
Active File Index=3
Active File Index=1
4
Open File Line0=528
5
Open File Line1=21785
Open File Line1=23217
6
Open File Line2=6501
7
Open File Line3=437
Open File Line3=913
8
Open File Line4=1289
9
Open File Line5=13086
10
Open File Pos0=1170
Open File Pos0=808
11
Open File Pos1=23041
Open File Pos1=23956
12
Open File Pos2=7034
13
Open File Pos3=1125
Open File Pos3=1583
14
Open File Pos4=1714
15
Open File Pos5=13860
Open File Pos5=13889
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
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
19
Open File Window Pos3=2,3,-1,-1,-8,-30,175,175,988,570
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
21
Open File Window Pos5=0,1,-1,-1,-8,-30,125,125,938,520
22
Open File0=.\GHI\ghi_buff.lua
...
30
31
[Project Information]
32
Project Start=DB0706000300010012001D00300000004B
33
Working Time=799731
Working Time=825402
34
35
[Folders]
36
GHI=1
44
--GHI_ItemLinkHookings(self);
45
-- GHI_CommunicationHookings(self);
46
--GHI_TradeHookings(self);
47
GHI_BuffHookings(self);
--GHI_BuffHookings(self);
48
GHI_ActionbarHookings(self);
49
GHI_ChatLogHookings(self); --]]
50
284
GHI_DeleteDurationWatchlistItems()
285
--GHI_CheckUpdateWatcher();
286
287
GHI_CheckTarget()
--GHI_CheckTarget()
288
end
289
290
function GHI_EachTenSec()
class = GHClass("GHI_ActionAPI");
local api = {};
23
local itemGuid,itemSlot,itemBag,itemCreatorGuid;
local itemGuid,itemSlot,itemBag,itemCreatorGuid,playerIsCreator,playerGuid,playerName;
24
25
local expressionHandler = GHI_ExpressionHandler();
26
local buffHandler = GHI_BuffHandler();
--local buffHandler = GHI_BuffHandler();
27
local areaSound = GHI_AreaSound();
28
29
api.emote = function(text,delay) expressionHandler.DoEmote(text,delay,itemGuid,true); end
api.emote = function(text,delay,evtManualItemGuid) expressionHandler.DoEmote(text,delay,evtManualItemGuid or itemGuid,true); end
api.say = function(text,delay) expressionHandler.DoSay(text,delay,itemGuid,true); end
api.say = function(text,delay,evtManualItemGuid) expressionHandler.DoSay(text,delay,evtManualItemGuid or itemGuid,true); end
api.ApplyBuff = function(...) buffHandler.CastBuff(...); end
api.CountBuffs = function(name,unit) return buffHandler.CountBuffs(name,unit) end
api.RemoveBuff = function(name,count) return buffHandler.RemoveBuff(name,unit) end
api.RemoveAllBuffs = function() buffHandler.RemoveAllBuffs() end
api.PlaySound = function(path,delay) areaSound.PlaySound(path,0,delay); end
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;
GHI_ShowBook(click.title,click[1],edit,click.material,click.font,click.n,click.h1,click.h2)
GHI_ItemTextFrameCurrentPage:SetText("1/"..click.pages);
if click.pages == 1 then
51
GHI_ItemTextFramePrevPageButton:Hide();
52
GHI_ItemTextFrameNextPageButton:Hide();
53
else
54
GHI_ItemTextFramePrevPageButton:Show();
55
GHI_ItemTextFrameNextPageButton:Show();
56
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
70
-- alias functions
71
api.Emote = api.emote;
72
api.Say = api.say;
73
api.RemoveAllGHIBuffs = api.RemoveAllBuffs;
76
api.CountGHIBuff = api.CountBuff;
77
78
class.ApplyAPI = function(environment)
79
class.GetAPI = function()
assert(type(environment)=="table" and environment.IsClass("GHI_ScriptEnviroment"),"Useage: GHI_ActionAPI.ApplyAPI(GHI_ScriptEnviroment)");
80
return api;
for index,func in pairs(api) do
environment.SetValue(index,func);
81
82
class.SetMetaInfoForCurrentExecutedItem = function(guid,slot,bag,creatorGuid)
83
class.SetMetaInfoForCurrentExecutedItem = function(_creatorGuid,_itemGuid)
itemGuid = guid;
84
itemGuid = _itemGuid;
itemSlot = slot;
85
itemCreatorGuid = _creatorGuid;
itemBag = bag;
86
playerIsCreator = (itemCreatorGuid == playerGuid) or (itemCreatorGuid == playerName);
itemCreatorGuid = creatorGuid;
87
88
89
playerGuid = UnitGUID("player");
90
playerName = UnitName("player");
91
92
return class;
93
888
GHI_BuffUI.hooked ={};
889
890
-- standard
891
_["GHI_BuffUI"] = function(...)
_G["GHI_BuffUI"] = function(...)
892
893
local obj = {}
894
setmetatable(obj,GHI_BuffUI)
GameTooltip:AddLine(GHI_BAG_DRAG);
GameTooltip:Show();
94
self.UpdateTooltip = nil;
--self.UpdateTooltip = nil;
95
96
97
OnClick = function(b)
1980
1981
1982
1983
local importExportEnvironment = GHI_ScriptEnviroment();
local importExportEnvironment;
1984
1985
function GHI_ImportItem(code)
1986
if not(importExportEnvironment) then
1987
importExportEnvironment = GHI_ScriptEnviroment();
1988
importExportEnvironment.SetValue("GHI_MiscData",{Import = GHI_MiscData.Import});
1989
1990
1991
local s = Decrypt(code,true);
1992
local t = StringToTable(s);
1993
if not(type(t)=="table") then
1994
2043
GHI_MiscData.Import = misc.Import;
2048
2044
2049
2045
2050
2046
local f = CreateFrame("frame");
2047
f:SetScript("OnEvent",function(self,...)
end);
f:RegisterEvent("VARIABLES_LOADED");
2051
2052
131
InsertLinksInText = function(text,link)
132
133
134
135
136
function GHI_ItemInfo()
function GHI_ItemInfo(itemTable)
local class = GHClass("GHI_ItemInfo");
local guid, name, itemType, quality, white1, white2, comment, icon, useText, stackSize, version, creatorName, creatorGuid, rawData;
local guid, name, itemType, quality, white1, white2, comment, icon, useText, stackSize, version, creatorName, creatorGuid, rawData, cooldown, lastCastTime;
local GetTimeString;
InitializeItemData = function()
guid = 0;
name = '';
itemType = '';
itemType = 1;
quality = 1;
white1 = '';
white2 = '';
version = 0;
creatorName = '';
creatorGuid = '';
rawData = nil;
cooldown = 0;
lastCastTime = 0;
if type(itemTable)=="table" then
local t = itemTable;
guid = t.guid or t.ID or guid;
name = t.name or name;
itemType = t.itemType or itemType;
quality = t.quality or quality;
white1 = t.white1 or white1;
white2 = t.white2 or white2;
comment = t.comment or comment;
icon = t.icon or icon;
useText = t.rightClicktext or useText;
stackSize = t.StackSize or stackSize;
version = t.version or version;
creatorName = t.creater or t.creator or creatorName;
creatorGuid = t.creatorGuid or t.creator or creatorGuid;
cooldown = t.cooldown or (t.rightClick or {}).CD or cooldown;
class.ReturnItemData = function()
return {
guid = guid,
t.guid = guid;
name = name,
t.name = name;
itemType = itemType,
t.itemType = itemType;
quality = quality,
t.quality = quality;
white1 = white1,
t.white1 = white1;
white2 = white2,
t.white2 = white2;
comment = comment,
t.comment = comment;
icon = icon,
t.icon = icon;
useTex = useText,
t.useTex = useText;
stackSize = stackSize,
t.stackSize = stackSize;
version = version,
t.version = version;
creatorName = creatorName,
t.creatorName = creatorName;
creatorGuid = creatorGuid,
t.creatorGuid = creatorGuid;
rawData = rawData
return t;
}
class.GetTooltipLines = function()
local lines = {};
table.insert(lines,{
order = 10,
text = name,
r = ITEM_QUALITY_COLORS[quality].r,
g = ITEM_QUALITY_COLORS[quality].g,
b = ITEM_QUALITY_COLORS[quality].b,
});
order = 20,
74
text = white1,
75
r = 1,
g = 1,
b = 1,
order = 30,
text = white2,
order = 50,
text = comment,
g = 0.8196079,
b = 0,
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
105
106
107
108
109
110
111
112
local timeSinceLastCast = GetTime() - lastCastTime;
113
if (timeSinceLastCast > cooldown) then
114
115
order = 60,
116
text = string.format("%s %s",GHI_CD_LEFT,GetTimeString(cooldown - timeSinceLastCast));
117
118
119
120
121
122
123
124
order = 70,
125
text = string.format("<%s %s>",GHI_MADE_BY,creatorName);
126
127
128
129
130
tooltip:AddLine("<"..GHI_MADE_BY.." "..creater..">",color2.r,color2.g,color2.b);
return lines;
GetTimeString = function(secs)
if secs == 1 then
137
return secs.." "..GHI_SEC_S;
138
139
if secs < 60 then
140
return secs.." "..GHI_SECS_S;
141
142
local mins = floor(secs/60);
143
if mins == 1 then
144
return mins.." "..GHI_MIN_S;
145
146
if mins < 60 then
147
return mins.." "..GHI_MINS_S;
148
149
local hours = floor(mins/60);
150
if hours == 1 then
151
return hours.." "..GHI_HOUR_S;
152
153
if hours < 24 then
154
return hours.." "..GHI_HOURS_S;
155
156
local days = floor(hours/24);
157
if days == 1 then
158
return days.." "..GHI_DAY_S;
159
160
return days.." "..GHI_DAYS_S;
161
162
InitializeItemData();
163
164
165
-- All rights reservated
--===================================================
function GHI_ScriptEnviroment()
function GHI_ScriptEnviroment(ownerGuid)
local class = GHClass("GHI_ScriptEnviroment"); -- a class object
local delayedScripts = {};
local api = GHI_ActionAPI();
local currentItemGuid;
-- create special objects
local GHUIParent = CreateFrame("Frame",UIParent);
845
end,
848
846
849
847
850
environment._G = environment;
851
852
853
if type(GHI_MiscData["WhiteList"]) == "table" then
854
for _,var in pairs(GHI_MiscData["WhiteList"]) do
855
857
858
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
868
869
end,1);
870
871
class.SetCurrentItemGuid = function(_currentItemGuid)
872
currentItemGuid = _currentItemGuid;
873
874
875
class.GetCurrentItemGuid = function()
876
return currentItemGuid;
877
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
884
-- execute the code in the enviroment
885
local codeFunc,err = loadstring(code);
886
if not(codeFunc) then
887
print("Error in GHI item");
error(err);
setfenv(codeFunc, environment);
return codeFunc();
895
environment.DoScript = class.ExecuteScript;
896
class.SetValue = function(name,val)
897
GHCheck("GHI_ScriptEnviroment.SetValue",{"string","any"},{name,val});
898
local codeFunc = function() _G[name] = val end;
899
908
909
910
911
912
913
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
922
923
924
925
926
-- return;
-- end
local code = GHI_RemoveShortcuts(code);
--local code = GHI_RemoveShortcuts(code);
--isert link
local link = GHI_GenerateLink(ID);
443
--GHI_Message(a..": "..d.." = "..string.sub(code,a-1,a-1));
444
--GHR_Message("c: "..c);
445
if c == 40 and (d == 10 or d == 32) then
446
code = strsub(code,0,a-1).."GHI_DoEmote"..strsub(code,b+1);
--code = strsub(code,0,a-1).."GHI_DoEmote"..strsub(code,b+1);
447
b = b+5;
448
449
465
466
467
468
code = strsub(code,0,a-1).."GHI_DoSay"..strsub(code,b+1);
--code = strsub(code,0,a-1).."GHI_DoSay"..strsub(code,b+1);
469
--b = b+5;
470
471
472
Active File Index=3Active File Index=1Open File Line1=21785Open File Line1=23217Open File Line3=437Open File Line3=913Open File Pos0=1170Open File Pos0=808Open File Pos1=23041Open File Pos1=23956Open File Pos3=1125Open File Pos3=1583Open File Pos5=13860Open File Pos5=13889Open File Window Pos1=0,1,-1,-1,-8,-30,125,125,938,520Open File Window Pos1=2,3,-1,-1,-8,-30,125,125,938,520Open File Window Pos3=2,3,-1,-1,-8,-30,175,175,988,570Open File Window Pos3=0,1,-1,-1,-8,-30,175,175,988,570Working Time=799731Working Time=825402--GHI_BuffHookings(self);--GHI_CheckTarget()class = GHClass("GHI_ActionAPI");class = GHClass("GHI_ActionAPI");local api = {};local api = {};local itemGuid,itemSlot,itemBag,itemCreatorGuid,playerIsCreator,playerGuid,playerName;--local buffHandler = GHI_BuffHandler();api.emote = function(text,delay) expressionHandler.DoEmote(text,delay,itemGuid,true); endapi.emote = function(text,delay,evtManualItemGuid) expressionHandler.DoEmote(text,delay,evtManualItemGuid or itemGuid,true); endapi.say = function(text,delay) expressionHandler.DoSay(text,delay,itemGuid,true); endapi.say = function(text,delay,evtManualItemGuid) expressionHandler.DoSay(text,delay,evtManualItemGuid or itemGuid,true); endif itemCreatorGuid == UnitGUID("player") thenGHI_ItemTextFrameCurrentPage:SetText("1/"..click.pages);class.ApplyAPI = function(environment)class.GetAPI = function()assert(type(environment)=="table" and environment.IsClass("GHI_ScriptEnviroment"),"Useage: GHI_ActionAPI.ApplyAPI(GHI_ScriptEnviroment)");return api;for index,func in pairs(api) doenvironment.SetValue(index,func);endclass.SetMetaInfoForCurrentExecutedItem = function(guid,slot,bag,creatorGuid)class.SetMetaInfoForCurrentExecutedItem = function(_creatorGuid,_itemGuid)itemGuid = guid;itemGuid = _itemGuid;itemSlot = slot;itemCreatorGuid = _creatorGuid;itemBag = bag;playerIsCreator = (itemCreatorGuid == playerGuid) or (itemCreatorGuid == playerName);itemCreatorGuid = creatorGuid;playerGuid = UnitGUID("player");playerName = UnitName("player");return class;GHI_BuffUI.hooked ={};GHI_BuffUI.hooked ={};_G["GHI_BuffUI"] = function(...)local obj = {}local obj = {}--self.UpdateTooltip = nil;local importExportEnvironment = GHI_ScriptEnviroment();importExportEnvironment.SetValue("GHI_MiscData",{Import = GHI_MiscData.Import});local f = CreateFrame("frame");f:SetScript("OnEvent",function(self,...)importExportEnvironment.SetValue("GHI_MiscData",{Import = GHI_MiscData.Import});end);f:RegisterEvent("VARIABLES_LOADED");return class;function GHI_ItemInfo(itemTable)local class = GHClass("GHI_ItemInfo");local class = GHClass("GHI_ItemInfo");local guid, name, itemType, quality, white1, white2, comment, icon, useText, stackSize, version, creatorName, creatorGuid, rawData, cooldown, lastCastTime;local GetTimeString;itemType = '';itemType = 1;rawData = nil;cooldown = 0;lastCastTime = 0;if type(itemTable)=="table" thenlocal t = itemTable;guid = t.guid or t.ID or guid;name = t.name or name;itemType = t.itemType or itemType;quality = t.quality or quality;white1 = t.white1 or white1;white2 = t.white2 or white2;comment = t.comment or comment;icon = t.icon or icon;useText = t.rightClicktext or useText;stackSize = t.StackSize or stackSize;version = t.version or version;creatorName = t.creater or t.creator or creatorName;creatorGuid = t.creatorGuid or t.creator or creatorGuid;cooldown = t.cooldown or (t.rightClick or {}).CD or cooldown;endreturn {local t = itemTable;guid = guid,t.guid = guid;name = name,t.name = name;itemType = itemType,t.itemType = itemType;quality = quality,t.quality = quality;white1 = white1,t.white1 = white1;white2 = white2,t.white2 = white2;comment = comment,t.comment = comment;icon = icon,t.icon = icon;useTex = useText,t.useTex = useText;stackSize = stackSize,t.stackSize = stackSize;version = version,t.version = version;creatorName = creatorName,t.creatorName = creatorName;creatorGuid = creatorGuid,t.creatorGuid = creatorGuid;rawData = rawDatareturn t;}local lines = {};table.insert(lines,{table.insert(lines,{table.insert(lines,{table.insert(lines,{table.insert(lines,{table.insert(lines,{table.insert(lines,{text = string.format("%s %s",GHI_CD_LEFT,GetTimeString(cooldown - timeSinceLastCast));table.insert(lines,{text = string.format("<%s %s>",GHI_MADE_BY,creatorName);tooltip:AddLine("<"..GHI_MADE_BY.." "..creater..">",color2.r,color2.g,color2.b);function GHI_ScriptEnviroment(ownerGuid)local class = GHClass("GHI_ScriptEnviroment"); -- a class objectlocal class = GHClass("GHI_ScriptEnviroment"); -- a class objectlocal delayedScripts = {};local GHUIParent = CreateFrame("Frame",UIParent);local GHUIParent = CreateFrame("Frame",UIParent);environment._G = environment;class.ExecuteScript = function(code)GHI_Timer(function()for i,v in pairs(delayedScripts) doif type(v) == "table" and (v.time or 0) <= time() thenclass.ExecuteScript(v.code,0);delayedScripts[i] = nil;endendend,1);class.SetCurrentItemGuid = function(_currentItemGuid)currentItemGuid = _currentItemGuid;endclass.GetCurrentItemGuid = function()return currentItemGuid;endclass.ExecuteScript = function(code,delay)if type(delay) == "number" and delay > 0 thentable.insert(delayedScripts,{code = code,time= time()+delay});returnendprint("Error in GHI item");print("Error in GHI item");environment.DoScript = class.ExecuteScript;GHCheck("GHI_ScriptEnviroment.SetValue",{"string","any"},{name,val});GHCheck("GHI_ScriptEnviroment.SetValue",{"string","any"},{name,val});local result = {v(...)};--local code = GHI_RemoveShortcuts(code);--GHR_Message("c: "..c);--GHR_Message("c: "..c);--code = strsub(code,0,a-1).."GHI_DoEmote"..strsub(code,b+1);--GHR_Message("c: "..c);--GHR_Message("c: "..c);--code = strsub(code,0,a-1).."GHI_DoSay"..strsub(code,b+1);--b = b+5;