← Back to team overview

widelands-dev team mailing list archive

Re: [Merge] lp:~widelands-dev/widelands/bug-1366725 into lp:widelands

 

Review: Needs Fixing

I think the code contains a bug. See below.

Diff comments:

> === modified file 'tribes/scripting/format_help.lua'
> --- tribes/scripting/format_help.lua	2014-07-27 12:51:29 +0000
> +++ tribes/scripting/format_help.lua	2014-09-15 10:33:45 +0000
> @@ -667,15 +667,15 @@
>  		local worker_description = building_description.working_positions[1]
>  		local becomes_description = nil
>  		local number_of_workers = 0
> -		local toolname = nil
> +		local toolnames = {}
>  
>  		for i, worker_description in ipairs(building_description.working_positions) do
>  
> -			-- get the tool for the workers. This assumes that each building only uses 1 tool
> +			-- get the tools for the workers

missing '.' at the end of the sentence.

>  			if(worker_description.buildable) then
>  				for j, buildcost in ipairs(worker_description.buildcost) do
>  					if( not (buildcost == "carrier" or buildcost == "none" or buildcost == nil)) then
> -						toolname = buildcost
> +						toolnames[#toolnames + 1] = buildcost
>  					end
>  				end
>  			end
> @@ -692,7 +692,9 @@
>  			end
>  		end
>  
> -		if(toolname) then result = result .. building_help_tool_string(tribename, toolname, number_of_workers) end
> +		if(#toolnames + 1 > 0) then

I think this is a bug. #toolnames is the number of tools. Don't you want to check for that?

> +			result = result .. building_help_tool_string(tribename, toolnames, number_of_workers)
> +		end
>  
>  		if(becomes_description) then
>  
> @@ -723,17 +725,21 @@
>  -- RST
>  -- .. function building_help_tool_string(tribename, toolname)
>  --
> ---    Displays a tool with an intro text and image
> +--    Displays tools with an intro text and images
>  --
>  --    :arg tribename: e.g. "barbarians".
> ---    :arg toolname: e.g. "felling_axe".
> ---    :arg no_of_workers: the number of workers using the tool; for plural formatting.
> ---    :returns: text_line for the tool
> +--    :arg toolnames: e.g. {"shovel", "basket"}.
> +--    :arg no_of_workers: the number of workers using the tools; for plural formatting.
> +--    :returns: text_line for the tools
>  --
> -function building_help_tool_string(tribename, toolname, no_of_workers)
> -	local ware_description = wl.Game():get_ware_description(tribename, toolname)
> -	return text_line((ngettext("Worker uses:","Workers use:", no_of_workers)),
> -		ware_description.descname, ware_description.icon_name)
> +function building_help_tool_string(tribename, toolnames, no_of_workers)
> +	local result = rt(h3(ngettext("Worker uses:","Workers use:", no_of_workers)))
> +	local game  = wl.Game();
> +	for i, toolname in ipairs(toolnames) do
> +		local ware_description = game:get_ware_description(tribename, toolname)
> +		result = result .. image_line(ware_description.icon_name, 1, p(ware_description.descname))
> +	end
> +	return result
>  end
>  
>  -- RST
> 


-- 
https://code.launchpad.net/~widelands-dev/widelands/bug-1366725/+merge/233750
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/bug-1366725.


References