import "Turbine.UI";
import "Turbine.UI.Lotro";
import "KragenPlugs.Utils";
import "KragenPlugs.KragenBars";
-- load settings file
function LoadSettings()
-- Set main version number
vars = { };
vars.vers = 3.20;
vars.player = Turbine.Gameplay.LocalPlayer.GetInstance();
vars.playerlevel = vars.player:GetLevel();
vars.effects = vars.player:GetEffects();
vars.classid = vars.player:GetClass();
vars.classattr = vars.player:GetClassAttributes();
vars.locale = Turbine.Engine.GetLocale();
limbo = Turbine.UI.Window();
limbo:SetPosition(-35, -35);
limbo:SetVisible(false);
settings = DecodeTable(Turbine.PluginData.Load( Turbine.DataScope.Character, "KragenBarsSettings" ));
-- declare settings as a table and set default opacity
if ( type( settings ) ~= "table" ) then
settings = { };
settings.opacity = 1;
settings.lockslots = false;
settings.snaptogrid = true;
if(settings.language == nil) then
if (vars.locale == "fr") then
settings.language = 2;
elseif (vars.locale == "de") then
settings.language = 3;
else
settings.language = 1;
end
end
end
-- if version is not declared then wipe settings file and set version number
-- if version <3.00 (prior versions had string version number) then add required settings
if (settings.vers == nil or type(settings.vers) == "string" or settings.vers < 3.00) then
settings = nil;
settings = { };
settings.vers = vars.vers;
settings.opacity = 1;
settings.lockslots = false;
settings.snaptogrid = true;
if(settings.language == nil) then
if (vars.locale == "fr") then
settings.language = 2;
elseif (vars.locale == "de") then
settings.language = 3;
else
settings.language = 1;
end
end
SaveSettings();
elseif (settings.vers < 3.20) then
if(settings.language == nil) then
if (vars.locale == "fr") then
settings.language = 2;
elseif (vars.locale == "de") then
settings.language = 3;
else
settings.language = 1;
end
end
end
if (vars.classid == 40) then
vars.playerclass = "Burglar";
KragenBars = BurglarBars();
elseif (vars.classid == 24) then
vars.playerclass = "Captain";
KragenBars = CaptainBars();
elseif (vars.classid == 172) then
vars.playerclass = "Champion";
KragenBars = ChampionBars();
elseif (vars.classid == 23) then
vars.playerclass = "Guardian";
KragenBars = GuardianBars();
elseif (vars.classid == 162) then
vars.playerclass = "Hunter";
KragenBars = HunterBars();
elseif (vars.classid == 185) then
vars.playerclass = "Loremaster";
KragenBars = LoreBars();
elseif (vars.classid == 31) then
vars.playerclass = "Minstrel";
KragenBars = MiniBars();
elseif (vars.classid == 193) then
vars.playerclass = "Runekeeper";
KragenBars = RuneBars();
elseif (vars.classid == 194) then
vars.playerclass = "Warden";
Turbine.Shell.WriteLine("KragenBars: Warden is not currently implemented in KragenBars. Look for this feature in a future version.");
-- KragenBars = WardenBars();
end
end
-- save to settings file
function SaveSettings()
Turbine.PluginData.Save( Turbine.DataScope.Character, "KragenBarsSettings", EncodeTable(settings) );
end
function EncodeTable(data)
if ((vars.locale == "fr" or vars.locale == "de") and data ~= nil) then
local newdata = {};
local newkey = nil;
for k,v in pairs(data) do
if (type(k) == "number") then
newkey = ("<num>%f</num>"):format(k);
else
newkey = k;
end
if (type(data[k]) == "number") then
newdata[newkey] = ("<num>%f</num>"):format(data[k]);
elseif(type(data[k]) == "table") then
newdata[newkey] = EncodeTable(data[k]);
else
newdata[newkey] = data[k];
end
end
return newdata;
else
return data;
end
end
function DecodeTable(data)
if ((vars.locale == "fr" or vars.locale == "de") and data ~= nil) then
local newdata = {};
local newkey = nil;
for k,v in pairs(data) do
if (type(k) == "string") then
local match = k:match("<num>(%d+.%d+)</num>");
if (match ~= nil) then
newkey = tonumber(match);
else
newkey = k;
end
else
newkey = k;
end
if (type(data[k]) == "string") then
local match = data[k]:match("<num>(%d+.%d+)</num>");
if (match ~= nil) then
newdata[newkey] = tonumber(match);
else
newdata[newkey] = data[k];
end
elseif(type(data[k]) == "table") then
newdata[newkey] = DecodeTable(data[k]);
else
newdata[newkey] = data[k];
end
end
return newdata;
else
return data;
end
end
-- on unload call each instances unload function to save settings
function UnloadPlugin()
KragenBars:SaveSettings();
end
function ValidatePosition(x, y, width, height)
x = math.min(math.max(x, 0), Turbine.UI.Display:GetWidth() - width);
y = math.min(math.max(y, 0), Turbine.UI.Display:GetHeight() - height);
return x, y;
end
-- setup user chat commands
KragenBarsCommand = Turbine.ShellCommand();
function KragenBarsCommand:Execute( command, arguments )
if (arguments == "setup") then
KragenBars:ShowSetup();
elseif (arguments == "refresh") then
KragenBars:Refresh();
elseif (arguments == "save") then
KragenBars:SaveSettings();
elseif (arguments == "reset") then
KragenBars:DefaultPosition();
KragenBars:DefaultSettings();
KragenBars:Refresh();
elseif (arguments == "defaultpos") then
KragenBars:DefaultPosition();
else
Turbine.Shell.WriteLine("KragenBars Help:\n - /Kragenbars setup - Opens Kragens setup window\n - /Kragenbars refresh - Refreshes Kragens bar settings (ie. after level up)\n - /Kragenbars reset - Resets settings to default\n - /Kragenbars defaultpos - Sets window positions to default");
end
end
function AddCallback(object, event, callback)
if (object[event] == nil) then
object[event] = callback;
else
if (type(object[event]) == "table") then
table.insert(object[event], callback);
else
object[event] = {object[event], callback};
end
end
end
-- inialize plugin
function init()
settings = { };
-- setup plugin unload function to save setting on unload.
pluginName="KragenBars";
window = Turbine.UI.Window();
window:SetWantsUpdates(true);
window.Update = function(sender,args)
if (Plugins[pluginName] ~= nil) then
Plugins[pluginName].Unload = function(self,sender,args)
UnloadPlugin();
end
window:SetWantsUpdates(false);
end
end
Turbine.Shell.AddCommand( "Kragenbars", KragenBarsCommand );
LoadSettings();
end
-- codeblock
init();