Module:PlantDetails: Difference between revisions
From Eco - English Wiki
[unchecked revision] | [unchecked revision] |
No edit summary |
Remove old data and add new data |
||
Line 16: | Line 16: | ||
return args | return args | ||
end | end | ||
-- Main entry point for the Module | -- Main entry point for the Module | ||
function p.main() | function p.main() | ||
-- get args from the Template | |||
local args = norm() | local args = norm() | ||
if args.plant == nil or | -- create values outside of if statements to ensure they are available to whole function | ||
return ' | local species = '' | ||
local check = '' | |||
-- assign variables for plant or tree whatever is passed. Plant has priority so if both are passed only plant will continue. | |||
if args.plant ~= nil then | |||
species = args.plant | |||
check = 'plant' | |||
elseif args.tree ~= nil then | |||
species = args.tree | |||
check = 'tree' | |||
end | |||
-- check to see if species was actually passed in | |||
if species == '' then | |||
return 'plant or tree must be specified.' | |||
end | |||
local speciesData = {} | |||
local speciesTable = {} | |||
-- checks if plant and assigns correct modules based on check | |||
if check == 'plant' then | |||
speciesData = require( "Module:PlantData" ) | |||
speciesTable = speciesData.plants[species] | |||
else | |||
speciesData = require( "Module:TreeData" ) | |||
speciesTable = speciesData.trees[species] | |||
end | |||
-- checks if species can be found in plant data or tree data based on what was requested | |||
if speciesTable == {} then | |||
if check == 'plant' then | |||
return species .. ' could not be found in Module:PlantData.' | |||
else | |||
return species .. ' could not be found in Module:TreeData.' | |||
end | |||
end | end | ||
-- | -- From now on using speciesTable."KeyValue" will return the value from that key. for most things a check for species type is not necessary | ||
-- Build an Infobox_Plant | |||
-- string used to build the infobox | |||
local infobox = '{| class=\"infobox\"\n' | |||
-- name of the plant/tree | |||
infobox = infobox .. '|- style=\"color: white; background-color: dodgerblue; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. species .. '</big>\'\'\'\n' | |||
-- the sub heading plant or tree | |||
infobox = infobox .. '|- style=\"text-align: center; color: white; background-color: ' | |||
if check == 'plant' then | |||
infobox = infobox .. 'limegreen;\"\n| colspan=\"2\" | \'\'\'Plant\'\'\'[[Category:Plants]]\n' | |||
else | |||
infobox = infobox .. 'olive;\"\n| colspan=\"2\" | \'\'\'Tree\'\'\'[[Category:Trees]]\n' | |||
end | |||
-- Plants Image | |||
local checkImage = {'_Plant.png','_Plant.jpg','_Plant.jpeg','_Tree.png','_Tree.jpg','_Tree.jpeg'} | |||
local image = '' | |||
local speciesimagename = string.gsub(species, ' ', '') | |||
for i,v in ipairs(checkImage) do | |||
image = speciesimagename .. checkImage[i] | |||
if mw.title.makeTitle('File', image).file.exists then | |||
break | |||
end | |||
if table.getn(checkImage) == i then | |||
image = 'NoImage.png' | |||
if check == 'Plant' then | |||
image = image .. '|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. speciesimagename .. '_Plant.png|[[Category:Pages_with_missing_plant]]' | |||
end | |||
if check == 'Tree' then | |||
image = image .. '|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. speciesimagename .. '_Tree.png|[[Category:Pages_with_missing_tree]]' | |||
end | |||
end | |||
end | |||
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n' | |||
-- 'General' section header | |||
infobox = infobox .. '|- style=\"background-color: #4B9130; text-align: center;\"\n| colspan=\"2\" | \'\'\'General\'\'\'\n' | |||
if | --Harvestable plant | ||
if | |||
-- speciesTable.seedDrop ~= nil or | |||
speciesTable.resourceItem ~= nil or speciesTable.requireHarvestable ~= nil then | |||
infobox = infobox .. '|- valign=\"center\"\n| Harvestable:\n| style=\"text-align: right;\" | Yes \n' | |||
end | end | ||
if | |||
--Underwater plant | |||
if speciesTable.isWater ~= nil then | |||
infobox = infobox .. '|- valign=\"center\"\n| Underwater Plant:\n| style=\"text-align: right;\" | Yes \n' | |||
end | end | ||
if | |||
--Decorative Plant | |||
if speciesTable.isDecorative ~= nil then | |||
infobox = infobox .. '|- valign=\"center\"\n| Decorative Plant:\n| style=\"text-align: right;\" | Yes \n' | |||
end | end | ||
--Plant Height | |||
if speciesTable.height ~= nil then | |||
infobox = infobox .. '|- valign=\"center\"\n| Harvest Tool Required:\n| style=\"text-align: right;\" | ' .. height .. ' \n' | |||
-- | end | ||
-- | -- 'Agriculture' section header | ||
if | |||
-- speciesTable.seedDrop ~= nil or | |||
speciesTable.resourceItem ~= nil or speciesTable.requireHarvestable ~= nil then | |||
infobox = infobox .. '|- style=\"background-color: #4B9130; text-align: center;\"\n| colspan=\"2\" | \'\'\'Agriculture\'\'\'\n' | |||
-- Harvested Tool | |||
if speciesTable.harvestTool ~= nil then | |||
infobox = infobox .. '|- valign=\"center\"\n| Harvest Tool Required:\n| style=\"text-align: right;\" | ' .. harvestTool .. ' \n' | |||
end | |||
-- Harvested Seed | |||
-- if speciesTable.seedDrop ~= nil and speciesTable.seedMax ~= '0.0' then | |||
-- infobox = infobox .. '|- valign=\"center\"\n| Harvested Seed:\n| style=\"text-align: right;\" | ' .. speciesTable.seedDrop .. '\n' | |||
-- end | |||
-- Harvested Item | |||
if speciesTable.resourceItem ~= nil then | |||
infobox = infobox .. '|- valign=\"center\"\n| Harvested Item:\n| style=\"text-align: right;\" | ' .. speciesTable.resourceItem .. '\n' | |||
end | |||
--Plant Calorie Value | |||
if speciesTable.calorieValue ~= nil then | |||
infobox = infobox .. '|- valign=\"center\"\n| Plant Calorie Value:\n| style=\"text-align: right;\" |' .. calorieValue .. ' \n' | |||
end | |||
-- | --Experience Per Harvest | ||
if speciesTable.experiencePerHarvest ~= nil then | |||
infobox = infobox .. '|- valign=\"center\"\n| Base Experience Per Harvest:\n| style=\"text-align: right;\" |' .. experiencePerHarvest .. ' \n' | |||
end | |||
-- Ideal Growth Rate | |||
if speciesTable.idealGrowthRate ~= nil then | |||
infobox = infobox .. '|- valign=\"center\"\n| Ideal Growth Rate:\n| style=\"text-align: right;\" |' .. idealGrowthRate .. ' \n' | |||
end | |||
-- Ideal Death Rate | |||
if speciesTable.idealDeathRate ~= nil then | |||
infobox = infobox .. '|- valign=\"center\"\n| Ideal Death Rate:\n| style=\"text-align: right;\" |' .. idealDeathRate .. ' \n' | |||
end | |||
-- Ideal Temp | |||
if speciesTable.idealTempMin ~= nil then | |||
infobox = infobox .. '|- valign=\"center\"\n| Ideal Temperature Range:\n| style=\"text-align: right;\" | ' .. speciesTable.idealTempMin .. ' - ' .. speciesTable.idealTempMax .. '\n' | |||
end | |||
-- Ideal Moisture | |||
if speciesTable.idealMoistureMin ~= nil then | |||
infobox = infobox .. '|- valign=\"center\"\n| Ideal Moisture Range:\n| style=\"text-align: right;\" | ' .. speciesTable.idealMoistureMin .. ' - ' .. speciesTable.idealMoistureMax .. '\n' | |||
end | |||
-- Ground nutrients | |||
if speciesTable.nitrogenHalfSpeed ~= nil or speciesTable.phosphorusHalfSpeed ~= nil or speciesTable.potassiumHalfSpeed ~= nil or speciesTable.soilMoistureHalfSpeed ~= nil then | |||
infobox = infobox .. '|-\n| Minimum Soil Nutrients:\n| style=\"text-align: right;\" | \n' | |||
if speciesTable.nitrogenHalfSpeed ~= nil then | |||
infobox = infobox .. '|- style=\"color: red; valign: center;\"\n| Nitrogen:\n| style=\"text-align: right;\" | ' .. speciesTable.nitrogenHalfSpeed .. '\n' | |||
end | |||
if speciesTable.phosphorusHalfSpeed ~= nil then | |||
infobox = infobox .. '|- style=\"color: darkorange; valign: center;\"\n| Phosphorous:\n| style=\"text-align: right;\" | ' .. speciesTable.phosphorusHalfSpeed .. '\n' | |||
end | |||
if speciesTable.potassiumHalfSpeed ~= nil then | |||
infobox = infobox .. '|- style=\"color: gold; valign: center;\"\n| Potassium:\n| style=\"text-align: right;\" | ' .. speciesTable.potassiumHalfSpeed .. '\n' | |||
end | |||
if speciesTable.soilMoistureHalfSpeed ~= nil then | |||
infobox = infobox .. '|- style=\"color: teal; valign: center;\"\n| Soil Moisture:\n| style=\"text-align: right;\" | ' .. speciesTable.soilMoistureHalfSpeed .. '\n' | |||
end | |||
end | |||
end | end | ||
-- 'Other' section header | |||
infobox = infobox .. '|- style=\"background-color: #4B9130; text-align: center;\"\n| colspan=\"2\" | \'\'\'Polution\'\'\'\n' | |||
-- | --Carbon release | ||
if speciesTable.carbonRelease ~= nil then | |||
local absoluteCarbon = string.sub(speciesTable.carbonRelease , 2) | |||
infobox = infobox .. '|- valign=\"center\"\n| Carbon Absorbed:\n| style=\"text-align: right;\" | ' .. absoluteCarbon .. ' ppm \n' | |||
end | |||
-- | -- Max Pollution Density | ||
if speciesTable.maxPollutionDensity ~= nil then | |||
if | infobox = infobox .. '|- valign=\"center\"\n|Max Pollution Density:\n| style=\"text-align: right;\" |' .. maxPollutionDensity .. ' \n' | ||
end | end | ||
-- Pollution Tolerance | |||
if speciesTable.pollutionTolerance ~= nil then | |||
infobox = infobox .. '|- valign=\"center\"\n| Pollution Tolerance:\n| style=\"text-align: right;\" |' .. pollutionTolerance .. ' \n' | |||
end | |||
if | |||
infobox = infobox .. '|}' | |||
end | |||
return infobox | |||
end | end | ||
return p | return p |
Revision as of 19:17, 14 August 2020
Documentation
This module provides the back end functionality of the Template:PlantDetails.
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()
-- create values outside of if statements to ensure they are available to whole function
local species = ''
local check = ''
-- assign variables for plant or tree whatever is passed. Plant has priority so if both are passed only plant will continue.
if args.plant ~= nil then
species = args.plant
check = 'plant'
elseif args.tree ~= nil then
species = args.tree
check = 'tree'
end
-- check to see if species was actually passed in
if species == '' then
return 'plant or tree must be specified.'
end
local speciesData = {}
local speciesTable = {}
-- checks if plant and assigns correct modules based on check
if check == 'plant' then
speciesData = require( "Module:PlantData" )
speciesTable = speciesData.plants[species]
else
speciesData = require( "Module:TreeData" )
speciesTable = speciesData.trees[species]
end
-- checks if species can be found in plant data or tree data based on what was requested
if speciesTable == {} then
if check == 'plant' then
return species .. ' could not be found in Module:PlantData.'
else
return species .. ' could not be found in Module:TreeData.'
end
end
-- From now on using speciesTable."KeyValue" will return the value from that key. for most things a check for species type is not necessary
-- Build an Infobox_Plant
-- string used to build the infobox
local infobox = '{| class=\"infobox\"\n'
-- name of the plant/tree
infobox = infobox .. '|- style=\"color: white; background-color: dodgerblue; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. species .. '</big>\'\'\'\n'
-- the sub heading plant or tree
infobox = infobox .. '|- style=\"text-align: center; color: white; background-color: '
if check == 'plant' then
infobox = infobox .. 'limegreen;\"\n| colspan=\"2\" | \'\'\'Plant\'\'\'[[Category:Plants]]\n'
else
infobox = infobox .. 'olive;\"\n| colspan=\"2\" | \'\'\'Tree\'\'\'[[Category:Trees]]\n'
end
-- Plants Image
local checkImage = {'_Plant.png','_Plant.jpg','_Plant.jpeg','_Tree.png','_Tree.jpg','_Tree.jpeg'}
local image = ''
local speciesimagename = string.gsub(species, ' ', '')
for i,v in ipairs(checkImage) do
image = speciesimagename .. checkImage[i]
if mw.title.makeTitle('File', image).file.exists then
break
end
if table.getn(checkImage) == i then
image = 'NoImage.png'
if check == 'Plant' then
image = image .. '|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. speciesimagename .. '_Plant.png|[[Category:Pages_with_missing_plant]]'
end
if check == 'Tree' then
image = image .. '|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. speciesimagename .. '_Tree.png|[[Category:Pages_with_missing_tree]]'
end
end
end
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
-- 'General' section header
infobox = infobox .. '|- style=\"background-color: #4B9130; text-align: center;\"\n| colspan=\"2\" | \'\'\'General\'\'\'\n'
--Harvestable plant
if
-- speciesTable.seedDrop ~= nil or
speciesTable.resourceItem ~= nil or speciesTable.requireHarvestable ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Harvestable:\n| style=\"text-align: right;\" | Yes \n'
end
--Underwater plant
if speciesTable.isWater ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Underwater Plant:\n| style=\"text-align: right;\" | Yes \n'
end
--Decorative Plant
if speciesTable.isDecorative ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Decorative Plant:\n| style=\"text-align: right;\" | Yes \n'
end
--Plant Height
if speciesTable.height ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Harvest Tool Required:\n| style=\"text-align: right;\" | ' .. height .. ' \n'
end
-- 'Agriculture' section header
if
-- speciesTable.seedDrop ~= nil or
speciesTable.resourceItem ~= nil or speciesTable.requireHarvestable ~= nil then
infobox = infobox .. '|- style=\"background-color: #4B9130; text-align: center;\"\n| colspan=\"2\" | \'\'\'Agriculture\'\'\'\n'
-- Harvested Tool
if speciesTable.harvestTool ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Harvest Tool Required:\n| style=\"text-align: right;\" | ' .. harvestTool .. ' \n'
end
-- Harvested Seed
-- if speciesTable.seedDrop ~= nil and speciesTable.seedMax ~= '0.0' then
-- infobox = infobox .. '|- valign=\"center\"\n| Harvested Seed:\n| style=\"text-align: right;\" | ' .. speciesTable.seedDrop .. '\n'
-- end
-- Harvested Item
if speciesTable.resourceItem ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Harvested Item:\n| style=\"text-align: right;\" | ' .. speciesTable.resourceItem .. '\n'
end
--Plant Calorie Value
if speciesTable.calorieValue ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Plant Calorie Value:\n| style=\"text-align: right;\" |' .. calorieValue .. ' \n'
end
--Experience Per Harvest
if speciesTable.experiencePerHarvest ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Base Experience Per Harvest:\n| style=\"text-align: right;\" |' .. experiencePerHarvest .. ' \n'
end
-- Ideal Growth Rate
if speciesTable.idealGrowthRate ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Ideal Growth Rate:\n| style=\"text-align: right;\" |' .. idealGrowthRate .. ' \n'
end
-- Ideal Death Rate
if speciesTable.idealDeathRate ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Ideal Death Rate:\n| style=\"text-align: right;\" |' .. idealDeathRate .. ' \n'
end
-- Ideal Temp
if speciesTable.idealTempMin ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Ideal Temperature Range:\n| style=\"text-align: right;\" | ' .. speciesTable.idealTempMin .. ' - ' .. speciesTable.idealTempMax .. '\n'
end
-- Ideal Moisture
if speciesTable.idealMoistureMin ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Ideal Moisture Range:\n| style=\"text-align: right;\" | ' .. speciesTable.idealMoistureMin .. ' - ' .. speciesTable.idealMoistureMax .. '\n'
end
-- Ground nutrients
if speciesTable.nitrogenHalfSpeed ~= nil or speciesTable.phosphorusHalfSpeed ~= nil or speciesTable.potassiumHalfSpeed ~= nil or speciesTable.soilMoistureHalfSpeed ~= nil then
infobox = infobox .. '|-\n| Minimum Soil Nutrients:\n| style=\"text-align: right;\" | \n'
if speciesTable.nitrogenHalfSpeed ~= nil then
infobox = infobox .. '|- style=\"color: red; valign: center;\"\n| Nitrogen:\n| style=\"text-align: right;\" | ' .. speciesTable.nitrogenHalfSpeed .. '\n'
end
if speciesTable.phosphorusHalfSpeed ~= nil then
infobox = infobox .. '|- style=\"color: darkorange; valign: center;\"\n| Phosphorous:\n| style=\"text-align: right;\" | ' .. speciesTable.phosphorusHalfSpeed .. '\n'
end
if speciesTable.potassiumHalfSpeed ~= nil then
infobox = infobox .. '|- style=\"color: gold; valign: center;\"\n| Potassium:\n| style=\"text-align: right;\" | ' .. speciesTable.potassiumHalfSpeed .. '\n'
end
if speciesTable.soilMoistureHalfSpeed ~= nil then
infobox = infobox .. '|- style=\"color: teal; valign: center;\"\n| Soil Moisture:\n| style=\"text-align: right;\" | ' .. speciesTable.soilMoistureHalfSpeed .. '\n'
end
end
end
-- 'Other' section header
infobox = infobox .. '|- style=\"background-color: #4B9130; text-align: center;\"\n| colspan=\"2\" | \'\'\'Polution\'\'\'\n'
--Carbon release
if speciesTable.carbonRelease ~= nil then
local absoluteCarbon = string.sub(speciesTable.carbonRelease , 2)
infobox = infobox .. '|- valign=\"center\"\n| Carbon Absorbed:\n| style=\"text-align: right;\" | ' .. absoluteCarbon .. ' ppm \n'
end
-- Max Pollution Density
if speciesTable.maxPollutionDensity ~= nil then
infobox = infobox .. '|- valign=\"center\"\n|Max Pollution Density:\n| style=\"text-align: right;\" |' .. maxPollutionDensity .. ' \n'
end
-- Pollution Tolerance
if speciesTable.pollutionTolerance ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Pollution Tolerance:\n| style=\"text-align: right;\" |' .. pollutionTolerance .. ' \n'
end
infobox = infobox .. '|}'
return infobox
end
return p