View Single Post
  #13  
Unread 07-22-2011, 10:49 AM
Equendil Equendil is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Apr 2011
Posts: 52
It appears to me that it's not currently possible to achieve communication between plugins if they are in different 'apartments', in any other way than using shell commands, which I'd rather not do as a generic solution to that particular problem.

Still, I wanted to move forward with Bootstrap. As mentioned above, my primary objective with that plugin other than functionalities already existing in other plugin managers, was to offer the user a graphical user interface to interact with plugins. I've now added icons to Bootstrap's menu, which makes it fairly similar to Turbine's own panel menu, and gives me the option of turning it into an icon-only bar or something in the future.

Currently, I've assigned every existing plugin (that might have any business being in the menu) an icon, either from the plugin's resources (preferably), or in game resources that I thought appropriate. I hope the authors of those plugins will find them suitable (feel free to criticize !).

Ideally though, plugin authors themselves should be picking the icons they want used. To that end, I devised a relatively simple way for a plugin to expose a 'favourite icon', in a way that is not intrinsically bound to my own plugin (and hence can be used by others).

It's rather lightweight for plugin authors to do so, and I hope it catches (if not, oh well, I'll keep assigning icons by hand). Anyway, here goes:

Declaring a favourite icon - Favicon.lua

By adding a "Favicon.lua" file to their plugins, authors can declare an icon to be used by other plugins. Favicon.lua should be in the same folder as the 'package' (entry point of the plugin) defined in .plugin definition files.

Favicon.lua should contain a table named "Favicon". Favicon should itself have a subtable named 'Regular" (to allow for other icon states), with the following fields:
  • Resource: either an ID of an in game image resource, or the path of a JPEG or targa image relative to plugins/
  • Width: the width of the image
  • Height: the height of the image


Eg: if a plugin hiearchy looks like this :

Code:
Plugins/
	Author/
		PluginName.plugin (with <Package>Author.PluginName.Main</Package>
		PluginName/
			Resources/
				icon.tga (32x32 icon)
			Main.lua
			Favicon.lua
Favicon.lua would contain:
Code:
Favicon = {
	Regular = { Resource = "Author/PluginName/Resources/icon.tga", Width = 32, Height = 32 }
}

Retrieving a plugin's favourite icon

Because it might not be immediately obvious, below is a code snippet to extract the icon data from a plugin's Favicon.lua.

GetPluginFavicon( pluginData )

parameters
pluginData: definition table of a plugin as returned by Turbine.PluginManager.GetAvailablePlugins()

Returns
- nil if it fails
- resource, width, height if success (where resource is a resource that can be sent to Turbine.UI.Control:SetBackground() )

Note: for the sake of code safety, it is preferable to call subsequent SetBackground() on those resources in a protected call. Never vouch for external data.

Code:
function GetPluginFavicon( pluginData )
	-- extract the 'path' of the 'package' of the plugin (which is set up in the .plugin definition file)
	i, j = string.find( pluginData.Package, "[%w_%.]+%." ); -- extract "a.b.c." from "a.b.c.d"
	if i == nil then return nil; end
	local path = string.sub( package, i, j );
	
	-- import a "Favicon.lua" in the same place as the 'package' if it exists
	local success = pcall( import, path .. "Favicon" ); -- protected call to catch errors ...
	if not success then	
		return nil;	-- import will fail if the file does not exist or is malformed, time to return ...
	end

	-- Favicon.lua should now be imported, go down the namespaces where it should have been loaded
	local env = _G -- begin from the global environment
	for name in string.gfind( path, "[%w_]+" ) do -- for each 'name' in the path
		env = env[name]; -- go down one level
		if env == nil then -- this shouldn't occur, but just in case something went terribly wrong ...
			return nil;
		end
	end
	
	-- and extracts the information we need
	local icon = env.Favicon;
	if icon == nil or icon.Regular == nil then 
		return nil;
	end
	
	return icon.Regular.Resource, icon.Regular.Width, icon.Regular.Height;
end
__________________
Author of LIP, Bootstrap and Baruk

Last edited by Equendil : 07-22-2011 at 10:52 AM.
Reply With Quote