Module:PlantInfoCard: Difference between revisions

From Eco - English Wiki
[unchecked revision][checked revision]
No edit summary
No edit summary
 
(15 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
local p = {}


-- Grabs args from the parent frame
local Utils = require('Module:Utils')
-- Trims and parses the args into a table, then returns the table
local IconUtils = require('Module:IconUtils')
function norm()
local InfoCardUtils = require('Module:InfoCardUtils')
    local origArgs = mw.getCurrentFrame():getParent().args
local Lang = Utils.WikiLang
    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


 
function p.main(frame)
-- Main entry point for the Module
local PageName = frame.args[1]
function p.main()
if (Lang == 'English') then PlantName = PageName else PlantName = Utils.PlantSearch(PageName) end
    -- get args from the Template
local PlantData = mw.loadData( "Module:PlantData" )
    local args = norm()
local Plant = PlantData.plants[PlantName]
   
local WikiText =''
-- 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.
WikiText = WikiText ..'__NOTOC__'
    if args.plant ~= nil then
WikiText WikiText ..'Page name get test: ' .. PageName ..'</br>'
        species = args.plant
WikiText = WikiText ..'Plant name get test: ' .. PlantName ..'</br>'
        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: #1165AF; 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 .. 'seagreen;\"\n| colspan=\"2\" | \'\'\'Plant\'\'\'[[Category:Plants]]\n'
    else
infobox = infobox .. 'olivedrab;\"\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 speciesEN = speciesTable.untranslated
local speciesimagename = string.gsub(speciesEN, ' ', '')
for i,v in ipairs(checkImage) do
WikiText =  WikiText .. '<div class="row gy-4 gx-5"><div class="col-md-6">'
image = speciesimagename .. checkImage[i]
local GalleryImagesList = PlantName .. "_Plant.jpg|" .. PlantName .."\n" .. PlantName .. "_Plant.jpg"
if mw.title.makeTitle('File', image).file.exists then
WikiText = WikiText .. frame:callParserFunction{ name = '#tag:gallery', args = { mode = 'slideshow', widths = '100%', ''.. GalleryImagesList .. '' , showthumbnails = 'true'} }
break
WikiText = WikiText .. '</div>'
end
WikiText = WikiText ..'<div class="col-md-6"><div class="card border-primary"><div class="card-body">'
if table.getn(checkImage) == i then
    WikiText =  WikiText ..'<h2 class="card-title fs-40">' .. IconUtils.main{name = Plant.Name[Lang], id = Plant.ID , size = 48, style = 1} .. '  ' .. Plant.Name[Lang] .. '</h2>'
image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile='  
--WikiText =  WikiText ..'<p class="col-lg-10 card-text">' .. Plant.Description[Lang] .. '</p>'
if check == 'Plant' then
WikiText = WikiText .. '<table class="table table-striped table-bordered w-80"><tr class="thead-dark">';
image = image .. speciesimagename .. '_Plant.png|[[Category:Pages_with_missing_plant]]'
WikiText =  WikiText .. '<th>' .. Utils.Translate("Name") .. '</th><th>' .. Utils.Translate("Value") .. '</th>'
elseif check == 'Tree' then
image = image .. speciesimagename .. '_Tree.png|[[Category:Pages_with_missing_tree]]'
end
end
end
 
 
infobox = infobox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|250x250px]]\n'
-- 'General' section header
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'General\'\'\'\n'
--Harvestable plant
WikiText = WikiText .. '</table>'
if
WikiText = WikiText ..'</div></div></div></div>'
-- speciesTable.seedDrop ~= nil or
speciesTable.resourceItem ~= nil or speciesTable.requireHarvestable ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Harvestable:\n| style=\"text-align: right; padding: 3px;\" | Yes \n'
end
--Underwater plant
if (Lang ~= 'English') then WikiText =  WikiText .. '[[en:' .. Plant.Name.English .. ']]' end
if speciesTable.isWater ~= nil then
if (Lang ~= 'Russian') then WikiText = WikiText .. '[[ru:' .. Plant.Name.Russian .. ']]' end
infobox = infobox .. '|- valign=\"center\"\n| Underwater Plant:\n| style=\"text-align: right; padding: 3px;\" | Yes \n'
if (Lang ~= 'German') then WikiText = WikiText .. '[[de:' .. Plant.Name.German .. ']]' end
end
if (Lang ~= 'French') then WikiText =  WikiText .. '[[fr:' .. Plant.Name.French .. ']]' end
--Decorative Plant
local descriptionpage = Plant.Name[Lang] .. " - it is Plant."
if speciesTable.isDecorative ~= nil then
WikiText = WikiText .. frame:callParserFunction{ name = '#description2', args = { descriptionpage }}
infobox = infobox .. '|- valign=\"center\"\n| Decorative Plant:\n| style=\"text-align: right; padding: 3px;\" | Yes \n'
WikiText WikiText .. frame:callParserFunction{ name = '#setmainimage', args = { PlantName .. "_Plant.jpg" }}
end
--Plant Height
if speciesTable.height ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Plant Height:\n| style=\"text-align: right; padding: 3px;\" | ' .. speciesTable.height .. ' m \n'
end
    -- 'Agriculture' section header
if
-- speciesTable.seedDrop ~= nil or
speciesTable.resourceItem ~= nil or speciesTable.requireHarvestable ~= nil then
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Agriculture\'\'\'\n'
-- 'Harvesting' sub section header
infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | \'\'\'Harvesting\'\'\'\n'
-- Harvested Tool
if speciesTable.harvestTool ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Harvest Tool:\n| style=\"text-align: right; padding: 3px;\" | ' .. speciesTable.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; padding: 3px;\" | ' .. speciesTable.seedDrop .. '\n'
-- end
-- Harvested Item
if speciesTable.resourceItem ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Harvested Item:\n| style=\"text-align: right; padding: 3px;\" | ' .. 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; padding: 3px;\" |' .. speciesTable.calorieValue .. ' \n'
end
--XP Per Harvest
if speciesTable.experiencePerHarvest ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Base XP Per Harvest:\n| style=\"text-align: right; padding: 3px;\" |' .. speciesTable.experiencePerHarvest .. ' \n'
end
infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | \'\'\'Ideal Conditions\'\'\'\n'
-- Ideal Growth Rate
if speciesTable.idealGrowthRate ~= nil then
speciesTable.idealGrowthRate = speciesTable.idealGrowthRate*100
infobox = infobox .. '|- valign=\"center\"\n| Ideal Growth Rate:\n| style=\"text-align: right; padding: 3px;\" |' .. speciesTable.idealGrowthRate .. ' % \n'
end
 
-- Ideal Death Rate
if speciesTable.idealDeathRate ~= nil then
speciesTable.idealDeathRate = speciesTable.idealDeathRate*100
infobox = infobox .. '|- valign=\"center\"\n| Ideal Death Rate:\n| style=\"text-align: right; padding: 3px;\" |' .. speciesTable.idealDeathRate .. ' % \n'
end
 
-- Ideal Temp
if speciesTable.idealTempMin ~= nil then
speciesTable.idealTempMin = speciesTable.idealTempMin*40
infobox = infobox .. '|- valign=\"center\"\n| Ideal Temperature Range:\n| style=\"text-align: right; padding: 3px;\" | ' .. speciesTable.idealTempMin .. ' - ' .. speciesTable.idealTempMax .. ' Celsius \n'
end
-- Ideal Moisture
if speciesTable.idealMoistureMin ~= nil then
infobox = infobox .. '|- valign=\"center\"\n| Ideal Moisture Range:\n| style=\"text-align: right; padding: 3px;\" | ' .. speciesTable.idealMoistureMin .. ' -  ' .. speciesTable.idealMoistureMax .. '\n'
end
 
-- Max Pollution Density
if speciesTable.maxPollutionDensity ~= nil then
speciesTable.maxPollutionDensity = speciesTable.maxPollutionDensity*100
infobox = infobox .. '|- valign=\"center\"\n|Max Ground Pollution:\n| style=\"text-align: right; padding: 3px;\" |' .. speciesTable.maxPollutionDensity .. ' %\n'
end
 
-- Pollution Tolerance
if speciesTable.pollutionTolerance ~= nil then
speciesTable.pollutionTolerance = speciesTable.pollutionTolerance*100
infobox = infobox .. '|- valign=\"center\"\n| Pollution Tolerance:\n| style=\"text-align: right; padding: 3px;\" |' .. speciesTable.pollutionTolerance .. ' %\n'
end
 
-- Ground nutrients
if speciesTable.nitrogenHalfSpeed ~= nil or speciesTable.phosphorusHalfSpeed ~= nil or speciesTable.potassiumHalfSpeed ~= nil or speciesTable.soilMoistureHalfSpeed ~= nil then
-- 'Minimum Soil Nutrients' Mini section header
infobox = infobox .. '|- style=\"text-align: center;\"\n| colspan=\"2\" | \'\'\'Minimum Soil Nutrients\'\'\'\n'
if speciesTable.nitrogenHalfSpeed ~= nil then
infobox = infobox .. '|- style=\"color: red; valign: center;\"\n| Nitrogen:\n| style=\"text-align: right; padding: 3px;\" | ' .. speciesTable.nitrogenHalfSpeed .. '\n'
end
if speciesTable.phosphorusHalfSpeed ~= nil then
infobox = infobox .. '|- style=\"color: darkorange; valign: center;\"\n| Phosphorous:\n| style=\"text-align: right; padding: 3px;\" | ' .. speciesTable.phosphorusHalfSpeed .. '\n'
end
if speciesTable.potassiumHalfSpeed ~= nil then
infobox = infobox .. '|- style=\"color: green; valign: center;\"\n| Potassium:\n| style=\"text-align: right; padding: 3px;\" | ' .. speciesTable.potassiumHalfSpeed .. '\n'
end
if speciesTable.soilMoistureHalfSpeed ~= nil then
speciesTable.soilMoistureHalfSpeed = speciesTable.soilMoistureHalfSpeed*100
infobox = infobox .. '|- style=\"color: dodgerblue; valign: center;\"\n| Soil Moisture:\n| style=\"text-align: right; padding: 3px;\" | ' .. speciesTable.soilMoistureHalfSpeed .. ' ppm \n'
end
end
end
-- 'Effects on Environment' section header
infobox = infobox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Effects on Environment\'\'\'\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; padding: 3px;\" | ' .. absoluteCarbon .. ' ppm \n'
    end
 
    infobox = infobox .. '|}'
    return infobox
return WikiText
end
end


return p
return p

Latest revision as of 11:39, 13 April 2026

Documentation for this module may be created at Module:PlantInfoCard/doc

local p = {}

local Utils = require('Module:Utils')
local IconUtils = require('Module:IconUtils')
local InfoCardUtils = require('Module:InfoCardUtils')
local Lang = Utils.WikiLang

function p.main(frame)
	local PageName = frame.args[1]
	if (Lang == 'English') then PlantName = PageName else PlantName = Utils.PlantSearch(PageName) end
	local PlantData = mw.loadData( "Module:PlantData" )
	local Plant = PlantData.plants[PlantName]
	local WikiText =''
	
	WikiText =  WikiText ..'__NOTOC__'
	WikiText =  WikiText ..'Page name get test: ' .. PageName ..'</br>'
	WikiText =  WikiText ..'Plant name get test: ' .. PlantName ..'</br>'
	
	WikiText =  WikiText .. '<div class="row gy-4 gx-5"><div class="col-md-6">'
	local GalleryImagesList = PlantName .. "_Plant.jpg|" .. PlantName .."\n" .. PlantName .. "_Plant.jpg"
	WikiText =  WikiText .. frame:callParserFunction{ name = '#tag:gallery', args = { mode = 'slideshow', widths = '100%', ''.. GalleryImagesList .. '' , showthumbnails = 'true'} }
	WikiText =  WikiText .. '</div>'
	WikiText =  WikiText ..'<div class="col-md-6"><div class="card border-primary"><div class="card-body">'
    WikiText =  WikiText ..'<h2 class="card-title fs-40">' .. IconUtils.main{name = Plant.Name[Lang], id = Plant.ID , size = 48, style = 1} .. '  ' .. Plant.Name[Lang] .. '</h2>'
	--WikiText =  WikiText ..'<p class="col-lg-10 card-text">' .. Plant.Description[Lang] .. '</p>'
	WikiText =  WikiText .. '<table class="table table-striped table-bordered w-80"><tr class="thead-dark">';
	WikiText =  WikiText .. '<th>' .. Utils.Translate("Name") .. '</th><th>' .. Utils.Translate("Value") .. '</th>'
	
	WikiText =  WikiText .. '</table>'
	WikiText =  WikiText ..'</div></div></div></div>'
	
	if (Lang ~= 'English') then WikiText =  WikiText .. '[[en:' .. Plant.Name.English .. ']]' end
	if (Lang ~= 'Russian') then WikiText =  WikiText .. '[[ru:' .. Plant.Name.Russian .. ']]' end
	if (Lang ~= 'German') then WikiText =  WikiText .. '[[de:' .. Plant.Name.German .. ']]' end
	if (Lang ~= 'French') then WikiText =  WikiText .. '[[fr:' .. Plant.Name.French .. ']]' end
	
	local descriptionpage = Plant.Name[Lang] .. " - it is Plant."
	WikiText =  WikiText .. frame:callParserFunction{ name = '#description2', args = { descriptionpage }}
	WikiText =  WikiText .. frame:callParserFunction{ name = '#setmainimage', args = { PlantName .. "_Plant.jpg" }}
	
	return WikiText
end

return p