Module:TreeDetails: Difference between revisions

From Eco - English Wiki
[unchecked revision][unchecked revision]
mNo edit summary
 
m 1 revision imported
(No difference)

Revision as of 22:18, 6 December 2019

Documentation

This module provides the back end functionality of the Template:TreeDetails.

If the template is passed, this module creates a table using details from the following Modules:


local p = {}

-- Grabs args from the parent frame
-- Trims and parses the args into a table, then returns the table
function norm()
    local origArgs = mw.getCurrentFrame():getParent().args
    local args = {}
    
    for k, v in pairs( origArgs ) do
        v = mw.text.trim( tostring( v ) )
        if v ~= '' then
            args[k] = v
        end
    end
    
    return args
end

-- Main entry point for the Module
function p.main()
    -- get args from the Template
    local args = norm()
    
	if args.tree == nil or args.tree == '' then
        return '\'tree\' must be specified.'
    end
	
    -- assign variables for tree
    local tree = args.tree
   
    -- load list of recipes
    local treeData = require( "Module:TreeData" )
    local treeTable = treeData.trees[tree]
    if treeTable == nil then
		return tree .. ' could not be found in Module:TreeData.'
	end    
	
	local wikibox = '=== Tree Properties===\n'
	
	if treeTable.isDecorative == 'Decorative' then
		wikibox = wikibox .. 'This tree is decorative only. \n'
	end
	if treeTable.isWater == 'Underwater' then
		wikibox = wikibox .. 'This tree grows underwater. \n'
	end
	if treeTable.scytheKills =='Yes' then
		wikibox = wikibox .. 'Scything this tree will kill it. \n'
	end
	
	wikibox = wikibox .. '\n===Environmental Conditions===\n'	
	wikibox = wikibox .. '{| class=\"wikitable\"\n'
	
	-- Temperature row
	wikibox = wikibox .. '| rowspan="4" | Temperature Ranges \n'
	wikibox = wikibox .. '| Ideal Minimum : ' .. treeTable.idealTempMin .. '\n'
	wikibox = wikibox .. '| rowspan="2" |  Ideal Range: The tree\'s preferred temperature range.  Temperatures in this range won\'t inhibit population growth or reduce yield.\n'
	wikibox = wikibox .. '|- \n| Ideal Maximum : ' .. treeTable.idealTempMax .. '\n'
	wikibox = wikibox .. '|- \n| Extreme Minimum  : ' .. treeTable.extremeTempMin .. '\n'
	wikibox = wikibox .. '| rowspan="2" | Extreme Range : The temperature range that can support this tree (albeit at reduced efficiency if the temperature is not also within the ideal range).  Temperatures outside this range prohibit reproduction entirely and prevent any yield at all. \n'
	wikibox = wikibox .. '|- \n| Extreme Maximum : ' .. treeTable.extremeTempMax .. '\n'
	
	-- Moisture row
	wikibox = wikibox .. '|- \n| rowspan="4" | Moisture Ranges \n'
	wikibox = wikibox .. '| Ideal Minimum : ' .. treeTable.idealMoistureMin .. '\n'
	wikibox = wikibox .. '| rowspan="2" |  Ideal Range: The tree\'s preferred moisture range.  Moisture in this range won\'t inhibit population growth or reduce yield.\n'
	wikibox = wikibox .. '|- \n| Ideal Maximum : ' .. treeTable.idealMoistureMax .. '\n'
	wikibox = wikibox .. '|- \n| Extreme Minimum  : ' .. treeTable.extremeMoistureMin .. '\n'
	wikibox = wikibox .. '| rowspan="2" | Extreme Range : The moisture range that can support this tree (albeit at reduced efficiency if the moisture is not also within the ideal range).  Moisture outside this range prohibits reproduction entirely and prevent any yield at all. \n'
	wikibox = wikibox .. '|- \n| Extreme Maximum : ' .. treeTable.extremeMoistureMax .. '\n'
	
	-- Soil Restrictions
	wikibox = wikibox .. '|- \n| rowspan="4" | Soil Conditions \n'
	if treeTable.nitrogenHalfSpeed == nil then
		wikibox = wikibox .. '| Nitrogen minimum : None \n'
	else
		wikibox = wikibox .. '| Nitrogen minimum : ' .. treeTable.nitrogenHalfSpeed .. '\n'
	end
	wikibox = wikibox .. '| rowspan="4" | Any nutirent dropping below its minimum will reduce the growth of the tree to half speed\n'
	if treeTable.phosphorusHalfSpeed == nil then
		wikibox = wikibox .. '|- \n| Phosphorus minimum : None \n'
	else
		wikibox = wikibox .. '|- \n| Phosphorus minimum : ' .. treeTable.phosphorusHalfSpeed .. '\n'
	end
	if treeTable.potassiumHalfSpeed == nil then
		wikibox = wikibox .. '|- \n| Potassium minimum : None \n'
	else
		wikibox = wikibox .. '|- \n| Potassium minimum  : ' .. treeTable.potassiumHalfSpeed .. '\n'
	end
	if treeTable.soilMoistureHalfSpeed == nil then
		wikibox = wikibox .. '|- \n| Soil Moisture minimum : None \n'
	else
		wikibox = wikibox .. '|- \n| Soil Moisture minimum : ' .. treeTable.soilMoistureHalfSpeed .. '\n'
	end
	wikibox = wikibox .. '|}\n\n'
	
	wikibox = wikibox .. '===Tree Harvest===\n'
	wikibox = wikibox .. '{| class=\"wikitable\"\n'
	
	-- Growth Details
	wikibox = wikibox .. '|- \n| rowspan="4" | Growth Stages \n'
	wikibox = wikibox .. '| Mature in ' .. treeTable.maturity .. ' days\n'
	wikibox = wikibox .. '| How many days it takes for this tree to mature \n'
	wikibox = wikibox .. '|- \n| Seeds at ' .. treeTable.seedAtGrowth .. '% growth\n'
	wikibox = wikibox .. '| The growth required for seeds \n'
	wikibox = wikibox .. '|- \n| Bonus seeds at ' .. treeTable.seedBonusGrowth .. '% growth\n'
	wikibox = wikibox .. '| The growth required for bonus seeds \n'
	if treeTable.killOnHarvest == 'Yes' then
		wikibox = wikibox .. '|- \n| Harvesting Kills \n'
		wikibox = wikibox .. '| This tree must be planted from seeds after harvesting \n'
	else
		wikibox = wikibox .. '|- \n| Returns to ' .. treeTable.postHarvestGrowth .. '% growth\n'
		wikibox = wikibox .. '| This tree will return to an immature state on harvesting \n'
	end
	
	-- Resource Yields (Seed)

	wikibox = wikibox .. '|- \n| rowspan="4" | Resource Yield \n'	

	wikibox = wikibox .. '| Seed drop chance : ' .. treeTable.seedDropChance .. '% \n'	
	wikibox = wikibox .. '| The chance this tree will drop seeds upon harvesting the leaves \n'
	wikibox = wikibox .. '|- \n| Minimum Item Yield : ' .. treeTable.resourceMin .. '\n'
	wikibox = wikibox .. '| The minimum item yield from harvesting this tree at maturity \n'
	wikibox = wikibox .. '|- \n| Maximum Item Yield : ' .. treeTable.resourceMax .. '\n'
	wikibox = wikibox .. '| The maximum item yield from harvesting this tree at maturity \n'
	wikibox = wikibox .. '|- \n| Yield Bonus : ' .. treeTable.resourceBonus .. '% growth\n'
	wikibox = wikibox .. '| The growth at which you get a Resource bonus from the minimum \n'
	wikibox = wikibox .. '|}\n\n'
	
	wikibox = wikibox .. '===Environmental Effects===\n'
	wikibox = wikibox .. '{| class=\"wikitable\"\n'
	
	-- Soil Effects
	wikibox = wikibox .. '| rowspan="4" | Nutrients Depleted \n'
	if treeTable.nitrogenContent == nil then
		wikibox = wikibox .. '| Nitrogen absorbed : None \n'
	else
		wikibox = wikibox .. '| Nitrogen absorbed : ' .. treeTable.nitrogenContent .. '\n'
	end
	wikibox = wikibox .. '| rowspan="4" | The amount of nutrients an adult tree absorbs from the soil\n'
	if treeTable.phosphorusContent == nil then
		wikibox = wikibox .. '|- \n| Phosphorus absorbed : None \n'
	else
		wikibox = wikibox .. '|- \n| Phosphorus absorbed : ' .. treeTable.phosphorusContent .. '\n'
	end
	if treeTable.potassiumContent == nil then
		wikibox = wikibox .. '|- \n| Potassium absorbed : None \n'
	else
		wikibox = wikibox .. '|- \n| Potassium absorbed  : ' .. treeTable.potassiumContent .. '\n'
	end
	if treeTable.soilMoistureContent == nil then
		wikibox = wikibox .. '|- \n| Soil Moisture absorbed : None \n'
	else
		wikibox = wikibox .. '|- \n| Soil Moisture absorbed : ' .. treeTable.soilMoistureContent .. '\n'
	end
	
	-- Overcrowding Effects
	wikibox = wikibox .. '|- \n| rowspan="4" | Space Required \n'
	if treeTable.consumedFertileGround == nil then
		wikibox = wikibox .. '| Fertile ground occupied : None \n'
	else
		wikibox = wikibox .. '| Fertile ground occupied : ' .. treeTable.consumedFertileGround .. '\n'
	end
	wikibox = wikibox .. '| rowspan="4" | The amount of each space occupied by each tree\n'
	if treeTable.consumedUnderwaterFertileGorund == nil then
		wikibox = wikibox .. '|- \n| Underwater fertile ground occupied : None \n'
	else
		wikibox = wikibox .. '|- \n| Underwater fertile ground occupied : ' .. treeTable.consumedUnderwaterFertileGorund .. '\n'
	end
	if treeTable.consumedShrubSpace == nil then
		wikibox = wikibox .. '|- \n| Shrub space occupied : None \n'
	else
		wikibox = wikibox .. '|- \n| Shrub space occupied : ' .. treeTable.consumedShrubSpace .. '\n'
	end
	if treeTable.consumedCanopySpace == nil then
		wikibox = wikibox .. '|- \n| Canopy space occupied : None \n'
	else
		wikibox = wikibox .. '|- \n| Canopy space occupied : ' .. treeTable.consumedCanopySpace .. '\n'
	end
	wikibox = wikibox .. '|}\n\n'
	
	return wikibox
	
end

return p