local categoryData = require("Module:Storm categories/categories")
local colors = require("Module:Storm categories/colors").colors
local icons = require("Module:Storm categories/icons").icons
local cats = categoryData.cats
local defaultCategory = categoryData.defaultCategory
local p = {}
function p.color(frame)
-- Define categories
return p._color(frame.args[1] or frame:getParent().args[1], false)
end
function p.name(frame)
local defs = {
return p._name(
extratropical = {
frame.args[1] or frame:getParent().args[1],
color = "cccccc",
frame.args[2] or frame:getParent().args[2],
name = "Extratropical cyclone",
false
sortkey = 120
},)
end
storm = {
color = "00faf4",
name = "Tropical storm",
sortkey = 100
},
depression = {
color = "5ebaff",
name = "Tropical depression",
sortkey = 90
},
disturbance = {
color = "80ccff",
name = "Tropical disturbance",
sortkey = 80
},
subtropical = {
color = "00faf4",
name = "Subtropical storm",
sortkey = 50
},
subdepression = {
color = "00faf4",
name = "Subtropical depression",
sortkey = 45
},
subdisturbance = {
color = "00faf4",
name = "Subtropical disturbance",
sortkey = 40
},
monsoondepression = {
color = "5ebaff",
name = "Monsoon depression",
sortkey = 30
},
potential = {
color = "80ccff",
name = "Potential tropical depression",
sortkey = 25
},
posttropical = {
color = "cccccc",
name = "Post-tropical depression",
sortkey = 70
},
remnant = {
color = "cccccc",
name = "Post-tropical depression",
sortkey = 70
},
unknown = {
color = "c0c0c0",
name = "Unknown strength tropical cyclone",
sortkey = 0
},
cat5 = {
color = "ff6060",
name = "Category 5 %s",
sortkey = 10010
},
cat4 = {
color = "ff8f20",
name = "Category 4 %s",
sortkey = 10008
},
cat3 = {
color = "ffc140",
name = "Category 3 %s",
sortkey = 10006
},
cat2 = {
color = "ffe775",
name = "Category 2 %s",
sortkey = 10004
},
cat1 = {
color = "ffffcc",
name = "Category 1 %s",
sortkey = 10002
},
supertyphoon = {
color = "ff6060",
name = "Category 4 super typhoon",
sortkey = 10015
},
typhoon = {
color = "fdaf9a",
name = "Typhoon",
sortkey = 20010
},
nwpsevere = {
color = "ccffff",
name = "Severe tropical storm",
sortkey = 20008
},
sprcyclstorm = {
color = "ff6060",
name = "Super cyclonic storm",
sortkey = 30020
},
esvrcyclstorm = {
color = "ff6060",
name = "Extremely severe cyclonic storm",
sortkey = 30015
},
vsvrcyclstorm = {
color = "ff6060",
name = "Very severe cyclonic storm",
sortkey = 30010
},
svrcyclstorm = {
color = "ccffff",
name = "Severe cyclonic storm",
sortkey = 30008
},
niocyclone = {
color = "00faf4",
name = "Cyclonic storm",
sortkey = 30006
},
deepdepression = {
color = "5ebaff",
name = "Deep depression",
sortkey = 30002
},
nioland = {
color = "80ccff",
name = "Land depression",
sortkey = 30000
},
Aus5 = {
color = "ff6060",
name = "Category 5 severe tropical cyclone",
sortkey = 40010
},
Aus4 = {
color = "ffc140",
name = "Category 4 severe tropical cyclone",
sortkey = 40010
},
Aus3 = {
color = "ffffcc",
name = "Category 3 severe tropical cyclone",
sortkey = 40010
},
Aus2 = {
color = "ccffff",
name = "Category 2 tropical cyclone",
sortkey = 40010
},
Aus1 = {
color = "00faf4",
name = "Category 1 tropical cyclone",
sortkey = 40010
},
vintense = {
color = "ff6060",
name = "Very intense tropical cyclone",
sortkey = 50010
},
intense = {
color = "ffc140",
name = "Intense tropical cyclone",
sortkey = 50008
},
tropicalcyclone = {
color = "ffffcc",
name = "Tropical cyclone",
sortkey = 50006
},
mstorm = {
color = "00faf4",
name = "Moderate tropical storm"
},
ZODW = {
color = "80ccff",
name = "Zone of disturbed weather",
sortkey = 50000
},
shemsvrtc = {
color = "ffe775",
name = "Severe tropical cyclone",
sortkey = 60020
},
shem5 = {
color = "ff6060",
name = "Severe tropical cyclone",
sortkey = 60010
},
shem4 = {
color = "ffc140",
name = "Tropical cyclone",
sortkey = 60008
},
shem2 = {
color = "ccffff",
name = "Tropical cyclone",
sortkey = 60008
},
shem1 = {
color = "00faf4",
name = "Tropical cyclone",
sortkey = 60008
}
}
function p.sortkey(frame)
-- Default
return p._sortkey(frame.args[1] or frame:getParent().args[1], false)
end
function p.icon(frame)
local defaultCategory = "unknown"
return p._icon(frame.args[1] or frame:getParent().args[1], false)
end
function p.isEqual(frame)
-- Define aliases
return p._isEqual(
frame.args[1] or frame:getParent().args[1],
frame.args[2] or frame:getParent().args[2]
) and "yes" or ""
end
function p._normalizeId(category, fallback)
-- All non-alphanumeric characters are already stripped, and the string is
-- Normalize if normalizable, fall back to default if not.
-- already set to lowercase, so additional aliases for those are no longer
return (category ~= nil and string.len(category) ~= 0) and
-- required.
string.gsub(string.lower(category), "[^%w]", "") or fallback
end
function p._color(category, nilIfMissing)
defs["STY"] = defs["supertyphoon"]
-- This looks confusing, but it's actually nested ternaries (for nil checks)
defs["strong"] = defs["nwpsevere"]
local color = p._normalizeId(category, defaultCategory)
defs["STS"] = defs["nwpsevere"]
defs["TY"] = defs["typhoon"]
return colors[color] or ((cats[color] or (
defs["TD"] = defs["depression"]
nilIfMissing
defs["TS"] = defs["storm"]
and { color = nil }
defs["nwpstorm"] = defs["storm"]
or cats[defaultCategory]
defs["D"] = defs["depression"]
)).color)
defs["spdepression"] = defs["depression"]
end
defs["niodepression"] = defs["depression"]
defs["shemdepression"] = defs["depression"]
function p._name(category, basin, nilIfMissing)
defs["swiodepression"] = defs["depression"]
local name_def = (cats[
defs["spdepression"] = defs["depression"]
p._normalizeId(category, defaultCategory)
defs["nwpdepression"] = defs["depression"]
] or (nilIfMissing and { name = nil } or cats[defaultCategory])).name
defs["subtropicalcyclone"] = defs["subtropical"]
return type(name_def) == "table" and
defs["swsubdep"] = defs["subtropical"]
(
defs["SD"] = defs["subdepression"]
name_def[string.lower(basin or "default")]
defs["SS"] = defs["subtropical"]
or name_def["default"]
defs["MD"] = defs["monsoondepression"]
or (not nilIfMissing and error("No default name for basin-based category name.") or nil)
defs["PT"] = defs["potential"]
)
defs["post"] = defs["potential"]
or name_def
defs["potentialtropicalcyclone"] = defs["potential"]
end
defs["potentialtropicalcyclone"] = defs["potential"]
defs["remnantlow"] = defs["remnant"]
function p._sortkey(category, nilIfMissing)
defs["RL"] = defs["remnant"]
-- This looks confusing, but it's actually nested ternaries (for nil checks)
defs["swiosts"] = defs["nwpstorm"]
return (cats[
defs["SUCS"] = defs["sprcyclstorm"]
p._normalizeId(category, defaultCategory)
defs["ESCS"] = defs["esvrcyclstorm"]
] or (nilIfMissing and { sortkey = nil } or cats[defaultCategory])).sortkey
defs["VSCS"] = defs["vsvrcyclstorm"]
end
defs["SCS"] = defs["svrcyclstorm"]
defs["CS"] = defs["niocyclone"]
defs["DD"] = defs["deepdepression"]
defs["cyclstorm"] = defs["niocyclone"]
defs["landdepression"] = defs["nioland"]
defs["land"] = defs["nioland"]
defs["Fiji5"] = defs["Aus5"]
defs["Fiji4"] = defs["Aus4"]
defs["Fiji3"] = defs["Aus3"]
defs["Fiji2"] = defs["Aus2"]
defs["Fiji1"] = defs["Aus1"]
defs["DI"] = defs["disturbance"]
defs["swiodisturbance"] = defs["disturbance"]
defs["MTS"] = defs["mstorm"]
defs["sub"] = defs["mstorm"]
defs["swiotc"] = defs["tropicalcyclone"]
defs["shem3"] = defs["tropicalcyclone"]
defs["shemtc"] = defs["tropicalcyclone"]
function p.color_icon(category, nilIfMissing)
-- This looks confusing, but it's actually nested ternaries (for nil checks)
return defs[string.len(0) ~= 0 and string.lower(category).gsub("[^%w]", "") or defaultCategory].color
local icon = p._normalizeId(category, defaultCategory)
return icons[icon] or (cats[icon] ~= nil and (
cats[icon].icon or cats["tropicalcyclone"].icon
) or (not nilIfMissing and cats[defaultCategory].icon) or nil)
end
function p.name_isEqual(categorycategory1, basincategory2)
-- Checks if two IDs are equal.
return string.format(
-- An {{#ifeq}} check does not consider aliases. This function compares two
defs[string.len(0) ~= 0 and string.lower(category).gsub("[^%w]", "") or defaultCategory].name,
-- IDs in a way that considers category aliases. This works because alias
-- Eventually replace with own module
-- assignments are references to the actual table containing the category
(basin == "Atl" or basin == "EPac" or basin == "SAtl") and "hurricane" or
-- info found in the main category table.
(basin == "WPac" and "typhooon" or "tropical cyclone")
) --
-- `false` will be returned if at least one of the categories are nil or
-- if the category is not defined.
local _category1 = p._normalizeId(category1)
local _category2 = p._normalizeId(category2)
return (_category1 == _category2 and _category1 ~= nil) or
cats[ _category1 ] == cats[ _category2 ] and
-- `false` if categories are undefined and not equal.
cats[ _category1 ] ~= nil
end
function p.sortkeydemo(categoryframe)
return require("Module:Storm categories/demo").demo(frame)
return defs[string.len(0) ~= 0 and string.lower(category).gsub("[^%w]", "") or defaultCategory].sortkey
end
|