Please note that some information on this wiki is still based on the demo version.
If you notice any errors, feel free to correct them.

Module:Abilities/Grid: Difference between revisions

From Super Fantasy Kingdom Official Wiki
wgg>Cadaei
all fix
wgg>Cadaei
border for center square
Line 12: Line 12:
     local centerIndex = math.floor(columns * rows / 2) + 1
     local centerIndex = math.floor(columns * rows / 2) + 1
      
      
     local classes = {
     local classDefinitions = {
     ['center'] = ' class="influence-center"',
     ['center'] = 'influence-center',
     [1] = ' class="influence-blue"',
     ['1'] = 'influence-blue',
     ['all'] = ' class="influence-red"'
     ['all'] = 'influence-red'
     }
     }
      
      
Line 24: Line 24:
     for y=1, rows do
     for y=1, rows do
     index = index + 1
     index = index + 1
     local class = ''
     local classes = {}
    local customClasses = false
     if index == centerIndex then
     if index == centerIndex then
     class = classes['center']
     table.insert(classes, classes['center'])
    customClasses = true
     end
     end
if args['all'] == '1' then
if args['all'] == '1' then
     class = classes['all']
     table.insert(classes, classes['all'])
    customClasses = true
     end
     end
if args[index] == '1' then
if args[index] == '1' then
     class = classes[1]
     table.insert(classes, classes['1'])
    end
    customClasses = true
table.insert(fieldsResult, '<td'..class..'></td>')
end
local classStyling = ''
if customClasses then
classStyling = ' class="'..table.concat(customClasses, ' ')..'"'
end
table.insert(fieldsResult, '<td'..classStyling..'></td>')
     end
     end
     table.insert(rowsResult, '<tr>'..table.concat(fieldsResult)..'</tr>')
     table.insert(rowsResult, '<tr>'..table.concat(fieldsResult)..'</tr>')
     end
     end
     return '<table class="influence-table">'..table.concat(rowsResult)..'</table>'
     return '<table class="influence-table" title="The center square represents the hero, colored squares represent heroes affected by the effect.">'..table.concat(rowsResult)..'</table>'
end
end


return p
return p

Revision as of 11:11, 18 November 2023

Creates a grid where some cells can be highlighted. The center is always white unless highlighted by another color.

This module is used by Module:Abilities.

Arguments

  • mark: all or comma separated list of indices to highlight, e.g. 7,8,9.
  • markSource: comma separated list of indices to highlight as effect source, e.g. 7,8,9.

Indices

1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25

Examples

mark = 7,8,9,12,14 Script error: The function "gridInvoke" does not exist. mark = 7,8,9,12,14 | markSource=18 Script error: The function "gridInvoke" does not exist. mark = all Script error: The function "gridInvoke" does not exist.


local p = {}

function p.grid(f)
	return p.create(f:getParent().args)
end
		             
function p.create(args)
    local columns = args.columns or 5
    local rows = args.rows or 5
    
    -- indexing fields: starting top left with 1, counting up row by row
    local centerIndex = math.floor(columns * rows / 2) + 1
    
    local classDefinitions = {
    	['center'] = 'influence-center',
    	['1'] = 'influence-blue',
    	['all'] = 'influence-red'
    	}
    
    local rowsResult = {}
    local index = 0
    for x=1, columns do
    	local fieldsResult = {}
    	for y=1, rows do
    		index = index + 1
    		local classes = {}
    		local customClasses = false
    		if index == centerIndex then
    			table.insert(classes, classes['center'])
    			customClasses = true
    		end
			if args['all'] == '1' then
    			table.insert(classes, classes['all'])
    			customClasses = true
    		end
			if args[index] == '1' then
    			table.insert(classes, classes['1'])
    			customClasses = true
			end
			local classStyling = ''
			if customClasses then
				classStyling = ' class="'..table.concat(customClasses, ' ')..'"'
			end
			
			table.insert(fieldsResult, '<td'..classStyling..'></td>')
    	end
    	table.insert(rowsResult, '<tr>'..table.concat(fieldsResult)..'</tr>')
    end
    return '<table class="influence-table" title="The center square represents the hero, colored squares represent heroes affected by the effect.">'..table.concat(rowsResult)..'</table>'
end

return p