From Dark and Darker Wiki
Overview
Utility functions
Functions
insert_space_before_capitals
Adds spaces before capital letters (other than if its the first character). i.e. "ElementalBolt" -> "Elemental Bolt"
Can be invoked within wikitext, or called within another lua module. See Module:MergeSpells for an example that utilizes this module.
Parameters
- input_text - input string
Examples
{{#invoke:Utilities|insert_space_before_capitals|ElementalBolt}}
Elemental Bolt
dash_for_space
Replaces all spaces with dashes. i.e. "Physical Damage" -> "Physical Damage". Useful for turning text into something that can be used as a css class.
See Module:Enchantments for an example that utilizes this module.
Parameters
- input_text - input string
Examples
{{#invoke:Utilities|dash_for_space|Physical Damage}}
Physical-Damage1
rarity_name_to_num
Translates the rarity name to its corresponding number, where Junk has numerical equivalent of 0, up to Artifact as 8.
Used by draw_socket_cost_table() in Module:Enchantments to determine the order and css class for each rarity.
Parameters
- rarity_name - Name of the rarity: Junk, Poor, Common, Uncommon, Rare, Epic, Legend, Unique, and Artifact
Examples
{{#invoke:Utilities|rarity_name_to_num|Poor}}
1
rarity_num_to_name
Translates the rarity number to its corresponding name, where Junk has numerical equivalent of 0, up to Artifact as 8.
Parameters
- rarity_num - Number of the rarity: 0, 1, 2, 3, 4, 5, 6, 7, 8
Examples
{{#invoke:Utilities|rarity_num_to_name|1}}
Poor
local p = {}
local rarity_name_to_num_map = {
["Junk"] = 0,
["Poor"] = 1,
["Common"] = 2,
["Uncommon"] = 3,
["Rare"] = 4,
["Epic"] = 5,
["Legend"] = 6,
["Unique"] = 7
}
local rarity_num_to_name_map = {
["0"] = "Junk",
["1"] = "Poor",
["2"] = "Common",
["3"] = "Uncommon",
["4"] = "Rare",
["5"] = "Epic",
["6"] = "Legend",
["7"] = "Unique"
}
function p.insert_space_before_capitals(input_text)
if type(input_text) == "table" and input_text.args then -- if called via wikitext instead of lua
local frame = input_text
input_text = frame.args[1]
end
-- Add a space before each capital letter that is not the first character
local output_text = input_text:gsub("(%S)(%u)", "%1 %2")
return output_text
end
function p.dash_for_space(input_text)
if type(input_text) == "table" and input_text.args then -- if called via wikitext instead of lua
local frame = input_text
input_text = frame.args[1]
end
return input_text:gsub(" ", "-")
end
function p.rarity_name_to_num(rarity_name)
if type(rarity_name) == "table" and rarity_name.args then -- if called via wikitext instead of lua
local frame = rarity_name
rarity_name = frame.args[1]
end
if rarity_name == nil then return "rarity_name " .. rarity_num .. " cannot be blank" end
return rarity_name_to_num_map[rarity_name]
end
function p.rarity_num_to_name(rarity_num)
if type(rarity_num) == "table" and rarity_num.args then -- if called via wikitext instead of lua
local frame = rarity_num
rarity_num = frame.args[1]
end
if rarity_num == nil then return "rarity_num " .. rarity_num .. " cannot be blank" end
return rarity_num_to_name_map[rarity_num]
end
return p