--[[nef_20221122 SUPPORT_extended All support functions are contained in the table game.SP. Module contains: user - returns the human player as userdata Player colored_link - can be used instead of the featured text link but will add a suitable background color. background - the table (function) used for colored_link allowing for more complex message strings. get_link_bb - can be used to find a 'hot link' in a string. Takes one argument - the string. The function returns the identified object - userdata of type Tile, Unit, or City of the first valid link bbcode in the string and the 'name' if there is one. Will return nil if this search fails. If the argument is not a string then the argument is returned unchanged. This allows the choice of providing a featured text string OR userdata using the form: object = get_link_bb(object). Module requires the FEATURED_TEXT and PARSER modules. ]] do -- SUPPORT_extended -- SUPPORT_basic local _ENV, _G, setmetatable, assert, find, game, log, type = _ENV, _G, setmetatable, assert, find, game, log, tolua.type local featured = setmetatable({},{ -- FEATURED_TEXT __index = function(t,k) local ft = assert(log.featured, 'Featured text not loaded') return assert(ft[k], 'Featured '..k..' not loaded.' ) end;}) local function link (...) link = featured.link; return link (...) end local function color(...) color = featured.color; return color(...) end _ENV = game SP = setmetatable(SP or {},{ __index = function(t,k) if k == 'user' then for player in _G.players_iterate() do if player.ai_controlled then else t[k] = function () return player end return t[k] end end end end; }) _ENV = SP background = setmetatable({Tile = "#ffffff";City = "#400040";Unit = '#404000';}, {__index = function(t,k) return "#ffffff" end; __call = function(t,v) return t[type(v)] end;}) colored_link = function (object, text) return color (link(object, text),nil,background(object)) end; -- SUPPORT_extended local bb_iterate = function(...) -- PARSER return assert(log.bb_iterate, 'Parser not loaded.')(...) end get_link_bb = function (text) if type(text) ~= "string" then return text end local WE_size = find.tile (0, 0).y local SKEW = WE_size ~= 0 local get_link = setmetatable( { tile = function (options) local x, y = options.x, options.y return find.tile( SKEW and (x-y + WE_size)//2 or x, SKEW and (x+y - WE_size) or y) end; unit = function (options); return find.unit(nil, options.id), options.name end; city = function (options); return find.city(nil, options.id), options.name end; }, {__index = function () return function () end end;}) for current, preamble, bbcode in bb_iterate(text) do if bbcode and bbcode.bb =="l" then local options = bbcode.options; local target, name = get_link[options.tgt or options.target](options) if target then return target, name end end end end end -- end SUPPORT_extended