모듈:Storm categories
이 틀은 루아를 사용합니다: |
이 틀은 {{폭풍 색}}, {{폭풍 이름}} 등등 폭풍과 관련된 틀에서 쓰이는 기본 모듈입니다. 데이터는 아래의 하부 모듈에 나눠져 있습니다.
- 모듈:Storm categories/categories - 폭풍 분류 모음
- 모듈:Storm categories/colors - 색만 있는 모음
- 모듈:Storm categories/icons - 아이콘만 있는 모음
사용법[편집]
이 모듈은 총 3가지 기능을 사용합니다. 그 작동되는 기능 함수는 p.color
, p.name
, p.sortkey
, p.icon
입니다. 그 외에도 타 모듈로 향하는 함수로 p._color
, p._name
, p._sortkey
, p._icon
가 있습니다.
색[편집]
집어넣은 코드에 맞는 폭풍 색깔 코드를 출력합니다. 16진수 숫자로 색을 출력합니다. 이 함수는 {{폭풍 색}} 문서에도 사용됩니다.
코드 | 출력 |
---|---|
<span style="padding:4px;border:1px solid black;background-color:#{{#invoke:Storm categories|color|depression}}">depression</span>
|
depression |
이름[편집]
Provides the name of the given tropical cyclone category code. A optional basin argument can be provided as the second argument in order to slightly tweak the name of the category, if the given category definition supports it. This function is available as a template at {{storm name}}.
Code | Interpreted | Output | |
---|---|---|---|
ID | Basin | ||
{{#invoke:Storm categories|name|severe}}
|
severe | (default) | Severe tropical storm |
{{#invoke:Storm categories|name|spr - cYcL -s TorM}}
|
sprcyclstorm | (default) | Super cyclonic storm |
{{#invoke:Storm categories|name|cat5}}
|
cat5 | (default) | Category 5-equivalent tropical cyclone |
{{#invoke:Storm categories|name|cat5|ATl}}
|
cat5 | ATl | Category 5 hurricane |
{{#invoke:Storm categories|name|cat5|WPac}}
|
cat5 | WPac | Category 5-equivalent super typhoon |
숏키[편집]
The sortkey is a number that aids in sorting categories. Using the sortkey, it is possible to automatically sort a table of tropical cyclones given their category code. Due to the ambiguous nature of sortkeys, tables may be sorted incorrectly if values from other basins were used. For categories that span multiple basins, however, (e.g. depression
and storm
) they are given the lowest possible sortkeys in order to achieve maximum compatibility.
This sortkey is used in {{storm sortkey}} and {{Tropical cyclone season effects (cyclone)}}, a subtemplate of {{Tropical cyclone season effects}}.
The sortkey format is as follows. Note that not all values between the given ranges were used. The arrangement of these were determined by their positions in the {{Storm colour}} template.
Basin | Sortkey range |
---|---|
Global (unused) | 90000 to 99999 |
Atl/EPac/SAtl | 80000 to 89999 |
WPac | 60000 to 69999 |
Nio | 50000 to 59999 |
Aus/Fiji | 40000 to 49999 |
SWio | 30000 to 39999 |
Historical | 20000 to 29999 |
Global | 0 to 9999 |
A demonstration of a sortable table using these sortkeys can be found below. Note that it does not use categories outside of its own basin (in this case, the Atl/EPac/SAtl basin) and the global range.
Category | Sortkey | Code |
---|---|---|
cat3 | 80,030 | {{#invoke:Storm categories|sortkey|cat3}}
|
cat1 | 80,010 | {{#invoke:Storm categories|sortkey|cat1}}
|
cat5 | 80,050 | {{#invoke:Storm categories|sortkey|cat5}}
|
cat4 | 80,040 | {{#invoke:Storm categories|sortkey|cat4}}
|
depression | 90 | {{#invoke:Storm categories|sortkey|depression}}
|
cat2 | 80,020 | {{#invoke:Storm categories|sortkey|cat2}}
|
Category | Sortkey | Code |
---|---|---|
typhoon | 60,010 | {{#invoke:Storm categories|sortkey|typhoon}}
|
potential | 25 | {{#invoke:Storm categories|sortkey|potential}}
|
cat5 | 80,050 | {{#invoke:Storm categories|sortkey|cat5}}
|
svrcyclstorm | 50,008 | {{#invoke:Storm categories|sortkey|svrcyclstorm}}
|
unknown | 0 | {{#invoke:Storm categories|sortkey|unknown}}
|
supertyphoon | 80,045 | {{#invoke:Storm categories|sortkey|supertyphoon}}
|
niodepression | 50,001 | {{#invoke:Storm categories|sortkey|niodepression}}
|
local categoryData = require("모듈:Storm categories/categories")
local colors = require("모듈:Storm categories/colors").colors
local icons = require("모듈:Storm categories/icons").icons
local cats = categoryData.cats
local defaultCategory = categoryData.defaultCategory
local p = {}
function p.color(frame)
return p._color(frame.args[1] or frame:getParent().args[1], false)
end
function p.name(frame)
return p._name(
frame.args[1] or frame:getParent().args[1],
frame.args[2] or frame:getParent().args[2],
false
)
end
function p.sortkey(frame)
return p._sortkey(frame.args[1] or frame:getParent().args[1], false)
end
function p.icon(frame)
return p._icon(frame.args[1] or frame:getParent().args[1], false)
end
function p.isEqual(frame)
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)
-- Normalize if normalizable, fall back to default if not.
return (category ~= nil and string.len(category) ~= 0) and
string.gsub(string.lower(category), "[^%w]", "") or fallback
end
function p._color(category, nilIfMissing)
-- This looks confusing, but it's actually nested ternaries (for nil checks)
local color = p._normalizeId(category, defaultCategory)
return colors[color] or ((cats[color] or (
nilIfMissing
and { color = nil }
or cats[defaultCategory]
)).color)
end
function p._name(category, basin, nilIfMissing)
local name_def = (cats[
p._normalizeId(category, defaultCategory)
] or (nilIfMissing and { name = nil } or cats[defaultCategory])).name
return type(name_def) == "table" and
(
name_def[string.lower(basin or "default")]
or name_def["default"]
or (not nilIfMissing and error("이 해역의 기본 분류 이름이 없습니다.") or nil)
)
or name_def
end
function p._sortkey(category, nilIfMissing)
-- This looks confusing, but it's actually nested ternaries (for nil checks)
return (cats[
p._normalizeId(category, defaultCategory)
] or (nilIfMissing and { sortkey = nil } or cats[defaultCategory])).sortkey
end
function p._icon(category, nilIfMissing)
-- This looks confusing, but it's actually nested ternaries (for nil checks)
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._isEqual(category1, category2)
-- Checks if two IDs are equal.
-- An {{#ifeq}} check does not consider aliases. This function compares two
-- IDs in a way that considers category aliases. This works because alias
-- assignments are references to the actual table containing the category
-- info found in the main category table.
--
-- `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.demo(frame)
return require("모듈:Storm categories/demo").demo(frame)
end
return p